diff --git a/db/magicmushroom_db.txt b/db/magicmushroom_db.txt index 0be5adce100..687a5973621 100644 --- a/db/magicmushroom_db.txt +++ b/db/magicmushroom_db.txt @@ -1,4 +1,4 @@ -// Magic Mushroom DB +// Magic Mushroom Database // List of skills that are randomly used through Magic Mushroom status change. // // Structure of Database: diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 1801e375742..3ac3a26be92 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -4092,7 +4092,16 @@ This command will return the SVN revision number that the server is currently running on. if ( get_revision() >= 15000 ) - mes "Welcome rAthena!"; + mes "Welcome to rAthena!"; + +--------------------------------------- + +*get_githash() + +This command will return the Git Hash that the server is currently running on. + + set .@gitHash$,get_githash(); + mes "Welcome to rAthena! Git Hash: "+.@gitHash$; --------------------------------------- \\ diff --git a/src/map/atcommand.c b/src/map/atcommand.c index f1b3578ab5a..df56c521270 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2410,10 +2410,10 @@ ACMD_FUNC(zeny) *------------------------------------------*/ ACMD_FUNC(param) { - int i, value = 0, new_value; + uint8 i; + int value = 0; const char* param[] = { "str", "agi", "vit", "int", "dex", "luk" }; - short* status[6]; - short max_status[6]; + short new_value, *status[6], max_status[6]; //we don't use direct initialization because it isn't part of the c standard. nullpo_retr(-1, sd); @@ -2438,30 +2438,23 @@ ACMD_FUNC(param) status[4] = &sd->status.dex; status[5] = &sd->status.luk; - if( battle_config.atcommand_max_stat_bypass ){ - max_status[0] = SHRT_MAX; - max_status[1] = SHRT_MAX; - max_status[2] = SHRT_MAX; - max_status[3] = SHRT_MAX; - max_status[4] = SHRT_MAX; - max_status[5] = SHRT_MAX; - } + if( battle_config.atcommand_max_stat_bypass ) + max_status[0] = max_status[1] = max_status[2] = max_status[3] = max_status[4] = max_status[5] = SHRT_MAX; else { - max_status[0] = pc_maxparameter(sd->class_,sd->status.sex,PARAM_STR); - max_status[1] = pc_maxparameter(sd->class_,sd->status.sex,PARAM_AGI); - max_status[2] = pc_maxparameter(sd->class_,sd->status.sex,PARAM_VIT); - max_status[3] = pc_maxparameter(sd->class_,sd->status.sex,PARAM_INT); - max_status[4] = pc_maxparameter(sd->class_,sd->status.sex,PARAM_DEX); - max_status[5] = pc_maxparameter(sd->class_,sd->status.sex,PARAM_LUK); + max_status[0] = pc_maxparameter(sd,PARAM_STR); + max_status[1] = pc_maxparameter(sd,PARAM_AGI); + max_status[2] = pc_maxparameter(sd,PARAM_VIT); + max_status[3] = pc_maxparameter(sd,PARAM_INT); + max_status[4] = pc_maxparameter(sd,PARAM_DEX); + max_status[5] = pc_maxparameter(sd,PARAM_LUK); } - if(value < 0 && *status[i] <= -value) { - new_value = 1; - } else if(max_status[i] - *status[i] < value) { + if(value > 0 && *status[i] + value >= max_status[i]) new_value = max_status[i]; - } else { + else if(value < 0 && *status[i] <= -value) + new_value = 1; + else new_value = *status[i] + value; - } if (new_value != *status[i]) { *status[i] = new_value; @@ -2485,10 +2478,9 @@ ACMD_FUNC(param) *------------------------------------------*/ ACMD_FUNC(stat_all) { - int index, count, value, new_value; - short* status[PARAM_MAX]; - short max_status[PARAM_MAX]; - short values[PARAM_MAX]; + int value = 0; + uint8 count, i; + short *status[PARAM_MAX], max_status[PARAM_MAX]; //we don't use direct initialization because it isn't part of the c standard. nullpo_retr(-1, sd); @@ -2500,39 +2492,40 @@ ACMD_FUNC(stat_all) status[5] = &sd->status.luk; if (!message || !*message || sscanf(message, "%d", &value) < 1 || value == 0) { - uint8 i; - for (i = 0; i < PARAM_MAX; i++) { - values[i] = pc_maxparameter(sd->class_,sd->status.sex,(enum e_params)i); - max_status[i] = pc_maxparameter(sd->class_,sd->status.sex,(enum e_params)i); - } + max_status[0] = pc_maxparameter(sd,PARAM_STR); + max_status[1] = pc_maxparameter(sd,PARAM_AGI); + max_status[2] = pc_maxparameter(sd,PARAM_VIT); + max_status[3] = pc_maxparameter(sd,PARAM_INT); + max_status[4] = pc_maxparameter(sd,PARAM_DEX); + max_status[5] = pc_maxparameter(sd,PARAM_LUK); + value = SHRT_MAX; } else { - uint8 i; - for (i = 0; i < PARAM_MAX; i++) - values[i] = value; - - if( battle_config.atcommand_max_stat_bypass ) { - for (i = 0; i < PARAM_MAX; i++) - max_status[i] = SHRT_MAX; - } + if( battle_config.atcommand_max_stat_bypass ) + max_status[0] = max_status[1] = max_status[2] = max_status[3] = max_status[4] = max_status[5] = SHRT_MAX; else { - for (i = 0; i < PARAM_MAX; i++) - max_status[i] = pc_maxparameter(sd->class_,sd->status.sex,(enum e_params)i); + max_status[0] = pc_maxparameter(sd,PARAM_STR); + max_status[1] = pc_maxparameter(sd,PARAM_AGI); + max_status[2] = pc_maxparameter(sd,PARAM_VIT); + max_status[3] = pc_maxparameter(sd,PARAM_INT); + max_status[4] = pc_maxparameter(sd,PARAM_DEX); + max_status[5] = pc_maxparameter(sd,PARAM_LUK); } } count = 0; - for (index = 0; index < ARRAYLENGTH(status); index++) { - if (values[index] > 0 && *status[index] > max_status[index] - values[index]) - new_value = max_status[index]; - else if (values[index] < 0 && *status[index] <= -values[index]) + for (i = 0; i < ARRAYLENGTH(status); i++) { + short new_value; + if (value > 0 && *status[i] + value >= max_status[i]) + new_value = max_status[i]; + else if (value < 0 && *status[i] <= -value) new_value = 1; else - new_value = *status[index] +values[index]; + new_value = *status[i] + value; - if (new_value != (int)*status[index]) { - *status[index] = new_value; - clif_updatestatus(sd, SP_STR + index); - clif_updatestatus(sd, SP_USTR + index); + if (new_value != *status[i]) { + *status[i] = new_value; + clif_updatestatus(sd, SP_STR + i); + clif_updatestatus(sd, SP_USTR + i); count++; } } @@ -5580,7 +5573,7 @@ ACMD_FUNC(marry) return -1; } - if (pc_marriage(sd, pl_sd) == 0) { + if (pc_marriage(sd, pl_sd)) { clif_displaymessage(fd, msg_txt(sd,1173)); // They are married... wish them well. clif_wedding_effect(&pl_sd->bl); //wedding effect and music [Lupus] getring(sd); // Auto-give named rings (Aru) @@ -5600,7 +5593,7 @@ ACMD_FUNC(divorce) { nullpo_retr(-1, sd); - if (pc_divorce(sd) != 0) { + if (!pc_divorce(sd)) { sprintf(atcmd_output, msg_txt(sd,1175), sd->status.name); // '%s' is not married. clif_displaymessage(fd, atcmd_output); return -1; @@ -8955,7 +8948,7 @@ ACMD_FUNC(cart) { MC_CART_MDFY(1); } - if( pc_setcart(sd, val) ) { + if( !pc_setcart(sd, val) ) { if( need_skill ) { MC_CART_MDFY(0); } diff --git a/src/map/chrif.c b/src/map/chrif.c index af3315349f6..6439c4e8a78 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -1779,7 +1779,8 @@ int chrif_bsdata_request(int char_id) { * @param sd */ int chrif_save_bsdata(struct map_session_data *sd) { - int i, count=0; + int i; + uint8 count = 0; unsigned int tick; struct bonus_script_data bs; const struct TimerData *timer; @@ -1801,7 +1802,7 @@ int chrif_save_bsdata(struct map_session_data *sd) { pc_bonus_script_clear(sd,i); for (i = 0; i < MAX_PC_BONUS_SCRIPT; i++) { - if (!(&sd->bonus_script[i]) || !sd->bonus_script[i].script || strlen(sd->bonus_script[i].script_str) == 0) + if (!(&sd->bonus_script[i]) || !sd->bonus_script[i].script || sd->bonus_script[i].script_str == '\0') continue; timer = get_timer(sd->bonus_script[i].tid); @@ -1835,9 +1836,9 @@ int chrif_save_bsdata(struct map_session_data *sd) { */ int chrif_load_bsdata(int fd) { struct map_session_data *sd; - struct bonus_script_data *bs; int cid, count; - uint8 i, count_ = 0; + uint8 i; + bool calc = false; cid = RFIFOL(fd,4); sd = map_charid2sd(cid); @@ -1856,9 +1857,9 @@ int chrif_load_bsdata(int fd) { for (i = 0; i < count; i++) { struct script_code *script; - bs = (struct bonus_script_data*)RFIFOP(fd,10 + i*sizeof(struct bonus_script_data)); + struct bonus_script_data *bs = (struct bonus_script_data*)RFIFOP(fd,10 + i*sizeof(struct bonus_script_data)); - if (!(script = parse_script(bs->script,"chrif_load_bsdata",1,1))) + if (bs->script == '\0' || !(script = parse_script(bs->script,"chrif_load_bsdata",1,1))) continue; memcpy(sd->bonus_script[i].script_str,bs->script,strlen(bs->script)); @@ -1869,9 +1870,9 @@ int chrif_load_bsdata(int fd) { sd->bonus_script[i].icon = bs->icon; if (bs->icon != SI_BLANK) //Gives status icon if exist clif_status_change(&sd->bl,sd->bonus_script[i].icon,1,bs->tick,1,0,0); - count_++; + calc = true; } - if (count_) + if (calc) status_calc_pc(sd,false); return 0; } diff --git a/src/map/itemdb.c b/src/map/itemdb.c index c67a5b3ff49..04d78fbf9dc 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -148,7 +148,7 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str) * @param sub_group: Default is 1 * @return nameid */ -int itemdb_searchrandomid(int group_id, uint8 sub_group) +unsigned short itemdb_searchrandomid(int group_id, uint8 sub_group) { if (sub_group) sub_group -= 1; @@ -197,10 +197,9 @@ uint16 itemdb_get_randgroupitem_count(uint16 group_id, uint8 sub_group, uint16 n * Gives item(s) to the player based on item group * @param sd: Player that obtains item from item group * @param group_id: The group ID of item that obtained by player -* @param nameid_from: The item that trigger this item group * @param *group: struct s_item_group from itemgroup_db[group_id].random[idx] or itemgroup_db[group_id].must[sub_group][idx] */ -void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, uint16 group_id, uint16 nameid_from, struct s_item_group *group) { +static void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, uint16 group_id, struct s_item_group *group) { uint16 i; struct item tmp; @@ -226,7 +225,7 @@ void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, uint16 group_id, u clif_additem(sd,0,0,flag); else if (!flag && group->isAnnounced) { ///TODO: Move this broadcast to proper behavior (it should on at different packet) char output[CHAT_SIZE_MAX]; - sprintf(output,msg_txt(NULL,717),sd->status.name,itemdb_jname(group->nameid),itemdb_jname(nameid_from)); + sprintf(output,msg_txt(NULL,717),sd->status.name,itemdb_jname(group->nameid),itemdb_jname(sd->itemid)); clif_broadcast(&sd->bl,output,strlen(output),0,ALL_CLIENT); //clif_broadcast_obtain_special_item(); } @@ -239,10 +238,9 @@ void itemdb_pc_get_itemgroup_sub(struct map_session_data *sd, uint16 group_id, u * Find item(s) that will be obtained by player based on Item Group * @param group_id: The group ID that will be gained by player * @param nameid: The item that trigger this item group -* @param sd: Player that obtains item from item group * @return val: 0:success, 1:no sd, 2:invalid item group */ -uint8 itemdb_pc_get_itemgroup(uint16 group_id, uint16 nameid, struct map_session_data *sd) { +char itemdb_pc_get_itemgroup(uint16 group_id, struct map_session_data *sd) { uint16 i = 0; nullpo_retr(1,sd); @@ -255,7 +253,7 @@ uint8 itemdb_pc_get_itemgroup(uint16 group_id, uint16 nameid, struct map_session //Get the 'must' item(s) for (i = 0; i < itemgroup_db[group_id].must_qty; i++) { if (&itemgroup_db[group_id].must[i] && itemdb_exists(itemgroup_db[group_id].must[i].nameid)) - itemdb_pc_get_itemgroup_sub(sd,group_id,nameid,&itemgroup_db[group_id].must[i]); + itemdb_pc_get_itemgroup_sub(sd,group_id,&itemgroup_db[group_id].must[i]); } //Get the 'random' item each random group @@ -269,7 +267,7 @@ uint8 itemdb_pc_get_itemgroup(uint16 group_id, uint16 nameid, struct map_session continue; } if (itemdb_exists(itemgroup_db[group_id].random[i][rand].nameid)) - itemdb_pc_get_itemgroup_sub(sd,group_id,nameid,&itemgroup_db[group_id].random[i][rand]); + itemdb_pc_get_itemgroup_sub(sd,group_id,&itemgroup_db[group_id].random[i][rand]); } return 0; @@ -307,7 +305,7 @@ struct item_data* itemdb_exists(int nameid) /// Returns human readable name for given item type. /// @param type Type id to retrieve name for ( IT_* ). -const char* itemdb_typename(int type) +const char* itemdb_typename(enum item_types type) { switch(type) { @@ -469,7 +467,7 @@ struct item_data* itemdb_search(int nameid) /*========================================== * Returns if given item is a player-equippable piece. *------------------------------------------*/ -int itemdb_isequip(int nameid) +bool itemdb_isequip(int nameid) { int type=itemdb_type(nameid); switch (type) { @@ -477,16 +475,16 @@ int itemdb_isequip(int nameid) case IT_ARMOR: case IT_AMMO: case IT_SHADOWGEAR: - return 1; + return true; default: - return 0; + return false; } } /*========================================== * Alternate version of itemdb_isequip *------------------------------------------*/ -int itemdb_isequip2(struct item_data *data) +bool itemdb_isequip2(struct item_data *data) { nullpo_ret(data); switch(data->type) { @@ -494,34 +492,34 @@ int itemdb_isequip2(struct item_data *data) case IT_ARMOR: case IT_AMMO: case IT_SHADOWGEAR: - return 1; + return true; default: - return 0; + return false; } } /*========================================== * Returns if given item's type is stackable. *------------------------------------------*/ -int itemdb_isstackable(int nameid) +bool itemdb_isstackable(uint16 nameid) { - int type=itemdb_type(nameid); + uint8 type = itemdb_type(nameid); switch(type) { case IT_WEAPON: case IT_ARMOR: case IT_PETEGG: case IT_PETARMOR: case IT_SHADOWGEAR: - return 0; + return false; default: - return 1; + return true; } } /*========================================== * Alternate version of itemdb_isstackable *------------------------------------------*/ -int itemdb_isstackable2(struct item_data *data) +bool itemdb_isstackable2(struct item_data *data) { nullpo_ret(data); switch(data->type) { @@ -530,9 +528,9 @@ int itemdb_isstackable2(struct item_data *data) case IT_PETEGG: case IT_PETARMOR: case IT_SHADOWGEAR: - return 0; + return false; default: - return 1; + return true; } } @@ -576,29 +574,29 @@ int itemdb_canauction_sub(struct item_data* item, int gmlv, int unused) { return (item && (!(item->flag.trade_restriction&256) || gmlv >= item->gm_lv_trade_override)); } -int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int)) +bool itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int)) { struct item_data* item_data = itemdb_search(item->nameid); int i; if (!func(item_data, gmlv, gmlv2)) - return 0; + return false; if(item_data->slot == 0 || itemdb_isspecial(item->card[0])) - return 1; + return true; for(i = 0; i < item_data->slot; i++) { if (!item->card[i]) continue; if (!func(itemdb_search(item->card[i]), gmlv, gmlv2)) - return 0; + return false; } - return 1; + return true; } /*========================================== * Specifies if item-type should drop unidentified. *------------------------------------------*/ -int itemdb_isidentified(int nameid) +char itemdb_isidentified(int nameid) { int type=itemdb_type(nameid); switch (type) { @@ -693,10 +691,10 @@ static void itemdb_read_itemgroup_sub(const char* filename) } //Checking group_id - if (!atoi(str[0])) //Try reads group id by const - script_get_constant(trim(str[0]),&group_id); - else + if (atoi(str[0])) group_id = atoi(str[0]); + else //Try reads group id by const + script_get_constant(trim(str[0]),&group_id); if (!group_id || group_id >= MAX_ITEMGROUP) { ShowWarning("itemdb_read_itemgroup: Invalid group id '%s' in %s:%d\n", str[0], filename, ln); continue; @@ -709,12 +707,12 @@ static void itemdb_read_itemgroup_sub(const char* filename) } //Checking item - if (!atoi(str[1]) && itemdb_searchname(str[1])) { + if ((nameid = atoi(str[1])) && itemdb_exists(nameid)) + found = true; + else if (itemdb_searchname(str[1])) { found = true; nameid = itemdb_searchname(str[1])->nameid; } - else if ((nameid = atoi(str[1])) && itemdb_exists(nameid)) - found = true; if (!found) { ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln); continue; @@ -741,10 +739,16 @@ static void itemdb_read_itemgroup_sub(const char* filename) itemgroup_db[group_id].must[idx].isNamed = named; itemgroup_db[group_id].must[idx].bound = bound; itemgroup_db[group_id].must_qty++; + group = 1; } + prob = max(prob,0); + if (!prob) { + entries++; + continue; + } + group -= 1; for (j = 0; j < prob; j++) { uint16 idx; - if (group > 0) group -= 1; idx = itemgroup_db[group_id].random_qty[group]; itemgroup_db[group_id].random[group][idx].nameid = nameid; itemgroup_db[group_id].random[group][idx].amount = amt; @@ -950,7 +954,7 @@ static bool itemdb_read_nouse(char* fields[], int columns, int current) /** * @return: amount of retrieved entries. **/ -int itemdb_combo_split_atoi (char *str, int *val) { +static int itemdb_combo_split_atoi (char *str, int *val) { int i; for (i=0; i,<{ script }> **/ -void itemdb_read_combos() { +static void itemdb_read_combos() { uint32 lines = 0, count = 0; char line[1024]; @@ -1115,7 +1119,7 @@ void itemdb_read_combos() { /*====================================== * Applies gender restrictions according to settings. [Skotlex] *======================================*/ -static int itemdb_gendercheck(struct item_data *id) +static char itemdb_gendercheck(struct item_data *id) { if (id->nameid == WEDDING_RING_M) //Grom Ring return 1; @@ -1133,7 +1137,7 @@ static int itemdb_gendercheck(struct item_data *id) * For backwards compatibility, in Renewal mode, MATK from weapons comes from the atk slot * We use a ':' delimiter which, if not found, assumes the weapon does not provide any matk. **/ -void itemdb_re_split_atoi(char *str, int *atk, int *matk) { +static void itemdb_re_split_atoi(char *str, int *atk, int *matk) { int i, val[2]; for (i=0; i<2; i++) { @@ -1477,7 +1481,7 @@ static int itemdb_read_sqldb(void) { * 2 set new value bypassing anything * 3/other return last value *------------------------------------------*/ -uint64 itemdb_unique_id(int8 flag, int64 value) { +static uint64 itemdb_unique_id(int8 flag, int64 value) { static uint64 item_uid = 0; if(flag) @@ -1493,7 +1497,7 @@ uint64 itemdb_unique_id(int8 flag, int64 value) { return ++item_uid; } -int itemdb_uid_load(){ +static void itemdb_uid_load(){ char * uid; if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='unique_id'")) @@ -1503,14 +1507,12 @@ int itemdb_uid_load(){ { ShowError("itemdb_uid_load: Unable to fetch unique_id data\n"); Sql_FreeResult(mmysql_handle); - return -1; + return; } Sql_GetData(mmysql_handle, 0, &uid, NULL); itemdb_unique_id(1, (uint64)strtoull(uid, NULL, 10)); Sql_FreeResult(mmysql_handle); - - return 0; } /*========================================== diff --git a/src/map/itemdb.h b/src/map/itemdb.h index 1f24a9e6b60..bd80ab0f092 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -223,7 +223,7 @@ struct item_data* itemdb_exists(int nameid); const char* itemdb_typename(int type); int itemdb_group_bonus(struct map_session_data* sd, int itemid); -int itemdb_searchrandomid(int group_id, uint8 sub_group); +unsigned short itemdb_searchrandomid(int group_id, uint8 sub_group); #define itemdb_value_buy(n) itemdb_search(n)->value_buy #define itemdb_value_sell(n) itemdb_search(n)->value_sell @@ -238,7 +238,7 @@ int itemdb_canstore_sub(struct item_data*, int, int); int itemdb_canguildstore_sub(struct item_data*, int, int); int itemdb_canmail_sub(struct item_data*, int, int); int itemdb_canauction_sub(struct item_data*, int, int); -int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int)); +bool itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int)); #define itemdb_isdropable(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_isdropable_sub) #define itemdb_cantrade(item, gmlv, gmlv2) itemdb_isrestricted(item, gmlv, gmlv2, itemdb_cantrade_sub) #define itemdb_canpartnertrade(item, gmlv, gmlv2) itemdb_isrestricted(item, gmlv, gmlv2, itemdb_canpartnertrade_sub) @@ -249,15 +249,15 @@ int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(stru #define itemdb_canmail(item, gmlv) itemdb_isrestricted(item , gmlv, 0, itemdb_canmail_sub) #define itemdb_canauction(item, gmlv) itemdb_isrestricted(item , gmlv, 0, itemdb_canauction_sub) -int itemdb_isequip(int); -int itemdb_isequip2(struct item_data *); -int itemdb_isidentified(int); -int itemdb_isstackable(int); -int itemdb_isstackable2(struct item_data *); +bool itemdb_isequip(int); +bool itemdb_isequip2(struct item_data *); +char itemdb_isidentified(int); +bool itemdb_isstackable(uint16 nameid); +bool itemdb_isstackable2(struct item_data *data); uint64 itemdb_unique_id(int8 flag, int64 value); // Unique Item ID bool itemdb_isNoEquip(struct item_data *id, uint16 m); -uint8 itemdb_pc_get_itemgroup(uint16 group_id, uint16 nameid, struct map_session_data *sd); +char itemdb_pc_get_itemgroup(uint16 group_id, struct map_session_data *sd); uint16 itemdb_get_randgroupitem_count(uint16 group_id, uint8 sub_group, uint16 nameid); DBMap * itemdb_get_combodb(); diff --git a/src/map/mob.h b/src/map/mob.h index 892b662dfb4..8cc2d1c0409 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -139,8 +139,8 @@ struct mob_data { int provoke_flag; // Celest } state; struct guardian_data* guardian_data; - struct { - int id; + struct s_dmglog { + int id; //char id unsigned int dmg; unsigned int flag : 2; //0: Normal. 1: Homunc exp. 2: Pet exp } dmglog[DAMAGELOG_SIZE]; diff --git a/src/map/pc.c b/src/map/pc.c index a11c011a087..33b191f7c19 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -620,11 +620,11 @@ int pc_equippoint(struct map_session_data *sd,int n){ */ int pc_setinventorydata(struct map_session_data *sd) { - int i; + uint8 i; nullpo_retr(1,sd); for(i=0;istatus.inventory[i].nameid; + uint16 id = sd->status.inventory[i].nameid; sd->inventory_data[i] = id?itemdb_search(id):NULL; } return 0; @@ -741,11 +741,11 @@ int pc_setequipindex(struct map_session_data *sd) */ bool pc_isequipped(struct map_session_data *sd, int nameid) { - int i, j; + uint8 i; for( i = 0; i < EQI_MAX; i++ ) { - int index = sd->equip_index[i]; + uint8 index = sd->equip_index[i], j; if( index < 0 ) continue; if( i == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue; @@ -865,7 +865,7 @@ bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, [Haru] for third-classes extension [Cydh] finishing :D *------------------------------------------*/ -bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) { +static bool pc_isItemClass (struct map_session_data *sd, struct item_data* item) { while (1) { if (item->class_upper&ITEMJ_NORMAL && !(sd->class_&(JOBL_UPPER|JOBL_THIRD|JOBL_BABY))) //normal classes (no upper, no baby, no third) break; @@ -1174,31 +1174,31 @@ void pc_authfail(struct map_session_data *sd) * @param sd : player session * @param pos : hate position [0;2] * @param bl : target bl - * @return 0:failed, 1:success + * @return false:failed, true:success */ -int pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl) +bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl) { int class_; if (!sd || !bl || pos < 0 || pos > 2) - return 0; + return false; if (sd->hate_mob[pos] != -1) { //Can't change hate targets. clif_hate_info(sd, pos, sd->hate_mob[pos], 0); //Display current - return 0; + return false; } class_ = status_get_class(bl); if (!pcdb_checkid(class_)) { unsigned int max_hp = status_get_max_hp(bl); if ((pos == 1 && max_hp < 6000) || (pos == 2 && max_hp < 20000)) - return 0; + return false; if (pos != status_get_size(bl)) - return 0; //Wrong size + return false; //Wrong size } sd->hate_mob[pos] = class_; pc_setglobalreg(sd,sg_info[pos].hate_var,class_+1); clif_hate_info(sd, pos, class_, 1); - return 1; + return true; } /*========================================== @@ -1206,7 +1206,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; + uint8 i; sd->change_level_2nd = pc_readglobalreg(sd,"jobchange_level"); sd->change_level_3rd = pc_readglobalreg(sd,"jobchange_level_3rd"); @@ -1231,7 +1231,7 @@ int pc_reg_received(struct map_session_data *sd) //SG map and mob read [Komurka] for(i=0;ifeel_map[i].index = j; sd->feel_map[i].m = map_mapindex2mapid(j); @@ -1334,13 +1334,14 @@ int pc_reg_received(struct map_session_data *sd) static int pc_calc_skillpoint(struct map_session_data* sd) { - int i,inf2,skill_point=0; + uint16 i, skill_point=0; + nullpo_ret(sd); for(i=1;i 0) { - inf2 = skill_get_inf2(i); + uint8 skill_lv; + if( (skill_lv = pc_checkskill(sd,i)) > 0) { + uint16 inf2 = skill_get_inf2(i); if((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) && !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL)) //Do not count wedding/link skills. [Skotlex] ) { @@ -1606,9 +1607,9 @@ static void pc_check_skilltree(struct map_session_data *sd, int skill) // Make sure all the skills are in the correct condition // before persisting to the backend.. [MouseJstr] -int pc_clean_skilltree(struct map_session_data *sd) +void pc_clean_skilltree(struct map_session_data *sd) { - int i; + uint16 i; for (i = 0; i < MAX_SKILL; i++){ if (sd->status.skill[i].flag == SKILL_FLAG_TEMPORARY || sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED) { @@ -1622,8 +1623,6 @@ int pc_clean_skilltree(struct map_session_data *sd) sd->status.skill[i].flag = SKILL_FLAG_PERMANENT; } } - - return 0; } int pc_calc_skilltree_normalize_job(struct map_session_data *sd) @@ -5125,7 +5124,7 @@ int pc_checkskill(struct map_session_data *sd,uint16 skill_id) * @param sd * @return 0:error, 1:check done */ -int pc_checkallowskill(struct map_session_data *sd) +static void pc_checkallowskill(struct map_session_data *sd) { const enum sc_type scw_list[] = { SC_TWOHANDQUICKEN, @@ -5139,11 +5138,11 @@ int pc_checkallowskill(struct map_session_data *sd) SC_GATLINGFEVER, SC_FEARBREEZE }; - int i; - nullpo_ret(sd); + uint8 i; + nullpo_retv(sd); if(!sd->sc.count) - return 0; + return; for (i = 0; i < ARRAYLENGTH(scw_list); i++) { // Skills requiring specific weapon types @@ -5169,7 +5168,6 @@ int pc_checkallowskill(struct map_session_data *sd) if(sd->sc.data[scs_list[i]]) status_change_end(&sd->bl, scs_list[i], INVALID_TIMER); } - return 1; } /*========================================== @@ -5178,9 +5176,9 @@ int pc_checkallowskill(struct map_session_data *sd) * -1 : mean nothing equiped * idx : (this index could be used in inventory to found item_data) *------------------------------------------*/ -int pc_checkequip(struct map_session_data *sd,int pos) +short pc_checkequip(struct map_session_data *sd,int pos) { - int i; + uint8 i; nullpo_retr(-1, sd); @@ -5200,7 +5198,7 @@ int pc_checkequip(struct map_session_data *sd,int pos) * @max : see pc.h enum equip_index for @min to ? * -return true,false *------------------------------------------*/ -int pc_checkequip2(struct map_session_data *sd,int nameid, int min, int max){ +bool pc_checkequip2(struct map_session_data *sd,int nameid, int min, int max){ int i; for(i=min;iclass_,sd->status.sex,PARAM_STR); break; - case SP_AGI: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_AGI); break; - case SP_VIT: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_VIT); break; - case SP_INT: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_INT); break; - case SP_DEX: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_DEX); break; - case SP_LUK: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_LUK); break; - } + max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); if ( low >= max && val > 0 ) return 0; // Official servers show '0' when max is reached @@ -6157,14 +6147,8 @@ int pc_statusup(struct map_session_data* sd, int type) } // check limits - switch(type) { - case SP_STR: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_STR); break; - case SP_AGI: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_AGI); break; - case SP_VIT: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_VIT); break; - case SP_INT: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_INT); break; - case SP_DEX: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_DEX); break; - case SP_LUK: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_LUK); break; - } + max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); + if( pc_getstat(sd,type) >= max ) { clif_statusupack(sd,type,0,0); @@ -6210,16 +6194,8 @@ int pc_statusup2(struct map_session_data* sd, int type, int val) } need = pc_need_status_point(sd,type,1); + max = pc_maxparameter(sd,(enum e_params)(type-SP_STR)); // set new value - // set new value - switch(type) { - case SP_STR: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_STR); break; - case SP_AGI: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_AGI); break; - case SP_VIT: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_VIT); break; - case SP_INT: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_INT); break; - case SP_DEX: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_DEX); break; - case SP_LUK: max = pc_maxparameter(sd->class_,sd->status.sex,PARAM_LUK); break; - } val = pc_setstat(sd, type, cap_value(pc_getstat(sd,type) + val, 1, max)); status_calc_pc(sd,0); @@ -7269,8 +7245,9 @@ int pc_readparam(struct map_session_data* sd,int type) /*========================================== * script set pc status registry *------------------------------------------*/ -int pc_setparam(struct map_session_data *sd,int type,int val){ - nullpo_ret(sd); +bool pc_setparam(struct map_session_data *sd,int type,int val) +{ + nullpo_retr(false,sd); switch(type){ case SP_BASELEVEL: @@ -7316,7 +7293,7 @@ int pc_setparam(struct map_session_data *sd,int type,int val){ break; case SP_ZENY: if( val < 0 ) - return 0;// can't set negative zeny + return false;// can't set negative zeny log_zeny(sd, LOG_TYPE_SCRIPT, sd, -(sd->status.zeny - cap_value(val, 0, MAX_ZENY))); sd->status.zeny = cap_value(val, 0, MAX_ZENY); break; @@ -7366,22 +7343,22 @@ int pc_setparam(struct map_session_data *sd,int type,int val){ } break; case SP_STR: - sd->status.str = cap_value(val, 1, pc_maxparameter(sd->class_,sd->status.sex,PARAM_STR)); + sd->status.str = cap_value(val, 1, pc_maxparameter(sd,PARAM_STR)); break; case SP_AGI: - sd->status.agi = cap_value(val, 1, pc_maxparameter(sd->class_,sd->status.sex,PARAM_AGI)); + sd->status.agi = cap_value(val, 1, pc_maxparameter(sd,PARAM_AGI)); break; case SP_VIT: - sd->status.vit = cap_value(val, 1, pc_maxparameter(sd->class_,sd->status.sex,PARAM_VIT)); + sd->status.vit = cap_value(val, 1, pc_maxparameter(sd,PARAM_VIT)); break; case SP_INT: - sd->status.int_ = cap_value(val, 1, pc_maxparameter(sd->class_,sd->status.sex,PARAM_INT)); + sd->status.int_ = cap_value(val, 1, pc_maxparameter(sd,PARAM_INT)); break; case SP_DEX: - sd->status.dex = cap_value(val, 1, pc_maxparameter(sd->class_,sd->status.sex,PARAM_DEX)); + sd->status.dex = cap_value(val, 1, pc_maxparameter(sd,PARAM_DEX)); break; case SP_LUK: - sd->status.luk = cap_value(val, 1, pc_maxparameter(sd->class_,sd->status.sex,PARAM_LUK)); + sd->status.luk = cap_value(val, 1, pc_maxparameter(sd,PARAM_LUK)); break; case SP_KARMA: sd->status.karma = val; @@ -7394,20 +7371,20 @@ int pc_setparam(struct map_session_data *sd,int type,int val){ break; case SP_KILLERRID: sd->killerrid = val; - return 1; + return true; case SP_KILLEDRID: sd->killedrid = val; - return 1; + return true; case SP_CHARMOVE: sd->status.character_moves = val; - return 1; + return true; default: ShowError("pc_setparam: Attempted to set unknown parameter '%d'.\n", type); - return 0; + return false; } clif_updatestatus(sd,type); - return 1; + return true; } /*========================================== @@ -7755,9 +7732,9 @@ int pc_jobchange(struct map_session_data *sd,int job, int upper) /*========================================== * Tell client player sd has change equipement *------------------------------------------*/ -int pc_equiplookall(struct map_session_data *sd) +void pc_equiplookall(struct map_session_data *sd) { - nullpo_ret(sd); + nullpo_retv(sd); clif_changelook(&sd->bl,LOOK_WEAPON,0); clif_changelook(&sd->bl,LOOK_SHOES,0); @@ -7765,16 +7742,14 @@ int pc_equiplookall(struct map_session_data *sd) clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top); clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid); clif_changelook(&sd->bl,LOOK_ROBE, sd->status.robe); - - return 0; } /*========================================== * Tell client player sd has change look (hair,equip...) *------------------------------------------*/ -int pc_changelook(struct map_session_data *sd,int type,int val) +void pc_changelook(struct map_session_data *sd,int type,int val) { - nullpo_ret(sd); + nullpo_retv(sd); switch(type){ case LOOK_HAIR: //Use the battle_config limits! [Skotlex] @@ -7825,16 +7800,15 @@ int pc_changelook(struct map_session_data *sd,int type,int val) break; } clif_changelook(&sd->bl,type,val); - return 0; } /*========================================== * Give an option (type) to player (sd) and display it to client *------------------------------------------*/ -int pc_setoption(struct map_session_data *sd,int type) +void pc_setoption(struct map_session_data *sd,int type) { int p_type, new_look=0; - nullpo_ret(sd); + nullpo_retv(sd); p_type = sd->sc.option; //Option has to be changed client-side before the class sprite or it won't always work (eg: Wedding sprite) [Skotlex] @@ -7934,7 +7908,7 @@ int pc_setoption(struct map_session_data *sd,int type) new_look = -1; if (sd->disguise || !new_look) - return 0; //Disguises break sprite changes + return; //Disguises break sprite changes if (new_look < 0) { //Restore normal look. status_set_viewdata(&sd->bl, sd->status.class_); @@ -7946,25 +7920,23 @@ int pc_setoption(struct map_session_data *sd,int type) if (sd->vd.cloth_color) clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->vd.cloth_color); clif_skillinfoblock(sd); // Skill list needs to be updated after base change. - - return 0; } /*========================================== * Give player a cart *------------------------------------------*/ -int pc_setcart(struct map_session_data *sd,int type) { +bool pc_setcart(struct map_session_data *sd,int type) { #ifndef NEW_CARTS int cart[6] = {0x0000,OPTION_CART1,OPTION_CART2,OPTION_CART3,OPTION_CART4,OPTION_CART5}; int option; #endif - nullpo_ret(sd); + nullpo_retr(false,sd); if( type < 0 || type > MAX_CARTS ) - return 1;// Never trust the values sent by the client! [Skotlex] + return false;// Never trust the values sent by the client! [Skotlex] if( pc_checkskill(sd,MC_PUSHCART) <= 0 && type != 0 ) - return 1;// Push cart is required + return false;// Push cart is required #ifdef NEW_CARTS @@ -7996,13 +7968,13 @@ int pc_setcart(struct map_session_data *sd,int type) { pc_setoption(sd, option); #endif - return 0; + return true; } /*========================================== * Give player a falcon *------------------------------------------*/ -int pc_setfalcon(TBL_PC* sd, int flag) +void pc_setfalcon(TBL_PC* sd, int flag) { if( flag ){ if( pc_checkskill(sd,HT_FALCON)>0 ) // add falcon if he have the skill @@ -8010,14 +7982,12 @@ int pc_setfalcon(TBL_PC* sd, int flag) } else if( pc_isfalcon(sd) ){ pc_setoption(sd,sd->sc.option&~OPTION_FALCON); // remove falcon } - - return 0; } /*========================================== * Set player riding *------------------------------------------*/ -int pc_setriding(TBL_PC* sd, int flag) +void pc_setriding(TBL_PC* sd, int flag) { if( flag ){ if( pc_checkskill(sd,KN_RIDING) > 0 ) // add peco @@ -8025,14 +7995,12 @@ int pc_setriding(TBL_PC* sd, int flag) } else if( pc_isriding(sd) ){ pc_setoption(sd, sd->sc.option&~OPTION_RIDING); } - - return 0; } /*========================================== * Give player a mado *------------------------------------------*/ -int pc_setmadogear(TBL_PC* sd, int flag) +void pc_setmadogear(TBL_PC* sd, int flag) { if( flag ){ if( pc_checkskill(sd,NC_MADOLICENCE) > 0 ) @@ -8040,19 +8008,17 @@ int pc_setmadogear(TBL_PC* sd, int flag) } else if( pc_ismadogear(sd) ){ pc_setoption(sd, sd->sc.option&~OPTION_MADOGEAR); } - - return 0; } /*========================================== * Check if player can drop an item *------------------------------------------*/ -int pc_candrop(struct map_session_data *sd, struct item *item) +bool pc_candrop(struct map_session_data *sd, struct item *item) { if( item && (item->expire_time || (item->bound && !pc_can_give_bounded_items(sd))) ) - return 0; + return false; if( !pc_can_give_items(sd) || sd->sc.cant.drop) //check if this GM level can drop items - return 0; + return false; return (itemdb_isdropable(item, pc_get_group_level(sd))); } @@ -8073,17 +8039,17 @@ int pc_readreg(struct map_session_data* sd, int reg) * Set ram register for player sd * memo val(int) at reg for player sd *------------------------------------------*/ -int pc_setreg(struct map_session_data* sd, int reg, int val) +bool pc_setreg(struct map_session_data* sd, int reg, int val) { int i; - nullpo_ret(sd); + nullpo_retr(false,sd); ARR_FIND( 0, sd->reg_num, i, sd->reg[i].index == reg ); if( i < sd->reg_num ) {// overwrite existing entry sd->reg[i].data = val; - return 1; + return true; } ARR_FIND( 0, sd->reg_num, i, sd->reg[i].data == 0 ); @@ -8095,7 +8061,7 @@ int pc_setreg(struct map_session_data* sd, int reg, int val) sd->reg[i].index = reg; sd->reg[i].data = val; - return 1; + return true; } /*========================================== @@ -8115,11 +8081,11 @@ char* pc_readregstr(struct map_session_data* sd, int reg) * Set ram register for player sd * memo val(str) at reg for player sd *------------------------------------------*/ -int pc_setregstr(struct map_session_data* sd, int reg, const char* str) +bool pc_setregstr(struct map_session_data* sd, int reg, const char* str) { int i; - nullpo_ret(sd); + nullpo_retr(false,sd); ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].index == reg ); if( i < sd->regstr_num ) @@ -8140,11 +8106,11 @@ int pc_setregstr(struct map_session_data* sd, int reg, const char* str) {// create sd->regstr[i].data = aStrdup(str); } - return 1; + return true; } if( str == NULL || *str == '\0' ) - return 1;// nothing to add, empty string + return true;// nothing to add, empty string ARR_FIND( 0, sd->regstr_num, i, sd->regstr[i].data == NULL ); if( i == sd->regstr_num ) @@ -8155,7 +8121,7 @@ int pc_setregstr(struct map_session_data* sd, int reg, const char* str) sd->regstr[i].index = reg; sd->regstr[i].data = aStrdup(str); - return 1; + return true; } int pc_readregistry(struct map_session_data *sd,const char *reg,int type) @@ -8224,12 +8190,12 @@ char* pc_readregistry_str(struct map_session_data *sd,const char *reg,int type) return ( i < max ) ? sd_reg[i].value : NULL; } -int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type) +bool pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type) { struct global_reg *sd_reg; int i,*max, regmax; - nullpo_ret(sd); + nullpo_retr(false,sd); switch( type ) { @@ -8271,11 +8237,11 @@ int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type) regmax = ACCOUNT_REG2_NUM; break; default: - return 0; + return false; } if (*max == -1) { ShowError("pc_setregistry : refusing to set %s (type %d) until vars are received.\n", reg, type); - return 1; + return true; } // delete reg @@ -8289,7 +8255,7 @@ int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type) (*max)--; sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved" } - return 1; + return true; } // change value if found ARR_FIND( 0, *max, i, strcmp(sd_reg[i].str, reg) == 0 ); @@ -8297,7 +8263,7 @@ int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type) { safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val); sd->state.reg_dirty |= 1<<(type-1); - return 1; + return true; } // add value if not found @@ -8307,23 +8273,23 @@ int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type) safesnprintf(sd_reg[i].value, sizeof(sd_reg[i].value), "%d", val); (*max)++; sd->state.reg_dirty |= 1<<(type-1); - return 1; + return true; } ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax); - return 0; + return false; } -int pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *val,int type) +bool pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *val,int type) { struct global_reg *sd_reg; int i,*max, regmax; - nullpo_ret(sd); + nullpo_retr(false,sd); if (reg[strlen(reg)-1] != '$') { ShowError("pc_setregistry_str : reg %s must be string (end in '$') to use this!\n", reg); - return 0; + return false; } switch (type) { @@ -8343,11 +8309,11 @@ int pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *v regmax = ACCOUNT_REG2_NUM; break; default: - return 0; + return false; } if (*max == -1) { ShowError("pc_setregistry_str : refusing to set %s (type %d) until vars are received.\n", reg, type); - return 0; + return false; } // delete reg @@ -8363,7 +8329,7 @@ int pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *v sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved" if (type!=3) intif_saveregistry(sd,type); } - return 1; + return true; } // change value if found @@ -8373,7 +8339,7 @@ int pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *v safestrncpy(sd_reg[i].value, val, sizeof(sd_reg[i].value)); sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved" if (type!=3) intif_saveregistry(sd,type); - return 1; + return true; } // add value if not found @@ -8384,12 +8350,11 @@ int pc_setregistry_str(struct map_session_data *sd,const char *reg,const char *v (*max)++; sd->state.reg_dirty |= 1<<(type-1); //Mark this registry as "need to be saved" if (type!=3) intif_saveregistry(sd,type); - return 1; + return true; } ShowError("pc_setregistry : couldn't set %s, limit of registries reached (%d)\n", reg, regmax); - - return 0; + return false; } /*========================================== @@ -8420,33 +8385,32 @@ static int pc_eventtimer(int tid, unsigned int tick, int id, intptr_t data) /*========================================== * Add eventtimer for player sd ? *------------------------------------------*/ -int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name) +bool pc_addeventtimer(struct map_session_data *sd,int tick,const char *name) { int i; - nullpo_ret(sd); + nullpo_retr(false,sd); ARR_FIND( 0, MAX_EVENTTIMER, i, sd->eventtimer[i] == INVALID_TIMER ); if( i == MAX_EVENTTIMER ) - return 0; + return false; sd->eventtimer[i] = add_timer(gettick()+tick, pc_eventtimer, sd->bl.id, (intptr_t)aStrdup(name)); sd->eventcount++; - return 1; + return true; } /*========================================== * Del eventtimer for player sd ? *------------------------------------------*/ -int pc_deleventtimer(struct map_session_data *sd,const char *name) +bool pc_deleventtimer(struct map_session_data *sd,const char *name) { char* p = NULL; int i; - nullpo_ret(sd); - + nullpo_retr(false,sd); if (sd->eventcount == 0) - return 0; + return false; // find the named event timer ARR_FIND( 0, MAX_EVENTTIMER, i, @@ -8455,7 +8419,7 @@ int pc_deleventtimer(struct map_session_data *sd,const char *name) strcmp(p, name) == 0 ); if( i == MAX_EVENTTIMER ) - return 0; // not found + return false; // not found delete_timer(sd->eventtimer[i],pc_eventtimer); sd->eventtimer[i] = INVALID_TIMER; @@ -8463,17 +8427,17 @@ int pc_deleventtimer(struct map_session_data *sd,const char *name) sd->eventcount--; aFree(p); - return 1; + return true; } /*========================================== * Update eventtimer count for player sd *------------------------------------------*/ -int pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick) +void pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick) { int i; - nullpo_ret(sd); + nullpo_retv(sd); for(i=0;ieventtimer[i] != INVALID_TIMER && strcmp( @@ -8481,21 +8445,19 @@ int pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick) addtick_timer(sd->eventtimer[i],tick); break; } - - return 0; } /*========================================== * Remove all eventtimer for player sd *------------------------------------------*/ -int pc_cleareventtimer(struct map_session_data *sd) +void pc_cleareventtimer(struct map_session_data *sd) { int i; - nullpo_ret(sd); + nullpo_retv(sd); if (sd->eventcount == 0) - return 0; + return; for(i=0;ieventtimer[i] != INVALID_TIMER ){ @@ -8507,7 +8469,6 @@ int pc_cleareventtimer(struct map_session_data *sd) if (p) aFree(p); } } - return 0; } /** @@ -8516,12 +8477,12 @@ int pc_cleareventtimer(struct map_session_data *sd) * @param *data struct item_data * @return success numbers of succeed combo */ -int pc_checkcombo(struct map_session_data *sd, struct item_data *data) { - int i, j, k, z; - int index, idx, success = 0; +static int pc_checkcombo(struct map_session_data *sd, struct item_data *data) { + uint16 i; + int success = 0; for( i = 0; i < data->combos_count; i++ ) { - int16 *combo_idx = NULL; + int16 *combo_idx = NULL, idx, j; /* ensure this isn't a duplicate combo */ if( sd->combos.bonus != NULL ) { int x; @@ -8535,11 +8496,12 @@ int pc_checkcombo(struct map_session_data *sd, struct item_data *data) { CREATE(combo_idx,int16,data->combos[i]->count); memset(combo_idx,0,data->combos[i]->count); for( j = 0; j < data->combos[i]->count; j++ ) { - int id = data->combos[i]->nameid[j]; + uint16 id = data->combos[i]->nameid[j], k; bool found = false; for( k = 0; k < EQI_MAX; k++ ) { bool do_continue = false; //used to continue that specific loop with some check that also use some loop + uint16 index; index = sd->equip_index[k]; if( index < 0 ) continue; if( k == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue; @@ -8549,6 +8511,7 @@ int pc_checkcombo(struct map_session_data *sd, struct item_data *data) { if(!sd->inventory_data[index]) continue; if(j>0){ + uint16 z; for (z = 0; z < data->combos[i]->count; z++) if(combo_idx[z] == index) //we already have that index recorded do_continue=true; @@ -8564,6 +8527,7 @@ int pc_checkcombo(struct map_session_data *sd, struct item_data *data) { found = true; break; } else { //Cards + uint16 z; if ( sd->inventory_data[index]->slot == 0 || itemdb_isspecial(sd->status.inventory[index].card[0]) ) continue; for (z = 0; z < sd->inventory_data[index]->slot; z++) { @@ -8608,7 +8572,7 @@ int pc_checkcombo(struct map_session_data *sd, struct item_data *data) { * @param *data struct item_data * @return retval numbers of removed combo */ -int pc_removecombo(struct map_session_data *sd, struct item_data *data ) { +static int pc_removecombo(struct map_session_data *sd, struct item_data *data ) { int i, retval = 0; if( sd->combos.bonus == NULL ) @@ -8685,17 +8649,18 @@ int pc_load_combo(struct map_session_data *sd) { } /*========================================== * Equip item on player sd at req_pos from inventory index n + * return: false - fail; true - success *------------------------------------------*/ -int pc_equipitem(struct map_session_data *sd,int n,int req_pos) +bool pc_equipitem(struct map_session_data *sd,int n,int req_pos) { int i,pos,flag=0,iflag; struct item_data *id; - nullpo_ret(sd); + nullpo_retr(false,sd); if( n < 0 || n >= MAX_INVENTORY ) { clif_equipitemack(sd,0,0,0); - return 0; + return false; } if( sd->sc.count && ( @@ -8704,16 +8669,16 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) sd->sc.data[SC_SATURDAYNIGHTFEVER]) ) { clif_equipitemack(sd,0,0,0); - return 0; + return false; } if( DIFF_TICK(sd->canequip_tick,gettick()) > 0 ) { clif_equipitemack(sd,n,0,0); - return 0; + return false; } if (!(id = sd->inventory_data[n])) - return 0; + return false; pos = pc_equippoint(sd,n); //With a few exceptions, item should go in all specified slots. if(battle_config.battle_log) @@ -8722,7 +8687,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) if(!pc_isequip(sd,n) || !(pos&req_pos) || sd->status.inventory[n].equip != 0 || sd->status.inventory[n].attribute==1 ) { // [Valaris] // FIXME: pc_isequip: equip level failure uses 2 instead of 0 clif_equipitemack(sd,n,0,0); // fail - return 0; + return false; } if(pos == EQP_ACC) { //Accesories should only go in one of the two, @@ -8895,7 +8860,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) } sd->npc_item_flag = iflag; - return 0; + return true; } /*========================================== @@ -8904,15 +8869,16 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos) * 0 - only unequip * 1 - calculate status after unequipping * 2 - force unequip + * return: false - fail; true - success *------------------------------------------*/ -int pc_unequipitem(struct map_session_data *sd,int n,int flag) { +bool pc_unequipitem(struct map_session_data *sd,int n,int flag) { int i,iflag; bool status_cacl = false; - nullpo_ret(sd); + nullpo_retr(false,sd); if( n < 0 || n >= MAX_INVENTORY ) { clif_unequipitemack(sd,0,0,0); - return 0; + return false; } // status change that makes player cannot unequip equipment @@ -8924,7 +8890,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) { (sd->sc.data[SC_PYROCLASTIC] && sd->inventory_data[n]->type == IT_WEAPON)) ) // can't switch weapon { clif_unequipitemack(sd,n,0,0); - return 0; + return false; } if (&sd->sc) { if (sd->sc.data[SC_HEAT_BARREL]) @@ -8938,7 +8904,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) { if(!sd->status.inventory[n].equip){ //Nothing to unequip clif_unequipitemack(sd,n,0,0); - return 0; + return false; } for(i=0;istatus.inventory[n].equip & equip_pos[i]) @@ -9069,21 +9035,21 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) { } sd->npc_item_flag = iflag; - return 0; + return true; } /*========================================== * Checking if player (sd) has an invalid item * and is unequiped on map load (item_noequip) *------------------------------------------*/ -int pc_checkitem(struct map_session_data *sd) { +void pc_checkitem(struct map_session_data *sd) { int i, calc_flag = 0; struct item it; - nullpo_ret(sd); + nullpo_retv(sd); if( sd->state.vending ) //Avoid reorganizing items when we are vending, as that leads to exploits (pointed out by End of Exam) - return 0; + return; for( i = 0; i < MAX_INVENTORY; i++ ) { it = sd->status.inventory[i]; @@ -9110,17 +9076,17 @@ int pc_checkitem(struct map_session_data *sd) { status_calc_pc(sd,0); } - return 0; + return; } /*========================================== * Checks for unavailable items and removes them. *------------------------------------------*/ -int pc_check_available_item(struct map_session_data *sd) { +void pc_check_available_item(struct map_session_data *sd) { int i, it; char output[256]; - nullpo_ret(sd); + nullpo_retv(sd); if( battle_config.item_check&1 ) { // Check for invalid(ated) items in inventory. for( i = 0; i < MAX_INVENTORY; i++ ) { @@ -9160,14 +9126,12 @@ int pc_check_available_item(struct map_session_data *sd) { } } } - - return 0; } /*========================================== * Update PVP rank for sd1 in cmp to sd2 *------------------------------------------*/ -int pc_calc_pvprank_sub(struct block_list *bl,va_list ap) +static int pc_calc_pvprank_sub(struct block_list *bl,va_list ap) { struct map_session_data *sd1,*sd2; @@ -9189,10 +9153,9 @@ int pc_calc_pvprank_sub(struct block_list *bl,va_list ap) *------------------------------------------*/ int pc_calc_pvprank(struct map_session_data *sd) { - int old; - struct map_data *m; - m=&map[sd->bl.m]; - old=sd->pvp_rank; + int old = sd->pvp_rank; + struct map_data *m = &map[sd->bl.m]; + sd->pvp_rank=1; map_foreachinmap(pc_calc_pvprank_sub,sd->bl.m,BL_PC,sd); if(old!=sd->pvp_rank || sd->pvp_lastusers!=m->users_pvp) @@ -9239,43 +9202,43 @@ int pc_ismarried(struct map_session_data *sd) /*========================================== * Marry player sd to player dstsd * Return: - * -1 = fail - * 0 = success + * false = fail + * true = success *------------------------------------------*/ -int pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd) +bool pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd) { if(sd == NULL || dstsd == NULL || sd->status.partner_id > 0 || dstsd->status.partner_id > 0 || (sd->class_&JOBL_BABY) || (dstsd->class_&JOBL_BABY)) - return -1; + return false; sd->status.partner_id = dstsd->status.char_id; dstsd->status.partner_id = sd->status.char_id; - return 0; + return true; } /*========================================== * Divorce sd from its partner * Return: - * -1 = fail - * 0 = success + * false = fail + * true = success *------------------------------------------*/ -int pc_divorce(struct map_session_data *sd) +bool pc_divorce(struct map_session_data *sd) { struct map_session_data *p_sd; int i; if( sd == NULL || !pc_ismarried(sd) ) - return -1; + return false; if( !sd->status.partner_id ) - return -1; // Char is not married + return false; // Char is not married if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL ) { // Lets char server do the divorce if( chrif_divorce(sd->status.char_id, sd->status.partner_id) ) - return -1; // No char server connected + return false; // No char server connected - return 0; + return true; } // Both players online, lets do the divorce manually @@ -9292,7 +9255,7 @@ int pc_divorce(struct map_session_data *sd) clif_divorced(sd, p_sd->status.name); clif_divorced(p_sd, sd->status.name); - return 0; + return true; } /*========================================== @@ -9300,11 +9263,10 @@ int pc_divorce(struct map_session_data *sd) *------------------------------------------*/ struct map_session_data *pc_get_partner(struct map_session_data *sd) { - if (sd && pc_ismarried(sd)) + if (!sd || !pc_ismarried(sd)) // charid2sd returns NULL if not found - return map_charid2sd(sd->status.partner_id); - - return NULL; + return NULL; + return map_charid2sd(sd->status.partner_id); } /*========================================== @@ -9312,11 +9274,11 @@ struct map_session_data *pc_get_partner(struct map_session_data *sd) *------------------------------------------*/ struct map_session_data *pc_get_father (struct map_session_data *sd) { - if (sd && sd->class_&JOBL_BABY && sd->status.father > 0) + if (!sd || !sd->class_&JOBL_BABY || !sd->status.father) // charid2sd returns NULL if not found - return map_charid2sd(sd->status.father); + return NULL; - return NULL; + return map_charid2sd(sd->status.father); } /*========================================== @@ -9324,10 +9286,10 @@ struct map_session_data *pc_get_father (struct map_session_data *sd) *------------------------------------------*/ struct map_session_data *pc_get_mother (struct map_session_data *sd) { - if (sd && sd->class_&JOBL_BABY && sd->status.mother > 0) + if (!sd || sd->class_&JOBL_BABY || !sd->status.mother) // charid2sd returns NULL if not found - return map_charid2sd(sd->status.mother); - return NULL; + return NULL; + return map_charid2sd(sd->status.mother); } /*========================================== @@ -9335,11 +9297,10 @@ struct map_session_data *pc_get_mother (struct map_session_data *sd) *------------------------------------------*/ struct map_session_data *pc_get_child (struct map_session_data *sd) { - if (sd && pc_ismarried(sd) && sd->status.child > 0) + if (!sd || !pc_ismarried(sd) || !sd->status.child) // charid2sd returns NULL if not found - return map_charid2sd(sd->status.child); - - return NULL; + return NULL; + return map_charid2sd(sd->status.child); } /*========================================== @@ -9372,8 +9333,6 @@ void pc_bleeding (struct map_session_data *sd, unsigned int diff_tick) if (hp > 0 || sp > 0) status_zap(&sd->bl, hp, sp); - - return; } //Character regen. Flag is used to know which types of regen can take place. @@ -9401,28 +9360,24 @@ void pc_regen (struct map_session_data *sd, unsigned int diff_tick) if (hp > 0 || sp > 0) status_heal(&sd->bl, hp, sp, 0); - - return; } /*========================================== * Memo player sd savepoint. (map,x,y) *------------------------------------------*/ -int pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y) +void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y) { - nullpo_ret(sd); + nullpo_retv(sd); sd->status.save_point.map = mapindex; sd->status.save_point.x = x; sd->status.save_point.y = y; - - return 0; } /*========================================== * Save 1 player data at autosave intervalle *------------------------------------------*/ -int pc_autosave(int tid, unsigned int tick, int id, intptr_t data) +static int pc_autosave(int tid, unsigned int tick, int id, intptr_t data) { int interval; struct s_mapiterator* iter; @@ -9727,7 +9682,7 @@ int pc_level_penalty_mod(struct map_session_data *sd, int mob_level, uint32 mob_ return rate; } #endif -int pc_split_str(char *str,char **val,int num) +static int pc_split_str(char *str,char **val,int num) { int i; @@ -9740,7 +9695,7 @@ int pc_split_str(char *str,char **val,int num) return i; } -int pc_split_atoi(char* str, int* val, char sep, int max) +static int pc_split_atoi(char* str, int* val, char sep, int max) { int i,j; for (i=0; i= NAME_LENGTH ) - {// crashes newer clients + if( ( ptr = strstr(buf, " :") ) != NULL && ptr-buf >= NAME_LENGTH ) // crashes newer clients ShowWarning("Found sequence '"CL_WHITE" :"CL_RESET"' on line '"CL_WHITE"%u"CL_RESET"' in '"CL_WHITE"%s"CL_RESET"'. This can cause newer clients to crash.\n", lines, motd_txt); - } } else {// empty line buf[0] = ' '; @@ -10264,9 +10217,8 @@ int pc_read_motd(void) fclose(fp); ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, motd_txt); } - else { + else ShowWarning("File '"CL_WHITE"%s"CL_RESET"' not found.\n", motd_txt); - } return 0; } @@ -10309,7 +10261,7 @@ void pc_itemcd_do(struct map_session_data *sd, bool load) { * @param sd * @param md **/ -void pc_clear_log_damage_sub(int char_id, struct mob_data *md) +static void pc_clear_log_damage_sub(int char_id, struct mob_data *md) { uint8 i; ARR_FIND(0,DAMAGELOG_SIZE,i,md->dmglog[i].id == char_id); @@ -10323,7 +10275,7 @@ void pc_clear_log_damage_sub(int char_id, struct mob_data *md) /** * Add log to player's dmglog * @param sd -* @param id Monster's id +* @param id Monster's GID **/ void pc_damage_log_add(struct map_session_data *sd, int id) { @@ -10332,12 +10284,13 @@ void pc_damage_log_add(struct map_session_data *sd, int id) if (!sd) return; - for (i = 0; i < DAMAGELOG_SIZE_PC && sd->dmglog[i].id != id; i++) - if (!sd->dmglog[i].id) { - sd->dmglog[i].id = id; - break; - } - return; + //Only store new data, don't need to renew the old one with same id + for (i = 0; i < DAMAGELOG_SIZE_PC; i++) { + if (sd->dmglog[i] == id) + return; + sd->dmglog[i] = id; + return; + } } /** @@ -10349,26 +10302,27 @@ void pc_damage_log_clear(struct map_session_data *sd, int id) { uint8 i; struct mob_data *md = NULL; + if (!sd) return; if (!id) { for (i = 0; i < DAMAGELOG_SIZE_PC; i++) { - if( !sd->dmglog[i].id ) //skip the empty value + if( !sd->dmglog[i] ) //skip the empty value continue; - if ((md = map_id2md(sd->dmglog[i].id))) + if ((md = map_id2md(sd->dmglog[i]))) pc_clear_log_damage_sub(sd->status.char_id,md); + sd->dmglog[i] = 0; } - memset(sd->dmglog,0,sizeof(sd->dmglog)); // clear all } else { if ((md = map_id2md(id))) pc_clear_log_damage_sub(sd->status.char_id,md); - ARR_FIND(0,DAMAGELOG_SIZE_PC,i,sd->dmglog[i].id == id); // find the id position + ARR_FIND(0,DAMAGELOG_SIZE_PC,i,sd->dmglog[i] == id); // find the id position if (i < DAMAGELOG_SIZE_PC) - sd->dmglog[i].id = 0; + sd->dmglog[i] = 0; } } @@ -10445,15 +10399,17 @@ void pc_crimson_marker_clear(struct map_session_data *sd) { **/ void pc_show_version(struct map_session_data *sd) { const char* svn = get_svn_revision(); - const char* git = get_git_hash(); char buf[CHAT_SIZE_MAX]; if( svn[0] != UNKNOWN_VERSION ) sprintf(buf,msg_txt(sd,1295),"SVN: r",svn); //rAthena Version SVN: r%s - else if( git[0] != UNKNOWN_VERSION ) - sprintf(buf,msg_txt(sd,1295),"Git Hash: ",git); //rAthena Version Git Hash: %s - else - sprintf(buf,"%s",msg_txt(sd,1296)); //Cannot determine SVN/Git version. + else { + const char* git = get_git_hash(); + if( git[0] != UNKNOWN_VERSION ) + sprintf(buf,msg_txt(sd,1295),"Git Hash: ",git); //rAthena Version Git Hash: %s + else + sprintf(buf,"%s",msg_txt(sd,1296)); //Cannot determine SVN/Git version. + } clif_displaymessage(sd->fd,buf); } @@ -10495,7 +10451,7 @@ void pc_bonus_script_remove(struct map_session_data *sd, uint8 i) { script_free_code(sd->bonus_script[i].script); memset(&sd->bonus_script[i].script,0,sizeof(sd->bonus_script[i].script)); - memset(sd->bonus_script[i].script_str,'\0',sizeof(sd->bonus_script[i].script_str)); + *sd->bonus_script[i].script_str = '\0'; sd->bonus_script[i].tick = 0; sd->bonus_script[i].tid = 0; sd->bonus_script[i].flag = 0; @@ -10552,29 +10508,27 @@ void pc_cell_basilica(struct map_session_data *sd) { * @param flag: parameter will be checked * @return max_param */ -short pc_maxparameter(int class_, int sex, enum e_params param) { - short max_param = 0; - int idx = -1; +short pc_maxparameter(struct map_session_data *sd, enum e_params param) { + int idx = -1, class_ = sd->class_; - max_param = ((class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_parameter : - ((class_&JOBL_THIRD) ? ((class_&JOBL_UPPER) ? battle_config.max_third_trans_parameter : ((class_&JOBL_BABY) ? battle_config.max_baby_third_parameter : battle_config.max_third_parameter)) : - ((class_&JOBL_BABY) ? battle_config.max_baby_parameter : - ((class_&JOBL_UPPER) ? battle_config.max_trans_parameter : battle_config.max_parameter))); - - if ((idx = pc_class2idx(pc_mapid2jobid(class_,sex))) >= 0) { - short max_param_ = 0; + if ((idx = pc_class2idx(pc_mapid2jobid(class_,sd->status.sex))) >= 0) { + short max_param = 0; switch (param) { - case PARAM_STR: max_param_ = job_info[idx].max_param.str; break; - case PARAM_AGI: max_param_ = job_info[idx].max_param.agi; break; - case PARAM_VIT: max_param_ = job_info[idx].max_param.vit; break; - case PARAM_INT: max_param_ = job_info[idx].max_param.int_; break; - case PARAM_DEX: max_param_ = job_info[idx].max_param.dex; break; - case PARAM_LUK: max_param_ = job_info[idx].max_param.luk; break; + case PARAM_STR: max_param = job_info[idx].max_param.str; break; + case PARAM_AGI: max_param = job_info[idx].max_param.agi; break; + case PARAM_VIT: max_param = job_info[idx].max_param.vit; break; + case PARAM_INT: max_param = job_info[idx].max_param.int_; break; + case PARAM_DEX: max_param = job_info[idx].max_param.dex; break; + case PARAM_LUK: max_param = job_info[idx].max_param.luk; break; } - if (max_param_ > 0) - return max_param_; + if (max_param > 0) + return max_param; } - return max_param; + + return ((class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO || (class_&MAPID_UPPERMASK) == MAPID_REBELLION) ? battle_config.max_extended_parameter : + ((class_&JOBL_THIRD) ? ((class_&JOBL_UPPER) ? battle_config.max_third_trans_parameter : ((class_&JOBL_BABY) ? battle_config.max_baby_third_parameter : battle_config.max_third_parameter)) : + ((class_&JOBL_BABY) ? battle_config.max_baby_parameter : + ((class_&JOBL_UPPER) ? battle_config.max_trans_parameter : battle_config.max_parameter))); } /*========================================== diff --git a/src/map/pc.h b/src/map/pc.h index 5afec103c27..206b307075b 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -128,10 +128,10 @@ struct skill_cooldown_entry { }; #ifdef VIP_ENABLE - struct vip_info { - unsigned int enabled : 1; - time_t time; - }; +struct vip_info { + unsigned int enabled : 1; + time_t time; +}; #endif enum npc_timeout_type { @@ -150,7 +150,7 @@ struct map_session_data { struct regen_data_sub sregen, ssregen; //NOTE: When deciding to add a flag to state or special_state, take into consideration that state is preserved in //status_calc_pc, while special_state is recalculated in each call. [Skotlex] - struct { + struct s_state { unsigned int active : 1; //Marks active player (not active is logging in/out, or changing map servers) unsigned int menu_or_input : 1;// if a script is waiting for feedback from the player unsigned int dead_sit : 2; @@ -242,12 +242,12 @@ struct map_session_data { unsigned int chatID; time_t idletime; - struct{ + struct s_progressbar { int npc_id; unsigned int timeout; } progressbar; //Progress Bar [Inkfish] - struct{ + struct s_ignore { char name[NAME_LENGTH]; } ignore[MAX_IGNORE_LIST]; @@ -274,7 +274,7 @@ struct map_session_data { unsigned int cansendmail_tick; // [Mail System Flood Protection] unsigned int ks_floodprotect_tick; // [Kill Steal Protection] - struct { + struct s_item_delay { short nameid; unsigned int tick; } item_delay[MAX_ITEMDELAYS]; // [Paradox924X] @@ -316,11 +316,11 @@ struct map_session_data { struct s_addeffect addeff[MAX_PC_BONUS], addeff2[MAX_PC_BONUS]; struct s_addeffectonskill addeff3[MAX_PC_BONUS]; - struct { //skillatk raises bonus dmg% of skills, skillheal increases heal%, skillblown increases bonus blewcount for some skills. + struct s_skill_bonus { //skillatk raises bonus dmg% of skills, skillheal increases heal%, skillblown increases bonus blewcount for some skills. unsigned short id; short val; } skillatk[MAX_PC_BONUS], skillusesprate[MAX_PC_BONUS], skillusesp[MAX_PC_BONUS], skillheal[5], skillheal2[5], skillblown[MAX_PC_BONUS], skillcast[MAX_PC_BONUS], skillcooldown[MAX_PC_BONUS], skillfixcast[MAX_PC_BONUS], skillvarcast[MAX_PC_BONUS], skillfixcastrate[MAX_PC_BONUS]; - struct { + struct s_regen { short value; int rate; int tick; @@ -329,11 +329,11 @@ struct map_session_data { short class_, rate; } add_def[MAX_PC_BONUS], add_mdef[MAX_PC_BONUS], add_mdmg[MAX_PC_BONUS]; struct s_add_drop add_drop[MAX_PC_BONUS]; - struct { + struct s_healrate { int nameid; int rate; } itemhealrate[MAX_PC_BONUS]; - struct { + struct s_subele2 { short flag, rate; unsigned char ele; } subele2[MAX_PC_BONUS]; @@ -346,7 +346,7 @@ struct map_session_data { struct s_autobonus autobonus[MAX_PC_BONUS], autobonus2[MAX_PC_BONUS], autobonus3[MAX_PC_BONUS]; //Auto script on attack, when attacked, on skill usage // manually zeroed structures end here. // zeroed vars start here. - struct { + struct s_bonus { int hp, sp; int atk_rate; int arrow_atk,arrow_ele,arrow_cri,arrow_hit; @@ -415,8 +415,8 @@ struct map_session_data { struct script_regstr *regstr; int trade_partner; - struct { - struct { + struct s_deal { + struct s_item { short index, amount; } item[10]; int zeny, weight; @@ -450,10 +450,10 @@ struct map_session_data { struct mercenary_data *md; struct elemental_data *ed; - struct{ + struct s_hate_mob { int m; //-1 - none, other: map index corresponding to map name. unsigned short index; //map index - }feel_map[3];// 0 - Sun; 1 - Moon; 2 - Stars + } feel_map[3];// 0 - Sun; 1 - Moon; 2 - Stars short hate_mob[3]; int pvp_timer; @@ -479,12 +479,12 @@ struct map_session_data { int rental_timer; // Auction System [Zephyrus] - struct { + struct s_auction{ int index, amount; } auction; // Mail System [Zephyrus] - struct { + struct s_mail { short nameid; int index, amount, zeny; struct mail_data inbox; @@ -524,7 +524,7 @@ struct map_session_data { enum npc_timeout_type npc_idle_type; #endif - struct { + struct s_combos { struct script_code **bonus;/* the script */ unsigned short *id;/* array of combo ids */ unsigned char count; @@ -549,9 +549,7 @@ struct map_session_data { const char* delunit_prevfile; int delunit_prevline; - struct { - int id; - } dmglog[DAMAGELOG_SIZE_PC]; + uint16 dmglog[DAMAGELOG_SIZE_PC]; ///target ids struct s_crimson_marker { ///Store target that marked by Crimson Marker [Cydh] int target[MAX_SKILL_CRIMSON_MARKER]; //Target id storage @@ -724,7 +722,7 @@ enum e_params { PARAM_LUK, PARAM_MAX }; -short pc_maxparameter(int class_, int sex, enum e_params param); +short pc_maxparameter(struct map_session_data *sd, enum e_params param); /** * Ranger @@ -813,19 +811,18 @@ int pc_equippoint(struct map_session_data *sd,int n); int pc_setinventorydata(struct map_session_data *sd); int pc_checkskill(struct map_session_data *sd,uint16 skill_id); -int pc_checkallowskill(struct map_session_data *sd); -int pc_checkequip(struct map_session_data *sd,int pos); -int pc_checkequip2(struct map_session_data *sd,int nameid,int min, int max); +short pc_checkequip(struct map_session_data *sd,int pos); +bool pc_checkequip2(struct map_session_data *sd,int nameid,int min, int max); int pc_calc_skilltree(struct map_session_data *sd); int pc_calc_skilltree_normalize_job(struct map_session_data *sd); -int pc_clean_skilltree(struct map_session_data *sd); +void pc_clean_skilltree(struct map_session_data *sd); #define pc_checkoverhp(sd) ((sd)->battle_status.hp == (sd)->battle_status.max_hp) #define pc_checkoversp(sd) ((sd)->battle_status.sp == (sd)->battle_status.max_sp) int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype); -int pc_setsavepoint(struct map_session_data*,short,int,int); +void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y); int pc_randomwarp(struct map_session_data *sd,clr_type type); int pc_memo(struct map_session_data* sd, int pos); @@ -902,10 +899,10 @@ int pc_resetstate(struct map_session_data*); int pc_resetskill(struct map_session_data*, int); int pc_resetfeel(struct map_session_data*); int pc_resethate(struct map_session_data*); -int pc_equipitem(struct map_session_data*,int,int); -int pc_unequipitem(struct map_session_data*,int,int); -int pc_checkitem(struct map_session_data*); -int pc_check_available_item(struct map_session_data *sd); +bool pc_equipitem(struct map_session_data*,int,int); +bool pc_unequipitem(struct map_session_data*,int,int); +void pc_checkitem(struct map_session_data*); +void pc_check_available_item(struct map_session_data *sd); int pc_useitem(struct map_session_data*,int); int pc_skillatk_bonus(struct map_session_data *sd, uint16 skill_id); @@ -919,20 +916,20 @@ void pc_heal(struct map_session_data *sd,unsigned int hp,unsigned int sp, int ty int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp); int pc_percentheal(struct map_session_data *sd,int,int); int pc_jobchange(struct map_session_data *,int, int); -int pc_setoption(struct map_session_data *,int); -int pc_setcart(struct map_session_data* sd, int type); -int pc_setfalcon(struct map_session_data* sd, int flag); -int pc_setriding(struct map_session_data* sd, int flag); -int pc_setmadogear(struct map_session_data* sd, int flag); -int pc_changelook(struct map_session_data *,int,int); -int pc_equiplookall(struct map_session_data *sd); +void pc_setoption(struct map_session_data *,int); +bool pc_setcart(struct map_session_data* sd, int type); +void pc_setfalcon(struct map_session_data* sd, int flag); +void pc_setriding(struct map_session_data* sd, int flag); +void pc_setmadogear(struct map_session_data* sd, int flag); +void pc_changelook(struct map_session_data *,int,int); +void pc_equiplookall(struct map_session_data *sd); int pc_readparam(struct map_session_data*,int); -int pc_setparam(struct map_session_data*,int,int); +bool pc_setparam(struct map_session_data*,int,int); int pc_readreg(struct map_session_data*,int); -int pc_setreg(struct map_session_data*,int,int); +bool pc_setreg(struct map_session_data*,int,int); char *pc_readregstr(struct map_session_data *sd,int reg); -int pc_setregstr(struct map_session_data *sd,int reg,const char *str); +bool pc_setregstr(struct map_session_data *sd,int reg,const char *str); #define pc_readglobalreg(sd,reg) pc_readregistry(sd,reg,3) #define pc_setglobalreg(sd,reg,val) pc_setregistry(sd,reg,val,3) @@ -947,21 +944,21 @@ int pc_setregstr(struct map_session_data *sd,int reg,const char *str); #define pc_readaccountreg2str(sd,reg) pc_readregistry_str(sd,reg,1) #define pc_setaccountreg2str(sd,reg,val) pc_setregistry_str(sd,reg,val,1) int pc_readregistry(struct map_session_data*,const char*,int); -int pc_setregistry(struct map_session_data*,const char*,int,int); +bool pc_setregistry(struct map_session_data*,const char*,int,int); char *pc_readregistry_str(struct map_session_data*,const char*,int); -int pc_setregistry_str(struct map_session_data*,const char*,const char*,int); +bool pc_setregistry_str(struct map_session_data*,const char*,const char*,int); -int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name); -int pc_deleventtimer(struct map_session_data *sd,const char *name); -int pc_cleareventtimer(struct map_session_data *sd); -int pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick); +bool pc_addeventtimer(struct map_session_data *sd,int tick,const char *name); +bool pc_deleventtimer(struct map_session_data *sd,const char *name); +void pc_cleareventtimer(struct map_session_data *sd); +void pc_addeventtimercount(struct map_session_data *sd,const char *name,int tick); int pc_calc_pvprank(struct map_session_data *sd); int pc_calc_pvprank_timer(int tid, unsigned int tick, int id, intptr_t data); int pc_ismarried(struct map_session_data *sd); -int pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd); -int pc_divorce(struct map_session_data *sd); +bool pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd); +bool pc_divorce(struct map_session_data *sd); struct map_session_data *pc_get_partner(struct map_session_data *sd); struct map_session_data *pc_get_father(struct map_session_data *sd); struct map_session_data *pc_get_mother(struct map_session_data *sd); @@ -971,7 +968,7 @@ void pc_bleeding (struct map_session_data *sd, unsigned int diff_tick); void pc_regen (struct map_session_data *sd, unsigned int diff_tick); void pc_setstand(struct map_session_data *sd); -int pc_candrop(struct map_session_data *sd,struct item *item); +bool pc_candrop(struct map_session_data *sd,struct item *item); int pc_jobid2mapid(unsigned short b_class); // Skotlex int pc_mapid2jobid(unsigned short class_, int sex); // Skotlex @@ -1006,7 +1003,7 @@ int pc_addspiritball(struct map_session_data *sd,int,int); int pc_delspiritball(struct map_session_data *sd,int,int); void pc_addfame(struct map_session_data *sd,int count); unsigned char pc_famerank(int char_id, int job); -int pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl); +bool pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl); extern struct fame_list smith_fame_list[MAX_FAME_LIST]; extern struct fame_list chemist_fame_list[MAX_FAME_LIST]; @@ -1070,9 +1067,6 @@ void pc_bonus_script_clear(struct map_session_data *sd, uint16 flag); void pc_cell_basilica(struct map_session_data *sd); -unsigned int pc_get_maxhp(uint16 level, uint16 class_, uint16 vit, int bonus, int bonus_rate); -unsigned int pc_get_maxsp(uint16 level, uint16 class_, uint16 int_, int bonus, int bonus_rate); - #if defined(RENEWAL_DROP) || defined(RENEWAL_EXP) int pc_level_penalty_mod(struct map_session_data *sd, int mob_level, uint32 mob_race, uint32 mob_mode, int type); #endif diff --git a/src/map/script.c b/src/map/script.c index 38302df8736..fcd12d43079 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11779,7 +11779,7 @@ BUILDIN_FUNC(marriage) TBL_PC *sd=script_rid2sd(st); TBL_PC *p_sd=map_nick2sd(partner); - if(sd==NULL || p_sd==NULL || pc_marriage(sd,p_sd) < 0){ + if(!sd || !p_sd || !pc_marriage(sd,p_sd)){ script_pushint(st,0); return 0; } @@ -11803,7 +11803,7 @@ BUILDIN_FUNC(wedding_effect) BUILDIN_FUNC(divorce) { TBL_PC *sd=script_rid2sd(st); - if(sd==NULL || pc_divorce(sd) < 0){ + if(!sd || !pc_divorce(sd)){ script_pushint(st,0); return 0; } @@ -17345,6 +17345,18 @@ BUILDIN_FUNC(get_revision) { script_pushint(st,-1); //unknown return SCRIPT_CMD_SUCCESS; } +/* get_hash() -> retrieves the current git hash (if available)*/ +BUILDIN_FUNC(get_githash) { + const char* git = get_git_hash(); + char buf[CHAT_SIZE_MAX]; + safestrncpy(buf,git,strlen(git)+1); + + if ( git[0] != UNKNOWN_VERSION ) + script_pushstr(st,buf); + else + script_pushstr(st,"Unknown"); //unknown + return SCRIPT_CMD_SUCCESS; +} /** * freeloop() -> toggles this script instance's looping-check ability **/ @@ -17568,7 +17580,7 @@ BUILDIN_FUNC(getgroupitem) { if (!(sd = script_rid2sd(st))) return SCRIPT_CMD_SUCCESS; - if (itemdb_pc_get_itemgroup(group_id,sd->itemid,sd)) { + if (itemdb_pc_get_itemgroup(group_id,sd)) { ShowError("getgroupitem: Invalid group id '%d' specified.",group_id); return SCRIPT_CMD_FAILURE; } @@ -18224,7 +18236,7 @@ BUILDIN_FUNC(bonus_script) { uint32 dur; char type = 0; TBL_PC* sd; - const char *script_str = NULL; + const char *script_str = '\0'; struct script_code *script = NULL; if (script_hasdata(st,7)) @@ -18241,7 +18253,7 @@ BUILDIN_FUNC(bonus_script) { FETCH(5,type); FETCH(6,icon); - if (!strlen(script_str) || !dur) { + if (script_str == '\0' || !dur) { //ShowWarning("buildin_bonus_script: Invalid value(s). Skipping...\n"); return 0; } @@ -18719,6 +18731,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(getcharip,"?"), BUILDIN_DEF(is_function,"s"), BUILDIN_DEF(get_revision,""), + BUILDIN_DEF(get_githash,""), BUILDIN_DEF(freeloop,"i"), BUILDIN_DEF(getrandgroupitem,"ii?"), BUILDIN_DEF(cleanmap,"s"), diff --git a/src/map/status.c b/src/map/status.c index a5702f13e75..671dc6f40a8 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -2074,6 +2074,7 @@ unsigned short status_base_matk(const struct status_data* status, int level) { r **/ void status_calc_misc(struct block_list *bl, struct status_data *status, int level) { + int stat; // Non players get the value set, players need to stack with previous bonuses. if( bl->type != BL_PC ) status->batk = @@ -2083,34 +2084,71 @@ void status_calc_misc(struct block_list *bl, struct status_data *status, int lev #ifdef RENEWAL // Renewal formulas if (bl->type == BL_MOB) { - status->hit += level + status->dex + 175; - status->flee += level + status->agi + 100; + //Hit + stat = status->hit; + stat += level + status->dex + 175; + status->hit = cap_value(stat,1,SHRT_MAX); + //Flee + stat = status->flee; + stat += level + status->agi + 100; + status->flee = cap_value(stat,1,SHRT_MAX); } else if (bl->type == BL_HOM) { - status->hit = level + status->dex + 150; // base level + dex + 150 - status->flee = level + status->agi + level/10; // base level + agi + base level/10 + status->hit = cap_value(level + status->dex + 150,1,SHRT_MAX); // base level + dex + 150 + status->flee = cap_value(level + status->agi + level/10,1,SHRT_MAX); // base level + agi + base level/10 } else { - status->hit += level + status->dex + status->luk/3 + 175; // base level + ( every 1 dex = +1 hit ) + (every 3 luk = +1 hit) + 175 - status->flee += level + status->agi + status->luk/5 + 100; // base level + ( every 1 agi = +1 flee ) + (every 5 luk = +1 flee) + 100 + //Hit + stat = status->hit; + stat += level + status->dex + status->luk/3 + 175; // base level + ( every 1 dex = +1 hit ) + (every 3 luk = +1 hit) + 175 + status->hit = cap_value(stat,1,SHRT_MAX); + //Flee + stat = status->flee; + stat += level + status->agi + status->luk/5 + 100; // base level + ( every 1 agi = +1 flee ) + (every 5 luk = +1 flee) + 100 + status->flee = cap_value(stat,1,SHRT_MAX); } status->matk_min = status->matk_max = status_base_matk(status, level); - status->def2 += (int)(((float)level + status->vit)/2 + ((float)status->agi/5)); // base level + (every 2 vit = +1 def) + (every 5 agi = +1 def) - status->mdef2 += (int)(status->int_ + ((float)level/4) + ((float)status->dex/5) + ((float)status->vit/5)); // (every 4 base level = +1 mdef) + (every 1 int = +1 mdef) + (every 5 dex = +1 mdef) + (every 5 vit = +1 mdef) + //Def2 + stat = status->def2; + stat += (int)(((float)level + status->vit)/2 + ((float)status->agi/5)); // base level + (every 2 vit = +1 def) + (every 5 agi = +1 def) + status->def2 = cap_value(stat,0,SHRT_MAX); + //MDef2 + stat = status->mdef2; + stat += (int)(status->int_ + ((float)level/4) + ((float)status->dex/5) + ((float)status->vit/5)); // (every 4 base level = +1 mdef) + (every 1 int = +1 mdef) + (every 5 dex = +1 mdef) + (every 5 vit = +1 mdef) + status->mdef2 = cap_value(stat,0,SHRT_MAX); #else status->matk_min = status_base_matk_min(status); status->matk_max = status_base_matk_max(status); - status->hit += level + status->dex; - status->flee += level + status->agi; - status->def2 += status->vit; - status->mdef2 += status->int_ + (status->vit>>1); + //Hit + stat = status->hit; + stat += level + status->dex; + status->hit = cap_value(stat,1,SHRT_MAX); + //Flee + stat = status->flee; + stat += level + status->agi; + status->flee = cap_value(stat,1,SHRT_MAX); + //Def2 + stat = status->def2; + stat += status->vit; + status->def2 = cap_value(stat,0,SHRT_MAX); + //MDef2 + stat = status->mdef2; + stat += status->int_ + (status->vit>>1); + status->mdef2 = cap_value(stat,0,SHRT_MAX); #endif - if( bl->type&battle_config.enable_critical ) - status->cri += 10 + (status->luk*10/3); // (every 1 luk = +0.3 critical) + //Critical + if( bl->type&battle_config.enable_critical ) { + stat = status->cri; + stat += 10 + (status->luk*10/3); // (every 1 luk = +0.3 critical) + status->cri = cap_value(stat,1,SHRT_MAX); + } else status->cri = 0; - if (bl->type&battle_config.enable_perfect_flee) - status->flee2 += status->luk + 10; // (every 10 luk = +1 perfect flee) + if (bl->type&battle_config.enable_perfect_flee) { + stat = status->flee2; + stat += status->luk + 10; // (every 10 luk = +1 perfect flee) + status->flee2 = cap_value(stat,0,SHRT_MAX); + } else status->flee2 = 0; @@ -2123,7 +2161,7 @@ void status_calc_misc(struct block_list *bl, struct status_data *status, int lev switch (bl->type) { case BL_MOB: if(battle_config.mob_critical_rate != 100) - status->cri = status->cri*battle_config.mob_critical_rate/100; + status->cri = cap_value(status->cri*battle_config.mob_critical_rate/100,1,SHRT_MAX); if(!status->cri && battle_config.mob_critical_rate) status->cri = 10; break; @@ -2132,7 +2170,7 @@ void status_calc_misc(struct block_list *bl, struct status_data *status, int lev break; default: if(battle_config.critical_rate != 100) - status->cri = status->cri*battle_config.critical_rate/100; + status->cri = cap_value(status->cri*battle_config.critical_rate/100,1,SHRT_MAX); if (!status->cri && battle_config.critical_rate) status->cri = 10; } @@ -3184,7 +3222,7 @@ int status_calc_pc_(struct map_session_data* sd, bool first) if(sd->critical_rate < 0) sd->critical_rate = 0; if(sd->critical_rate != 100) - status->cri = status->cri * sd->critical_rate/100; + status->cri = cap_value(status->cri * sd->critical_rate/100,SHRT_MIN,SHRT_MAX); if(sd->flee2_rate < 0) sd->flee2_rate = 0;