From 2b870c24d5453e301d92a72aa2cb73dc2ec3cce2 Mon Sep 17 00:00:00 2001 From: aleos89 Date: Thu, 2 Oct 2014 09:16:52 -0400 Subject: [PATCH] Various cleanups. * Added and cleaned up comments. * Added checks to prevent map server crashes. * Cleaned up some reports from CPPCheck. * Other various stylization cleanups. --- src/map/battle.c | 349 ++++++----- src/map/battleground.c | 59 +- src/map/channel.c | 7 +- src/map/clif.c | 15 +- src/map/party.c | 405 +++++++------ src/map/path.c | 23 +- src/map/pc.c | 2 +- src/map/quest.c | 60 +- src/map/script.c | 123 ++-- src/map/searchstore.c | 113 ++-- src/map/skill.c | 1294 ++++++++++++++++++++-------------------- src/map/status.c | 1180 ++++++++++++++++++------------------ src/map/trade.c | 133 +++-- src/map/unit.c | 23 +- src/map/vending.c | 105 ++-- 15 files changed, 2036 insertions(+), 1855 deletions(-) diff --git a/src/map/battle.c b/src/map/battle.c index 578f62020e..d1b1c48353 100644 --- a/src/map/battle.c +++ b/src/map/battle.c @@ -44,23 +44,33 @@ static struct eri *delay_damage_ers; //For battle delay damage structures. #define DAMAGE_SUBRATE(a) { damage -= (int64)damage * (a) / 100; } #define DAMAGE_ADDRATE(a) { damage += (int64)damage * (a) / 100; } -int battle_getcurrentskill(struct block_list *bl) { //Returns the current/last skill in use by this bl. +/** + * Returns the current/list skill used by the bl + * @param bl + * @return skill_id + */ +int battle_getcurrentskill(struct block_list *bl) +{ struct unit_data *ud; if( bl->type == BL_SKILL ) { - struct skill_unit * su = (struct skill_unit*)bl; - return su->group?su->group->skill_id:0; + struct skill_unit *su = (struct skill_unit*)bl; + return (su && su->group?su->group->skill_id:0); } ud = unit_bl2ud(bl); - return ud?ud->skill_id:0; + return (ud?ud->skill_id:0); } -/*========================================== - * Get random targetting enemy - *------------------------------------------*/ -static int battle_gettargeted_sub(struct block_list *bl, va_list ap) { +/** + * Get random targeting enemy + * @param bl + * @param ap + * @return Found target (1) or not found (0) + */ +static int battle_gettargeted_sub(struct block_list *bl, va_list ap) +{ struct block_list **bl_list; struct unit_data *ud; int target_id; @@ -87,7 +97,13 @@ static int battle_gettargeted_sub(struct block_list *bl, va_list ap) { return 0; } -struct block_list* battle_gettargeted(struct block_list *target) { +/** + * Returns list of targets + * @param target + * @return Target list + */ +struct block_list* battle_gettargeted(struct block_list *target) +{ struct block_list *bl_list[24]; int c = 0; nullpo_retr(NULL, target); @@ -101,9 +117,14 @@ struct block_list* battle_gettargeted(struct block_list *target) { return bl_list[rnd()%c]; } - -//Returns the id of the current targetted character of the passed bl. [Skotlex] -int battle_gettarget(struct block_list* bl) { +/** + * Returns the ID of the current targeted character of the passed bl + * @param bl + * @return Target Unit ID + * @author [Skotlex] + */ +int battle_gettarget(struct block_list* bl) +{ switch (bl->type) { case BL_PC: return ((struct map_session_data*)bl)->ud.target; @@ -117,7 +138,14 @@ int battle_gettarget(struct block_list* bl) { return 0; } -static int battle_getenemy_sub(struct block_list *bl, va_list ap) { +/** + * Get random enemy + * @param bl + * @param ap + * @return Found target (1) or not found (0) + */ +static int battle_getenemy_sub(struct block_list *bl, va_list ap) +{ struct block_list **bl_list; struct block_list *target; int *c; @@ -143,8 +171,16 @@ static int battle_getenemy_sub(struct block_list *bl, va_list ap) { return 0; } -// Picks a random enemy of the given type (BL_PC, BL_CHAR, etc) within the range given. [Skotlex] -struct block_list* battle_getenemy(struct block_list *target, int type, int range) { +/** + * Returns list of enemies within given range + * @param target + * @param type + * @param range + * @return Target list + * @author [Skotlex] + */ +struct block_list* battle_getenemy(struct block_list *target, int type, int range) +{ struct block_list *bl_list[24]; int c = 0; @@ -159,7 +195,15 @@ struct block_list* battle_getenemy(struct block_list *target, int type, int rang return bl_list[rnd()%c]; } -static int battle_getenemyarea_sub(struct block_list *bl, va_list ap) { + +/** + * Get random enemy within area + * @param bl + * @param ap + * @return Found target (1) or not found (0) + */ +static int battle_getenemyarea_sub(struct block_list *bl, va_list ap) +{ struct block_list **bl_list, *src; int *c, ignore_id; @@ -185,8 +229,18 @@ static int battle_getenemyarea_sub(struct block_list *bl, va_list ap) { return 0; } -// Pick a random enemy -struct block_list* battle_getenemyarea(struct block_list *src, int x, int y, int range, int type, int ignore_id) { +/** + * Returns list of enemies within an area + * @param src + * @param x + * @param y + * @param range + * @param type + * @param ignore_id + * @return Target list + */ +struct block_list* battle_getenemyarea(struct block_list *src, int x, int y, int range, int type, int ignore_id) +{ struct block_list *bl_list[24]; int c = 0; @@ -201,7 +255,7 @@ struct block_list* battle_getenemyarea(struct block_list *src, int x, int y, int return bl_list[rnd()%c]; } -// Damage delayed info +/// Damage Delayed Structure struct delay_damage { int src_id; int target_id; @@ -216,7 +270,8 @@ struct delay_damage { enum bl_type src_type; }; -int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr_t data) { +int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr_t data) +{ struct delay_damage *dat = (struct delay_damage *)data; if ( dat ) { @@ -246,10 +301,7 @@ int battle_delay_damage_sub(int tid, unsigned int tick, int id, intptr_t data) { if( dat->dmg_lv > ATK_BLOCK && dat->attack_type ) skill_counter_additional_effect(src,target,dat->skill_id,dat->skill_lv,dat->attack_type,tick); map_freeblock_unlock(); - } else if( !src && dat->skill_id == CR_REFLECTSHIELD ) { - /** - * it was monster reflected damage, and the monster died, we pass the damage to the character as expected - **/ + } else if( !src && dat->skill_id == CR_REFLECTSHIELD ) { // it was monster reflected damage, and the monster died, we pass the damage to the character as expected map_freeblock_lock(); status_fix_damage(target, target, dat->damage, dat->delay); map_freeblock_unlock(); @@ -310,11 +362,11 @@ int battle_delay_damage(unsigned int tick, int amotion, struct block_list *src, } /** -* Get attribute ratio -* @param atk_elem Attack element enum e_element -* @param def_type Defense element enum e_element -* @param def_lv Element level 1 ~ MAX_ELE_LEVEL -*/ + * Get attribute ratio + * @param atk_elem Attack element enum e_element + * @param def_type Defense element enum e_element + * @param def_lv Element level 1 ~ MAX_ELE_LEVEL + */ int battle_attr_ratio(int atk_elem,int def_type, int def_lv) { if (!CHK_ELEMENT(atk_elem) || !CHK_ELEMENT(def_type) || !CHK_ELEMENT_LEVEL(def_lv)) return 100; @@ -322,14 +374,21 @@ int battle_attr_ratio(int atk_elem,int def_type, int def_lv) { return attr_fix_table[def_lv-1][atk_elem][def_type]; } -/*========================================== +/** * Does attribute fix modifiers. * Added passing of the chars so that the status changes can affect it. [Skotlex] * Note: Passing src/target == NULL is perfectly valid, it skips SC_ checks. - *------------------------------------------*/ + * @param src + * @param target + * @param damage + * @param atk_elem + * @param def_type + * @param def_lv + * @return damage + */ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 damage,int atk_elem,int def_type, int def_lv) { - struct status_change *sc=NULL, *tsc=NULL; + struct status_change *sc = NULL, *tsc = NULL; int ratio; if (src) sc = status_get_sc(src); @@ -339,7 +398,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d atk_elem = rnd()%ELE_ALL; if (!CHK_ELEMENT(def_type) || !CHK_ELEMENT_LEVEL(def_lv)) { - ShowError("battle_attr_fix: unknown attr type: atk=%d def_type=%d def_lv=%d\n",atk_elem,def_type,def_lv); + ShowError("battle_attr_fix: unknown attribute type: atk=%d def_type=%d def_lv=%d\n",atk_elem,def_type,def_lv); return damage; } @@ -360,6 +419,7 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d break; } } + if( target && target->type == BL_SKILL ) { if( atk_elem == ELE_FIRE && battle_getcurrentskill(target) == GN_WALLOFTHORN ) { struct skill_unit *su = (struct skill_unit*)target; @@ -381,7 +441,6 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d } } - if( tsc && tsc->count ) { //increase dmg by target status switch(atk_elem) { case ELE_FIRE: @@ -424,9 +483,19 @@ int64 battle_attr_fix(struct block_list *src, struct block_list *target, int64 d return (int64)damage*ratio/100; } -/*========================================== +/** * Calculates card bonuses damage adjustments. - *------------------------------------------*/ + * @param attack_type + * @param src + * @param target + * @param nk + * @param s_ele + * @param s_ele_ + * @param damage + * @param left + * @param flag + * @return damage + */ int battle_calc_cardfix(int attack_type, struct block_list *src, struct block_list *target, int nk, int s_ele, int s_ele_, int64 damage, int left, int flag){ struct map_session_data *sd, *tsd; short cardfix = 1000, t_class, s_class, s_race2, t_race2; @@ -718,11 +787,18 @@ int battle_calc_cardfix(int attack_type, struct block_list *src, struct block_li return (int)(damage - original_damage); } -/*========================================== +/** * Check damage through status. - * ATK may be MISS, BLOCKED FAIL, reduc, increase, end status... + * ATK may be MISS, BLOCKED FAIL, reduc, increase, end status. * After this we apply bg/gvg reduction - *------------------------------------------*/ + * @param src + * @param bl + * @param d + * @param damage + * @param skill_id + * @param skill_lv + * @return damage + */ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Damage *d,int64 damage,uint16 skill_id,uint16 skill_lv) { struct map_session_data *sd = NULL; @@ -764,10 +840,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam if (skill_id == PA_PRESSURE) return damage; //This skill bypass everything else. - if( sc && sc->count ) { - /** - * SC_* that reduce damage to 0. - **/ + if( sc && sc->count ) { // SC_* that reduce damage to 0. if( sc->data[SC_BASILICA] && !(status_get_mode(src)&MD_BOSS) ) { d->dmg_lv = ATK_BLOCK; return 0; @@ -1010,9 +1083,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam status_change_end(bl,SC_VOICEOFSIREN,INVALID_TIMER); } - /** - * Damage reductions - **/ + // Damage reductions // Assumptio doubles the def & mdef on RE mode, otherwise gives a reduction on the final damage. [Igniz] #ifndef RENEWAL if( sc->data[SC_ASSUMPTIO] ) { @@ -1286,9 +1357,14 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam return damage; } -/*========================================== +/** * Calculates BG related damage adjustments. - *------------------------------------------ + * @param src + * @param bl + * @param damage + * @param skill_id + * @param flag + * @return damage * Credits: * Original coder Skoltex * Initial refactoring by Baalberith @@ -1326,6 +1402,14 @@ int64 battle_calc_bg_damage(struct block_list *src, struct block_list *bl, int64 return damage; } +/** + * Determines whether target can be hit + * @param src + * @param bl + * @param skill_id + * @param flag + * @return Can be hit (true) or can't be hit (false) + */ bool battle_can_hit_gvg_target(struct block_list *src,struct block_list *bl,uint16 skill_id,int flag) { struct mob_data* md = BL_CAST(BL_MOB, bl); @@ -1347,9 +1431,15 @@ bool battle_can_hit_gvg_target(struct block_list *src,struct block_list *bl,uint return true; } -/*========================================== +/** * Calculates GVG related damage adjustments. - *------------------------------------------*/ + * @param src + * @param bl + * @param damage + * @param skill_id + * @param flag + * @return damage + */ int64 battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int64 damage,uint16 skill_id,int flag) { if (!damage) //No reductions to make. @@ -1381,9 +1471,13 @@ int64 battle_calc_gvg_damage(struct block_list *src,struct block_list *bl,int64 return damage; } -/*========================================== +/** * HP/SP drain calculation - *------------------------------------------*/ + * @param damage + * @param rate + * @param per + * @return diff + */ static int battle_calc_drain(int64 damage, int rate, int per) { int64 diff = 0; @@ -1400,9 +1494,14 @@ static int battle_calc_drain(int64 damage, int rate, int per) return (int)diff; } -/*========================================== +/** * Passive skill damage increases - *------------------------------------------*/ + * @param sd + * @param target + * @param dmg + * @param type + * @return damage + */ int64 battle_addmastery(struct map_session_data *sd,struct block_list *target,int64 dmg,int type) { int64 damage; @@ -1517,7 +1616,6 @@ int64 battle_addmastery(struct map_session_data *sd,struct block_list *target,in break; } - if(sd->sc.data[SC_GN_CARTBOOST]) // cart boost adds mastery type damage damage += 10*sd->sc.data[SC_GN_CARTBOOST]->val1; @@ -1750,11 +1848,12 @@ static int battle_blewcount_bonus(struct map_session_data *sd, uint16 skill_id) return 0; } -/** Damage calculation for adjusting skill damage +/** + * Damage calculation for adjusting skill damage * @param caster Applied caster type for damage skill * @param type BL_Type of attacker * @author [Lilith] for the first release of this, [Cydh] - **/ + */ #ifdef ADJUST_SKILL_DAMAGE static bool battle_skill_damage_iscaster(uint8 caster, enum bl_type src_type) { if (caster == 0) @@ -1771,12 +1870,13 @@ static bool battle_skill_damage_iscaster(uint8 caster, enum bl_type src_type) { return false; } -/** Gets skill damage rate from a skill (based on skill_damage_db.txt) -* @param src -* @param target -* @param skill_id -* @return Skill damage rate -*/ +/** + * Gets skill damage rate from a skill (based on skill_damage_db.txt) + * @param src + * @param target + * @param skill_id + * @return Skill damage rate + */ static int battle_skill_damage_skill(struct block_list *src, struct block_list *target, uint16 skill_id) { uint16 idx = skill_get_index(skill_id), m = src->m; struct s_skill_damage *damage = NULL; @@ -1813,12 +1913,13 @@ static int battle_skill_damage_skill(struct block_list *src, struct block_list * return 0; } -/** Gets skill damage rate from a skill (based on 'skill_damage' mapflag) -* @param src -* @param target -* @param skill_id -* @return Skill damage rate -*/ +/** + * Gets skill damage rate from a skill (based on 'skill_damage' mapflag) + * @param src + * @param target + * @param skill_id + * @return Skill damage rate + */ static int battle_skill_damage_map(struct block_list *src, struct block_list *target, uint16 skill_id) { int rate = 0; uint16 m = src->m; @@ -1868,12 +1969,13 @@ static int battle_skill_damage_map(struct block_list *src, struct block_list *ta return rate; } -/** Check skill damage adjustment based on mapflags and skill_damage_db.txt for specified skill -* @param src -* @param target -* @param skill_id -* @return Total damage rate -*/ +/** + * Check skill damage adjustment based on mapflags and skill_damage_db.txt for specified skill + * @param src + * @param target + * @param skill_id + * @return Total damage rate + */ static int battle_skill_damage(struct block_list *src, struct block_list *target, uint16 skill_id) { if (!target) return 0; @@ -1919,7 +2021,7 @@ static bool target_has_infinite_defense(struct block_list *target, int skill_id) if(target->type == BL_SKILL) { TBL_SKILL *su = ((TBL_SKILL*)target); - if (su->group && (su->group->skill_id == WM_REVERBERATION || su->group->skill_id == WM_POEMOFNETHERWORLD)) + if (su && su->group && (su->group->skill_id == WM_REVERBERATION || su->group->skill_id == WM_POEMOFNETHERWORLD)) return true; } return (tstatus->mode&MD_PLANT && skill_id != RA_CLUSTERBOMB @@ -3419,9 +3521,6 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s skillratio = 50 * skill_lv + 10 * (sd ? pc_checkskill(sd,KN_SPEARMASTERY) : 5); RE_LVL_DMOD(150); // Base level bonus. break; - /** - * GC Guilotine Cross - **/ case GC_CROSSIMPACT: skillratio += 900 + 100 * skill_lv; RE_LVL_DMOD(120); @@ -3447,15 +3546,9 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s case GC_DARKCROW: skillratio += 100 * (skill_lv - 1); break; - /** - * Arch Bishop - **/ case AB_DUPLELIGHT_MELEE: skillratio += 10 * skill_lv; break; - /** - * Ranger - **/ case RA_ARROWSTORM: skillratio += 900 + 80 * skill_lv; RE_LVL_DMOD(100); @@ -3484,9 +3577,6 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s case RA_SENSITIVEKEEN: skillratio += 50 * skill_lv; break; - /** - * Mechanic - **/ case NC_BOOSTKNUCKLE: skillratio += 100 + 100 * skill_lv + status_get_dex(src); RE_LVL_DMOD(120); @@ -3862,9 +3952,6 @@ static int battle_calc_attack_skill_ratio(struct Damage wd, struct block_list *s skillratio += -100 + 100 * skill_lv + 3 * status_get_lv(src); skillratio = (skillratio * status_get_lv(src)) / 120; break; - /** - * Rebellion - **/ case RL_MASS_SPIRAL: // 200%:400%:600%:800%:1000% skillratio += -100 + (200 * skill_lv); @@ -4291,10 +4378,10 @@ struct Damage battle_calc_defense_reduction(struct Damage wd, struct block_list #ifdef RENEWAL /** - * RE DEF Reduction - * Damage = Attack * (4000+eDEF)/(4000+eDEF*10) - sDEF - * Pierce defence gains 1 atk per def/2 - **/ + * RE DEF Reduction + * Damage = Attack * (4000+eDEF)/(4000+eDEF*10) - sDEF + * Pierce defence gains 1 atk per def/2 + */ if( def1 == -400 ) /* being hit by a gazillion units, -400 creates a division by 0 and subsequently crashes */ def1 = -399; ATK_ADD2(wd.damage, wd.damage2, @@ -4591,13 +4678,8 @@ struct Damage battle_calc_weapon_final_atk_modifiers(struct Damage wd, struct bl hp = 2*hp/100; //2% hp loss per hit status_zap(src, hp, 0); } - /** - * affecting non-skills - **/ + // affecting non-skills if( !skill_id ) { - /** - * RK Enchant Blade - **/ if( sc->data[SC_ENCHANTBLADE] && sd && ( (is_attack_right_handed(src, skill_id) && sd->weapontype1) || (is_attack_left_handed(src, skill_id) && sd->weapontype2) ) ) { //[( ( Skill Lv x 20 ) + 100 ) x ( casterBaseLevel / 150 )] + casterInt ATK_ADD(wd.damage, wd.damage2, ( sc->data[SC_ENCHANTBLADE]->val1*20+100 ) * status_get_lv(src) / 150 + status_get_int(src) ); @@ -4728,10 +4810,10 @@ static struct Damage initialize_weapon_data(struct block_list *src, struct block } /** -* Check if bl is devoted by someone -* @param bl -* @return 'd_bl' if devoted or NULL if not devoted -*/ + * Check if bl is devoted by someone + * @param bl + * @return 'd_bl' if devoted or NULL if not devoted + */ struct block_list *battle_check_devotion(struct block_list *bl) { struct block_list *d_bl = NULL; @@ -4743,7 +4825,7 @@ struct block_list *battle_check_devotion(struct block_list *bl) { return d_bl; } -/* +/** * Check if we should reflect the damage and calculate it if so * @param attack_type : BL_WEAPON,BL_MAGIC or BL_MISC * @param wd : weapon damage @@ -5216,9 +5298,10 @@ 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); - if( target->type == BL_SKILL){ + if( target->type == BL_SKILL) { TBL_SKILL *su = (TBL_SKILL*)target; - if( su->group && (su->group->skill_id == WM_REVERBERATION || su->group->skill_id == WM_POEMOFNETHERWORLD) ) + + if( su && su->group && (su->group->skill_id == WM_REVERBERATION || su->group->skill_id == WM_POEMOFNETHERWORLD) ) flag.infdef = 1; } @@ -5257,9 +5340,6 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list case AL_HEAL: case PR_BENEDICTIO: case PR_SANCTUARY: - /** - * Arch Bishop - **/ case AB_HIGHNESSHEAL: ad.damage = skill_calc_heal(src, target, skill_id, skill_lv, false); break; @@ -5295,9 +5375,6 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list case PF_SOULBURN: ad.damage = tstatus->sp * 2; break; - /** - * Arch Bishop - **/ case AB_RENOVATIO: ad.damage = status_get_lv(src) * 10 + sstatus->int_; break; @@ -5360,9 +5437,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list } break; case MG_THUNDERSTORM: - /** - * in Renewal Thunder Storm boost is 100% (in pre-re, 80%) - **/ + // in Renewal Thunder Storm boost is 100% (in pre-re, 80%) #ifndef RENEWAL skillratio -= 20; #endif @@ -5455,9 +5530,6 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list skillratio += 20*skill_lv-20; break; #endif - /** - * Arch Bishop - **/ case AB_JUDEX: skillratio += 200 + 20 * skill_lv; RE_LVL_DMOD(100); @@ -5469,9 +5541,6 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list case AB_DUPLELIGHT_MAGIC: skillratio += 100 + 20 * skill_lv; break; - /** - * Warlock - **/ case WL_SOULEXPANSION: skillratio += 300 + 100 * skill_lv + status_get_int(src); RE_LVL_DMOD(100); @@ -5793,7 +5862,7 @@ struct Damage battle_calc_magic_attack(struct block_list *src,struct block_list /** * RE MDEF Reduction * Damage = Magic Attack * (1000+eMDEF)/(1000+eMDEF) - sMDEF - **/ + */ if (mdef < -99) mdef = -99; // Avoid divide by 0 @@ -6231,7 +6300,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * if(md.damage < 0) md.damage = 0; - else if(md.damage && tstatus->mode&MD_PLANT){ + else if(md.damage && tstatus->mode&MD_PLANT) { switch(skill_id){ case NJ_ISSEN: // Final Strike will MISS on "plant"-type mobs [helvetica] md.damage = 0; @@ -6248,9 +6317,10 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list * default: md.damage = 1; } - }else if( target->type == BL_SKILL ){ + } else if( target->type == BL_SKILL ) { TBL_SKILL *su = (TBL_SKILL*)target; - if( su->group && (su->group->skill_id == WM_REVERBERATION || su->group->skill_id == WM_POEMOFNETHERWORLD) ) + + if( su && su->group && (su->group->skill_id == WM_REVERBERATION || su->group->skill_id == WM_POEMOFNETHERWORLD) ) md.damage = 1; } @@ -6678,7 +6748,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t /** * We need to calculate the DMG before the hp reduction, because it can kill the source. * For further information: bugreport:4950 - **/ + */ ret_val = (damage_lv)skill_attack(BF_WEAPON,src,src,target,PA_SACRIFICE,skill_lv,tick,0); status_zap(src, sstatus->max_hp*9/100, 0);//Damage to self is always 9% @@ -6762,10 +6832,10 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t if (sd && sd->bonus.splash_range > 0 && damage > 0) skill_castend_damage_id(src, target, 0, 1, tick, 0); - if ( target->type == BL_SKILL && damage > 0 ){ + if ( target->type == BL_SKILL && damage > 0 ) { TBL_SKILL *su = (TBL_SKILL*)target; - if (su->group) { + if (su && su->group) { if (su->group->skill_id == HT_BLASTMINE) skill_blown(src, target, 3, -1, 0); if (su->group->skill_id == GN_WALLOFTHORN) { @@ -7077,9 +7147,8 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f case BL_SKILL: { TBL_SKILL *su = (TBL_SKILL*)target; - if( !su->group ) - return 0; - if( skill_get_inf2(su->group->skill_id)&INF2_TRAP ) { //Only a few skills can target traps... + + if( su && su->group && skill_get_inf2(su->group->skill_id)&INF2_TRAP ) { //Only a few skills can target traps... switch( battle_getcurrentskill(src) ) { case RK_DRAGONBREATH:// it can only hit traps in pvp/gvg maps case RK_DRAGONBREATH_WATER: @@ -7183,10 +7252,8 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f break; case BL_SKILL: { struct skill_unit *su = (struct skill_unit *)src; - if (!su->group) - return 0; - if (su->group->src_id == target->id) { + if (su && su->group && su->group->src_id == target->id) { int inf2 = skill_get_inf2(su->group->skill_id); if (inf2&INF2_NO_TARGET_SELF) return -1; @@ -7754,9 +7821,7 @@ static const struct _battle_data { { "bg_magic_attack_damage_rate", &battle_config.bg_magic_damage_rate, 60, 0, INT_MAX, }, { "bg_misc_attack_damage_rate", &battle_config.bg_misc_damage_rate, 60, 0, INT_MAX, }, { "bg_flee_penalty", &battle_config.bg_flee_penalty, 20, 0, INT_MAX, }, - /** - * rAthena - **/ +// rAthena { "max_third_parameter", &battle_config.max_third_parameter, 135, 10, SHRT_MAX, }, { "max_baby_third_parameter", &battle_config.max_baby_third_parameter, 108, 10, SHRT_MAX, }, { "max_trans_parameter", &battle_config.max_trans_parameter, 99, 10, SHRT_MAX, }, @@ -7837,10 +7902,9 @@ static const struct _battle_data { { "devotion_rdamage_skill_only", &battle_config.devotion_rdamage_skill_only, 1, 0, 1, }, { "max_extended_aspd", &battle_config.max_extended_aspd, 193, 100, 199, }, }; + #ifndef STATS_OPT_OUT -/** - * rAthena anonymous statistic usage report -- packet is built here, and sent to char server to report. - **/ +// rAthena anonymous statistic usage report -- packet is built here, and sent to char server to report. void rAthena_report(char* date, char *time_c) { int i, rev = 0, bd_size = ARRAYLENGTH(battle_data); unsigned int config = 0; @@ -7933,7 +7997,6 @@ void rAthena_report(char* date, char *time_c) { CREATE(buf, char, 6 + 12 + 9 + 24 + 4 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ) + 1 ); /* build packet */ - WBUFW(buf,0) = 0x3000; WBUFW(buf,2) = 6 + 12 + 9 + 24 + 4 + 4 + 4 + 4 + ( bd_size * ( BFLAG_LENGTH + 4 ) ); WBUFW(buf,4) = 0x9c; diff --git a/src/map/battleground.c b/src/map/battleground.c index 37ee275d4e..43e753d3dd 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -27,16 +27,21 @@ static unsigned int bg_team_counter = 0; // Next bg_id struct battleground_data* bg_team_search(int bg_id) { // Search a BG Team using bg_id - if( !bg_id ) return NULL; + if( !bg_id ) + return NULL; + return (struct battleground_data *)idb_get(bg_team_db, bg_id); } struct map_session_data* bg_getavailablesd(struct battleground_data *bg) { int i; + nullpo_retr(NULL, bg); + ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd != NULL); - return( i < MAX_BG_MEMBERS ) ? bg->members[i].sd : NULL; + + return ( i < MAX_BG_MEMBERS ) ? bg->members[i].sd : NULL; } int bg_team_delete(int bg_id) @@ -44,9 +49,10 @@ int bg_team_delete(int bg_id) int i; struct battleground_data *bg = bg_team_search(bg_id); - if( bg == NULL ) return 0; - for( i = 0; i < MAX_BG_MEMBERS; i++ ) - { + if( bg == NULL ) + return 0; + + for( i = 0; i < MAX_BG_MEMBERS; i++ ) { struct map_session_data *sd; if( (sd = bg->members[i].sd) == NULL ) @@ -55,7 +61,9 @@ int bg_team_delete(int bg_id) bg_send_dot_remove(sd); sd->bg_id = 0; } + idb_remove(bg_team_db, bg_id); + return 1; } @@ -63,7 +71,10 @@ int bg_team_warp(int bg_id, unsigned short mapindex, short x, short y) { // Warps a Team int i; struct battleground_data *bg = bg_team_search(bg_id); - if( bg == NULL ) return 0; + + if( bg == NULL ) + return 0; + for( i = 0; i < MAX_BG_MEMBERS; i++ ) if( bg->members[i].sd != NULL ) pc_setpos(bg->members[i].sd, mapindex, x, y, CLR_TELEPORT); return 1; @@ -81,10 +92,12 @@ int bg_team_join(int bg_id, struct map_session_data *sd) int i; struct battleground_data *bg = bg_team_search(bg_id); - if( bg == NULL || sd == NULL || sd->bg_id ) return 0; + if( bg == NULL || sd == NULL || sd->bg_id ) + return 0; ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == NULL); - if( i == MAX_BG_MEMBERS ) return 0; // No free slots + if( i == MAX_BG_MEMBERS ) + return 0; // No free slots sd->bg_id = bg_id; bg->members[i].sd = sd; @@ -94,8 +107,7 @@ int bg_team_join(int bg_id, struct map_session_data *sd) guild_send_dot_remove(sd); - for( i = 0; i < MAX_BG_MEMBERS; i++ ) - { + for( i = 0; i < MAX_BG_MEMBERS; i++ ) { struct map_session_data *pl_sd; if( (pl_sd = bg->members[i].sd) != NULL && pl_sd != sd ) @@ -126,12 +138,14 @@ int bg_team_leave(struct map_session_data *sd, int flag) ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == sd); if( i < MAX_BG_MEMBERS ) // Removes member from BG memset(&bg->members[i], 0, sizeof(bg->members[0])); + bg->count--; if( flag ) sprintf(output, "Server : %s has quit the game...", sd->status.name); else sprintf(output, "Server : %s is leaving the battlefield...", sd->status.name); + clif_bg_message(bg, 0, "Server", output, strlen(output) + 1); if( bg->logout_event[0] && flag ) @@ -143,10 +157,13 @@ int bg_team_leave(struct map_session_data *sd, int flag) int bg_member_respawn(struct map_session_data *sd) { // Respawn after killed struct battleground_data *bg; + if( sd == NULL || !pc_isdead(sd) || !sd->bg_id || (bg = bg_team_search(sd->bg_id)) == NULL ) return 0; + if( bg->mapindex == 0 ) return 0; // Respawn not handled by Core + pc_setpos(sd, bg->mapindex, bg->x, bg->y, CLR_OUTSIGHT); status_revive(&sd->bl, 1, 100); @@ -176,20 +193,20 @@ int bg_create(unsigned short mapindex, short rx, short ry, const char *ev, const int bg_team_get_id(struct block_list *bl) { nullpo_ret(bl); - switch( bl->type ) - { + switch( bl->type ) { case BL_PC: return ((TBL_PC*)bl)->bg_id; case BL_PET: if( ((TBL_PET*)bl)->master ) return ((TBL_PET*)bl)->master->bg_id; break; - case BL_MOB: - { + case BL_MOB: { struct map_session_data *msd; struct mob_data *md = (TBL_MOB*)bl; + if( md->special_state.ai && (msd = map_id2sd(md->master_id)) != NULL ) return msd->bg_id; + return md->bg_id; } case BL_HOM: @@ -212,9 +229,12 @@ int bg_send_message(struct map_session_data *sd, const char *mes, int len) struct battleground_data *bg; nullpo_ret(sd); + if( sd->bg_id == 0 || (bg = bg_team_search(sd->bg_id)) == NULL ) return 0; + clif_bg_message(bg, sd->bl.id, sd->status.name, mes, len); + return 0; } @@ -226,24 +246,27 @@ int bg_send_xy_timer_sub(DBKey key, DBData *data, va_list ap) struct battleground_data *bg = db_data2ptr(data); struct map_session_data *sd; int i; + nullpo_ret(bg); - for( i = 0; i < MAX_BG_MEMBERS; i++ ) - { + + for( i = 0; i < MAX_BG_MEMBERS; i++ ) { if( (sd = bg->members[i].sd) == NULL ) continue; - if( sd->bl.x != bg->members[i].x || sd->bl.y != bg->members[i].y ) - { // xy update + + if( sd->bl.x != bg->members[i].x || sd->bl.y != bg->members[i].y ) { // xy update bg->members[i].x = sd->bl.x; bg->members[i].y = sd->bl.y; clif_bg_xy(sd); } } + return 0; } int bg_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data) { bg_team_db->foreach(bg_team_db, bg_send_xy_timer_sub, tick); + return 0; } diff --git a/src/map/channel.c b/src/map/channel.c index 2fa65dfe84..0188edc775 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -496,11 +496,14 @@ int channel_display_list(struct map_session_data *sd, char *options){ clif_displaymessage(sd->fd, msg_txt(sd,1476)); // You have not joined any channels. else { unsigned char k; - struct Channel *channel; - for(k=0; kchannel_count; k++){ + + for(k = 0; k < sd->channel_count; k++) { char output[128]; + struct Channel *channel; + if (!(channel = sd->channels[k])) continue; + sprintf(output, msg_txt(sd,1409), channel->name, db_size(channel->users));// - #%s (%d users) clif_displaymessage(sd->fd, output); } diff --git a/src/map/clif.c b/src/map/clif.c index 8313cdbd18..ab9ccd7006 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -17373,7 +17373,8 @@ void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, boo //void clif_broadcast_obtain_special_item() {} #ifdef DUMP_UNKNOWN_PACKET -void DumpUnknow(int fd,TBL_PC *sd,int cmd,int packet_len){ +void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len) +{ const char* packet_txt = "save/packet.txt"; FILE* fp; time_t time_server; @@ -17527,7 +17528,7 @@ static int clif_parse(int fd) packet_db[packet_ver][cmd].func(fd, sd); } #ifdef DUMP_UNKNOWN_PACKET - else DumpUnknow(fd,sd,cmd,packet_len); + else DumpUnknown(fd,sd,cmd,packet_len); #endif RFIFOSKIP(fd, packet_len); }; // main loop end @@ -17540,7 +17541,6 @@ static int clif_parse(int fd) *------------------------------------------*/ void packetdb_readdb(void) { - FILE *fp; char line[1024]; int cmd,i,j; int max_cmd=-1; @@ -18038,13 +18038,14 @@ void packetdb_readdb(void) packet_len(i) = packet_len_table[i]; clif_config.packet_db_ver = MAX_PACKET_VER; - for(f = 0; f < ARRAYLENGTH(filename); f++){ - int ln=0; + for(f = 0; f < ARRAYLENGTH(filename); f++) { + FILE *fp; + int ln = 0; int entries = 0; - char *str[64],*p,*str2[64],*p2; + char *str[64], *p, *str2[64], *p2; sprintf(line, "%s/%s", db_path, filename[f]); - if( (fp = fopen(line,"r")) == NULL ){ + if( (fp = fopen(line,"r")) == NULL ) { if (f == 0) { ShowFatalError("Can't read %s\n", line); exit(EXIT_FAILURE); diff --git a/src/map/party.c b/src/map/party.c index 7c0be6c084..439e486382 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -29,7 +29,6 @@ #include #include - static DBMap* party_db; // int party_id -> struct party_data* (releases data) static DBMap* party_booking_db; // int char_id -> struct party_booking_ad_info* (releases data) // Party Booking [Spiria] static unsigned long party_booking_nextid = 1; @@ -53,39 +52,44 @@ static void party_fill_member(struct party_member* member, struct map_session_da member->leader = leader; } - /// Get the member_id of a party member. /// Return -1 if not in party. int party_getmemberid(struct party_data* p, struct map_session_data* sd) { int member_id; + nullpo_retr(-1, p); + if( sd == NULL ) - return -1;// no player + return -1; // no player + ARR_FIND(0, MAX_PARTY, member_id, p->party.member[member_id].account_id == sd->status.account_id && p->party.member[member_id].char_id == sd->status.char_id); + if( member_id == MAX_PARTY ) - return -1;// not found + return -1; // not found + return member_id; } - /*========================================== * Request an available sd of this party *------------------------------------------*/ struct map_session_data* party_getavailablesd(struct party_data *p) { int i; + nullpo_retr(NULL, p); + ARR_FIND(0, MAX_PARTY, i, p->data[i].sd != NULL); + return( i < MAX_PARTY ) ? p->data[i].sd : NULL; } /*========================================== * Retrieves and validates the sd pointer for this party member [Skotlex] *------------------------------------------*/ - static TBL_PC* party_sd_check(int party_id, int account_id, int char_id) { TBL_PC* sd = map_id2sd(account_id); @@ -94,9 +98,9 @@ static TBL_PC* party_sd_check(int party_id, int account_id, int char_id) return NULL; if( sd->status.party_id == 0 ) - sd->status.party_id = party_id;// auto-join if not in a party - if (sd->status.party_id != party_id) - { //If player belongs to a different party, kick him out. + sd->status.party_id = party_id; // auto-join if not in a party + + if (sd->status.party_id != party_id) { // If player belongs to a different party, kick him out. intif_party_leave(party_id,account_id,char_id); return NULL; } @@ -113,6 +117,7 @@ void do_final_party(void) party_db->destroy(party_db,NULL); party_booking_db->destroy(party_booking_db,NULL); // Party Booking [Spiria] } + // Constructor, init vars void do_init_party(void) { @@ -127,6 +132,7 @@ struct party_data* party_search(int party_id) { if(!party_id) return NULL; + return (struct party_data*)idb_get(party_db,party_id); } @@ -136,8 +142,7 @@ struct party_data* party_searchname(const char* str) struct party_data* p; DBIterator *iter = db_iterator(party_db); - for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) ) - { + for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) ) { if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 ) break; } @@ -154,21 +159,16 @@ int party_create(struct map_session_data *sd,char *name,int item,int item2) safestrncpy(tname, name, NAME_LENGTH); trim(tname); - if( !tname[0] ) - {// empty name + if( !tname[0] ) // empty name return 0; - } - if( sd->status.party_id > 0 || sd->party_joining || sd->party_creating ) - {// already associated with a party + if( sd->status.party_id > 0 || sd->party_joining || sd->party_creating ) { // already associated with a party clif_party_created(sd,2); return -2; } sd->party_creating = true; - party_fill_member(&leader, sd, 1); - intif_create_party(&leader,name,item,item2); return 1; } @@ -176,11 +176,11 @@ int party_create(struct map_session_data *sd,char *name,int item,int item2) void party_created(int account_id,int char_id,int fail,int party_id,char *name) { struct map_session_data *sd; - sd=map_id2sd(account_id); - if (!sd || sd->status.char_id != char_id || !sd->party_creating ) - { //Character logged off before creation ack? - if (!fail) //break up party since player could not be added to it. + sd = map_id2sd(account_id); + + if (!sd || sd->status.char_id != char_id || !sd->party_creating ) { // Character logged off before creation ack? + if (!fail) // break up party since player could not be added to it. intif_party_leave(party_id,account_id,char_id); return; } @@ -189,14 +189,14 @@ void party_created(int account_id,int char_id,int fail,int party_id,char *name) if( !fail ) { sd->status.party_id = party_id; - clif_party_created(sd,0); //Success message - //We don't do any further work here because the char-server sends a party info packet right after creating the party - if(party_create_byscript) { //returns party id in $@party_create_id if party is created by script + clif_party_created(sd,0); // Success message + + // We don't do any further work here because the char-server sends a party info packet right after creating the party + if(party_create_byscript) { // returns party id in $@party_create_id if party is created by script mapreg_setreg(add_str("$@party_create_id"),party_id); party_create_byscript = 0; } - } - else + } else clif_party_created(sd,1); // "party name already exists" } @@ -209,13 +209,15 @@ int party_request_info(int party_id, int char_id) int party_recv_noinfo(int party_id, int char_id) { party_broken(party_id); - if( char_id != 0 )// requester - { + if( char_id != 0 ) { // requester struct map_session_data* sd; + sd = map_charid2sd(char_id); + if( sd && sd->status.party_id == party_id ) sd->status.party_id = 0; } + return 0; } @@ -223,27 +225,28 @@ static void party_check_state(struct party_data *p) { int i; memset(&p->state, 0, sizeof(p->state)); - for (i = 0; i < MAX_PARTY; i ++) - { - if (!p->party.member[i].online) continue; //Those not online shouldn't aport to skill usage and all that. + for (i = 0; i < MAX_PARTY; i ++) { + if (!p->party.member[i].online) + continue; //Those not online shouldn't aport to skill usage and all that. + switch (p->party.member[i].class_) { - case JOB_MONK: - case JOB_BABY_MONK: - case JOB_CHAMPION: - p->state.monk = 1; - break; - case JOB_STAR_GLADIATOR: - p->state.sg = 1; - break; - case JOB_SUPER_NOVICE: - case JOB_SUPER_BABY: - case JOB_SUPER_NOVICE_E: - case JOB_SUPER_BABY_E: - p->state.snovice = 1; - break; - case JOB_TAEKWON: - p->state.tk = 1; - break; + case JOB_MONK: + case JOB_BABY_MONK: + case JOB_CHAMPION: + p->state.monk = 1; + break; + case JOB_STAR_GLADIATOR: + p->state.sg = 1; + break; + case JOB_SUPER_NOVICE: + case JOB_SUPER_BABY: + case JOB_SUPER_NOVICE_E: + case JOB_SUPER_BABY_E: + p->state.snovice = 1; + break; + case JOB_TAEKWON: + p->state.tk = 1; + break; } } } @@ -262,79 +265,90 @@ int party_recv_info(struct party* sp, int char_id) nullpo_ret(sp); p = (struct party_data*)idb_get(party_db, sp->party_id); - if( p != NULL )// diff members - { + + if( p != NULL ) { // diff members int i; - for( member_id = 0; member_id < MAX_PARTY; ++member_id ) - { + for( member_id = 0; member_id < MAX_PARTY; ++member_id ) { member = &p->party.member[member_id]; + if( member->char_id == 0 ) - continue;// empty + 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 ) 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 ) - continue;// empty + 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 ) added[added_count++] = member_id; } - } - else - { + } else { for( member_id = 0; member_id < MAX_PARTY; ++member_id ) if( sp->member[member_id].char_id != 0 ) added[added_count++] = member_id; + CREATE(p, struct party_data, 1); idb_put(party_db, sp->party_id, p); } - while( removed_count > 0 )// no longer in party - { + while( removed_count > 0 ) { // no longer in party member_id = removed[--removed_count]; sd = p->data[member_id].sd; + if( sd == NULL ) - continue;// not online + continue; // not online + party_member_withdraw(sp->party_id, sd->status.account_id, sd->status.char_id); } + memcpy(&p->party, sp, sizeof(struct party)); memset(&p->state, 0, sizeof(p->state)); memset(&p->data, 0, sizeof(p->data)); - for( member_id = 0; member_id < MAX_PARTY; member_id++ ) - { + + for( member_id = 0; member_id < MAX_PARTY; member_id++ ) { member = &p->party.member[member_id]; if ( member->char_id == 0 ) continue;// empty p->data[member_id].sd = party_sd_check(sp->party_id, member->account_id, member->char_id); } + party_check_state(p); - while( added_count > 0 )// new in party - { + + while( added_count > 0 ) { // new in party member_id = added[--added_count]; sd = p->data[member_id].sd; + if( sd == NULL ) continue;// not online + clif_charnameupdate(sd); //Update other people's display. [Skotlex] clif_party_member_info(p,sd); clif_party_option(p,sd,0x100); clif_party_info(p,NULL); + if( p->instance_id != 0 ) instance_reqinfo(sd,p->instance_id); } - if( char_id != 0 )// requester - { + + if( char_id != 0 ) { // requester sd = map_charid2sd(char_id); if( sd && sd->status.party_id == sp->party_id && party_getmemberid(p,sd) == -1 ) sd->status.party_id = 0;// was not in the party } + return 0; } @@ -405,29 +419,28 @@ int party_reply_invite(struct map_session_data *sd,int party_id,int flag) struct map_session_data* tsd; struct party_member member; - if( sd->party_invite != party_id ) - {// forged + if( sd->party_invite != party_id ) { // forged sd->party_invite = 0; sd->party_invite_account = 0; return 0; } + tsd = map_id2sd(sd->party_invite_account); - if( flag == 1 && !sd->party_creating && !sd->party_joining ) - {// accepted and allowed + if( flag == 1 && !sd->party_creating && !sd->party_joining ) { // accepted and allowed sd->party_joining = true; party_fill_member(&member, sd, 0); intif_party_addmember(sd->party_invite, &member); return 1; - } - else - {// rejected or failure + } else { // rejected or failure sd->party_invite = 0; sd->party_invite_account = 0; + if( tsd != NULL ) clif_party_inviteack(tsd,sd->status.name,1); return 0; } + return 0; } @@ -439,19 +452,20 @@ void party_member_joined(struct map_session_data *sd) { struct party_data* p = party_search(sd->status.party_id); int i; - if (!p) - { + + if (!p) { party_request_info(sd->status.party_id, sd->status.char_id); return; } + ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == sd->status.account_id && p->party.member[i].char_id == sd->status.char_id ); - if (i < MAX_PARTY) - { + + if (i < MAX_PARTY) { p->data[i].sd = sd; + if( p->instance_id ) instance_reqinfo(sd,p->instance_id); - } - else + } else sd->status.party_id = 0; //He does not belongs to the party really? } @@ -481,8 +495,7 @@ int party_member_added(int party_id,int account_id,int char_id, int flag) return 0; } - if( flag ) - {// failed + if( flag ) { // failed if( sd2 != NULL ) clif_party_inviteack(sd2,sd->status.name,3); return 0; @@ -497,12 +510,13 @@ int party_member_added(int party_id,int account_id,int char_id, int flag) if( sd2 != NULL ) clif_party_inviteack(sd2,sd->status.name,2); - for( i = 0; i < ARRAYLENGTH(p->data); ++i ) - {// hp of the other party members + for( i = 0; i < ARRAYLENGTH(p->data); ++i ) { // hp of the other party members sd2 = p->data[i].sd; + if( sd2 && sd2->status.account_id != account_id && sd2->status.char_id != char_id ) clif_hpmeter_single(sd->fd, sd2->bl.id, sd2->battle_status.hp, sd2->battle_status.max_hp); } + clif_party_hp(sd); clif_party_xy(sd); clif_charnameupdate(sd); //Update char name's display [Skotlex] @@ -520,6 +534,7 @@ int party_removemember(struct map_session_data* sd, int account_id, char* name) int i; p = party_search(sd->status.party_id); + if( p == NULL ) return 0; @@ -535,6 +550,7 @@ int party_removemember(struct map_session_data* sd, int account_id, char* name) return 0; // no such char in party intif_party_leave(p->party.party_id,account_id,p->party.member[i].char_id); + return 1; } @@ -543,7 +559,9 @@ int party_removemember2(struct map_session_data *sd,int char_id,int party_id) if( sd ) { if( !sd->status.party_id ) return -3; + intif_party_leave(sd->status.party_id,sd->status.account_id,sd->status.char_id); + return 1; } else { int i; @@ -557,8 +575,10 @@ int party_removemember2(struct map_session_data *sd,int char_id,int party_id) return -1; intif_party_leave(party_id,p->party.member[i].account_id,char_id); + return 1; } + return 0; } @@ -569,6 +589,7 @@ int party_leave(struct map_session_data *sd) int i; p = party_search(sd->status.party_id); + if( p == NULL ) return 0; @@ -588,6 +609,7 @@ int party_member_withdraw(int party_id, int account_id, int char_id) if( p ) { int i; + ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id ); if( i < MAX_PARTY ) { clif_party_withdraw(p,sd,account_id,p->party.member[i].name,0x0); @@ -602,13 +624,17 @@ int party_member_withdraw(int party_id, int account_id, int char_id) #ifdef BOUND_ITEMS int idxlist[MAX_INVENTORY]; //or malloc to reduce consumtion int j,i; + j = pc_bound_chk(sd,3,idxlist); - for(i=0;istatus.inventory[idxlist[i]].amount,0,1,LOG_TYPE_OTHER); #endif + sd->status.party_id = 0; clif_charnameupdate(sd); //Update name display [Skotlex] //TODO: hp bars should be cleared too + if( p->instance_id ) { int16 m = sd->bl.m; @@ -631,25 +657,24 @@ int party_broken(int party_id) int i; p = party_search(party_id); + if( p == NULL ) return 0; - if( p->instance_id ) - { + if( p->instance_id ) { instance_data[p->instance_id].party_id = 0; instance_destroy( p->instance_id ); } - for( i = 0; i < MAX_PARTY; i++ ) - { - if( p->data[i].sd!=NULL ) - { + for( i = 0; i < MAX_PARTY; i++ ) { + if( p->data[i].sd != NULL ) { clif_party_withdraw(p,p->data[i].sd,p->party.member[i].account_id,p->party.member[i].name,0x10); p->data[i].sd->status.party_id=0; } } idb_remove(party_db,party_id); + return 1; } @@ -659,7 +684,9 @@ int party_changeoption(struct map_session_data *sd,int exp,int item) if( sd->status.party_id == 0 ) return -3; + intif_party_changeoption(sd->status.party_id,sd->status.account_id,exp,item); + return 0; } @@ -667,9 +694,11 @@ int party_changeoption(struct map_session_data *sd,int exp,int item) int party_setoption(struct party_data *party, int option, int flag) { int i; + ARR_FIND(0,MAX_PARTY,i,party->party.member[i].leader); if(i >= MAX_PARTY) return 0; + switch(option) { case 0: intif_party_changeoption(party->party.party_id,party->party.member[i].account_id,flag,party->party.item); @@ -688,6 +717,7 @@ int party_setoption(struct party_data *party, int option, int flag) return 0; break; } + return 1; } @@ -695,17 +725,19 @@ int party_optionchanged(int party_id,int account_id,int exp,int item,int flag) { struct party_data *p; struct map_session_data *sd=map_id2sd(account_id); - if( (p=party_search(party_id))==NULL) + + if( (p = party_search(party_id)) == NULL) return 0; //Flag&1: Exp change denied. Flag&2: Item change denied. if(!(flag&0x01) && p->party.exp != exp) - p->party.exp=exp; + p->party.exp = exp; if(!(flag&0x10) && p->party.item != item) { - p->party.item=item; + p->party.item = item; } clif_party_option(p,sd,flag); + return 0; } @@ -714,7 +746,6 @@ int party_changeleader(struct map_session_data *sd, struct map_session_data *tsd int mi, tmi; if ( !p ) { - if (!sd || !sd->status.party_id) return -1; @@ -723,8 +754,7 @@ int party_changeleader(struct map_session_data *sd, struct map_session_data *tsd return -3; } - if ( map[sd->bl.m].flag.partylock ) - { + if ( map[sd->bl.m].flag.partylock ) { clif_displaymessage(sd->fd, msg_txt(sd,287)); return 0; } @@ -734,35 +764,36 @@ int party_changeleader(struct map_session_data *sd, struct map_session_data *tsd ARR_FIND( 0, MAX_PARTY, mi, p->data[mi].sd == sd ); if (mi == MAX_PARTY) - return 0; //Shouldn't happen + return 0; // Shouldn't happen - if (!p->party.member[mi].leader) - { //Need to be a party leader. + if (!p->party.member[mi].leader) { // Need to be a party leader. clif_displaymessage(sd->fd, msg_txt(sd,282)); return 0; } ARR_FIND( 0, MAX_PARTY, tmi, p->data[tmi].sd == tsd); if (tmi == MAX_PARTY) - return 0; //Shouldn't happen - } - else { + return 0; // Shouldn't happen + } else { ARR_FIND(0,MAX_PARTY,mi,p->party.member[mi].leader); ARR_FIND(0,MAX_PARTY,tmi,p->data[tmi].sd == tsd); } - //Change leadership. + // Change leadership. p->party.member[mi].leader = 0; + if (p->data[mi].sd && p->data[mi].sd->fd) clif_displaymessage(p->data[mi].sd->fd, msg_txt(sd,284)); p->party.member[tmi].leader = 1; + if (p->data[tmi].sd && p->data[tmi].sd->fd) clif_displaymessage(p->data[tmi].sd->fd, msg_txt(sd,285)); - //Update info. + // Update info. intif_party_leaderchange(p->party.party_id,p->party.member[tmi].account_id,p->party.member[tmi].char_id); clif_party_info(p,NULL); + return 1; } @@ -777,12 +808,12 @@ int party_recv_movemap(int party_id,int account_id,int char_id, unsigned short m int i; p = party_search(party_id); + if( p == NULL ) return 0; ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id ); - if( i == MAX_PARTY ) - { + if( i == MAX_PARTY ) { ShowError("party_recv_movemap: char %d/%d not found in party %s (id:%d)",account_id,char_id,p->party.name,party_id); return 0; } @@ -795,6 +826,7 @@ int party_recv_movemap(int party_id,int account_id,int char_id, unsigned short m p->data[i].sd = party_sd_check(party_id, account_id, char_id); clif_party_info(p,NULL); + return 0; } @@ -802,13 +834,15 @@ void party_send_movemap(struct map_session_data *sd) { struct party_data *p; - if( sd->status.party_id==0 ) + if( !sd->status.party_id ) return; intif_party_changemap(sd,1); - p=party_search(sd->status.party_id); - if (!p) return; + p = party_search(sd->status.party_id); + + if (!p) + return; if(sd->state.connect_new) { //Note that this works because this function is invoked before connect_new is cleared. @@ -846,8 +880,10 @@ int party_send_logout(struct map_session_data *sd) return 0; intif_party_changemap(sd,0); - p=party_search(sd->status.party_id); - if(!p) return 0; + p = party_search(sd->status.party_id); + + if(!p) + return 0; ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd ); if( i < MAX_PARTY ) @@ -860,8 +896,9 @@ int party_send_logout(struct map_session_data *sd) int party_send_message(struct map_session_data *sd,const char *mes,int len) { - if(sd->status.party_id==0) + if(sd->status.party_id == 0) return 0; + intif_party_message(sd->status.party_id,sd->status.account_id,mes,len); party_recv_message(sd->status.party_id,sd->status.account_id,mes,len); @@ -874,9 +911,12 @@ int party_send_message(struct map_session_data *sd,const char *mes,int len) int party_recv_message(int party_id,int account_id,const char *mes,int len) { struct party_data *p; - if( (p=party_search(party_id))==NULL) + + if( (p = party_search(party_id)) == NULL) return 0; + clif_party_message(p,account_id,mes,len); + return 0; } @@ -886,8 +926,9 @@ int party_skill_check(struct map_session_data *sd, int party_id, uint16 skill_id struct map_session_data *p_sd; int i; - if(!party_id || (p=party_search(party_id))==NULL) + if(!party_id || (p = party_search(party_id)) == NULL) return 0; + switch(skill_id) { case TK_COUNTER: //Increase Triple Attack rate of Monks. if (!p->state.monk) return 0; @@ -903,11 +944,13 @@ int party_skill_check(struct map_session_data *sd, int party_id, uint16 skill_id return 0; //Unknown case? } - for(i=0;idata[i].sd) == NULL) continue; + if (sd->bl.m != p_sd->bl.m) continue; + switch(skill_id) { case TK_COUNTER: //Increase Triple Attack rate of Monks. if((p_sd->class_&MAPID_UPPERMASK) == MAPID_MONK @@ -928,6 +971,7 @@ int party_skill_check(struct map_session_data *sd, int party_id, uint16 skill_id break; } } + return 0; } @@ -936,30 +980,28 @@ int party_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data) struct party_data* p; DBIterator *iter = db_iterator(party_db); - // for each existing party, - for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) ) - { + + // for each existing party + for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) ) { int i; - if( !p->party.count ) - {// no online party members so do not iterate + if( !p->party.count ) // no online party members so do not iterate continue; - } - // for each member of this party, - for( i = 0; i < MAX_PARTY; i++ ) - { + // for each member of this party + for( i = 0; i < MAX_PARTY; i++ ) { struct map_session_data* sd = p->data[i].sd; - if( !sd ) continue; - if( p->data[i].x != sd->bl.x || p->data[i].y != sd->bl.y ) - {// perform position update + if( !sd ) + continue; + + if( p->data[i].x != sd->bl.x || p->data[i].y != sd->bl.y ) { // perform position update clif_party_xy(sd); p->data[i].x = sd->bl.x; p->data[i].y = sd->bl.y; } - if (battle_config.party_hp_mode && p->data[i].hp != sd->battle_status.hp) - {// perform hp update + + if (battle_config.party_hp_mode && p->data[i].hp != sd->battle_status.hp) { // perform hp update clif_party_hp(sd); p->data[i].hp = sd->battle_status.hp; } @@ -976,8 +1018,10 @@ int party_send_xy_clear(struct party_data *p) nullpo_ret(p); - for(i=0;idata[i].sd) continue; + for(i = 0; i < MAX_PARTY; i++) { + if(!p->data[i].sd) + continue; + p->data[i].hp = 0; p->data[i].x = 0; p->data[i].y = 0; @@ -993,6 +1037,7 @@ int party_exp_share(struct party_data* p, struct block_list* src, unsigned int b #ifdef RENEWAL_EXP uint32 base_exp_bonus, job_exp_bonus; #endif + nullpo_ret(p); // count the number of players eligible for exp sharing @@ -1008,9 +1053,9 @@ int party_exp_share(struct party_data* p, struct block_list* src, unsigned int b job_exp/=c; zeny/=c; - if (battle_config.party_even_share_bonus && c > 1) - { + if (battle_config.party_even_share_bonus && c > 1) { double bonus = 100 + battle_config.party_even_share_bonus*(c-1); + if (base_exp) base_exp = (unsigned int) cap_value(base_exp * bonus/100, 0, UINT_MAX); if (job_exp) @@ -1018,13 +1063,15 @@ int party_exp_share(struct party_data* p, struct block_list* src, unsigned int b if (zeny) zeny = (unsigned int) cap_value(zeny * bonus/100, INT_MIN, INT_MAX); } + #ifdef RENEWAL_EXP base_exp_bonus = base_exp; job_exp_bonus = job_exp; #endif + for (i = 0; i < c; i++) { #ifdef RENEWAL_EXP - if( !(src && src->type == BL_MOB && ((TBL_MOB*)src)->db->mexp) ){ + if( !(src && src->type == BL_MOB && ((TBL_MOB*)src)->db->mexp) ) { TBL_MOB *md = BL_CAST(BL_MOB, src); int rate = 0; @@ -1036,11 +1083,13 @@ int party_exp_share(struct party_data* p, struct block_list* src, unsigned int b job_exp = (unsigned int)cap_value(job_exp_bonus * rate / 100, 1, UINT_MAX); } #endif + pc_gainexp(sd[i], src, base_exp, job_exp, false); if (zeny) // zeny from mobs [Valaris] pc_getzeny(sd[i],zeny,LOG_TYPE_PICKDROP_MONSTER,NULL); } + return 0; } @@ -1049,13 +1098,14 @@ int party_share_loot(struct party_data* p, struct map_session_data* sd, struct i { TBL_PC* target = NULL; int i; - if (p && p->party.item&2 && (first_charid || !(battle_config.party_share_type&1))) - { + + if (p && p->party.item&2 && (first_charid || !(battle_config.party_share_type&1))) { //item distribution to party members. - if (battle_config.party_share_type&2) - { //Round Robin + if (battle_config.party_share_type&2) { // Round Robin TBL_PC* psd; + i = p->itemc; + do { i++; if (i >= MAX_PARTY) @@ -1072,11 +1122,10 @@ int party_share_loot(struct party_data* p, struct map_session_data* sd, struct i target = psd; break; } while (i != p->itemc); - } - else - { //Random pick + } else { // Random pick TBL_PC* psd[MAX_PARTY]; int count = 0; + //Collect pick candidates for (i = 0; i < MAX_PARTY; i++) { if( (psd[count] = p->data[i].sd) == NULL || psd[count]->bl.m != sd->bl.m || pc_isdead(psd[count]) || (battle_config.idle_no_share && pc_isidle(psd[count])) ) @@ -1084,13 +1133,14 @@ int party_share_loot(struct party_data* p, struct map_session_data* sd, struct i count++; } + while (count > 0) { //Pick a random member. i = rnd()%count; - if (pc_additem(psd[i],item_data,item_data->amount,LOG_TYPE_PICKDROP_PLAYER)) - { //Discard this receiver. + + if (pc_additem(psd[i],item_data,item_data->amount,LOG_TYPE_PICKDROP_PLAYER)) { // Discard this receiver. psd[i] = psd[count-1]; count--; - } else { //Successful pick. + } else { // Successful pick. target = psd[i]; break; } @@ -1100,7 +1150,8 @@ int party_share_loot(struct party_data* p, struct map_session_data* sd, struct i if (!target) { target = sd; //Give it to the char that picked it up - if ((i=pc_additem(sd,item_data,item_data->amount,LOG_TYPE_PICKDROP_PLAYER))) + + if ((i = pc_additem(sd,item_data,item_data->amount,LOG_TYPE_PICKDROP_PLAYER))) return i; } @@ -1114,6 +1165,7 @@ int party_send_dot_remove(struct map_session_data *sd) { if (sd->status.party_id) clif_party_xy_remove(sd); + return 0; } @@ -1161,31 +1213,34 @@ int party_foreachsamemap(int (*func)(struct block_list*,va_list),struct map_sess nullpo_ret(sd); - if((p=party_search(sd->status.party_id))==NULL) + if((p = party_search(sd->status.party_id)) == NULL) return 0; - x0=sd->bl.x-range; - y0=sd->bl.y-range; - x1=sd->bl.x+range; - y1=sd->bl.y+range; + x0 = sd->bl.x-range; + y0 = sd->bl.y-range; + x1 = sd->bl.x+range; + y1 = sd->bl.y+range; - for(i=0;idata[i].sd; - if(!psd) continue; + + if(!psd) + continue; + if(psd->bl.m!=sd->bl.m || !psd->bl.prev) continue; + if(range && (psd->bl.xbl.ybl.x>x1 || psd->bl.y>y1 ) ) continue; + list[blockcount++]=&psd->bl; } map_freeblock_lock(); - for(i=0;iindex = party_booking_nextid++; + return pb_ad; } @@ -1216,13 +1272,10 @@ void party_booking_register(struct map_session_data *sd, short level, short mapi pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id); - if( pb_ad == NULL ) - { + if( pb_ad == NULL ) { pb_ad = create_party_booking_data(); idb_put(party_booking_db, sd->status.char_id, pb_ad); - } - else - {// already registered + } else { // already registered clif_PartyBookingRegisterAck(sd, 2); return; } @@ -1232,7 +1285,7 @@ void party_booking_register(struct map_session_data *sd, short level, short mapi pb_ad->p_detail.level = level; pb_ad->p_detail.mapid = mapid; - for(i=0;ip_detail.job[i] = job[i]; else pb_ad->p_detail.job[i] = -1; @@ -1253,10 +1306,11 @@ void party_booking_update(struct map_session_data *sd, short* job) pb_ad->starttime = (int)time(NULL);// Update time. - for(i=0;ip_detail.job[i] = job[i]; - else pb_ad->p_detail.job[i] = -1; + else + pb_ad->p_detail.job[i] = -1; clif_PartyBookingUpdateNotify(sd, pb_ad); } @@ -1271,29 +1325,30 @@ void party_booking_search(struct map_session_data *sd, short level, short mapid, memset(result_list, 0, sizeof(result_list)); - for( pb_ad = dbi_first(iter); dbi_exists(iter); pb_ad = dbi_next(iter) ) - { + for( pb_ad = dbi_first(iter); dbi_exists(iter); pb_ad = dbi_next(iter) ) { if (pb_ad->index < lastindex || (level && (pb_ad->p_detail.level < level-15 || pb_ad->p_detail.level > level))) continue; - if (count >= PARTY_BOOKING_RESULTS){ + + if (count >= PARTY_BOOKING_RESULTS) { more_result = true; break; } + if (mapid == 0 && job == -1) result_list[count] = pb_ad; else if (mapid == 0) { for(i=0; ip_detail.job[i] == job && job != -1) result_list[count] = pb_ad; - } else if (job == -1){ + } else if (job == -1) { if (pb_ad->p_detail.mapid == mapid) result_list[count] = pb_ad; } + if( result_list[count] ) - { count++; - } } + dbi_destroy(iter); clif_PartyBookingSearchAck(sd->fd, result_list, count, more_result); } @@ -1302,10 +1357,10 @@ bool party_booking_delete(struct map_session_data *sd) { struct party_booking_ad_info* pb_ad; - if((pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id))!=NULL) - { + if((pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id)) != NULL) { clif_PartyBookingDeleteNotify(sd, pb_ad->index); idb_remove(party_booking_db,sd->status.char_id); } + return true; } diff --git a/src/map/path.c b/src/map/path.c index d13dfd43c5..26cb2cca15 100644 --- a/src/map/path.c +++ b/src/map/path.c @@ -254,7 +254,7 @@ static int add_path(struct node_heap *heap, struct path_node *tp, int16 x, int16 *------------------------------------------*/ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int flag, cell_chk cell) { - register int i, j, x, y, dx = 0, dy = 0; + register int i, x, y, dx = 0, dy = 0; struct map_data *md; struct walkpath_data s_wpd; @@ -263,6 +263,7 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x if (!map[m].cell) return false; + md = &map[m]; #ifdef CELL_NOSTACK @@ -288,8 +289,7 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x x = x0; // Current position = starting cell y = y0; i = 0; - while( i < ARRAYLENGTH(wpd->path) ) - { + while( i < ARRAYLENGTH(wpd->path) ) { wpd->path[i] = walk_choices[-dy + 1][dx + 1]; i++; @@ -305,16 +305,14 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x break; // obstacle = failure } - if( x == x1 && y == y1 ) - { // easy path successful. + if( x == x1 && y == y1 ) { // easy path successful. wpd->path_len = i; wpd->path_pos = 0; return true; } return false; // easy path unsuccessful - } - else { // !(flag&1) + } else { // !(flag&1) // A* (A-star) pathfinding // We always use A* for finding walkpaths because it is what game client uses. // Easy pathfinding cuts corners of non-walkable cells, but client always walks around it. @@ -329,6 +327,8 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x int xs = md->xs - 1; int ys = md->ys - 1; int len = 0; + int j; + memset(tp, 0, sizeof(tp)); // Start node @@ -341,8 +341,8 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x tp[i].flag = SET_OPEN; heap_push_node(&open_set, &tp[i]); // Put start node to 'open' set - for(;;) - { + + for(;;) { int e = 0; // error flag // Saves allowed directions for the current cell. Diagonal directions @@ -407,18 +407,19 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x } for (it = current; it->parent != NULL; it = it->parent, len++); - if (len > sizeof(wpd->path)) { + if (len > sizeof(wpd->path)) return false; - } // Recreate path wpd->path_len = len; wpd->path_pos = 0; + for (it = current, j = len-1; j >= 0; it = it->parent, j--) { dx = it->x - it->parent->x; dy = it->y - it->parent->y; wpd->path[j] = walk_choices[-dy + 1][dx + 1]; } + return true; } // A* end diff --git a/src/map/pc.c b/src/map/pc.c index 27d5794d03..eeb0ec1548 100755 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -10870,7 +10870,7 @@ int pc_autotrade_timer(int tid, unsigned int tick, int id, intptr_t data) { buyingstore_reopen(sd); vending_reopen(sd); - if (sd && !sd->vender_id && !sd->buyer_id) { + if (!sd->vender_id && !sd->buyer_id) { sd->state.autotrade = 0; map_quit(sd); } diff --git a/src/map/quest.c b/src/map/quest.c index 02a0e3f2e0..70dad95ef8 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -38,9 +38,11 @@ * @param quest_id ID to lookup * @return Quest entry (equals to &quest_dummy if the ID is invalid) */ -struct quest_db *quest_db(int quest_id) { +struct quest_db *quest_db(int quest_id) +{ if( quest_id < 0 || quest_id > MAX_QUEST_DB || quest_db_data[quest_id] == NULL ) return &quest_dummy; + return quest_db_data[quest_id]; } @@ -50,7 +52,8 @@ struct quest_db *quest_db(int quest_id) { * @param sd Player's data * @return 0 in case of success, nonzero otherwise (i.e. the player has no quests) */ -int quest_pc_login(TBL_PC *sd) { +int quest_pc_login(TBL_PC *sd) +{ int i; if( sd->avail_quests == 0 ) @@ -75,7 +78,8 @@ int quest_pc_login(TBL_PC *sd) { * @param quest_id ID of the quest to add. * @return 0 in case of success, nonzero otherwise */ -int quest_add(TBL_PC *sd, int quest_id) { +int quest_add(TBL_PC *sd, int quest_id) +{ int n; struct quest_db *qi = quest_db(quest_id); @@ -125,7 +129,8 @@ int quest_add(TBL_PC *sd, int quest_id) { * @param qid2 New quest to add * @return 0 in case of success, nonzero otherwise */ -int quest_change(TBL_PC *sd, int qid1, int qid2) { +int quest_change(TBL_PC *sd, int qid1, int qid2) +{ int i; struct quest_db *qi = quest_db(qid2); @@ -152,8 +157,10 @@ int quest_change(TBL_PC *sd, int qid1, int qid2) { memset(&sd->quest_log[i], 0, sizeof(struct quest)); sd->quest_log[i].quest_id = qi->id; + if( qi->time ) sd->quest_log[i].time = (unsigned int)(time(NULL) + qi->time); + sd->quest_log[i].state = Q_ACTIVE; sd->save_quest = true; @@ -175,7 +182,8 @@ int quest_change(TBL_PC *sd, int qid1, int qid2) { * @param quest_id ID of the quest to remove * @return 0 in case of success, nonzero otherwise */ -int quest_delete(TBL_PC *sd, int quest_id) { +int quest_delete(TBL_PC *sd, int quest_id) +{ int i; //Search for quest @@ -184,15 +192,19 @@ int quest_delete(TBL_PC *sd, int quest_id) { ShowError("quest_delete: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id); return -1; } + if( sd->quest_log[i].state != Q_COMPLETE ) sd->avail_quests--; + if( i < --sd->num_quests ) //Compact the array memmove(&sd->quest_log[i], &sd->quest_log[i + 1], sizeof(struct quest) * (sd->num_quests - i)); + if( sd->num_quests == 0 ) { aFree(sd->quest_log); sd->quest_log = NULL; } else RECREATE(sd->quest_log, struct quest, sd->num_quests); + sd->save_quest = true; clif_quest_delete(sd, quest_id); @@ -211,7 +223,8 @@ int quest_delete(TBL_PC *sd, int quest_id) { * int Party ID * int Mob ID */ -int quest_update_objective_sub(struct block_list *bl, va_list ap) { +int quest_update_objective_sub(struct block_list *bl, va_list ap) +{ struct map_session_data *sd; int mob, party; @@ -237,7 +250,8 @@ int quest_update_objective_sub(struct block_list *bl, va_list ap) { * @param sd Character's data * @param mob_id Monster ID */ -void quest_update_objective(TBL_PC *sd, int mob) { +void quest_update_objective(TBL_PC *sd, int mob) +{ int i, j; for( i = 0; i < sd->avail_quests; i++ ) { @@ -268,7 +282,8 @@ void quest_update_objective(TBL_PC *sd, int mob) { * @param qs New quest state * @return 0 in case of success, nonzero otherwise */ -int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status) { +int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status) +{ int i; ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id); @@ -317,7 +332,8 @@ int quest_update_status(TBL_PC *sd, int quest_id, enum quest_state status) { * 1 if the quest's timeout has expired * 0 otherwise */ -int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type) { +int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type) +{ int i; ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id); @@ -354,7 +370,8 @@ int quest_check(TBL_PC *sd, int quest_id, enum quest_check_type type) { * * @return Number of loaded quests, or -1 if the file couldn't be read. */ -int quest_read_db(void) { +int quest_read_db(void) +{ const char* dbsubpath[] = { "", DBIMPORT"/", @@ -373,11 +390,14 @@ int quest_read_db(void) { if( (fp = fopen(filename, "r")) == NULL ) { if (f == 0) ShowError("Can't read %s\n", filename); + return -1; } + while( fgets(line, sizeof(line), fp) ) { if( line[0] == '/' && line[1] == '/' ) continue; + memset(str, 0, sizeof(str)); for( i = 0, p = line; i < 8; i++ ) { @@ -392,6 +412,7 @@ int quest_read_db(void) { continue; } } + if( str[0] == NULL ) continue; @@ -422,6 +443,7 @@ int quest_read_db(void) { memcpy(quest_db_data[entry.id], &entry, sizeof(struct quest_db)); count++; } + fclose(fp); ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filename); } @@ -437,7 +459,8 @@ int quest_read_db(void) { * @see map_foreachpc * @param ap Ignored */ -int quest_reload_check_sub(struct map_session_data *sd, va_list ap) { +int quest_reload_check_sub(struct map_session_data *sd, va_list ap) +{ int i, j; nullpo_ret(sd); @@ -451,12 +474,15 @@ int quest_reload_check_sub(struct map_session_data *sd, va_list ap) { clif_quest_delete(sd, sd->quest_log[i].quest_id); continue; } + if( i != j ) { //Move entries if there's a gap to fill memcpy(&sd->quest_log[j], &sd->quest_log[i], sizeof(struct quest)); } + j++; } + sd->num_quests = j; ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].state == Q_COMPLETE); sd->avail_quests = i; @@ -467,7 +493,8 @@ int quest_reload_check_sub(struct map_session_data *sd, va_list ap) { /** * Clears the quest database for shutdown or reload. */ -void quest_clear_db(void) { +void quest_clear_db(void) +{ int i; for( i = 0; i < MAX_QUEST_DB; i++ ) { @@ -481,14 +508,16 @@ void quest_clear_db(void) { /** * Initializes the quest interface. */ -void do_init_quest(void) { +void do_init_quest(void) +{ quest_read_db(); } /** * Finalizes the quest interface before shutdown. */ -void do_final_quest(void) { +void do_final_quest(void) +{ memset(&quest_dummy, 0, sizeof(quest_dummy)); quest_clear_db(); @@ -497,7 +526,8 @@ void do_final_quest(void) { /** * Reloads the quest database. */ -void do_reload_quest(void) { +void do_reload_quest(void) +{ memset(&quest_dummy, 0, sizeof(quest_dummy)); quest_clear_db(); diff --git a/src/map/script.c b/src/map/script.c index e17ee7c3bb..7e04ac596a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -7538,18 +7538,18 @@ BUILDIN_FUNC(getpartyname) BUILDIN_FUNC(getpartymember) { struct party_data *p; - int type = 0; unsigned char j = 0; p = party_search(script_getnum(st,2)); - if (p != NULL){ + if (p != NULL) { + int type = 0; unsigned char i; if (script_hasdata(st,3)) type = script_getnum(st,3); - for (i = 0;iparty.member[i].account_id) { switch (type) { case 2: @@ -7562,10 +7562,12 @@ BUILDIN_FUNC(getpartymember) mapreg_setregstr(reference_uid(add_str("$@partymembername$"), j),p->party.member[i].name); break; } + j++; } } } + mapreg_setreg(add_str("$@partymembercount"),j); return SCRIPT_CMD_SUCCESS; } @@ -14328,7 +14330,6 @@ BUILDIN_FUNC(unequip) { BUILDIN_FUNC(equip) { unsigned short nameid = 0; - int i; TBL_PC *sd; struct item_data *item_data; @@ -14337,6 +14338,8 @@ BUILDIN_FUNC(equip) { nameid = script_getnum(st,2); if ((item_data = itemdb_exists(nameid))) { + int i; + ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == nameid ); if (i < MAX_INVENTORY) { pc_equipitem(sd,i,item_data->equip); @@ -14584,7 +14587,6 @@ BUILDIN_FUNC(substr) char *output; int start = script_getnum(st,3); int end = script_getnum(st,4); - int len = 0; if(start >= 0 && end < strlen(str) && start <= end) { @@ -14613,17 +14615,13 @@ BUILDIN_FUNC(explode) size_t len = strlen(str); int i = 0, j = 0; int start; - - char *temp; const char* name; - TBL_PC* sd = NULL; temp = (char*)aMalloc(len + 1); - if( !data_isreference(data) ) - { + if( !data_isreference(data) ) { ShowError("script:explode: not a variable\n"); script_reportdata(data); st->state = END; @@ -14634,24 +14632,21 @@ BUILDIN_FUNC(explode) start = reference_getindex(data); name = reference_getname(data); - if( not_array_variable(*name) ) - { + if( not_array_variable(*name) ) { ShowError("script:explode: illegal scope\n"); script_reportdata(data); st->state = END; return 1;// not supported } - if( !is_string_variable(name) ) - { + if( !is_string_variable(name) ) { ShowError("script:explode: not string array\n"); script_reportdata(data); st->state = END; return 1;// data type mismatch } - if( not_server_variable(*name) ) - { + if( not_server_variable(*name) ) { sd = script_rid2sd(st); if( sd == NULL ) return 0;// no player attached @@ -14667,6 +14662,7 @@ BUILDIN_FUNC(explode) temp[j++] = str[i++]; } } + //set last string temp[j] = '\0'; set_reg(st, sd, reference_uid(id, start), name, (void*)temp, reference_getref(data)); @@ -14684,13 +14680,9 @@ BUILDIN_FUNC(implode) struct script_data* data = script_getdata(st, 2); const char *name; int32 glue_len = 0, array_size, id; - - TBL_PC* sd = NULL; - char *output; - if( !data_isreference(data) ) - { + if( !data_isreference(data) ) { ShowError("script:implode: not a variable\n"); script_reportdata(data); st->state = END; @@ -14700,25 +14692,23 @@ BUILDIN_FUNC(implode) id = reference_getid(data); name = reference_getname(data); - if( not_array_variable(*name) ) - { + if( not_array_variable(*name) ) { ShowError("script:implode: illegal scope\n"); script_reportdata(data); st->state = END; return 1;// not supported } - if( !is_string_variable(name) ) - { + if( !is_string_variable(name) ) { ShowError("script:implode: not string array\n"); script_reportdata(data); st->state = END; return 1;// data type mismatch } - if( not_server_variable(*name) ) - { - sd = script_rid2sd(st); + if( not_server_variable(*name) ) { + TBL_PC* sd = script_rid2sd(st); + if( sd == NULL ) return 0;// no player attached } @@ -14726,8 +14716,7 @@ BUILDIN_FUNC(implode) //count chars array_size = getarraysize(st, id, reference_getindex(data), is_string_variable(name), reference_getref(data)) - 1; - if(array_size == -1) //empty array check (AmsTaff) - { + 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"); @@ -14756,18 +14745,20 @@ BUILDIN_FUNC(implode) len = strlen(temp); memcpy(&output[k], temp, len); k += len; + if(glue_len != 0) { memcpy(&output[k], glue, glue_len); k += glue_len; } + script_removetop(st, -1, 0); } + temp = (char*) get_val2(st, reference_uid(id, array_size), reference_getref(data)); len = strlen(temp); memcpy(&output[k], temp, len); k += len; script_removetop(st, -1, 0); - output[k] = '\0'; } @@ -14797,7 +14788,7 @@ BUILDIN_FUNC(sprintf) len = strlen(format); // Skip parsing, where no parsing is required. - if(len==0){ + if(len == 0) { script_pushconststr(st,""); return 0; } @@ -14806,7 +14797,7 @@ BUILDIN_FUNC(sprintf) CREATE(buf, char, len+1); // Need not be parsed, just solve stuff like %%. - if(argc==0){ + if(argc == 0) { memcpy(buf,format,len+1); script_pushstrcopy(st, buf); aFree(buf); @@ -14818,30 +14809,36 @@ BUILDIN_FUNC(sprintf) // Issue sprintf for each parameter StringBuf_Init(&final_buf); q = buf; - while((p = strchr(q, '%'))!=NULL){ - if(p!=q){ - len = p-q+1; - if(buf2_len=argc){ + + if(arg >= argc) { ShowError("buildin_sprintf: Not enough arguments passed!\n"); if(buf) aFree(buf); if(buf2) aFree(buf2); @@ -14849,14 +14846,17 @@ BUILDIN_FUNC(sprintf) script_pushconststr(st,""); return 1; } - if((p = strchr(q+1, '%'))==NULL){ + + if((p = strchr(q+1, '%')) == NULL) p = strchr(q, 0); // EOS - } - len = p-q+1; - if(buf2_lensubtype != NPCTYPE_SHOP && nd->subtype != NPCTYPE_CASHSHOP && nd->subtype != NPCTYPE_ITEMSHOP && nd->subtype != NPCTYPE_POINTSHOP ) ) - { //Not found. + if( !nd || ( nd->subtype != NPCTYPE_SHOP && nd->subtype != NPCTYPE_CASHSHOP && nd->subtype != NPCTYPE_ITEMSHOP && nd->subtype != NPCTYPE_POINTSHOP ) ) { // Not found. script_pushint(st,0); return 0; } @@ -15678,13 +15677,11 @@ BUILDIN_FUNC(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 short nameid = script_getnum(st,i); ARR_FIND( 0, size, n, nd->u.shop.shop_item[n].nameid == nameid ); - if( n < size ) - { + 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--; } diff --git a/src/map/searchstore.c b/src/map/searchstore.c index 4dfad91ad4..957c1c4203 100644 --- a/src/map/searchstore.c +++ b/src/map/searchstore.c @@ -12,7 +12,8 @@ /// failure constants for clif functions -enum e_searchstore_failure { +enum e_searchstore_failure +{ SSI_FAILED_NOTHING_SEARCH_ITEM = 0, // "No matching stores were found." SSI_FAILED_OVER_MAXCOUNT = 1, // "There are too many results. Please enter more detailed search term." SSI_FAILED_SEARCH_CNT = 2, // "You cannot search anymore." @@ -20,81 +21,75 @@ enum e_searchstore_failure { SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE = 4, // "No sale (purchase) information available." }; - -enum e_searchstore_searchtype { +enum e_searchstore_searchtype +{ SEARCHTYPE_VENDING = 0, SEARCHTYPE_BUYING_STORE = 1, }; -enum e_searchstore_effecttype { +enum e_searchstore_effecttype +{ EFFECTTYPE_NORMAL = 0, EFFECTTYPE_CASH = 1, EFFECTTYPE_MAX }; - /// type for shop search function typedef bool (*searchstore_search_t)(struct map_session_data* sd, unsigned short nameid); typedef bool (*searchstore_searchall_t)(struct map_session_data* sd, const struct s_search_store_search* s); - /// retrieves search function by type static searchstore_search_t searchstore_getsearchfunc(unsigned char type) { - switch( type ) - { + switch( type ) { case SEARCHTYPE_VENDING: return &vending_search; case SEARCHTYPE_BUYING_STORE: return &buyingstore_search; } + return NULL; } - /// retrieves search-all function by type static searchstore_searchall_t searchstore_getsearchallfunc(unsigned char type) { - switch( type ) - { + switch( type ) { case SEARCHTYPE_VENDING: return &vending_searchall; case SEARCHTYPE_BUYING_STORE: return &buyingstore_searchall; } + return NULL; } - /// checks if the player has a store by type static bool searchstore_hasstore(struct map_session_data* sd, unsigned char type) { - switch( type ) - { + switch( type ) { case SEARCHTYPE_VENDING: return sd->state.vending; case SEARCHTYPE_BUYING_STORE: return sd->state.buyingstore; } + return false; } - /// returns player's store id by type static int searchstore_getstoreid(struct map_session_data* sd, unsigned char type) { - switch( type ) - { + switch( type ) { case SEARCHTYPE_VENDING: return sd->vender_id; case SEARCHTYPE_BUYING_STORE: return sd->buyer_id; } + return 0; } - -bool searchstore_open(struct map_session_data* sd, unsigned int uses, unsigned short effect) { - if( !battle_config.feature_search_stores || sd->searchstore.open ) { +bool searchstore_open(struct map_session_data* sd, unsigned int uses, unsigned short effect) +{ + if( !battle_config.feature_search_stores || sd->searchstore.open ) return false; - } - if( !uses || effect >= EFFECTTYPE_MAX ) {// invalid input + if( !uses || effect >= EFFECTTYPE_MAX ) // invalid input return false; - } sd->searchstore.open = true; sd->searchstore.uses = uses; @@ -105,7 +100,6 @@ bool searchstore_open(struct map_session_data* sd, unsigned int uses, unsigned s return true; } - void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned int min_price, unsigned int max_price, const unsigned short* itemlist, unsigned int item_count, const unsigned short* cardlist, unsigned int card_count) { unsigned int i; @@ -115,13 +109,11 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned searchstore_searchall_t store_searchall; time_t querytime; - if( !battle_config.feature_search_stores ) { + if( !battle_config.feature_search_stores ) return; - } - if( !sd->searchstore.open ) { + if( !sd->searchstore.open ) return; - } if( ( store_searchall = searchstore_getsearchallfunc(type) ) == NULL ) { ShowError("searchstore_query: Unknown search type %u (account_id=%d).\n", (unsigned int)type, sd->bl.id); @@ -156,9 +148,8 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned } } - if( max_price < min_price ) { + if( max_price < min_price ) swap(min_price, max_price); - } sd->searchstore.uses--; sd->searchstore.type = type; @@ -181,11 +172,10 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned iter = db_iterator((type == SEARCHTYPE_VENDING) ? vending_getdb() : buyingstore_getdb()); for( pl_sd = dbi_first(iter); dbi_exists(iter); pl_sd = dbi_next(iter) ) { - if( sd == pl_sd ) {// skip own shop, if any + if( sd == pl_sd ) // skip own shop, if any continue; - } - if( !store_searchall(pl_sd, &s) ) {// exceeded result size + if( !store_searchall(pl_sd, &s) ) { // exceeded result size clif_search_store_info_failed(sd, SSI_FAILED_OVER_MAXCOUNT); break; } @@ -214,18 +204,17 @@ void searchstore_query(struct map_session_data* sd, unsigned char type, unsigned } } - /// checks whether or not more results are available for the client -bool searchstore_querynext(struct map_session_data* sd) { - if( sd->searchstore.count && ( sd->searchstore.count-1 )/SEARCHSTORE_RESULTS_PER_PAGE < sd->searchstore.pages ) { +bool searchstore_querynext(struct map_session_data* sd) +{ + if( sd->searchstore.count && ( sd->searchstore.count-1 )/SEARCHSTORE_RESULTS_PER_PAGE < sd->searchstore.pages ) return true; - } return false; } - -void searchstore_next(struct map_session_data* sd) { +void searchstore_next(struct map_session_data* sd) +{ if( !battle_config.feature_search_stores || !sd->searchstore.open || sd->searchstore.count <= sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE ) {// nothing (more) to display return; @@ -238,11 +227,11 @@ void searchstore_next(struct map_session_data* sd) { sd->searchstore.pages++; } - -void searchstore_clear(struct map_session_data* sd) { +void searchstore_clear(struct map_session_data* sd) +{ searchstore_clearremote(sd); - if( sd->searchstore.items ) {// release results + if( sd->searchstore.items ) { // release results aFree(sd->searchstore.items); sd->searchstore.items = NULL; } @@ -252,7 +241,8 @@ void searchstore_clear(struct map_session_data* sd) { } -void searchstore_close(struct map_session_data* sd) { +void searchstore_close(struct map_session_data* sd) +{ if( sd->searchstore.open ) { searchstore_clear(sd); @@ -262,31 +252,30 @@ void searchstore_close(struct map_session_data* sd) { } -void searchstore_click(struct map_session_data* sd, int account_id, int store_id, unsigned short nameid) { +void searchstore_click(struct map_session_data* sd, int account_id, int store_id, unsigned short nameid) +{ unsigned int i; struct map_session_data* pl_sd; searchstore_search_t store_search; - if( !battle_config.feature_search_stores || !sd->searchstore.open || !sd->searchstore.count ) { + if( !battle_config.feature_search_stores || !sd->searchstore.open || !sd->searchstore.count ) return; - } searchstore_clearremote(sd); ARR_FIND( 0, sd->searchstore.count, i, sd->searchstore.items[i].store_id == store_id && sd->searchstore.items[i].account_id == account_id && sd->searchstore.items[i].nameid == nameid ); - if( i == sd->searchstore.count ) {// no such result, crafted + if( i == sd->searchstore.count ) { // no such result, crafted ShowWarning("searchstore_click: Received request with item %hu of account %d, which is not part of current result set (account_id=%d, char_id=%d).\n", nameid, account_id, sd->bl.id, sd->status.char_id); clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE); return; } - if( ( pl_sd = map_id2sd(account_id) ) == NULL ) {// no longer online + if( ( pl_sd = map_id2sd(account_id) ) == NULL ) { // no longer online clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE); return; } - if( !searchstore_hasstore(pl_sd, sd->searchstore.type) || searchstore_getstoreid(pl_sd, sd->searchstore.type) != store_id ) - {// no longer vending/buying or not same shop + if( !searchstore_hasstore(pl_sd, sd->searchstore.type) || searchstore_getstoreid(pl_sd, sd->searchstore.type) != store_id ) { // no longer vending/buying or not same shop clif_search_store_info_failed(sd, SSI_FAILED_SSILIST_CLICK_TO_OPEN_STORE); return; } @@ -301,26 +290,20 @@ void searchstore_click(struct map_session_data* sd, int account_id, int store_id switch( sd->searchstore.effect ) { case EFFECTTYPE_NORMAL: // display coords - - if( sd->bl.m != pl_sd->bl.m ) {// not on same map, wipe previous marker + if( sd->bl.m != pl_sd->bl.m ) // not on same map, wipe previous marker clif_search_store_info_click_ack(sd, -1, -1); - } else { + else clif_search_store_info_click_ack(sd, pl_sd->bl.x, pl_sd->bl.y); - } - break; case EFFECTTYPE_CASH: // open remotely - // to bypass range checks sd->searchstore.remote_id = account_id; - switch( sd->searchstore.type ) - { + switch( sd->searchstore.type ) { case SEARCHTYPE_VENDING: vending_vendinglistreq(sd, account_id); break; case SEARCHTYPE_BUYING_STORE: buyingstore_open(sd, account_id); break; } - break; default: // unknown @@ -328,27 +311,25 @@ void searchstore_click(struct map_session_data* sd, int account_id, int store_id } } - /// checks whether or not sd has opened account_id's shop remotely -bool searchstore_queryremote(struct map_session_data* sd, int account_id) { +bool searchstore_queryremote(struct map_session_data* sd, int account_id) +{ return (bool)( sd->searchstore.open && sd->searchstore.count && sd->searchstore.remote_id == account_id ); } - /// removes range-check bypassing for remotely opened stores -void searchstore_clearremote(struct map_session_data* sd) { +void searchstore_clearremote(struct map_session_data* sd) +{ sd->searchstore.remote_id = 0; } - /// receives results from a store-specific callback bool searchstore_result(struct map_session_data* sd, int store_id, int account_id, const char* store_name, unsigned short nameid, unsigned short amount, unsigned int price, const unsigned short* card, unsigned char refine) { struct s_search_store_info_item* ssitem; - if( sd->searchstore.count >= (unsigned int)battle_config.searchstore_maxresults ) {// no more + if( sd->searchstore.count >= (unsigned int)battle_config.searchstore_maxresults ) // no more return false; - } ssitem = &sd->searchstore.items[sd->searchstore.count++]; ssitem->store_id = store_id; diff --git a/src/map/skill.c b/src/map/skill.c index 594f35df07..dc2575165a 100755 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -65,7 +65,7 @@ DBMap* skillunit_db = NULL; // int id -> struct skill_unit* /** * Skill Unit Persistency during endack routes (mostly for songs see bugreport:4574) - **/ + */ DBMap* skillusave_db = NULL; // char_id -> struct skill_usave struct skill_usave { uint16 skill_id, skill_lv; @@ -329,14 +329,15 @@ int skill_get_range2 (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { return range; } -/** Calculates heal value of skill's effect -* @param src -* @param target -* @param skill_id -* @param skill_lv -* @param heal -* @return modified heal value -*/ +/** + * Calculates heal value of skill's effect + * @param src + * @param target + * @param skill_id + * @param skill_lv + * @param heal + * @return modified heal value + */ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, bool heal) { int skill, hp = 0; struct map_session_data *sd = BL_CAST(BL_PC, src); @@ -348,11 +349,11 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk switch( skill_id ) { case BA_APPLEIDUN: - #ifdef RENEWAL +#ifdef RENEWAL hp = 100+5*skill_lv+5*(status_get_vit(src)/10); // HP recovery - #else +#else hp = 30+5*skill_lv+5*(status_get_vit(src)/10); // HP recovery - #endif +#endif if( sd ) hp += 5*pc_checkskill(sd,BA_MUSICALLESSON); break; @@ -365,15 +366,15 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk default: if (skill_lv >= battle_config.max_heal_lv) return battle_config.max_heal; - #ifdef RENEWAL - /** - * Renewal Heal Formula - * Formula: ( [(Base Level + INT) / 5] x 30 ) x (Heal Level / 10) x (Modifiers) + MATK - **/ - hp = (status_get_lv(src) + status_get_int(src)) / 5 * 30 * (skill_id == AB_HIGHNESSHEAL ? ((sd) ? pc_checkskill(sd,AL_HEAL) : skill_get_max(AL_HEAL)) : skill_lv) / 10; - #else - hp = (status_get_lv(src) + status_get_int(src)) / 8 * (4 + ( (skill_id == AB_HIGHNESSHEAL ? ((sd) ? pc_checkskill(sd,AL_HEAL) : skill_get_max(AL_HEAL)) : skill_lv) * 8)); - #endif +#ifdef RENEWAL + /** + * Renewal Heal Formula + * Formula: ( [(Base Level + INT) / 5] x 30 ) x (Heal Level / 10) x (Modifiers) + MATK + */ + hp = (status_get_lv(src) + status_get_int(src)) / 5 * 30 * (skill_id == AB_HIGHNESSHEAL ? ((sd) ? pc_checkskill(sd,AL_HEAL) : skill_get_max(AL_HEAL)) : skill_lv) / 10; +#else + hp = (status_get_lv(src) + status_get_int(src)) / 8 * (4 + ( (skill_id == AB_HIGHNESSHEAL ? ((sd) ? pc_checkskill(sd,AL_HEAL) : skill_get_max(AL_HEAL)) : skill_lv) * 8)); +#endif if (skill_id == AB_HIGHNESSHEAL) hp = hp * ( 17 + 3 * skill_lv ) / 10; if( sd && ((skill = pc_checkskill(sd, HP_MEDITATIO)) > 0) ) @@ -446,13 +447,14 @@ int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 sk return hp; } -/** Making Plagiarism and Reproduce check their own function -* Previous prevention for NPC skills, Wedding skills, and INF3_DIS_PLAGIA are removed since we use skill_copyable_db.txt [Cydh] -* @param sd: Player who will copy the skill -* @param skill_id: Target skill -* @return 0 - Cannot be copied; 1 - Can be copied by Plagiarism 2 - Can be copied by Reproduce -* @author Aru - for previous check; Jobbie for class restriction idea; Cydh expands the copyable skill -*/ +/** + * Making Plagiarism and Reproduce check their own function + * Previous prevention for NPC skills, Wedding skills, and INF3_DIS_PLAGIA are removed since we use skill_copyable_db.txt [Cydh] + * @param sd: Player who will copy the skill + * @param skill_id: Target skill + * @return 0 - Cannot be copied; 1 - Can be copied by Plagiarism 2 - Can be copied by Reproduce + * @author Aru - for previous check; Jobbie for class restriction idea; Cydh expands the copyable skill + */ static char skill_isCopyable(struct map_session_data *sd, uint16 skill_id) { uint16 idx = skill_get_index(skill_id); @@ -485,13 +487,14 @@ static char skill_isCopyable(struct map_session_data *sd, uint16 skill_id) { return 0; } -/** Check if the skill is ok to cast and when. -* Done before check_condition_begin, requirement -* @param skill_id: Skill ID that casted -* @param sd: Player who casted -* @return true: Skill cannot be used, false: otherwise -* @author [MouseJstr] -*/ +/** + * Check if the skill is ok to cast and when. + * Done before check_condition_begin, requirement + * @param skill_id: Skill ID that casted + * @param sd: Player who casted + * @return true: Skill cannot be used, false: otherwise + * @author [MouseJstr] + */ bool skill_isNotOk(uint16 skill_id, struct map_session_data *sd) { int16 idx,m; @@ -529,7 +532,7 @@ bool skill_isNotOk(uint16 skill_id, struct map_session_data *sd) /** * It has been confirmed on a official server (thanks to Yommy) that item-cast skills bypass all the restrictions above * Also, without this check, an exploit where an item casting + healing (or any other kind buff) isn't deleted after used on a restricted map - **/ + */ if( sd->skillitem == skill_id ) return false; // Check skill restrictions [Celest] @@ -632,12 +635,13 @@ bool skill_isNotOk(uint16 skill_id, struct map_session_data *sd) return false; } -/** Check if the homunculus skill is ok to be processed -* After checking from Homunculus side, also check the master condition -* @param skill_id: Skill ID that casted -* @param hd: Homunculus who casted -* @return true: Skill cannot be used, false: otherwise -*/ +/** + * Check if the homunculus skill is ok to be processed + * After checking from Homunculus side, also check the master condition + * @param skill_id: Skill ID that casted + * @param hd: Homunculus who casted + * @return true: Skill cannot be used, false: otherwise + */ bool skill_isNotOk_hom(uint16 skill_id, struct homun_data *hd) { uint16 idx = skill_get_index(skill_id); @@ -699,38 +703,41 @@ bool skill_isNotOk_hom(uint16 skill_id, struct homun_data *hd) return skill_isNotOk(skill_id, hd->master); } -/** Check if the mercenary skill is ok to be processed -* After checking from Homunculus side, also check the master condition -* @param skill_id: Skill ID that casted -* @param md: Mercenary who casted -* @return true: Skill cannot be used, false: otherwise -*/ +/** + * Check if the mercenary skill is ok to be processed + * After checking from Homunculus side, also check the master condition + * @param skill_id: Skill ID that casted + * @param md: Mercenary who casted + * @return true: Skill cannot be used, false: otherwise + */ bool skill_isNotOk_mercenary(uint16 skill_id, struct mercenary_data *md) { uint16 idx = skill_get_index(skill_id); - nullpo_retr(1,md); - if( idx == 0 ) + nullpo_retr(1, md); + + if (!idx) return true; // Invalid Skill ID - if( md->blockskill[idx] > 0 ) + if (md->blockskill[idx] > 0) return true; return skill_isNotOk(skill_id, md->master); } -/** Check if the skill can be casted near NPC or not -* @param src Object who casted -* @param skill_id Skill ID that casted -* @param skill_lv Skill Lv -* @param pos_x Position x of the target -* @param pos_y Position y of the target -* @return true: Skill cannot be used, false: otherwise -* @author [Cydh] -*/ +/** + * Check if the skill can be casted near NPC or not + * @param src Object who casted + * @param skill_id Skill ID that casted + * @param skill_lv Skill Lv + * @param pos_x Position x of the target + * @param pos_y Position y of the target + * @return true: Skill cannot be used, false: otherwise + * @author [Cydh] + */ bool skill_isNotOk_npcRange(struct block_list *src, uint16 skill_id, uint16 skill_lv, int pos_x, int pos_y) { int inf; - if (!src || skill_get_index(skill_id) == 0) + if (!src || !skill_get_index(skill_id)) return false; if (src->type == BL_PC && pc_has_permission(BL_CAST(BL_PC,src),PC_PERM_SKILL_UNCONDITIONAL)) @@ -749,7 +756,8 @@ bool skill_isNotOk_npcRange(struct block_list *src, uint16 skill_id, uint16 skil return skill_check_unit_range2(src,pos_x,pos_y,skill_id,skill_lv,true); } -struct s_skill_unit_layout* skill_get_unit_layout (uint16 skill_id, uint16 skill_lv, struct block_list* src, int x, int y) { +struct s_skill_unit_layout *skill_get_unit_layout(uint16 skill_id, uint16 skill_lv, struct block_list* src, int x, int y) +{ int pos = skill_get_unit_layout_type(skill_id,skill_lv); uint8 dir; @@ -792,7 +800,7 @@ struct s_skill_nounit_layout* skill_get_nounit_layout(uint16 skill_id, uint16 sk /*========================================== * Add effect to skill when hit succesfully target *------------------------------------------*/ -int skill_additional_effect (struct block_list* src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int attack_type, int dmg_lv, unsigned int tick) +int skill_additional_effect(struct block_list* src, struct block_list *bl, uint16 skill_id, uint16 skill_lv, int attack_type, int dmg_lv, unsigned int tick) { struct map_session_data *sd, *dstsd; struct mob_data *md, *dstmd; @@ -1005,9 +1013,7 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint break; case WZ_STORMGUST: - /** - * Storm Gust counter was dropped in renewal - **/ + // Storm Gust counter was dropped in renewal #ifdef RENEWAL sc_start(src,bl,SC_FREEZE,65-(5*skill_lv),skill_lv,skill_get_time2(skill_id,skill_lv)); #else @@ -1015,9 +1021,7 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint if(tsc->sg_counter >= 3 && sc_start(src,bl,SC_FREEZE,150,skill_lv,skill_get_time2(skill_id,skill_lv))) tsc->sg_counter = 0; - /** - * being it only resets on success it'd keep stacking and eventually overflowing on mvps, so we reset at a high value - **/ + // Being it only resets on success it'd keep stacking and eventually overflowing on mvps, so we reset at a high value else if( tsc->sg_counter > 250 ) tsc->sg_counter = 0; #endif @@ -2217,13 +2221,14 @@ int skill_counter_additional_effect (struct block_list* src, struct block_list * return 0; } + /*========================================================================= Breaks equipment. On-non players causes the corresponding strip effect. - rate goes from 0 to 10000 (100.00%) - 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 *src,struct block_list *bl, unsigned short where, int rate, int flag) +int skill_break_equip(struct block_list *src, 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_STRIPWEAPON, SC_STRIPARMOR, SC_STRIPSHIELD, SC_STRIPHELM}; @@ -2350,7 +2355,7 @@ int skill_strip_equip(struct block_list *src,struct block_list *bl, unsigned sho */ static int skill_area_temp[8]; -/*========================================================================= +/** Used to knock back players, monsters, traps, etc * @param src Object that give knock back * @param target Object that receive knock back @@ -2365,14 +2370,15 @@ static int skill_area_temp[8]; 0x10 - if target has 'special_state.no_knockback'; 0x20 - if target is in Basilica area; * @return Number of knocked back cells done - -------------------------------------------------------------------------*/ -short skill_blown(struct block_list* src, struct block_list* target, char count, int8 dir, unsigned char flag) { + */ +short skill_blown(struct block_list* src, struct block_list* target, char count, int8 dir, unsigned char flag) +{ int dx = 0, dy = 0; nullpo_ret(src); nullpo_ret(target); - if (count == 0) + if (!count) return count; // Actual knockback distance is 0. if (src != target && (map_flag_gvg(target->m) || map[target->m].flag.battleground)) @@ -2460,7 +2466,7 @@ static int skill_magic_reflect(struct block_list* src, struct block_list* bl, in * @param skill_id: Target skill * @return true: Skill is a combo, false: otherwise * @author Panikon - **/ + */ bool skill_is_combo(uint16 skill_id) { switch(skill_id) { case MO_CHAINCOMBO: @@ -2619,14 +2625,16 @@ void skill_combo(struct block_list* src,struct block_list *dsrc, struct block_li } } -/** Copy skill by Plagiarism or Reproduce -* @param src: The caster -* @param bl: The target -* @param skill_id: Skill that casted -* @param skill_lv: Skill level of the casted skill -*/ -static void skill_do_copy(struct block_list* src,struct block_list *bl, uint16 skill_id, uint16 skill_lv){ - TBL_PC *tsd = BL_CAST(BL_PC,bl); +/** + * Copy skill by Plagiarism or Reproduce + * @param src: The caster + * @param bl: The target + * @param skill_id: Skill that casted + * @param skill_lv: Skill level of the casted skill + */ +static void skill_do_copy(struct block_list* src,struct block_list *bl, uint16 skill_id, uint16 skill_lv) +{ + TBL_PC *tsd = BL_CAST(BL_PC, bl); if (!tsd || (!pc_checkskill(tsd,RG_PLAGIARISM) && !pc_checkskill(tsd,SC_REPRODUCE))) return; @@ -2723,17 +2731,17 @@ static void skill_do_copy(struct block_list* src,struct block_list *bl, uint16 s } /** -* Knockback the target on skill_attack -* @param src is the master behind the attack -* @param dsrc is the actual originator of the damage, can be the same as src, or a BL_SKILL -* @param target is the target to be attacked. -* @param blewcount -* @param skill_id -* @param skill_lv -* @param damage -* @param tick -* @param flag can hold a bunch of information: -*/ + * Knockback the target on skill_attack + * @param src is the master behind the attack + * @param dsrc is the actual originator of the damage, can be the same as src, or a BL_SKILL + * @param target is the target to be attacked. + * @param blewcount + * @param skill_id + * @param skill_lv + * @param damage + * @param tick + * @param flag can hold a bunch of information: + */ void skill_attack_blow(struct block_list *src, struct block_list *dsrc, struct block_list *target, uint8 blewcount, uint16 skill_id, uint16 skill_lv, int64 damage, unsigned int tick, int flag) { int8 dir = -1; // Default direction //Only knockback if it's still alive, otherwise a "ghost" is left behind. [Skotlex] @@ -2920,9 +2928,7 @@ int64 skill_attack (int attack_type, struct block_list* src, struct block_list * } else if( type != 2 ) /* Kaite bypasses */ additional_effects = false; - /** - * Official Magic Reflection Behavior : damage reflected depends on gears caster wears, not target - **/ + // Official Magic Reflection Behavior : damage reflected depends on gears caster wears, not target #if MAGIC_REFLECTION_TYPE #ifdef RENEWAL if( dmg.dmg_lv != ATK_MISS ) { //Wiz SL cancelled and consumed fragment @@ -3249,10 +3255,7 @@ int64 skill_attack (int attack_type, struct block_list* src, struct block_list * battle_drain(sd, bl, dmg.damage, dmg.damage2, tstatus->race, tstatus->class_); } - if( damage > 0 ) { - /** - * Post-damage effects - **/ + if( damage > 0 ) { // Post-damage effects switch( skill_id ) { case GC_VENOMPRESSURE: { struct status_change *ssc = status_get_sc(src); @@ -3294,7 +3297,8 @@ int64 skill_attack (int attack_type, struct block_list* src, struct block_list * * then call func with source,target,skill_id,skill_lv,tick,flag *------------------------------------------*/ typedef int (*SkillFunc)(struct block_list *, struct block_list *, int, int, unsigned int, int); -int skill_area_sub (struct block_list *bl, va_list ap) { +int skill_area_sub(struct block_list *bl, va_list ap) +{ struct block_list *src; uint16 skill_id,skill_lv; int flag; @@ -3303,15 +3307,14 @@ int skill_area_sub (struct block_list *bl, va_list ap) { nullpo_ret(bl); - src=va_arg(ap,struct block_list *); - skill_id=va_arg(ap,int); - skill_lv=va_arg(ap,int); - tick=va_arg(ap,unsigned int); - flag=va_arg(ap,int); - func=va_arg(ap,SkillFunc); + src = va_arg(ap,struct block_list *); + skill_id = va_arg(ap,int); + skill_lv = va_arg(ap,int); + tick = va_arg(ap,unsigned int); + flag = va_arg(ap,int); + func = va_arg(ap,SkillFunc); - if(battle_check_target(src,bl,flag) > 0) - { + if(battle_check_target(src,bl,flag) > 0) { // several splash skills need this initial dummy packet to display correctly if (flag&SD_PREAMBLE && skill_area_temp[2] == 0) clif_skill_damage(src,bl,tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6); @@ -3324,7 +3327,7 @@ int skill_area_sub (struct block_list *bl, va_list ap) { return 0; } -static int skill_check_unit_range_sub (struct block_list *bl, va_list ap) +static int skill_check_unit_range_sub(struct block_list *bl, va_list ap) { struct skill_unit *unit; uint16 skill_id,g_skill_id; @@ -3425,15 +3428,16 @@ static int skill_check_unit_range2_sub (struct block_list *bl, va_list ap) return 1; } -/** Used to check range condition of the casted skill. Used if the skill has UF_NOFOOTSET or INF2_NO_NEARNPC -* @param bl Object that casted skill -* @param x Position x of the target -* @param y Position y of the target -* @param skill_id The casted skill -* @param skill_lv The skill Lv -* @param isNearNPC 'true' means, check the range between target and nearer NPC by using npc_isnear and range calculation [Cydh] -* @return 0: No object (BL_CHAR or BL_PC) within the range. If 'isNearNPC' the target oject is BL_NPC -*/ +/** + * Used to check range condition of the casted skill. Used if the skill has UF_NOFOOTSET or INF2_NO_NEARNPC + * @param bl Object that casted skill + * @param x Position x of the target + * @param y Position y of the target + * @param skill_id The casted skill + * @param skill_lv The skill Lv + * @param isNearNPC 'true' means, check the range between target and nearer NPC by using npc_isnear and range calculation [Cydh] + * @return 0: No object (BL_CHAR or BL_PC) within the range. If 'isNearNPC' the target oject is BL_NPC + */ static int skill_check_unit_range2 (struct block_list *bl, int x, int y, uint16 skill_id, uint16 skill_lv, bool isNearNPC) { int range = 0, type; @@ -3452,9 +3456,9 @@ static int skill_check_unit_range2 (struct block_list *bl, int x, int y, uint16 case GN_HELLS_PLANT: range = 0; break; - default: - { + default: { int layout_type = skill_get_unit_layout_type(skill_id,skill_lv); + if (layout_type == -1 || layout_type > MAX_SQUARE_LAYOUT) { ShowError("skill_check_unit_range2: unsupported layout type %d for skill %d\n",layout_type,skill_id); return 0; @@ -3475,8 +3479,7 @@ static int skill_check_unit_range2 (struct block_list *bl, int x, int y, uint16 type = BL_CHAR; else type = BL_PC; - } - else + } else type = BL_NPC; return (!isNearNPC) ? @@ -3729,9 +3732,6 @@ static int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data) } } break; - /** - * Warlock - **/ case WL_CHAINLIGHTNING_ATK: { skill_attack(BF_MAGIC,src,src,target,skl->skill_id,skl->skill_lv,tick,skl->flag); // Hit a Lightning on the current Target skill_toggle_magicpower(src, skl->skill_id); // only the first hit will be amplify @@ -3963,22 +3963,26 @@ int skill_cleartimerskill (struct block_list *src) } return 1; } -static int skill_ative_reverberation( struct block_list *bl, va_list ap) { +static int skill_active_reverberation(struct block_list *bl, va_list ap) { struct skill_unit *su = (TBL_SKILL*)bl; - struct skill_unit_group *sg; - if( bl->type != BL_SKILL ) + struct skill_unit_group *sg = NULL; + + nullpo_ret(su); + + if (bl->type != BL_SKILL) return 0; - if( su->alive && (sg = su->group) && sg->skill_id == WM_REVERBERATION ) { + if (su->alive && (sg = su->group) && sg->skill_id == WM_REVERBERATION) { map_foreachinrange(skill_trap_splash, bl, skill_get_splash(sg->skill_id, sg->skill_lv), sg->bl_flag, bl, gettick()); - su->limit=DIFF_TICK(gettick(),sg->tick); + su->limit = DIFF_TICK(gettick(), sg->tick); sg->unit_id = UNT_USED_TRAPS; } return 0; } -static int skill_reveal_trap (struct block_list *bl, va_list ap) +static int skill_reveal_trap(struct block_list *bl, va_list ap) { TBL_SKILL *su = (TBL_SKILL*)bl; + if (su->alive && su->group && skill_get_inf2(su->group->skill_id)&INF2_TRAP) { //Reveal trap. //Change look is not good enough, the client ignores it as an actual trap still. [Skotlex] @@ -4155,9 +4159,6 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint skill_attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag); break; - /** - * Mechanic (MADO GEAR) - **/ case NC_BOOSTKNUCKLE: case NC_PILEBUNKER: case NC_COLDSLOWER: @@ -4735,9 +4736,6 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint } break; #endif - /** - * Rune Knight - **/ case RK_DRAGONBREATH_WATER: case RK_DRAGONBREATH: { struct status_change *tsc2 = NULL; @@ -5086,11 +5084,10 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint } else { - struct skill_unit *su = BL_CAST(BL_SKILL,bl); + struct skill_unit *su = NULL; struct skill_unit_group* sg; - if( su && (sg=su->group) && skill_get_inf2(sg->skill_id)&INF2_TRAP ) - { + if (su && (sg = su->group) && skill_get_inf2(sg->skill_id)&INF2_TRAP) { if( !(sg->unit_id == UNT_USED_TRAPS || (sg->unit_id == UNT_ANKLESNARE && sg->val2 != 0 )) ) { struct item item_tmp; @@ -5536,10 +5533,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui return 1; if( src != bl && status_isdead(bl) ) { - /** - * Skills that may be cast on dead targets - **/ - switch( skill_id ) { + switch( skill_id ) { // Skills that may be cast on dead targets case NPC_WIDESOULDRAIN: case PR_REDEMPTIO: case ALL_RESURRECTION: @@ -5573,9 +5567,6 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui case AL_HEAL: case ALL_RESURRECTION: case PR_ASPERSIO: - /** - * Arch Bishop - **/ case AB_RENOVATIO: case AB_HIGHNESSHEAL: //Apparently only player casted skills can be offensive like this. @@ -5656,9 +5647,6 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui { case HLIF_HEAL: //[orn] case AL_HEAL: - /** - * Arch Bishop - **/ case AB_HIGHNESSHEAL: { int heal = skill_calc_heal(src, bl, skill_id, skill_lv, true); @@ -7345,9 +7333,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui case SC_EXTREMITYFIST2: #endif continue; - /** - * bugreport:4888 these songs may only be dispelled if you're not in their song area anymore - **/ + // bugreport:4888 these songs may only be dispelled if you're not in their song area anymore case SC_WHISTLE: case SC_ASSNCROS: case SC_POEMBRAGI: @@ -7746,7 +7732,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui case HT_REMOVETRAP: { struct skill_unit* su; - struct skill_unit_group* sg; + struct skill_unit_group* sg = NULL; su = BL_CAST(BL_SKILL, bl); // Mercenaries can remove any trap @@ -7831,12 +7817,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui case AS_SPLASHER: if(tstatus->mode&MD_BOSS - /** - * Renewal dropped the 3/4 hp requirement - **/ - #ifndef RENEWAL + // Renewal dropped the 3/4 hp requirement +#ifndef RENEWAL || tstatus-> hp > tstatus->max_hp*3/4 - #endif +#endif ) { if (sd) clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); map_freeblock_unlock(); @@ -8568,9 +8552,6 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui } break; - /** - * Guilotine Cross - **/ case GC_ROLLINGCUTTER: { short count = 1; @@ -8648,9 +8629,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui 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; - /** - * Arch Bishop - **/ + case AB_ANCILLA: if( sd ) { clif_skill_nodamage(src,bl,skill_id,skill_lv,1); @@ -8848,9 +8827,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui src, PR_LEXDIVINA, skill_lv, tick, flag|BCT_ENEMY|1, skill_castend_nodamage_id); clif_skill_nodamage(src, bl, skill_id, skill_lv, 1); break; - /** - * Warlock - **/ + case WL_STASIS: if( flag&1 ) sc_start(src,bl,type,100,skill_lv,skill_get_time(skill_id,skill_lv)); @@ -9024,9 +9001,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui clif_skill_nodamage(src, bl, skill_id, skill_lv, 1); } break; - /** - * Ranger - **/ + case RA_FEARBREEZE: clif_skill_damage(src, src, tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6); clif_skill_nodamage(src, bl, skill_id, skill_lv, sc_start(src,bl, type, 100, skill_lv, skill_get_time(skill_id, skill_lv))); @@ -9072,9 +9047,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui clif_skill_damage(src,src,tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6); map_foreachinrange(skill_area_sub,src,skill_get_splash(skill_id,skill_lv),BL_CHAR|BL_SKILL,src,skill_id,skill_lv,tick,flag|BCT_ENEMY,skill_castend_damage_id); break; - /** - * Mechanic - **/ + case NC_F_SIDESLIDE: case NC_B_SIDESLIDE: { @@ -9838,9 +9811,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui clif_skill_itemlistwindow(sd,skill_id,skill_lv); } break; - /** - * Genetic - **/ + case GN_BLOOD_SUCKER: { struct status_change *sc = status_get_sc(src); @@ -9915,9 +9886,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui clif_skill_nodamage(src,bl,skill_id,skill_lv,1); } break; - /** - * Elemental - **/ + case EL_CIRCLE_OF_FIRE: case EL_PYROTECHNIC: case EL_HEATER: @@ -9981,9 +9950,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui } } break; - /** - * Kagerou & Oboro - **/ + case KO_KAHU_ENTEN: case KO_HYOUHU_HUBUKI: case KO_KAZEHU_SEIRAN: @@ -10209,9 +10176,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui skill_blockhomun_start(hd, skill_id, skill_get_cooldown(skill_id, skill_lv)); } break; - /** - * Rebellion - **/ + case RL_RICHS_COIN: if (sd) { clif_skill_nodamage(src,bl,skill_id,skill_lv,1); @@ -11350,9 +11315,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui map_foreachinarea(skill_area_sub,src->m,x-i,y-i,x+i,y+i,splash_target(src), src, skill_id, skill_lv, tick, flag|BCT_ENEMY|1, skill_castend_nodamage_id); break; - /** - * Guilotine Cross - **/ + case GC_POISONSMOKE: if( !(sc && sc->data[SC_POISONINGWEAPON]) ) { if( sd ) @@ -11362,18 +11325,14 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui clif_skill_damage(src,src,tick,status_get_amotion(src),0,-30000,1,skill_id,skill_lv,6); skill_unitsetting(src, skill_id, skill_lv, x, y, flag); break; - /** - * Arch Bishop - **/ + case AB_EPICLESIS: if( (sg = skill_unitsetting(src, skill_id, skill_lv, x, y, 0)) ) { i = sg->unit->range; map_foreachinarea(skill_area_sub, src->m, x - i, y - i, x + i, y + i, BL_CHAR, src, ALL_RESURRECTION, 1, tick, flag|BCT_NOENEMY|1,skill_castend_nodamage_id); } break; - /** - * Warlock - **/ + case WL_COMET: if( sc ) { sc->comet_x = x; @@ -11400,17 +11359,13 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui } } break; - /** - * Ranger - **/ + case RA_DETONATOR: i = skill_get_splash(skill_id, skill_lv); map_foreachinarea(skill_detonator, src->m, x-i, y-i, x+i, y+i, BL_SKILL, src); clif_skill_damage(src, src, tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, 6); break; - /** - * Mechanic - **/ + case NC_NEUTRALBARRIER: case NC_STEALTHFIELD: if( (sc->data[SC_NEUTRALBARRIER_MASTER] && skill_id == NC_NEUTRALBARRIER) || (sc->data[SC_STEALTHFIELD_MASTER] && skill_id == NC_STEALTHFIELD) ) { @@ -11488,7 +11443,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui case WM_DOMINION_IMPULSE: i = skill_get_splash(skill_id, skill_lv); - map_foreachinarea( skill_ative_reverberation, + map_foreachinarea(skill_active_reverberation, src->m, x-i, y-i, x+i,y+i,BL_SKILL); break; @@ -11837,34 +11792,39 @@ int skill_dance_overlap(struct skill_unit* unit, int flag) return map_foreachincell(skill_dance_overlap_sub, unit->bl.m,unit->bl.x,unit->bl.y,BL_SKILL, unit,flag); } -/*========================================== +/** * Converts this group information so that it is handled as a Dissonance or Ugly Dance cell. - * Flag: 0 - Convert, 1 - Revert. - * TODO: This should be completely removed later and rewritten - * The entire execution of the overlapping songs instances is dirty and hacked together - * Overlapping cells should be checked on unit entry, not infinitely loop checked causing 1000's of executions a song/dance - *------------------------------------------*/ + * @param unit Skill unit data (from BA_DISSONANCE or DC_UGLYDANCE) + * @param flag 0 Convert + * @param flag 1 Revert + * @return true success + * @TODO: This should be completely removed later and rewritten + * The entire execution of the overlapping songs instances is dirty and hacked together + * Overlapping cells should be checked on unit entry, not infinitely loop checked causing 1000's of executions a song/dance + */ static bool skill_dance_switch(struct skill_unit* unit, int flag) { static int prevflag = 1; // by default the backup is empty static struct skill_unit_group backup; - struct skill_unit_group* group = unit->group; + struct skill_unit_group* group; - // val2&UF_ENSEMBLE is a hack to indicate dissonance - if ( !(group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) ) + if( unit == NULL || (group = unit->group) == NULL ) return false; - if( flag == prevflag ) - {// protection against attempts to read an empty backup / write to a full backup + //val2&UF_ENSEMBLE is a hack to indicate dissonance + if ( !((group->state.song_dance&0x1) && (unit->val2&UF_ENSEMBLE)) ) + return false; + + if( flag == prevflag ) { //Protection against attempts to read an empty backup/write to a full backup ShowError("skill_dance_switch: Attempted to %s (skill_id=%d, skill_lv=%d, src_id=%d).\n", flag ? "read an empty backup" : "write to a full backup", group->skill_id, group->skill_lv, group->src_id); return false; } + prevflag = flag; - if( !flag ) - { //Transform + if (!flag) { //Transform uint16 skill_id = unit->val2&UF_SONG ? BA_DISSONANCE : DC_UGLYDANCE; // backup @@ -11882,9 +11842,7 @@ static bool skill_dance_switch(struct skill_unit* unit, int flag) group->target_flag = skill_get_unit_target(skill_id); group->bl_flag = skill_get_unit_bl_target(skill_id); group->interval = skill_get_unit_interval(skill_id); - } - else - { //Restore + } else { //Restore group->skill_id = backup.skill_id; group->skill_lv = backup.skill_lv; group->unit_id = backup.unit_id; @@ -11897,7 +11855,7 @@ static bool skill_dance_switch(struct skill_unit* unit, int flag) } /** * Upon Ice Wall cast it checks all nearby mobs to find any who may be blocked by the IW - **/ + */ static int skill_icewall_block(struct block_list *bl,va_list ap) { struct block_list *target = NULL; struct mob_data *md = ((TBL_MOB*)bl); @@ -11917,7 +11875,8 @@ static int skill_icewall_block(struct block_list *bl,va_list ap) { return 0; } -/*========================================== + +/** * Initializes and sets a ground skill / skill unit. Usually called after skill_casted_pos() or skill_castend_map() * @param src Object that triggers the skill * @param skill_id Skill ID @@ -11926,8 +11885,8 @@ static int skill_icewall_block(struct block_list *bl,va_list ap) { * @param y Position y * @param flag &1: Used to determine when the skill 'morphs' (Warp portal becomes active, or Fire Pillar becomes active) * @return skill_unit_group - *------------------------------------------*/ -struct skill_unit_group* skill_unitsetting (struct block_list *src, uint16 skill_id, uint16 skill_lv, int16 x, int16 y, int flag) + */ +struct skill_unit_group *skill_unitsetting(struct block_list *src, uint16 skill_id, uint16 skill_lv, int16 x, int16 y, int flag) { struct skill_unit_group *group; int i, limit, val1 = 0, val2 = 0, val3 = 0; @@ -12024,9 +11983,6 @@ struct skill_unit_group* skill_unitsetting (struct block_list *src, uint16 skill case HT_FREEZINGTRAP: case MA_FREEZINGTRAP: case HT_BLASTMINE: - /** - * Ranger - **/ case RA_ELECTRICSHOCKER: case RA_CLUSTERBOMB: case RA_MAGENTATRAP: @@ -12035,9 +11991,6 @@ struct skill_unit_group* skill_unitsetting (struct block_list *src, uint16 skill case RA_VERDURETRAP: case RA_FIRINGTRAP: case RA_ICEBOUNDTRAP: - /** - * Rebellion - **/ case RL_B_TRAP: { struct skill_condition req = skill_get_requirement(sd,skill_id,skill_lv); @@ -12427,16 +12380,20 @@ struct skill_unit_group* skill_unitsetting (struct block_list *src, uint16 skill /*========================================== * *------------------------------------------*/ -void ext_skill_unit_onplace(struct skill_unit *unit, struct block_list *bl, unsigned int tick){skill_unit_onplace(unit, bl, tick);} +void ext_skill_unit_onplace(struct skill_unit *unit, struct block_list *bl, unsigned int tick) +{ + skill_unit_onplace(unit, bl, tick); +} + /** -* Triggeres when 'target' (based on skill unit target) is stand at unit area -* while skill unit initialized or moved (such by knock back). -* As a follow of skill_unit_effect flag &1 -* @param unit -* @param bl Target -* @param tick -*/ -static int skill_unit_onplace (struct skill_unit *unit, struct block_list *bl, unsigned int tick) + * Triggeres when 'target' (based on skill unit target) is stand at unit area + * while skill unit initialized or moved (such by knock back). + * As a follow of skill_unit_effect flag &1 + * @param unit + * @param bl Target + * @param tick + */ +static int skill_unit_onplace(struct skill_unit *unit, struct block_list *bl, unsigned int tick) { struct skill_unit_group *sg; struct block_list *ss; // Actual source that cast the skill unit @@ -12677,13 +12634,13 @@ static int skill_unit_onplace (struct skill_unit *unit, struct block_list *bl, u return skill_id; } -/*========================================== +/** * Process skill unit each interval (sg->interval, see interval field of skill_unit_db.txt) * @param unit Skill unit * @param bl Valid 'target' above the unit, that has been check in skill_unit_timer_sub_onplace * @param tick - *------------------------------------------*/ -int skill_unit_onplace_timer (struct skill_unit *unit, struct block_list *bl, unsigned int tick) + */ +int skill_unit_onplace_timer(struct skill_unit *unit, struct block_list *bl, unsigned int tick) { struct skill_unit_group *sg; struct block_list *ss; @@ -12762,28 +12719,22 @@ int skill_unit_onplace_timer (struct skill_unit *unit, struct block_list *bl, un break; case UNT_DUMMYSKILL: - switch (sg->skill_id) - { + switch (sg->skill_id) { case SG_SUN_WARM: //SG skills [Komurka] case SG_MOON_WARM: - case SG_STAR_WARM: - { + case SG_STAR_WARM: { int count = 0; const int x = bl->x, y = bl->y; //If target isn't knocked back it should hit every "interval" ms [Playtester] - do - { + do { if( bl->type == BL_PC ) status_zap(bl, 0, 15); // sp damage to players else // mobs - if( status_charge(ss, 0, 2) ) // costs 2 SP per hit - { + if( status_charge(ss, 0, 2) ) { // costs 2 SP per hit if( !skill_attack(BF_WEAPON,ss,&unit->bl,bl,sg->skill_id,sg->skill_lv,tick+count*sg->interval,0) ) status_charge(ss, 0, 8); //costs additional 8 SP if miss - } - else - { //should end when out of sp. + } else { //should end when out of sp. sg->limit = DIFF_TICK(tick,sg->tick); break; } @@ -12791,10 +12742,7 @@ int skill_unit_onplace_timer (struct skill_unit *unit, struct block_list *bl, un ++count < SKILLUNITTIMER_INTERVAL/sg->interval && !status_isdead(bl) ); } break; - /** - * The storm gust counter was dropped in renewal - **/ -#ifndef RENEWAL +#ifndef RENEWAL // The storm gust counter was dropped in renewal case WZ_STORMGUST: //SG counter does not reset per stormgust. IE: One hit from a SG and two hits from another will freeze you. if (tsc) tsc->sg_counter++; //SG hit counter. @@ -12807,7 +12755,7 @@ int skill_unit_onplace_timer (struct skill_unit *unit, struct block_list *bl, un skill_attack(BF_WEAPON,ss,&unit->bl,bl,sg->skill_id,sg->skill_lv,tick,0); break; case GN_CRAZYWEED_ATK: - if( bl->type == BL_SKILL ){ + if( bl->type == BL_SKILL ) { struct skill_unit *su = (struct skill_unit *)bl; if( su && !(skill_get_inf2(su->group->skill_id)&INF2_TRAP) ) break; @@ -13162,9 +13110,7 @@ int skill_unit_onplace_timer (struct skill_unit *unit, struct block_list *bl, un //clif_changetraplook(&src->bl, UNT_FIREPILLAR_ACTIVE); sg->limit=DIFF_TICK(tick,sg->tick)+1500; break; - /** - * 3rd stuff - **/ + case UNT_POISONSMOKE: if( battle_check_target(ss,bl,BCT_ENEMY) > 0 && !(tsc && tsc->data[sg->val2]) && rnd()%100 < 20 ) sc_start(ss,bl,(sc_type)sg->val2,100,sg->val3,skill_get_time2(GC_POISONINGWEAPON, 1)); @@ -13437,13 +13383,14 @@ int skill_unit_onplace_timer (struct skill_unit *unit, struct block_list *bl, un return skill_id; } -/*========================================== + +/** * Triggered when a char steps out of a skill unit * @param src Skill unit from char moved out * @param bl Char * @param tick - *------------------------------------------*/ -int skill_unit_onout (struct skill_unit *src, struct block_list *bl, unsigned int tick) + */ +int skill_unit_onout(struct skill_unit *src, struct block_list *bl, unsigned int tick) { struct skill_unit_group *sg; struct status_change *sc; @@ -13517,13 +13464,13 @@ int skill_unit_onout (struct skill_unit *src, struct block_list *bl, unsigned in return sg->skill_id; } -/*========================================== +/** * Triggered when a char steps out of a skill group (entirely) [Skotlex] * @param skill_id Skill ID * @param bl A char * @param tick - *------------------------------------------*/ -int skill_unit_onleft (uint16 skill_id, struct block_list *bl, unsigned int tick) + */ +int skill_unit_onleft(uint16 skill_id, struct block_list *bl, unsigned int tick) { struct status_change *sc; struct status_change_entry *sce; @@ -13655,7 +13602,7 @@ int skill_unit_onleft (uint16 skill_id, struct block_list *bl, unsigned int tick * flag&4: Invoke a onleft call (the unit might be scheduled for deletion) * flag&8: Recursive *------------------------------------------*/ -static int skill_unit_effect (struct block_list* bl, va_list ap) +static int skill_unit_effect(struct block_list* bl, va_list ap) { struct skill_unit* unit = va_arg(ap,struct skill_unit*); struct skill_unit_group* group = unit->group; @@ -13700,13 +13647,13 @@ static int skill_unit_effect (struct block_list* bl, va_list ap) return 0; } -/*========================================== +/** * Check skill unit while receiving damage * @param unit Skill unit * @param damage Received damage * @return Damage - *------------------------------------------*/ -int64 skill_unit_ondamaged (struct skill_unit *unit, int64 damage) + */ +int64 skill_unit_ondamaged(struct skill_unit *unit, int64 damage) { struct skill_unit_group *sg; @@ -13734,17 +13681,18 @@ int64 skill_unit_ondamaged (struct skill_unit *unit, int64 damage) damage = 0; break; } + return damage; } -/*========================================== +/** * Check char condition around the skill caster * @param bl Char around area * @param *c Counter for 'valid' condition found * @param *p_sd Stores 'rid' of char found * @param skill_id Skill ID * @param skill_lv Level of used skill - *------------------------------------------*/ + */ int skill_check_condition_char_sub (struct block_list *bl, va_list ap) { int *c, skill_id; @@ -13830,7 +13778,7 @@ int skill_check_condition_char_sub (struct block_list *bl, va_list ap) return 0; } -/*========================================== +/** * Checks and stores partners for ensemble skills [Skotlex] * Max partners is 2. * @param sd Caster @@ -13838,8 +13786,8 @@ int skill_check_condition_char_sub (struct block_list *bl, va_list ap) * @param skill_lv * @param range Area range to check * @param cast_flag Special handle - *------------------------------------------*/ -int skill_check_pc_partner (struct map_session_data *sd, uint16 skill_id, uint16 *skill_lv, int range, int cast_flag) + */ +int skill_check_pc_partner(struct map_session_data *sd, uint16 skill_id, uint16 *skill_lv, int range, int cast_flag) { static int c=0; static int p_sd[2] = { 0, 0 }; @@ -13897,15 +13845,15 @@ int skill_check_pc_partner (struct map_session_data *sd, uint16 skill_id, uint16 return c; } -/*========================================== +/** * Sub function to count how many spawned mob is around. * Some skills check with matched AI. * @param rid Source ID * @param mob_class Monster ID * @param skill_id Used skill * @param *c Counter for found monster - *------------------------------------------*/ -static int skill_check_condition_mob_master_sub (struct block_list *bl, va_list ap) + */ +static int skill_check_condition_mob_master_sub(struct block_list *bl, va_list ap) { int *c,src_id,mob_class,skill; uint16 ai; @@ -13927,17 +13875,17 @@ static int skill_check_condition_mob_master_sub (struct block_list *bl, va_list return 1; } -/*========================================== +/** * Determines if a given skill should be made to consume ammo * when used by the player. [Skotlex] * @param sd Player - * @param skill Skill ID + * @param skill_id Skill ID * @return True if skill is need ammo; False otherwise. - *------------------------------------------*/ -int skill_isammotype (struct map_session_data *sd, unsigned short skill_id) + */ +int skill_isammotype(struct map_session_data *sd, unsigned short skill_id) { return ( - battle_config.arrow_decrement==2 && + battle_config.arrow_decrement == 2 && (sd->status.weapon == W_BOW || (sd->status.weapon >= W_REVOLVER && sd->status.weapon <= W_GRENADE)) && skill_id != HT_PHANTASMIC && skill_get_type(skill_id) == BF_WEAPON && @@ -14001,14 +13949,17 @@ static bool skill_check_condition_sc_required(struct map_session_data *sd, unsig return true; } -/** Check skill condition when cast begin -* NOTE: For ammo, only check if the skill need ammo, for checking ammo requirement (type and amount) will be skill_check_condition_castend -* @param sd Player who uses skill -* @param skill_id ID of used skill -* @param skill_lv Level of used skill -* @return true: All condition passed, false: Failed -*/ -bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) { +/** + * Check skill condition when cast begin + * For ammo, only check if the skill need ammo + * For checking ammo requirement (type and amount) will be skill_check_condition_castend + * @param sd Player who uses skill + * @param skill_id ID of used skill + * @param skill_lv Level of used skill + * @return true: All condition passed, false: Failed + */ +bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) +{ struct status_data *status; struct status_change *sc; struct skill_condition require; @@ -14439,13 +14390,10 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i return false; } break; - /** - * Arch Bishop - **/ - case AB_ANCILLA: - { + case AB_ANCILLA: { int count = 0; - for( i = 0; i < MAX_INVENTORY; i ++ ) + + for( i = 0; i < MAX_INVENTORY; i++ ) if( sd->status.inventory[i].nameid == ITEMID_ANCILLA ) count += sd->status.inventory[i].amount; if( count >= 3 ) { @@ -14457,7 +14405,7 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i /** * Keeping as a note: * Bug Report #17 provides a link to a sep-2011 changelog that shows this requirement was removed - **/ + */ //case AB_LAUDAAGNUS: //case AB_LAUDARAMUS: // if( !sd->status.party_id ) { @@ -14468,9 +14416,6 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i case AB_ADORAMUS: // bugreport:7647 mistress card DOES remove requirements for gemstones from Adoramus and Comet -helvetica - /** - * Warlock - **/ case WL_COMET: if( skill_check_pc_partner(sd,skill_id,&skill_lv,1,0) <= 0 && require.itemid[0] && sd->special_state.no_gemstone == 0 @@ -14511,9 +14456,6 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i return false; } break; - /** - * Guillotine Cross - **/ case GC_HALLUCINATIONWALK: if( sc && (sc->data[SC_HALLUCINATIONWALK] || sc->data[SC_HALLUCINATIONWALK_POSTDELAY]) ) { clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); @@ -14527,9 +14469,6 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i return false; } break; - /** - * Ranger - **/ case RA_WUGMASTERY: if( (pc_isfalcon(sd) && !battle_config.warg_can_falcon) || pc_isridingwug(sd) || sd->sc.data[SC__GROOMY]) { clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); @@ -14554,9 +14493,6 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i return false; } break; - /** - * Royal Guard - **/ case LG_BANDING: if( sc && sc->data[SC_INSPIRATION] ) { clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); @@ -14866,14 +14802,16 @@ bool skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_i return true; } -/** Check skill condition when cast end. -* NOTE: Checking ammo requirement (type and amount) will be here, not at skill_check_condition_castbegin -* @param sd Player who uses skill -* @param skill_id ID of used skill -* @param skill_lv Level of used skill -* @return true: All condition passed, false: Failed -*/ -bool skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) { +/** + * Check skill condition when cast end. + * Checking ammo requirement (type and amount) will be here, not at skill_check_condition_castbegin + * @param sd Player who uses skill + * @param skill_id ID of used skill + * @param skill_lv Level of used skill + * @return true: All condition passed, false: Failed + */ +bool skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) +{ struct skill_condition require; struct status_data *status; int i; @@ -15061,14 +14999,14 @@ bool skill_check_condition_castend(struct map_session_data* sd, uint16 skill_id, } /** Consume skill requirement -* @param sd Player who uses the skill -* @param skill_id ID of used skill -* @param skill_lv Level of used skill -* @param type Consume type -* type&1: consume the others (before skill was used); -* type&2: consume items (after skill was used) -*/ -void skill_consume_requirement( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv, short type) + * @param sd Player who uses the skill + * @param skill_id ID of used skill + * @param skill_lv Level of used skill + * @param type Consume type + * type&1: consume the others (before skill was used); + * type&2: consume items (after skill was used) + */ +void skill_consume_requirement(struct map_session_data *sd, uint16 skill_id, uint16 skill_lv, short type) { struct skill_condition require; @@ -15155,12 +15093,12 @@ void skill_consume_requirement( struct map_session_data *sd, uint16 skill_id, ui } /** -* Get skill requirements and return the value after some additional/reduction condition (such item bonus and status change) -* @param sd Player's that will be checked -* @param skill_id Skill that's being used -* @param skill_lv Skill level of used skill -* @return skill_condition Struct 'skill_condition' that store the modified skill requirements -*/ + * Get skill requirements and return the value after some additional/reduction condition (such item bonus and status change) + * @param sd Player's that will be checked + * @param skill_id Skill that's being used + * @param skill_lv Skill level of used skill + * @return skill_condition Struct 'skill_condition' that store the modified skill requirements + */ struct skill_condition skill_get_requirement(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv) { struct skill_condition req; @@ -15455,7 +15393,7 @@ struct skill_condition skill_get_requirement(struct map_session_data* sd, uint16 /*========================================== * Does cast-time reductions based on dex, item bonuses and config setting *------------------------------------------*/ -int skill_castfix (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { +int skill_castfix(struct block_list *bl, uint16 skill_id, uint16 skill_lv) { int time = skill_get_cast(skill_id, skill_lv); nullpo_ret(bl); @@ -15502,16 +15440,14 @@ int skill_castfix (struct block_list *bl, uint16 skill_id, uint16 skill_lv) { return time; } -/*========================================== - * Does cast-time reductions based on sc data. - *------------------------------------------*/ #ifndef RENEWAL_CAST -/** Get the skill cast time for Pre-Re cast -* @param bl: The caster -* @param time: Cast time before Status Change addition or reduction -* @return time: Modified castime after status change addition or reduction -*/ -int skill_castfix_sc (struct block_list *bl, int time) +/** + * Get the skill cast time for Pre-Re cast + * @param bl: The caster + * @param time: Cast time before Status Change addition or reduction + * @return time: Modified castime after status change addition or reduction + */ +int skill_castfix_sc(struct block_list *bl, int time) { struct status_change *sc = status_get_sc(bl); @@ -15543,14 +15479,15 @@ int skill_castfix_sc (struct block_list *bl, int time) return time; } #else -/** Get the skill cast time for RENEWAL_CAST -* @param bl: The caster -* @param time: Cast time without reduction -* @param skill_id: Skill ID of the casted skill -* @param skill_lv: Skill level of the casted skill -* @return time: Modified castime after status and bonus addition or reduction -*/ -int skill_vfcastfix (struct block_list *bl, double time, uint16 skill_id, uint16 skill_lv) +/** + * Get the skill cast time for RENEWAL_CAST + * @param bl: The caster + * @param time: Cast time without reduction + * @param skill_id: Skill ID of the casted skill + * @param skill_lv: Skill level of the casted skill + * @return time: Modified castime after status and bonus addition or reduction + */ +int skill_vfcastfix(struct block_list *bl, double time, uint16 skill_id, uint16 skill_lv) { struct status_change *sc = status_get_sc(bl); struct map_session_data *sd = BL_CAST(BL_PC,bl); @@ -15930,7 +15867,7 @@ void skill_brandishspear(struct block_list* src, struct block_list* bl, uint16 s /*========================================== * Weapon Repair [Celest/DracoRPG] *------------------------------------------*/ -void skill_repairweapon (struct map_session_data *sd, int idx) { +void skill_repairweapon(struct map_session_data *sd, int idx) { int material; int materials[4] = { 1002, 998, 999, 756 }; struct item *item; @@ -15947,7 +15884,7 @@ void skill_repairweapon (struct map_session_data *sd, int idx) { return; //Invalid index?? item = &target_sd->status.inventory[idx]; - if( item->nameid == 0 || item->attribute == 0 ) + if( !item->nameid || !item->attribute ) return; //Again invalid item.... if( sd != target_sd && !battle_check_range(&sd->bl,&target_sd->bl, skill_get_range2(&sd->bl, sd->menuskill_id,sd->menuskill_val2) ) ){ @@ -15981,7 +15918,7 @@ void skill_repairweapon (struct map_session_data *sd, int idx) { /*========================================== * Item Appraisal *------------------------------------------*/ -void skill_identify (struct map_session_data *sd, int idx) +void skill_identify(struct map_session_data *sd, int idx) { int flag=1; @@ -15999,7 +15936,7 @@ void skill_identify (struct map_session_data *sd, int idx) /*========================================== * Weapon Refine [Celest] *------------------------------------------*/ -void skill_weaponrefine (struct map_session_data *sd, int idx) +void skill_weaponrefine(struct map_session_data *sd, int idx) { nullpo_retv(sd); @@ -16009,8 +15946,7 @@ void skill_weaponrefine (struct map_session_data *sd, int idx) 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 i = 0, per; int material[5] = { 0, ITEMID_PHRACON, ITEMID_EMVERETARCON, ITEMID_ORIDECON, ITEMID_ORIDECON, }; if( ditem->flag.no_refine ) { // if the item isn't refinable @@ -16081,7 +16017,7 @@ void skill_weaponrefine (struct map_session_data *sd, int idx) /*========================================== * *------------------------------------------*/ -int skill_autospell (struct map_session_data *sd, uint16 skill_id) +int skill_autospell(struct map_session_data *sd, uint16 skill_id) { uint16 skill_lv; int maxlv=1,lv; @@ -16124,7 +16060,7 @@ int skill_autospell (struct map_session_data *sd, uint16 skill_id) /*========================================== * Sitting skills functions. *------------------------------------------*/ -static int skill_sit_count (struct block_list *bl, va_list ap) +static int skill_sit_count(struct block_list *bl, va_list ap) { struct map_session_data *sd; int type =va_arg(ap,int); @@ -16219,7 +16155,7 @@ int skill_sit (struct map_session_data *sd, int type) /*========================================== * Do Forstjoke/Scream effect *------------------------------------------*/ -int skill_frostjoke_scream (struct block_list *bl, va_list ap) +int skill_frostjoke_scream(struct block_list *bl, va_list ap) { struct block_list *src; uint16 skill_id,skill_lv; @@ -16250,33 +16186,33 @@ int skill_frostjoke_scream (struct block_list *bl, va_list ap) return 0; } -/*========================================== +/** * Set map cell flag as skill unit effect * @param src Skill unit * @param skill_id * @param skill_lv * @param cell Cell type cell_t * @param flag 0/1 - *------------------------------------------*/ -static void skill_unitsetmapcell (struct skill_unit *src, uint16 skill_id, uint16 skill_lv, cell_t cell, bool flag) + */ +static void skill_unitsetmapcell(struct skill_unit *src, uint16 skill_id, uint16 skill_lv, cell_t cell, bool flag) { int range = skill_get_unit_range(skill_id,skill_lv); - int x,y; + int x, y; for( y = src->bl.y - range; y <= src->bl.y + range; ++y ) for( x = src->bl.x - range; x <= src->bl.x + range; ++x ) map_setcell(src->bl.m, x, y, cell, flag); } -/*========================================== +/** * Do skill attack area (such splash effect) around the 'first' target. * First target will skip skill condition, always receive damage. But, * around it, still need target/condition validation by * battle_check_target and status_check_skilluse * @param bl * @param ap { atk_type, src, dsrc, skill_id, skill_lv, tick, flag, type } - *------------------------------------------*/ -int skill_attack_area (struct block_list *bl, va_list ap) + */ +int skill_attack_area(struct block_list *bl, va_list ap) { struct block_list *src,*dsrc; int atk_type,skill_id,skill_lv,flag,type; @@ -16294,7 +16230,6 @@ int skill_attack_area (struct block_list *bl, va_list ap) flag = va_arg(ap,int); type = va_arg(ap,int); - if (skill_area_temp[1] == bl->id) //This is the target of the skill, do a full attack and skip target checks. return (int)skill_attack(atk_type,src,dsrc,bl,skill_id,skill_lv,tick,flag); @@ -16302,7 +16237,6 @@ int skill_attack_area (struct block_list *bl, va_list ap) !status_check_skilluse(NULL, bl, skill_id, 2)) return 0; - switch (skill_id) { case WZ_FROSTNOVA: //Skills that don't require the animation to be removed case NPC_ACIDBREATH: @@ -16317,18 +16251,19 @@ int skill_attack_area (struct block_list *bl, va_list ap) } } -/*========================================== +/** * Clear skill unit group * @param bl * @param flag &1 - *------------------------------------------*/ -int skill_clear_group (struct block_list *bl, int flag) + */ +int skill_clear_group(struct block_list *bl, int flag) { - struct unit_data *ud; + struct unit_data *ud = NULL; struct skill_unit_group *group[MAX_SKILLUNITGROUP]; int i, count = 0; nullpo_ret(bl); + if (!(ud = unit_bl2ud(bl))) return 0; @@ -16342,19 +16277,19 @@ int skill_clear_group (struct block_list *bl, int flag) case NJ_SUITON: case NJ_KAENSIN: if (flag&1) - group[count++]= ud->skillunit[i]; + group[count++] = ud->skillunit[i]; break; case SO_CLOUD_KILL: if( flag&4 ) - group[count++]= ud->skillunit[i]; + group[count++] = ud->skillunit[i]; break; case SO_WARMER: if( flag&8 ) - group[count++]= ud->skillunit[i]; + group[count++] = ud->skillunit[i]; break; default: if (flag&2 && skill_get_inf2(ud->skillunit[i]->skill_id)&INF2_TRAP) - group[count++]= ud->skillunit[i]; + group[count++] = ud->skillunit[i]; break; } @@ -16364,20 +16299,22 @@ int skill_clear_group (struct block_list *bl, int flag) return count; } -/*========================================== +/** * Returns the first element field found [Skotlex] * @param bl * @return skill_unit_group - *------------------------------------------*/ + */ struct skill_unit_group *skill_locate_element_field(struct block_list *bl) { - struct unit_data *ud; + struct unit_data *ud = NULL; int i; + nullpo_ret(bl); + if (!(ud = unit_bl2ud(bl))) return NULL; - for (i = 0; i < MAX_SKILLUNITGROUP && ud->skillunit[i];i++) { + for (i = 0; i < MAX_SKILLUNITGROUP && ud->skillunit[i]; i++) { switch (ud->skillunit[i]->skill_id) { case SA_DELUGE: case SA_VOLCANO: @@ -16393,31 +16330,33 @@ struct skill_unit_group *skill_locate_element_field(struct block_list *bl) } /// Graffiti cleaner [Valaris] -int skill_graffitiremover (struct block_list *bl, va_list ap) { - struct skill_unit *unit=NULL; +int skill_graffitiremover(struct block_list *bl, va_list ap) +{ + struct skill_unit *unit = NULL; nullpo_ret(bl); nullpo_ret(ap); - if(bl->type!=BL_SKILL || (unit=(struct skill_unit *)bl) == NULL) + if (bl->type != BL_SKILL || (unit = (struct skill_unit *)bl) == NULL) return 0; - if((unit->group) && (unit->group->unit_id == UNT_GRAFFITI)) + if ((unit->group) && (unit->group->unit_id == UNT_GRAFFITI)) skill_delunit(unit); return 0; } /// Greed effect -int skill_greed (struct block_list *bl, va_list ap) { +int skill_greed(struct block_list *bl, va_list ap) +{ struct block_list *src; - struct map_session_data *sd=NULL; - struct flooritem_data *fitem=NULL; + struct map_session_data *sd = NULL; + struct flooritem_data *fitem = NULL; nullpo_ret(bl); nullpo_ret(src = va_arg(ap, struct block_list *)); - if(src->type == BL_PC && (sd=(struct map_session_data *)src) && bl->type==BL_ITEM && (fitem=(struct flooritem_data *)bl)) + if(src->type == BL_PC && (sd = (struct map_session_data *)src) && bl->type == BL_ITEM && (fitem = (struct flooritem_data *)bl)) pc_takeitem(sd, fitem); return 0; @@ -16426,12 +16365,13 @@ int skill_greed (struct block_list *bl, va_list ap) { /// Ranger's Detonator [Jobbie/3CeAM] int skill_detonator(struct block_list *bl, va_list ap) { - struct skill_unit *unit=NULL; + struct skill_unit *unit = NULL; struct block_list *src; int unit_id; nullpo_ret(bl); nullpo_ret(ap); + src = va_arg(ap,struct block_list *); if( bl->type != BL_SKILL || (unit = (struct skill_unit *)bl) == NULL || !unit->group ) @@ -16461,6 +16401,7 @@ int skill_detonator(struct block_list *bl, va_list ap) break; default: map_foreachinrange(skill_trap_splash,bl,skill_get_splash(unit->group->skill_id,unit->group->skill_lv),unit->group->bl_flag,bl,unit->group->tick); + break; } clif_changetraplook(bl, UNT_USED_TRAPS); unit->group->unit_id = UNT_USED_TRAPS; @@ -16623,18 +16564,19 @@ int skill_changetarget(struct block_list *bl, va_list ap) * Splash effect for skill unit 'trap type'. * Chance triggered when damaged, timeout, or char step on it. *------------------------------------------*/ -static int skill_trap_splash (struct block_list *bl, va_list ap) +static int skill_trap_splash(struct block_list *bl, va_list ap) { - struct block_list *src; - int tick; - struct skill_unit *unit; + struct block_list *src = va_arg(ap,struct block_list *); + struct skill_unit *unit = NULL; + int tick = va_arg(ap,int); struct skill_unit_group *sg; - struct block_list *ss; //skill src bl - src = va_arg(ap,struct block_list *); - unit = (struct skill_unit *)src; - tick = va_arg(ap,int); + struct block_list *ss; //Skill src bl - if (!unit->alive || bl->prev == NULL) + nullpo_ret(src); + + unit = (struct skill_unit *)src; + + if (!unit || !unit->alive || bl->prev == NULL) return 0; nullpo_ret(sg = unit->group); @@ -16701,7 +16643,7 @@ static int skill_trap_splash (struct block_list *bl, va_list ap) if( bl->type == BL_SKILL ) { struct skill_unit *su = (struct skill_unit *)bl; - if( su->group->unit_id == UNT_USED_TRAPS ) + if (su && su->group->unit_id == UNT_USED_TRAPS) break; } case UNT_CLUSTERBOMB: @@ -16712,7 +16654,11 @@ static int skill_trap_splash (struct block_list *bl, va_list ap) if( src->id == bl->id ) break; if( bl->type == BL_SKILL ) { struct skill_unit *su = (struct skill_unit *)bl; - switch( su->group->unit_id ){ + + if (!su) + return 0; + + switch(su->group->unit_id) { case UNT_CLAYMORETRAP: case UNT_LANDMINE: case UNT_BLASTMINE: @@ -16740,6 +16686,8 @@ int skill_maelstrom_suction(struct block_list *bl, va_list ap) uint16 skill_id, skill_lv; struct skill_unit *unit; + nullpo_ret(bl); + skill_id = va_arg(ap,int); skill_lv = va_arg(ap,int); unit = (struct skill_unit *)bl; @@ -16750,10 +16698,12 @@ int skill_maelstrom_suction(struct block_list *bl, va_list ap) if( skill_get_inf2(skill_id)&INF2_TRAP ) return 0; - if( unit->group->skill_id == SC_MAELSTROM ){ + if( unit->group->skill_id == SC_MAELSTROM ) { struct block_list *src; + if( (src = map_id2bl(unit->group->src_id)) ){ int sp = unit->group->skill_lv * skill_lv; + if( src->type == BL_PC ) sp += ((TBL_PC*)src)->status.job_level / 5; status_heal(src, 0, sp/2, 1); @@ -16763,15 +16713,17 @@ int skill_maelstrom_suction(struct block_list *bl, va_list ap) return 0; } -/*========================================== +/** * Remove current enchanted element for new element * @param bl Char * @param type New element - *------------------------------------------*/ -void skill_enchant_elemental_end (struct block_list *bl, int type) { + */ +void skill_enchant_elemental_end(struct block_list *bl, int type) +{ struct status_change *sc; const enum sc_type scs[] = { SC_ENCPOISON, SC_ASPERSIO, SC_FIREWEAPON, SC_WATERWEAPON, SC_WINDWEAPON, SC_EARTHWEAPON, SC_SHADOWWEAPON, SC_GHOSTWEAPON, SC_ENCHANTARMS }; int i; + nullpo_retv(bl); nullpo_retv(sc= status_get_sc(bl)); @@ -16784,11 +16736,11 @@ void skill_enchant_elemental_end (struct block_list *bl, int type) { } /** -* Check camouflage condition -* @param bl -* @param sce -* @return True if near wall; False otherwise -**/ + * Check camouflage condition + * @param bl + * @param sce + * @return True if near wall; False otherwise + */ bool skill_check_cloaking(struct block_list *bl, struct status_change_entry *sce) { bool wall = true; @@ -16824,12 +16776,13 @@ bool skill_check_cloaking(struct block_list *bl, struct status_change_entry *sce } /** Check Shadow Form on the target -* @param bl: Target -* @param damage: Damage amount -* @param hit -* @return true - in Shadow Form state; false - otherwise -*/ -bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit) { + * @param bl: Target + * @param damage: Damage amount + * @param hit + * @return true - in Shadow Form state; false - otherwise + */ +bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit) +{ struct status_change *sc; nullpo_retr(false,bl); @@ -16866,12 +16819,12 @@ bool skill_check_shadowform(struct block_list *bl, int64 damage, int hit) { } /** -* Check camouflage condition -* @param bl -* @param sce -* @return True if near wall; False otherwise -* @TODO: Seems wrong -**/ + * Check camouflage condition + * @param bl + * @param sce + * @return True if near wall; False otherwise + * @TODO: Seems wrong + */ bool skill_check_camouflage(struct block_list *bl, struct status_change_entry *sce) { bool wall = true; @@ -16896,7 +16849,7 @@ bool skill_check_camouflage(struct block_list *bl, struct status_change_entry *s return wall; } -/*========================================== +/** * Initialize new skill unit for skill unit group. * Overall, Skill Unit makes skill unit group which each group holds their cell datas (skill unit) * @param group Skill unit group @@ -16905,8 +16858,8 @@ bool skill_check_camouflage(struct block_list *bl, struct status_change_entry *s * @param y * @param val1 * @param val2 - *------------------------------------------*/ -struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx, int x, int y, int val1, int val2) + */ +struct skill_unit *skill_initunit(struct skill_unit_group *group, int idx, int x, int y, int val1, int val2) { struct skill_unit *unit; @@ -16963,19 +16916,22 @@ struct skill_unit *skill_initunit (struct skill_unit_group *group, int idx, int return unit; } -/*========================================== +/** * Remove unit * @param unit - *------------------------------------------*/ -int skill_delunit (struct skill_unit* unit) { + */ +int skill_delunit(struct skill_unit* unit) +{ struct skill_unit_group *group; nullpo_ret(unit); + if( !unit->alive ) return 0; - unit->alive=0; - nullpo_ret(group=unit->group); + unit->alive = 0; + + nullpo_ret(group = unit->group); if( group->state.song_dance&0x1 ) //Cancel dissonance effect. skill_dance_overlap(unit, 0); @@ -17046,9 +17002,9 @@ struct skill_unit_group* skill_id2group(int group_id) { static int skill_unit_group_newid = MAX_SKILL_DB; /// Skill Unit Group ID /** -* Returns a new group_id that isn't being used in skillunit_group_db. -* Fatal error if nothing is available. -**/ + * Returns a new group_id that isn't being used in skillunit_group_db. + * Fatal error if nothing is available. + */ static int skill_get_new_group_id(void) { if( skill_unit_group_newid >= MAX_SKILL_DB && skill_id2group(skill_unit_group_newid) == NULL ) @@ -17069,17 +17025,17 @@ static int skill_get_new_group_id(void) } /** -* Initialize skill unit group called while setting new unit (skill unit/ground skill) in skill_unitsetting() -* @param src Object that cast the skill -* @param count How many 'cells' used that needed. Related with skill layout -* @param skill_id ID of used skill -* @param skill_lv Skill level of used skill -* @param unit_id Unit ID (look at skill_unit_db.txt) -* @param limit Lifetime for skill unit, uses skill_get_time(skill_id, skill_lv) -* @param interval Time interval -* @return skill_unit_group -**/ -struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count, uint16 skill_id, uint16 skill_lv, int unit_id, int limit, int interval) + * Initialize skill unit group called while setting new unit (skill unit/ground skill) in skill_unitsetting() + * @param src Object that cast the skill + * @param count How many 'cells' used that needed. Related with skill layout + * @param skill_id ID of used skill + * @param skill_lv Skill level of used skill + * @param unit_id Unit ID (look at skill_unit_db.txt) + * @param limit Lifetime for skill unit, uses skill_get_time(skill_id, skill_lv) + * @param interval Time interval + * @return skill_unit_group + */ +struct skill_unit_group* skill_initunitgroup(struct block_list* src, int count, uint16 skill_id, uint16 skill_lv, int unit_id, int limit, int interval) { struct unit_data* ud = unit_bl2ud( src ); struct skill_unit_group* group; @@ -17140,13 +17096,13 @@ struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count, return group; } -/*========================================== +/** * Remove skill unit group * @param group * @param file * @param line * @param *func - *------------------------------------------*/ + */ int skill_delunitgroup_(struct skill_unit_group *group, const char* file, int line, const char* func) { struct block_list* src; @@ -17158,7 +17114,7 @@ int skill_delunitgroup_(struct skill_unit_group *group, const char* file, int li return 0; } - src=map_id2bl(group->src_id); + src = map_id2bl(group->src_id); ud = unit_bl2ud(src); if (!src || !ud) { ShowError("skill_delunitgroup: Group's source not found! (src_id: %d skill_id: %d)\n", group->src_id, group->skill_id); @@ -17281,11 +17237,12 @@ int skill_delunitgroup_(struct skill_unit_group *group, const char* file, int li return 1; } -/*========================================== +/** * Clear all Skill Unit Group from an Object, example usage when player logged off or dead * @param src - *------------------------------------------*/ -void skill_clear_unitgroup (struct block_list *src) { + */ +void skill_clear_unitgroup(struct block_list *src) +{ struct unit_data *ud; nullpo_retv(src); @@ -17295,14 +17252,15 @@ void skill_clear_unitgroup (struct block_list *src) { skill_delunitgroup(ud->skillunit[0]); } -/*========================================== +/** * Search tickset for skill unit in skill unit group * @param bl Block List for skill_unit * @param group Skill unit group * @param tick * @return skill_unit_group_tickset if found - *------------------------------------------*/ -struct skill_unit_group_tickset *skill_unitgrouptickset_search (struct block_list *bl, struct skill_unit_group *group, int tick) { + */ +struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list *bl, struct skill_unit_group *group, int tick) +{ int i, j = -1, s, id; struct unit_data *ud; struct skill_unit_group_tickset *set; @@ -17344,15 +17302,18 @@ struct skill_unit_group_tickset *skill_unitgrouptickset_search (struct block_lis * Check for validity skill unit that triggered by skill_unit_timer_sub * And trigger skill_unit_onplace_timer for object that maybe stands there (catched object is *bl) *------------------------------------------*/ -int skill_unit_timer_sub_onplace (struct block_list* bl, va_list ap) { +int skill_unit_timer_sub_onplace(struct block_list* bl, va_list ap) +{ struct skill_unit* unit = va_arg(ap,struct skill_unit *); - struct skill_unit_group* group = unit->group; + struct skill_unit_group* group = NULL; unsigned int tick = va_arg(ap,unsigned int); + nullpo_ret(unit); + if( !unit->alive || bl->prev == NULL ) return 0; - nullpo_ret(group); + nullpo_ret(group = unit->group); if( !(skill_get_inf2(group->skill_id)&(INF2_SONG_DANCE|INF2_TRAP)) && !(skill_get_inf3(group->skill_id)&(INF3_NOLP)) && group->skill_id != NC_NEUTRALBARRIER && map_getcell(bl->m, bl->x, bl->y, CELL_CHKLANDPROTECTOR) ) return 0; //AoE skills are ineffective. [Skotlex] @@ -17370,22 +17331,23 @@ int skill_unit_timer_sub_onplace (struct block_list* bl, va_list ap) { */ static int skill_unit_timer_sub(DBKey key, DBData *data, va_list ap) { - struct skill_unit* unit = db_data2ptr(data); - struct skill_unit_group* group = unit->group; + struct skill_unit* unit = (struct skill_unit*)db_data2ptr(data); + struct skill_unit_group* group = NULL; unsigned int tick = va_arg(ap,unsigned int); bool dissonance; struct block_list* bl = &unit->bl; + nullpo_ret(unit); + if( !unit->alive ) return 0; - nullpo_ret(group); + nullpo_ret(group = unit->group); // Check for expiration if( !group->state.guildaura && (DIFF_TICK(tick,group->tick) >= group->limit || DIFF_TICK(tick,group->tick) >= unit->limit) ) {// skill unit expired (inlined from skill_unit_onlimit()) - switch( group->unit_id ) - { + switch( group->unit_id ) { case UNT_BLASTMINE: #ifdef RENEWAL case UNT_CLAYMORETRAP: @@ -17608,7 +17570,8 @@ static int skill_unit_timer_sub(DBKey key, DBData *data, va_list ap) /*========================================== * Executes on all skill units every SKILLUNITTIMER_INTERVAL miliseconds. *------------------------------------------*/ -int skill_unit_timer(int tid, unsigned int tick, int id, intptr_t data) { +int skill_unit_timer(int tid, unsigned int tick, int id, intptr_t data) +{ map_freeblock_lock(); skillunit_db->foreach(skillunit_db, skill_unit_timer_sub, tick); @@ -17624,23 +17587,26 @@ static int skill_unit_temp[20]; // temporary storage for tracking skill unit sk * 2 : clear that skill_unit * 4 : call_on_left *------------------------------------------*/ -int skill_unit_move_sub (struct block_list* bl, va_list ap) { +int skill_unit_move_sub(struct block_list* bl, va_list ap) +{ struct skill_unit* unit = (struct skill_unit *)bl; - struct skill_unit_group* group = unit->group; + struct skill_unit_group* group = NULL; struct block_list* target = va_arg(ap,struct block_list*); unsigned int tick = va_arg(ap,unsigned int); int flag = va_arg(ap,int); - bool dissonance; uint16 skill_id; int i; - nullpo_ret(group); + nullpo_ret(unit); + nullpo_ret(target); if( !unit->alive || target->prev == NULL ) return 0; + nullpo_ret(group = unit->group); + if( flag&1 && ( unit->group->skill_id == PF_SPIDERWEB || unit->group->skill_id == GN_THORNS_TRAP ) ) return 0; // Fiberlock is never supposed to trigger on skill_unit_move. [Inkfish] @@ -17681,12 +17647,14 @@ int skill_unit_move_sub (struct block_list* bl, va_list ap) { skill_unit_onleft(skill_id,target,tick); } - if( dissonance ) skill_dance_switch(unit, 1); + if( dissonance ) + skill_dance_switch(unit, 1); return 0; } else { if( flag&1 ) { int result = skill_unit_onplace(unit,target,tick); + if( flag&2 && result ) { //Clear skill ids we have stored in onout. ARR_FIND( 0, ARRAYLENGTH(skill_unit_temp), i, skill_unit_temp[i] == result ); if( i < ARRAYLENGTH(skill_unit_temp) ) @@ -17694,6 +17662,7 @@ int skill_unit_move_sub (struct block_list* bl, va_list ap) { } } else { int result = skill_unit_onout(unit,target,tick); + if( flag&2 && result ) { //Store this unit id. ARR_FIND( 0, ARRAYLENGTH(skill_unit_temp), i, skill_unit_temp[i] == 0 ); if( i < ARRAYLENGTH(skill_unit_temp) ) @@ -17706,7 +17675,8 @@ int skill_unit_move_sub (struct block_list* bl, va_list ap) { //TODO: Normally, this is dangerous since the unit and group could be freed //inside the onout/onplace functions. Currently it is safe because we know song/dance //cells do not get deleted within them. [Skotlex] - if( dissonance ) skill_dance_switch(unit, 1); + if( dissonance ) + skill_dance_switch(unit, 1); if( flag&4 ) skill_unit_onleft(skill_id,target,tick); @@ -17723,24 +17693,25 @@ int skill_unit_move_sub (struct block_list* bl, va_list ap) { * units to figure out when they have left a group. * flag&4: Force a onleft event (triggered when the bl is killed, for example) *------------------------------------------*/ -int skill_unit_move (struct block_list *bl, unsigned int tick, int flag) { +int skill_unit_move(struct block_list *bl, unsigned int tick, int flag) +{ nullpo_ret(bl); if( bl->prev == NULL ) return 0; - if( flag&2 && !(flag&1) ) { //Onout, clear data + if( flag&2 && !(flag&1) ) //Onout, clear data memset(skill_unit_temp, 0, sizeof(skill_unit_temp)); - } map_foreachincell(skill_unit_move_sub,bl->m,bl->x,bl->y,BL_SKILL,bl,tick,flag); if( flag&2 && flag&1 ) { //Onplace, check any skill units you have left. int i; + for( i = 0; i < ARRAYLENGTH(skill_unit_temp); i++ ) if( skill_unit_temp[i] ) skill_unit_onleft(skill_unit_temp[i], bl, tick); - } + } return 0; } @@ -17778,15 +17749,16 @@ void skill_unit_move_unit(struct block_list *bl, int dx, int dy) { return; } -/*========================================== +/** * Moves skill unit group to map m with coordinates x & y (example when knocked back) * @param group Skill Group * @param m Map * @param dx * @param dy - *------------------------------------------*/ -void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 dx, int16 dy) { - int i,j; + */ +void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 dx, int16 dy) +{ + int i, j; unsigned int tick = gettick(); int *m_flag; struct skill_unit *unit1; @@ -17794,8 +17766,10 @@ void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 d if (group == NULL) return; + if (group->unit_count <= 0) return; + if (group->unit == NULL) return; @@ -17808,25 +17782,25 @@ void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 d // 1: Unit will move to a slot that had another unit of the same group (skill_unit_onplace not needed) // 2: Another unit from same group will end up positioned on this unit (skill_unit_onout not needed) // 3: Both 1+2. - for(i = 0; i < group->unit_count; i++){ + for(i = 0; i < group->unit_count; i++) { unit1 =& group->unit[i]; if (!unit1->alive || unit1->bl.m != m) continue; - for(j = 0; j < group->unit_count; j++){ - unit2 =& group->unit[j]; + for(j = 0; j < group->unit_count; j++) { + unit2 = &group->unit[j]; if (!unit2->alive) continue; - if (unit1->bl.x+dx == unit2->bl.x && unit1->bl.y+dy == unit2->bl.y){ + if (unit1->bl.x+dx == unit2->bl.x && unit1->bl.y+dy == unit2->bl.y) m_flag[i] |= 0x1; - } - if (unit1->bl.x-dx == unit2->bl.x && unit1->bl.y-dy == unit2->bl.y){ + if (unit1->bl.x-dx == unit2->bl.x && unit1->bl.y-dy == unit2->bl.y) m_flag[i] |= 0x2; - } } } + j = 0; + for (i = 0; i < group->unit_count; i++) { - unit1 =& group->unit[i]; + unit1 = &group->unit[i]; if (!unit1->alive) continue; if (!(m_flag[i]&0x2)) { @@ -17843,8 +17817,8 @@ void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 d case 1: //Cell moves unto another cell, look for a replacement cell that won't collide //and has no cell moving into it (flag == 2) - for(;junit_count;j++) { - if(m_flag[j]!=2 || !group->unit[j].alive) + for(; j < group->unit_count; j++) { + if(m_flag[j] != 2 || !group->unit[j].alive) continue; //Move to where this cell would had moved. unit2 = &group->unit[j]; @@ -17864,11 +17838,11 @@ void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 d map_foreachincell(skill_unit_effect,unit1->bl.m,unit1->bl.x,unit1->bl.y,group->bl_flag,&unit1->bl,tick,1); } } + aFree(m_flag); - return; } -/*========================================== +/** * Checking product requirement in player's inventory. * Checking if player has the item or not, the amount, and the weight limit. * @param sd Player @@ -17876,17 +17850,18 @@ void skill_unit_move_unit_group(struct skill_unit_group *group, int16 m, int16 d * @param trigger Trigger criteria to match will 'ItemLv' * @param qty Amount of item will be created * @return 0 If failed or Index+1 of item found on skill_produce_db[] - *------------------------------------------*/ -short skill_can_produce_mix (struct map_session_data *sd, unsigned short nameid, int trigger, int qty) { + */ +short skill_can_produce_mix(struct map_session_data *sd, unsigned short nameid, int trigger, int qty) +{ short i, j; nullpo_ret(sd); - if (nameid == 0 || !itemdb_exists(nameid)) + if (!nameid || !itemdb_exists(nameid)) return 0; for (i = 0; i < MAX_SKILL_PRODUCE_DB; i++) { - if (skill_produce_db[i].nameid == nameid ) { + if (skill_produce_db[i].nameid == nameid) { if ((j = skill_produce_db[i].req_skill) > 0 && pc_checkskill(sd,j) < skill_produce_db[i].req_skill_lv) continue; // must iterate again to check other skills that produce it. [malufett] @@ -17920,25 +17895,26 @@ short skill_can_produce_mix (struct map_session_data *sd, unsigned short nameid, // Check on player's inventory for (j = 0; j < MAX_PRODUCE_RESOURCE; j++) { unsigned short nameid_produce; - if ((nameid_produce = skill_produce_db[i].mat_id[j]) == 0 ) + + if (!(nameid_produce = skill_produce_db[i].mat_id[j])) continue; if (skill_produce_db[i].mat_amount[j] == 0) { if (pc_search_inventory(sd,nameid_produce) < 0) return 0; - } - else { + } else { unsigned short idx, amt; + for (idx = 0, amt = 0; idx < MAX_INVENTORY; idx++) if (sd->status.inventory[idx].nameid == nameid_produce) amt += sd->status.inventory[idx].amount; - if (amt < qty*skill_produce_db[i].mat_amount[j]) + if (amt < qty * skill_produce_db[i].mat_amount[j]) return 0; } } - return i+1; + return i + 1; } -/*========================================== +/** * Attempt to produce an item * @param sd Player * @param skill_id Skill used @@ -17948,22 +17924,24 @@ short skill_can_produce_mix (struct map_session_data *sd, unsigned short nameid, * @param slot3 * @param qty Amount of requested item * @return True is success, False if failed - *------------------------------------------*/ -bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned short nameid, int slot1, int slot2, int slot3, int qty) { + */ +bool skill_produce_mix(struct map_session_data *sd, uint16 skill_id, unsigned short nameid, int slot1, int slot2, int slot3, int qty) +{ int slot[3]; - int i,sc,ele,idx,equip,wlv,make_per = 0,flag = 0,skill_lv = 0; + int i, sc, ele, idx, equip, wlv, make_per = 0, flag = 0, skill_lv = 0; int num = -1; // exclude the recipe struct status_data *status; struct item_data* data; nullpo_ret(sd); + status = status_get_status_data(&sd->bl); if( sd->skill_id_old == skill_id ) skill_lv = sd->skill_lv_old; if( !(idx = skill_can_produce_mix(sd,nameid,-1, qty)) ) - return 0; + return false; idx--; if (qty < 1) @@ -17979,14 +17957,14 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s slot[1] = slot2; slot[2] = slot3; - for (i = 0, sc = 0, ele = 0; i < 3; i++){ //Note that qty should always be one if you are using these! + for (i = 0, sc = 0, ele = 0; i < 3; i++) { //Note that qty should always be one if you are using these! short j; if (slot[i] <= 0) continue; j = pc_search_inventory(sd,slot[i]); if (j < 0) continue; - if (slot[i] == ITEMID_STAR_CRUMB){ + if (slot[i] == ITEMID_STAR_CRUMB) { pc_delitem(sd,j,1,1,0,LOG_TYPE_PRODUCE); sc++; } @@ -18012,9 +17990,7 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s clif_msgtable(sd->fd,RUNE_CANT_CREATE); return 0; } else { - /** - * the amount fits, say we got temp_qty 4 and 19 runes, we trim temp_qty to 1. - **/ + // The amount fits, say we got temp_qty 4 and 19 runes, we trim temp_qty to 1. if (temp_qty + sd->status.inventory[i].amount >= data->stack.amount) temp_qty = data->stack.amount - sd->status.inventory[i].amount; } @@ -18025,14 +18001,16 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s qty = temp_qty; } - for (i = 0; i < MAX_PRODUCE_RESOURCE; i++){ + for (i = 0; i < MAX_PRODUCE_RESOURCE; i++) { short id, x, j; - if ((id = skill_produce_db[idx].mat_id[i]) <= 0 || !itemdb_exists(id)) + + if (!(id = skill_produce_db[idx].mat_id[i]) || !itemdb_exists(id)) continue; num++; x = (skill_id == RK_RUNEMASTERY ? 1 : qty) * skill_produce_db[idx].mat_amount[i]; do { int y = 0; + j = pc_search_inventory(sd,id); if (j >= 0) { @@ -18042,15 +18020,15 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s pc_delitem(sd,j,y,0,0,LOG_TYPE_PRODUCE); } else { ShowError("skill_produce_mix: material item error\n"); - return 0; + return false; } - - x-=y; - } while( j>=0 && x>0 ); + x -= y; + } while( j >= 0 && x > 0 ); } if ((equip = (itemdb_isequip(nameid) && skill_id != GN_CHANGEMATERIAL && skill_id != GN_MAKEBOMB ))) wlv = itemdb_wlv(nameid); + if (!equip) { switch (skill_id) { case BS_IRON: @@ -18071,16 +18049,13 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s break; default: // Enchanted Stones make_per += 1000+i*500; // Enchanted stone Craft bonus: +15/+20/+25/+30/+35 - break; + break; } break; case ASC_CDP: make_per = (2000 + 40*status->dex + 20*status->luk); break; case AL_HOLYWATER: - /** - * Arch Bishop - **/ case AB_ANCILLA: make_per = 100000; //100% success break; @@ -18132,15 +18107,13 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s case SA_CREATECON: // Elemental Converter Creation make_per = 100000; // should be 100% success rate break; - /** - * Rune Knight - **/ - case RK_RUNEMASTERY: - { + + case RK_RUNEMASTERY: { int A = 100 * (51 + 2 * pc_checkskill(sd, skill_id)); int B = 100 * status->dex / 30 + 10 * (status->luk + sd->status.job_level); int C = 100 * cap_value(sd->itemid,0,100); //itemid depend on makerune() int D = 0; + switch (nameid) { //rune rank it_diff 9 craftable rune case ITEMID_BERKANA: D = -2000; @@ -18164,11 +18137,9 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s break; //not specified =-15% } make_per = A + B + C + D; - break; } - /** - * Guillotine Cross - **/ + break; + case GC_CREATENEWPOISON: make_per = 3000 + 500 * pc_checkskill(sd,GC_RESEARCHNEWPOISON); qty = 1+rnd()%pc_checkskill(sd,GC_RESEARCHNEWPOISON); @@ -18346,9 +18317,6 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s flag = battle_config.produce_item_name_input&0x2; break; case AL_HOLYWATER: - /** - * Arch Bishop - **/ case AB_ANCILLA: flag = battle_config.produce_item_name_input&0x8; break; @@ -18538,24 +18506,26 @@ bool skill_produce_mix (struct map_session_data *sd, uint16 skill_id, unsigned s if (sd->cook_mastery > 0) pc_setglobalreg(sd, "COOK_MASTERY", sd->cook_mastery - ( 1 << ((skill_produce_db[idx].itemlv - 11) / 2) ) - ( ( ( 1 << ((skill_produce_db[idx].itemlv - 11) / 2) ) >> 1 ) * 3 )); } + break; } } return false; } /** -* Attempt to create arrow by specified material -* @param sd Player -* @param nameid Item ID of material -* @return True if created, False is failed -*/ -bool skill_arrow_create(struct map_session_data *sd, unsigned short nameid) { - short i, j, idx =- 1; + * Attempt to create arrow by specified material + * @param sd Player + * @param nameid Item ID of material + * @return True if created, False is failed + */ +bool skill_arrow_create(struct map_session_data *sd, unsigned short nameid) +{ + short i, j, idx = -1; struct item tmp_item; nullpo_ret(sd); - if (nameid == 0 || !itemdb_exists(nameid) || !skill_arrow_count) + if (!nameid || !itemdb_exists(nameid) || !skill_arrow_count) return false; for (i = 0; i < MAX_SKILL_ARROW_DB;i++) { @@ -18565,12 +18535,13 @@ bool skill_arrow_create(struct map_session_data *sd, unsigned short nameid) { } } - if (idx < 0 || (j = pc_search_inventory(sd,nameid)) < 0) + if (!idx || (j = pc_search_inventory(sd,nameid)) < 0) return false; pc_delitem(sd,j,1,0,0,LOG_TYPE_PRODUCE); for (i = 0; i < MAX_ARROW_RESULT; i++) { char flag = 0; + if (skill_arrow_db[idx].cre_id[i] == 0 || !itemdb_exists(skill_arrow_db[idx].cre_id[i]) || skill_arrow_db[idx].cre_amount[i] == 0) continue; memset(&tmp_item,0,sizeof(tmp_item)); @@ -18592,11 +18563,12 @@ bool skill_arrow_create(struct map_session_data *sd, unsigned short nameid) { } /** -* Enchant weapon with poison -* @param sd Player -* @nameid Item ID of poison type -*/ -int skill_poisoningweapon( struct map_session_data *sd, unsigned short nameid) { + * Enchant weapon with poison + * @param sd Player + * @nameid Item ID of poison type + */ +int skill_poisoningweapon(struct map_session_data *sd, unsigned short nameid) +{ sc_type type; int chance, i; //uint16 msg = 1443; //Official is using msgstringtable.txt @@ -18605,7 +18577,7 @@ int skill_poisoningweapon( struct map_session_data *sd, unsigned short nameid) { nullpo_ret(sd); - if( nameid == 0 || (i = pc_search_inventory(sd,nameid)) < 0 || pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME) ) { + if( !nameid || (i = pc_search_inventory(sd,nameid)) < 0 || pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME) ) { clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_LEVEL,0); return 0; } @@ -18668,7 +18640,7 @@ int skill_magicdecoy(struct map_session_data *sd, unsigned short nameid) { nullpo_ret(sd); skill = sd->menuskill_val; - if( nameid == 0 || !itemdb_is_element(nameid) || (i = pc_search_inventory(sd,nameid)) < 0 || !skill || pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME) ) { + if( !nameid || !itemdb_is_element(nameid) || (i = pc_search_inventory(sd,nameid)) < 0 || !skill || pc_delitem(sd,i,1,0,0,LOG_TYPE_CONSUME) ) { clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0); return 0; } @@ -18904,15 +18876,18 @@ int skill_changematerial(struct map_session_data *sd, int n, unsigned short *ite return 0; } + /** - * for Royal Guard's LG_TRAMPLE - **/ -static int skill_destroy_trap( struct block_list *bl, va_list ap ) { + * For Royal Guard's LG_TRAMPLE + */ +static int skill_destroy_trap(struct block_list *bl, va_list ap) +{ struct skill_unit *su = (struct skill_unit *)bl; - struct skill_unit_group *sg; + struct skill_unit_group *sg = NULL; unsigned int tick; nullpo_ret(su); + tick = va_arg(ap, unsigned int); if (su->alive && (sg = su->group) && skill_get_inf2(sg->skill_id)&INF2_TRAP) { @@ -18935,13 +18910,16 @@ static int skill_destroy_trap( struct block_list *bl, va_list ap ) { // Traps aren't recovered. skill_delunit(su); } + return 0; } + /*========================================== -* -*------------------------------------------*/ + * + *------------------------------------------*/ int skill_blockpc_get(struct map_session_data *sd, int skillid) { int i; + nullpo_retr(-1, sd); ARR_FIND(0, MAX_SKILLCOOLDOWN, i, sd->scd[i] && sd->scd[i]->skill_id == skillid); @@ -18950,7 +18928,7 @@ int skill_blockpc_get(struct map_session_data *sd, int skillid) { int skill_blockpc_end(int tid, unsigned int tick, int id, intptr_t data) { struct map_session_data *sd = map_id2sd(id); - int i = (int) data; + int i = (int)data; if (!sd || data < 0 || data >= MAX_SKILLCOOLDOWN) return 0; @@ -18966,20 +18944,22 @@ int skill_blockpc_end(int tid, unsigned int tick, int id, intptr_t data) { } /** -* flags a singular skill as being blocked from persistent usage. -* @param sd the player the skill delay affects -* @param skill_id the skill which should be delayed -* @param tick the length of time the delay should last -* @param load whether this assignment is being loaded upon player login -* @return 0 if successful, -1 otherwise -*/ -int skill_blockpc_start(struct map_session_data *sd, int skillid, int tick) { + * Flags a singular skill as being blocked from persistent usage. + * @param sd the player the skill delay affects + * @param skill_id the skill which should be delayed + * @param tick the length of time the delay should last + * @param load whether this assignment is being loaded upon player login + * @return 0 if successful, -1 otherwise + */ +int skill_blockpc_start(struct map_session_data *sd, int skill_id, int tick) { int i; + nullpo_retr(-1, sd); - if (skillid == 0 || tick < 1) + + if (!skill_id || tick < 1) return -1; - ARR_FIND(0, MAX_SKILLCOOLDOWN, i, sd->scd[i] && sd->scd[i]->skill_id == skillid); + ARR_FIND(0, MAX_SKILLCOOLDOWN, i, sd->scd[i] && sd->scd[i]->skill_id == skill_id); if (i < MAX_SKILLCOOLDOWN) { // Skill already with cooldown delete_timer(sd->scd[i]->timer, skill_blockpc_end); aFree(sd->scd[i]); @@ -18989,11 +18969,11 @@ int skill_blockpc_start(struct map_session_data *sd, int skillid, int tick) { ARR_FIND(0, MAX_SKILLCOOLDOWN, i, !sd->scd[i]); if (i < MAX_SKILLCOOLDOWN) { // Free Slot found CREATE(sd->scd[i], struct skill_cooldown_entry, 1); - sd->scd[i]->skill_id = skillid; + sd->scd[i]->skill_id = skill_id; sd->scd[i]->timer = add_timer(gettick() + tick, skill_blockpc_end, sd->bl.id, i); if (battle_config.display_status_timers && tick > 0) - clif_skill_cooldown(sd, skillid, tick); + clif_skill_cooldown(sd, skill_id, tick); return 1; } else { @@ -19004,7 +18984,9 @@ int skill_blockpc_start(struct map_session_data *sd, int skillid, int tick) { int skill_blockpc_clear(struct map_session_data *sd) { int i; + nullpo_ret(sd); + for (i = 0; i < MAX_SKILLCOOLDOWN; i++) { if (!sd->scd[i]) continue; @@ -19018,9 +19000,12 @@ int skill_blockpc_clear(struct map_session_data *sd) { int skill_blockhomun_end(int tid, unsigned int tick, int id, intptr_t data) //[orn] { struct homun_data *hd = (TBL_HOM*) map_id2bl(id); + if (data <= 0 || data >= MAX_SKILL) return 0; - if (hd) hd->blockskill[data] = 0; + + if (hd) + hd->blockskill[data] = 0; return 1; } @@ -19028,26 +19013,31 @@ int skill_blockhomun_end(int tid, unsigned int tick, int id, intptr_t data) //[o int skill_blockhomun_start(struct homun_data *hd, uint16 skill_id, int tick) //[orn] { uint16 idx = skill_get_index(skill_id); - nullpo_retr (-1, hd); + nullpo_retr(-1, hd); - if (idx == 0) + if (!idx) return -1; if (tick < 1) { hd->blockskill[idx] = 0; return -1; } + hd->blockskill[idx] = 1; + return add_timer(gettick() + tick, skill_blockhomun_end, hd->bl.id, idx); } int skill_blockmerc_end(int tid, unsigned int tick, int id, intptr_t data) //[orn] { struct mercenary_data *md = (TBL_MER*)map_id2bl(id); + if( data <= 0 || data >= MAX_SKILL ) return 0; - if( md ) md->blockskill[data] = 0; + + if( md ) + md->blockskill[data] = 0; return 1; } @@ -19055,21 +19045,24 @@ int skill_blockmerc_end(int tid, unsigned int tick, int id, intptr_t data) //[or int skill_blockmerc_start(struct mercenary_data *md, uint16 skill_id, int tick) { uint16 idx = skill_get_index(skill_id); - nullpo_retr (-1, md); - if (idx == 0) + nullpo_retr(-1, md); + + if( !idx ) return -1; - if( tick < 1 ) - { + + if( tick < 1 ) { md->blockskill[idx] = 0; return -1; } + md->blockskill[idx] = 1; + return add_timer(gettick() + tick, skill_blockmerc_end, md->bl.id, idx); } /** * Adds a new skill unit entry for this player to recast after map load - **/ + */ void skill_usave_add(struct map_session_data * sd, uint16 skill_id, uint16 skill_lv) { struct skill_usave * sus = NULL; @@ -19077,8 +19070,8 @@ void skill_usave_add(struct map_session_data * sd, uint16 skill_id, uint16 skill idb_remove(skillusave_db,sd->status.char_id); } - CREATE( sus, struct skill_usave, 1 ); - idb_put( skillusave_db, sd->status.char_id, sus ); + CREATE(sus, struct skill_usave, 1); + idb_put(skillusave_db, sd->status.char_id, sus); sus->skill_id = skill_id; sus->skill_lv = skill_lv; @@ -19088,12 +19081,10 @@ void skill_usave_add(struct map_session_data * sd, uint16 skill_id, uint16 skill void skill_usave_trigger(struct map_session_data *sd) { struct skill_usave * sus = NULL; - if( ! (sus = idb_get(skillusave_db,sd->status.char_id)) ) { + if( ! (sus = idb_get(skillusave_db,sd->status.char_id)) ) return; - } skill_unitsetting(&sd->bl,sus->skill_id,sus->skill_lv,sd->bl.x,sd->bl.y,0); - idb_remove(skillusave_db,sd->status.char_id); return; @@ -19101,14 +19092,15 @@ void skill_usave_trigger(struct map_session_data *sd) { /* * */ -int skill_split_str (char *str, char **val, int num) { +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; + *str++ = 0; } return i; @@ -19121,7 +19113,8 @@ int skill_split_str (char *str, char **val, int num) { * @param val : array of MAX_SKILL_LEVEL to put value into * @return 0:error, x:number of value assign (should be MAX_SKILL_LEVEL) */ -int skill_split_atoi (char *str, int *val) { +int skill_split_atoi (char *str, int *val) +{ int i, j, step = 1; for (i=0; i} -*/ -static bool skill_parse_row_magicmushroomdb(char* split[], int column, int current) { + * Structure: SkillID + */ +static bool skill_parse_row_magicmushroomdb(char* split[], int column, int current) +{ unsigned short i, skill_id = atoi(split[0]); bool rem = (atoi(split[1]) == 1 ? true : false); @@ -20208,10 +20215,11 @@ static bool skill_parse_row_magicmushroomdb(char* split[], int column, int curre } /** Reads db of copyable skill -* SkillName,Option{,JobAllowed{,RequirementRemoved}} -* SkillID,Option{,JobAllowed{,RequirementRemoved}} -*/ -static bool skill_parse_row_copyabledb(char* split[], int column, int current) { + * Structure: SkillName,Option{,JobAllowed{,RequirementRemoved}} + * SkillID,Option{,JobAllowed{,RequirementRemoved}} + */ +static bool skill_parse_row_copyabledb(char* split[], int column, int current) +{ int16 id = 0; uint8 option = 0; @@ -20245,10 +20253,11 @@ static bool skill_parse_row_copyabledb(char* split[], int column, int current) { } /** Reads additional range for distance checking from NPC [Cydh] -* SkillName,AdditionalRange{,NPC Type} -* SkillID,AdditionalRange{,NPC Type} -*/ -static bool skill_parse_row_nonearnpcrangedb(char* split[], int column, int current) { + * Structure: SkillName,AdditionalRange{,NPC Type} + * SkillID,AdditionalRange{,NPC Type} + */ +static bool skill_parse_row_nonearnpcrangedb(char* split[], int column, int current) +{ uint16 id = 0; trim(split[0]); @@ -20268,9 +20277,10 @@ static bool skill_parse_row_nonearnpcrangedb(char* split[], int column, int curr } /** Reads skill chance by Abracadabra/Hocus Pocus spell -* SkillID,DummyName,RatePerLvl -*/ -static bool skill_parse_row_abradb(char* split[], int columns, int current) { + * Structure: SkillID,DummyName,RatePerLvl + */ +static bool skill_parse_row_abradb(char* split[], int columns, int current) +{ unsigned short i, skill_id = atoi(split[0]); if (!skill_get_index(skill_id) || !skill_get_max(skill_id)) { ShowError("skill_parse_row_abradb: Invalid skill ID %d\n", skill_id); @@ -20303,9 +20313,10 @@ static bool skill_parse_row_abradb(char* split[], int columns, int current) { } /** Reads change material db -* ID,ProductID,BaseRate,MakeAmount1,MakeAmountRate1...,MakeAmount5,MakeAmountRate5 -*/ -static bool skill_parse_row_changematerialdb(char* split[], int columns, int current) { + * Structure: ProductID,BaseRate,MakeAmount1,MakeAmountRate1...,MakeAmount5,MakeAmountRate5 + */ +static bool skill_parse_row_changematerialdb(char* split[], int columns, int current) +{ uint16 id = atoi(split[0]), nameid = atoi(split[1]); short rate = atoi(split[2]); bool found = false; @@ -20358,7 +20369,7 @@ static bool skill_parse_row_changematerialdb(char* split[], int columns, int cur /** * Manage Skill Damage database [Lilith] - **/ + */ #ifdef ADJUST_SKILL_DAMAGE static bool skill_parse_row_skilldamage(char* split[], int columns, int current) { @@ -20393,7 +20404,8 @@ static bool skill_parse_row_skilldamage(char* split[], int columns, int current) * create_arrow_db.txt * abra_db.txt *------------------------------*/ -static void skill_readdb(void) { +static void skill_readdb(void) +{ int i; const char* dbsubpath[] = { "", @@ -20460,6 +20472,7 @@ static void skill_readdb(void) { void skill_reload (void) { struct s_mapiterator *iter; struct map_session_data *sd; + skill_destroy_requirement(); skill_readdb(); /* lets update all players skill tree : so that if any skill modes were changed they're properly updated */ @@ -20467,13 +20480,13 @@ void skill_reload (void) { for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) clif_skillinfoblock(sd); mapit_free(iter); - } /*========================================== * *------------------------------------------*/ -void do_init_skill (void){ +void do_init_skill(void) +{ skilldb_name2id = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, 0); skill_readdb(); @@ -20493,7 +20506,8 @@ void do_init_skill (void){ add_timer_interval(gettick()+SKILLUNITTIMER_INTERVAL,skill_unit_timer,0,0,SKILLUNITTIMER_INTERVAL); } -void do_final_skill(void){ +void do_final_skill(void) +{ skill_destroy_requirement(); db_destroy(skilldb_name2id); db_destroy(skillunit_group_db); diff --git a/src/map/status.c b/src/map/status.c index 239d4f50db..114f34aa42 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -104,7 +104,7 @@ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned * Returns the status change associated with a skill. * @param skill The skill to look up * @return The status registered for this skill - **/ + */ sc_type status_skill2sc(int skill) { int idx = skill_get_index(skill); @@ -116,11 +116,11 @@ sc_type status_skill2sc(int skill) } /** -* Returns the FIRST skill (in order of definition in initChangeTables) to use a given status change. -* Utilized for various duration lookups. Use with caution! -* @param sc The status to look up -* @return A skill associated with the status -**/ + * Returns the FIRST skill (in order of definition in initChangeTables) to use a given status change. + * Utilized for various duration lookups. Use with caution! + * @param sc The status to look up + * @return A skill associated with the status + */ int status_sc2skill(sc_type sc) { if( sc < 0 || sc >= SC_MAX ) { @@ -132,10 +132,10 @@ int status_sc2skill(sc_type sc) } /** -* Returns the status calculation flag associated with a given status change. -* @param sc The status to look up -* @return The scb_flag registered for this status (see enum scb_flag) -**/ + * Returns the status calculation flag associated with a given status change. + * @param sc The status to look up + * @return The scb_flag registered for this status (see enum scb_flag) + */ unsigned int status_sc2scb_flag(sc_type sc) { if( sc < 0 || sc >= SC_MAX ) { @@ -147,10 +147,10 @@ unsigned int status_sc2scb_flag(sc_type sc) } /** -* Returns the bl types which require a status change packet to be sent for a given client status identifier. -* @param type The client-side status identifier to look up (see enum si_type) -* @return The bl types relevant to the type (see enum bl_type) -**/ + * Returns the bl types which require a status change packet to be sent for a given client status identifier. + * @param type The client-side status identifier to look up (see enum si_type) + * @return The bl types relevant to the type (see enum bl_type) + */ int status_type2relevant_bl_types(int type) { if( type < 0 || type >= SI_MAX ) { @@ -1241,24 +1241,24 @@ static void initDummyData(void) } /** -* For copying a status_data structure from b to a, without overwriting current Hp and Sp -* @param a: Status data structure to copy from -* @param b: Status data structure to copy to -**/ + * For copying a status_data structure from b to a, without overwriting current Hp and Sp + * @param a: Status data structure to copy from + * @param b: Status data structure to copy to + */ static inline void status_cpy(struct status_data* a, const struct status_data* b) { memcpy((void*)&a->max_hp, (const void*)&b->max_hp, sizeof(struct status_data)-(sizeof(a->hp)+sizeof(a->sp))); } /** -* Sets HP to a given value -* Will always succeed (overrides heal impedement statuses) but can't kill an object -* @param bl: Object whose HP will be set [PC|MOB|HOM|MER|ELEM] -* @param hp: What the HP is to be set as -* @param flag: Used in case final value is higher than current -* Use 2 to display healing effect -* @return heal or zapped HP if valid -**/ + * Sets HP to a given value + * Will always succeed (overrides heal impedement statuses) but can't kill an object + * @param bl: Object whose HP will be set [PC|MOB|HOM|MER|ELEM] + * @param hp: What the HP is to be set as + * @param flag: Used in case final value is higher than current + * Use 2 to display healing effect + * @return heal or zapped HP if valid + */ int status_set_hp(struct block_list *bl, unsigned int hp, int flag) { struct status_data *status; @@ -1275,13 +1275,13 @@ int status_set_hp(struct block_list *bl, unsigned int hp, int flag) } /** -* Sets SP to a given value -* @param bl: Object whose SP will be set [PC|HOM|MER|ELEM] -* @param sp: What the SP is to be set as -* @param flag: Used in case final value is higher than current -* Use 2 to display healing effect -* @return heal or zapped SP if valid -**/ + * Sets SP to a given value + * @param bl: Object whose SP will be set [PC|HOM|MER|ELEM] + * @param sp: What the SP is to be set as + * @param flag: Used in case final value is higher than current + * Use 2 to display healing effect + * @return heal or zapped SP if valid + */ int status_set_sp(struct block_list *bl, unsigned int sp, int flag) { struct status_data *status; @@ -1298,14 +1298,14 @@ int status_set_sp(struct block_list *bl, unsigned int sp, int flag) } /** -* Takes HP/SP from an Object -* @param bl: Object who will have HP/SP taken [PC|MOB|HOM|MER|ELEM] -* @param hp: How much HP to charge -* @param sp: How much SP to charge -* @return hp+sp through status_damage() -* Note: HP/SP are integer values, not percentages. Values should be -* calculated either within function call or before -**/ + * Takes HP/SP from an Object + * @param bl: Object who will have HP/SP taken [PC|MOB|HOM|MER|ELEM] + * @param hp: How much HP to charge + * @param sp: How much SP to charge + * @return hp+sp through status_damage() + * Note: HP/SP are integer values, not percentages. Values should be + * calculated either within function call or before + */ int64 status_charge(struct block_list* bl, int64 hp, int64 sp) { if(!(bl->type&BL_CONSUME)) @@ -1314,21 +1314,21 @@ int64 status_charge(struct block_list* bl, int64 hp, int64 sp) } /** -* Inflicts damage on the target with the according walkdelay. -* @param src: Source object giving damage [PC|MOB|PET|HOM|MER|ELEM] -* @param target: Target of the damage -* @param dhp: How much damage to HP -* @param dsp: How much damage to SP -* @param walkdelay: Amount of time before object can walk again -* @param flag: Damage flag decides various options -* flag&1: Passive damage - Does not trigger cancelling status changes -* flag&2: Fail if there is not enough to subtract -* flag&4: Mob does not give EXP/Loot if killed -* flag&8: Used to damage SP of a dead character -* @return hp+sp -* Note: HP/SP are integer values, not percentages. Values should be -* calculated either within function call or before -**/ + * Inflicts damage on the target with the according walkdelay. + * @param src: Source object giving damage [PC|MOB|PET|HOM|MER|ELEM] + * @param target: Target of the damage + * @param dhp: How much damage to HP + * @param dsp: How much damage to SP + * @param walkdelay: Amount of time before object can walk again + * @param flag: Damage flag decides various options + * flag&1: Passive damage - Does not trigger cancelling status changes + * flag&2: Fail if there is not enough to subtract + * flag&4: Mob does not give EXP/Loot if killed + * flag&8: Used to damage SP of a dead character + * @return hp+sp + * Note: HP/SP are integer values, not percentages. Values should be + * calculated either within function call or before + */ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, int64 dsp, int walkdelay, int flag) { struct status_data *status; @@ -1551,14 +1551,14 @@ int status_damage(struct block_list *src,struct block_list *target,int64 dhp, in } /** -* Heals an object -* @param bl: Object to heal [PC|MOB|HOM|MER|ELEM] -* @param hhp: How much HP to heal -* @param hsp: How much SP to heal -* @param flag: Whether it's Forced(&1) or gives HP/SP(&2) heal effect \n -* Forced healing overrides heal impedement statuses (Berserk) -* @return hp+sp -**/ + * Heals an object + * @param bl: Object to heal [PC|MOB|HOM|MER|ELEM] + * @param hhp: How much HP to heal + * @param hsp: How much SP to heal + * @param flag: Whether it's Forced(&1) or gives HP/SP(&2) heal effect \n + * Forced healing overrides heal impedement statuses (Berserk) + * @return hp+sp + */ int status_heal(struct block_list *bl,int64 hhp,int64 hsp, int flag) { struct status_data *status; @@ -1630,17 +1630,17 @@ int status_heal(struct block_list *bl,int64 hhp,int64 hsp, int flag) } /** -* Applies percentage based damage to a unit -* If a mob is killed this way and there is no src, no EXP/Drops will be awarded -* @param src: Object initiating HP/SP modification [PC|MOB|PET|HOM|MER|ELEM] -* @param target: Object to modify HP/SP -* @param hp_rate: Percentage of HP to modify -* @param sp_rate: Percentage of SP to modify -* @param flag: \n -* 0: Heal target \n -* 2: Target must not die from subtraction -* @return hp+sp through status_heal() -**/ + * Applies percentage based damage to a unit + * If a mob is killed this way and there is no src, no EXP/Drops will be awarded + * @param src: Object initiating HP/SP modification [PC|MOB|PET|HOM|MER|ELEM] + * @param target: Object to modify HP/SP + * @param hp_rate: Percentage of HP to modify + * @param sp_rate: Percentage of SP to modify + * @param flag: \n + * 0: Heal target \n + * 2: Target must not die from subtraction + * @return hp+sp through status_heal() + */ int status_percent_change(struct block_list *src,struct block_list *target,signed char hp_rate, signed char sp_rate, int flag) { struct status_data *status; @@ -1701,12 +1701,12 @@ int status_percent_change(struct block_list *src,struct block_list *target,signe } /** -* Revives a unit -* @param bl: Object to revive [PC|MOB|HOM] -* @param per_hp: Percentage of HP to revive with -* @param per_sp: Percentage of SP to revive with -* @return Successful (1) or Invalid target (0) -**/ + * Revives a unit + * @param bl: Object to revive [PC|MOB|HOM] + * @param per_hp: Percentage of HP to revive with + * @param per_sp: Percentage of SP to revive with + * @return Successful (1) or Invalid target (0) + */ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per_sp) { struct status_data *status; @@ -1743,20 +1743,20 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per return 1; } -/** [Skotlex] -* Checks whether the src can use the skill on the target, -* taking into account status/option of both source/target -* @param src: Object using skill on target [PC|MOB|PET|HOM|MER|ELEM] +/** + * Checks whether the src can use the skill on the target, + * taking into account status/option of both source/target + * @param src: Object using skill on target [PC|MOB|PET|HOM|MER|ELEM] src MAY be NULL to indicate we shouldn't check it, this is a ground-based skill attack -* @param target: Object being targeted by src [PC|MOB|HOM|MER|ELEM] + * @param target: Object being targeted by src [PC|MOB|HOM|MER|ELEM] target MAY be NULL, which checks if src can cast skill_id on the ground -* @param skill_id: Skill ID being used on target -* @param flag: 0 - Trying to use skill on target -* 1 - Cast bar is done -* 2 - Skill already pulled off, check is due to ground-based skills or splash-damage ones -* @return src can use skill (1) or cannot use skill (0) -* @author [Skotlex] -**/ + * @param skill_id: Skill ID being used on target + * @param flag: 0 - Trying to use skill on target + * 1 - Cast bar is done + * 2 - Skill already pulled off, check is due to ground-based skills or splash-damage ones + * @return src can use skill (1) or cannot use skill (0) + * @author [Skotlex] + */ bool status_check_skilluse(struct block_list *src, struct block_list *target, uint16 skill_id, int flag) { struct status_data *status; struct status_change *sc = NULL, *tsc; @@ -1976,12 +1976,12 @@ bool status_check_skilluse(struct block_list *src, struct block_list *target, ui } /** -* Checks whether the src can see the target -* @param src: Object using skill on target [PC|MOB|PET|HOM|MER|ELEM] -* @param target: Object being targeted by src [PC|MOB|HOM|MER|ELEM] -* @return src can see (1) or target is invisible (0) -* @author [Skotlex] -**/ + * Checks whether the src can see the target + * @param src: Object using skill on target [PC|MOB|PET|HOM|MER|ELEM] + * @param target: Object being targeted by src [PC|MOB|HOM|MER|ELEM] + * @return src can see (1) or target is invisible (0) + * @author [Skotlex] + */ int status_check_visibility(struct block_list *src, struct block_list *target) { int view_range; @@ -2027,12 +2027,12 @@ int status_check_visibility(struct block_list *src, struct block_list *target) } /** -* Base ASPD value taken from the job tables -* @param sd: Player object -* @param status: Player status -* @return base amotion after single/dual weapon and shield adjustments [RENEWAL] -* base amotion after single/dual weapon and stats adjustments [PRE-RENEWAL] -**/ + * Base ASPD value taken from the job tables + * @param sd: Player object + * @param status: Player status + * @return base amotion after single/dual weapon and shield adjustments [RENEWAL] + * base amotion after single/dual weapon and stats adjustments [PRE-RENEWAL] + */ int status_base_amotion_pc(struct map_session_data* sd, struct status_data* status) { int amotion; @@ -2075,12 +2075,12 @@ int status_base_amotion_pc(struct map_session_data* sd, struct status_data* stat } /** -* Base attack value calculated for units -* @param bl: Object to get attack for [PC|HOM] -* @param status: Object status -* @return base attack -* Note: Function only calculates Homunculus bATK in RENEWAL -**/ + * Base attack value calculated for units + * @param bl: Object to get attack for [PC|HOM] + * @param status: Object status + * @return base attack + * Note: Function only calculates Homunculus bATK in RENEWAL + */ static unsigned short status_base_atk(const struct block_list *bl, const struct status_data *status) { int flag = 0, str, dex, @@ -2140,11 +2140,11 @@ static unsigned short status_base_atk(const struct block_list *bl, const struct #ifdef RENEWAL /** -* Weapon attack value calculated for Players -* @param wa: Weapon attack -* @param status: Player status -* @return weapon attack -**/ + * Weapon attack value calculated for Players + * @param wa: Weapon attack + * @param status: Player status + * @return weapon attack + */ unsigned int status_weapon_atk(struct weapon_atk wa, struct status_data *status) { float str = status->str; @@ -2163,10 +2163,10 @@ unsigned int status_weapon_atk(struct weapon_atk wa, struct status_data *status) #endif /** -* Fills in the misc data that can be calculated from the other status info (except for level) -* @param bl: Object to calculate status on [PC|MOB|PET|HOM|MERC|ELEM] -* @param status: Player status -**/ + * Fills in the misc data that can be calculated from the other status info (except for level) + * @param bl: Object to calculate status on [PC|MOB|PET|HOM|MERC|ELEM] + * @param status: Player status + */ void status_calc_misc(struct block_list *bl, struct status_data *status, int level) { int stat; @@ -2273,13 +2273,14 @@ void status_calc_misc(struct block_list *bl, struct status_data *status, int lev status_calc_regen(bl, status, status_get_regen_data(bl)); } -/** [Skotlex] -* Calculates the initial status for the given mob -* @param md: Mob object -* @param opt: Whether or not it is the first calculation +/** + * Calculates the initial status for the given mob + * @param md: Mob object + * @param opt: Whether or not it is the first calculation This will only be false when a mob levels up (Regular and WoE Guardians) -* @return 1 for calculated special statuses or 0 for none -**/ + * @return 1 for calculated special statuses or 0 for none + * @author [Skotlex] + */ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) { struct status_data *status; @@ -2476,13 +2477,14 @@ int status_calc_mob_(struct mob_data* md, enum e_status_calc_opt opt) return 1; } -/** [Skotlex] -* Calculates the stats of the given pet -* @param pd: Pet object -* @param opt: Whether or not it is the first calculation +/** + * Calculates the stats of the given pet + * @param pd: Pet object + * @param opt: Whether or not it is the first calculation This will only be false when a pet levels up -* @return 1 -**/ + * @return 1 + * @author [Skotlex] + */ int status_calc_pet_(struct pet_data *pd, enum e_status_calc_opt opt) { nullpo_ret(pd); @@ -2549,12 +2551,13 @@ int status_calc_pet_(struct pet_data *pd, enum e_status_calc_opt opt) return 1; } -/** [Cydh] -* Get HP bonus modifiers -* @param bl: block_list that will be checked -* @param type: type of e_status_bonus (STATUS_BONUS_FIX or STATUS_BONUS_RATE) -* @return bonus: total bonus for HP -*/ +/** + * Get HP bonus modifiers + * @param bl: block_list that will be checked + * @param type: type of e_status_bonus (STATUS_BONUS_FIX or STATUS_BONUS_RATE) + * @return bonus: total bonus for HP + * @author [Cydh] + */ static int status_get_hpbonus(struct block_list *bl, enum e_status_bonus type) { int bonus = 0; @@ -2661,12 +2664,13 @@ static int status_get_hpbonus(struct block_list *bl, enum e_status_bonus type) { return min(bonus,INT_MAX); } -/** [Cydh] -* Get SP bonus modifiers -* @param bl: block_list that will be checked -* @param type: type of e_status_bonus (STATUS_BONUS_FIX or STATUS_BONUS_RATE) -* @return bonus: total bonus for SP -*/ +/** + * Get SP bonus modifiers + * @param bl: block_list that will be checked + * @param type: type of e_status_bonus (STATUS_BONUS_FIX or STATUS_BONUS_RATE) + * @return bonus: total bonus for SP + * @author [Cydh] + */ static int status_get_spbonus(struct block_list *bl, enum e_status_bonus type) { int bonus = 0; @@ -2736,13 +2740,13 @@ static int status_get_spbonus(struct block_list *bl, enum e_status_bonus type) { } /** -* Get final MaxHP or MaxSP for player. References: http://irowiki.org/wiki/Max_HP and http://irowiki.org/wiki/Max_SP -* The calculation needs base_level, base_status/battle_status (vit or int), additive modifier, and multiplicative modifier -* @param sd Player -* @param stat Vit/Int of player as param modifier -* @param isHP true - calculates Max HP, false - calculated Max SP -* @return max The max value of HP or SP -**/ + * Get final MaxHP or MaxSP for player. References: http://irowiki.org/wiki/Max_HP and http://irowiki.org/wiki/Max_SP + * The calculation needs base_level, base_status/battle_status (vit or int), additive modifier, and multiplicative modifier + * @param sd Player + * @param stat Vit/Int of player as param modifier + * @param isHP true - calculates Max HP, false - calculated Max SP + * @return max The max value of HP or SP + */ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned int stat, bool isHP) { double max = 0; uint16 idx, level, job_id; @@ -2768,12 +2772,12 @@ static unsigned int status_calc_maxhpsp_pc(struct map_session_data* sd, unsigned } /** -* Calculates player data from scratch without counting SC adjustments -* Should be invoked whenever players raise stats, learn passive skills or change equipment -* @param sd: Player object -* @param opt: Whether it is first calc (login) or not -* @return (-1) for too many recursive calls, (1) recursive call, (0) success -**/ + * Calculates player data from scratch without counting SC adjustments + * Should be invoked whenever players raise stats, learn passive skills or change equipment + * @param sd: Player object + * @param opt: Whether it is first calc (login) or not + * @return (-1) for too many recursive calls, (1) recursive call, (0) success + */ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) { static int calculating = 0; ///< Check for recursive call preemption. [Skotlex] @@ -3603,11 +3607,11 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) } /** -* Calculates Mercenary data -* @param md: Mercenary object -* @param opt: Whether it is first calc or not (0 on level up or status) -* @return 0 -**/ + * Calculates Mercenary data + * @param md: Mercenary object + * @param opt: Whether it is first calc or not (0 on level up or status) + * @return 0 + */ int status_calc_mercenary_(struct mercenary_data *md, enum e_status_calc_opt opt) { struct status_data *status = &md->base_status; @@ -3632,11 +3636,11 @@ int status_calc_mercenary_(struct mercenary_data *md, enum e_status_calc_opt opt } /** -* Calculates Homunculus data -* @param hd: Homunculus object -* @param opt: Whether it is first calc or not (0 on level up or status) -* @return 1 -**/ + * Calculates Homunculus data + * @param hd: Homunculus object + * @param opt: Whether it is first calc or not (0 on level up or status) + * @return 1 + */ int status_calc_homunculus_(struct homun_data *hd, enum e_status_calc_opt opt) { struct status_data *status = &hd->base_status; @@ -3730,11 +3734,11 @@ int status_calc_homunculus_(struct homun_data *hd, enum e_status_calc_opt opt) } /** -* Calculates Elemental data -* @param ed: Elemental object -* @param opt: Whether it is first calc or not (0 on status change) -* @return 0 -**/ + * Calculates Elemental data + * @param ed: Elemental object + * @param opt: Whether it is first calc or not (0 on status change) + * @return 0 + */ int status_calc_elemental_(struct elemental_data *ed, enum e_status_calc_opt opt) { struct status_data *status = &ed->base_status; @@ -3780,11 +3784,11 @@ int status_calc_elemental_(struct elemental_data *ed, enum e_status_calc_opt opt } /** -* Calculates NPC data -* @param nd: NPC object -* @param opt: Whether it is first calc or not (what?) -* @return 0 -**/ + * Calculates NPC data + * @param nd: NPC object + * @param opt: Whether it is first calc or not (what?) + * @return 0 + */ int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt) { struct status_data *status = &nd->status; @@ -3822,12 +3826,12 @@ int status_calc_npc_(struct npc_data *nd, enum e_status_calc_opt opt) } /** -* Calculates regeneration values -* Applies passive skill regeneration additions -* @param bl: Object to calculate regen for [PC|HOM|MER|ELEM] -* @param status: Object's status -* @param regen: Object's base regeneration data -**/ + * Calculates regeneration values + * Applies passive skill regeneration additions + * @param bl: Object to calculate regen for [PC|HOM|MER|ELEM] + * @param status: Object's status + * @param regen: Object's base regeneration data + */ void status_calc_regen(struct block_list *bl, struct status_data *status, struct regen_data *regen) { struct map_session_data *sd; @@ -3927,11 +3931,11 @@ void status_calc_regen(struct block_list *bl, struct status_data *status, struct } /** -* Calculates SC (Status Changes) regeneration values -* @param bl: Object to calculate regen for [PC|HOM|MER|ELEM] -* @param regen: Object's base regeneration data -* @param sc: Object's status change data -**/ + * Calculates SC (Status Changes) regeneration values + * @param bl: Object to calculate regen for [PC|HOM|MER|ELEM] + * @param regen: Object's base regeneration data + * @param sc: Object's status change data + */ void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, struct status_change *sc) { if (!(bl->type&BL_REGEN) || !regen) @@ -4016,12 +4020,12 @@ void status_calc_regen_rate(struct block_list *bl, struct regen_data *regen, str } /** -* Applies a state to a unit - See [StatusChangeStateTable] -* @param bl: Object to change state on [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change data -* @param flag: Which state to apply to bl -* @param start: (1) start state, (0) remove state -**/ + * Applies a state to a unit - See [StatusChangeStateTable] + * @param bl: Object to change state on [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change data + * @param flag: Which state to apply to bl + * @param start: (1) start state, (0) remove state + */ void status_calc_state( struct block_list *bl, struct status_change *sc, enum scs_flag flag, bool start ) { @@ -4086,11 +4090,11 @@ void status_calc_state( struct block_list *bl, struct status_change *sc, enum sc } /** -* Recalculates parts of an objects status according to specified flags -* See [set_sc] [add_sc] -* @param bl: Object whose status has changed [PC|MOB|HOM|MER|ELEM] -* @param flag: Which status has changed on bl -**/ + * Recalculates parts of an objects status according to specified flags + * See [set_sc] [add_sc] + * @param bl: Object whose status has changed [PC|MOB|HOM|MER|ELEM] + * @param flag: Which status has changed on bl + */ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) { const struct status_data *b_status = status_get_base_status(bl); @@ -4540,13 +4544,13 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) } /** -* Recalculates parts of an objects status according to specified flags -* Also sends updates to the client when necessary -* See [set_sc] [add_sc] -* @param bl: Object whose status has changed [PC|MOB|HOM|MER|ELEM] -* @param flag: Which status has changed on bl -* @param opt: If true, will cause status_calc_* functions to run their base status initialization code -**/ + * Recalculates parts of an objects status according to specified flags + * Also sends updates to the client when necessary + * See [set_sc] [add_sc] + * @param bl: Object whose status has changed [PC|MOB|HOM|MER|ELEM] + * @param flag: Which status has changed on bl + * @param opt: If true, will cause status_calc_* functions to run their base status initialization code + */ void status_calc_bl_(struct block_list* bl, enum scb_flag flag, enum e_status_calc_opt opt) { struct status_data b_status; // Previous battle status @@ -4723,12 +4727,12 @@ void status_calc_bl_(struct block_list* bl, enum scb_flag flag, enum e_status_ca } /** -* Adds strength modifications based on status changes -* @param bl: Object to change str [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param str: Initial str -* @return modified str with cap_value(str,0,USHRT_MAX) -**/ + * Adds strength modifications based on status changes + * @param bl: Object to change str [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param str: Initial str + * @return modified str with cap_value(str,0,USHRT_MAX) + */ static unsigned short status_calc_str(struct block_list *bl, struct status_change *sc, int str) { if(!sc || !sc->count) @@ -4791,12 +4795,12 @@ static unsigned short status_calc_str(struct block_list *bl, struct status_chang } /** -* Adds agility modifications based on status changes -* @param bl: Object to change agi [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param agi: Initial agi -* @return modified agi with cap_value(agi,0,USHRT_MAX) -**/ + * Adds agility modifications based on status changes + * @param bl: Object to change agi [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param agi: Initial agi + * @return modified agi with cap_value(agi,0,USHRT_MAX) + */ static unsigned short status_calc_agi(struct block_list *bl, struct status_change *sc, int agi) { if(!sc || !sc->count) @@ -4855,12 +4859,12 @@ static unsigned short status_calc_agi(struct block_list *bl, struct status_chang } /** -* Adds vitality modifications based on status changes -* @param bl: Object to change vit [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param vit: Initial vit -* @return modified vit with cap_value(vit,0,USHRT_MAX) -**/ + * Adds vitality modifications based on status changes + * @param bl: Object to change vit [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param vit: Initial vit + * @return modified vit with cap_value(vit,0,USHRT_MAX) + */ static unsigned short status_calc_vit(struct block_list *bl, struct status_change *sc, int vit) { if(!sc || !sc->count) @@ -4913,12 +4917,12 @@ static unsigned short status_calc_vit(struct block_list *bl, struct status_chang } /** -* Adds intelligence modifications based on status changes -* @param bl: Object to change int [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param int_: Initial int -* @return modified int with cap_value(int_,0,USHRT_MAX) -**/ + * Adds intelligence modifications based on status changes + * @param bl: Object to change int [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param int_: Initial int + * @return modified int with cap_value(int_,0,USHRT_MAX) + */ static unsigned short status_calc_int(struct block_list *bl, struct status_change *sc, int int_) { if(!sc || !sc->count) @@ -4982,12 +4986,12 @@ static unsigned short status_calc_int(struct block_list *bl, struct status_chang } /** -* Adds dexterity modifications based on status changes -* @param bl: Object to change dex [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param dex: Initial dex -* @return modified dex with cap_value(dex,0,USHRT_MAX) -**/ + * Adds dexterity modifications based on status changes + * @param bl: Object to change dex [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param dex: Initial dex + * @return modified dex with cap_value(dex,0,USHRT_MAX) + */ static unsigned short status_calc_dex(struct block_list *bl, struct status_change *sc, int dex) { if(!sc || !sc->count) @@ -5049,12 +5053,12 @@ static unsigned short status_calc_dex(struct block_list *bl, struct status_chang } /** -* Adds luck modifications based on status changes -* @param bl: Object to change luk [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param luk: Initial luk -* @return modified luk with cap_value(luk,0,USHRT_MAX) -**/ + * Adds luck modifications based on status changes + * @param bl: Object to change luk [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param luk: Initial luk + * @return modified luk with cap_value(luk,0,USHRT_MAX) + */ static unsigned short status_calc_luk(struct block_list *bl, struct status_change *sc, int luk) { if(!sc || !sc->count) @@ -5106,12 +5110,12 @@ static unsigned short status_calc_luk(struct block_list *bl, struct status_chang } /** -* Adds base attack modifications based on status changes -* @param bl: Object to change batk [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param batk: Initial batk -* @return modified batk with cap_value(batk,0,USHRT_MAX) -**/ + * Adds base attack modifications based on status changes + * @param bl: Object to change batk [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param batk: Initial batk + * @return modified batk with cap_value(batk,0,USHRT_MAX) + */ static unsigned short status_calc_batk(struct block_list *bl, struct status_change *sc, int batk) { if(!sc || !sc->count) @@ -5183,12 +5187,12 @@ static unsigned short status_calc_batk(struct block_list *bl, struct status_chan } /** -* Adds weapon attack modifications based on status changes -* @param bl: Object to change watk [PC] -* @param sc: Object's status change information -* @param watk: Initial watk -* @return modified watk with cap_value(watk,0,USHRT_MAX) -**/ + * Adds weapon attack modifications based on status changes + * @param bl: Object to change watk [PC] + * @param sc: Object's status change information + * @param watk: Initial watk + * @return modified watk with cap_value(watk,0,USHRT_MAX) + */ static unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc, int watk) { if(!sc || !sc->count) @@ -5276,12 +5280,12 @@ static unsigned short status_calc_watk(struct block_list *bl, struct status_chan #ifdef RENEWAL /** -* Adds equip magic attack modifications based on status changes [RENEWAL] -* @param bl: Object to change matk [PC] -* @param sc: Object's status change information -* @param matk: Initial matk -* @return modified matk with cap_value(matk,0,USHRT_MAX) -**/ + * Adds equip magic attack modifications based on status changes [RENEWAL] + * @param bl: Object to change matk [PC] + * @param sc: Object's status change information + * @param matk: Initial matk + * @return modified matk with cap_value(matk,0,USHRT_MAX) + */ static unsigned short status_calc_ematk(struct block_list *bl, struct status_change *sc, int matk) { if (!sc || !sc->count) @@ -5323,12 +5327,12 @@ static unsigned short status_calc_ematk(struct block_list *bl, struct status_cha #endif /** -* Adds magic attack modifications based on status changes -* @param bl: Object to change matk [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param matk: Initial matk -* @return modified matk with cap_value(matk,0,USHRT_MAX) -**/ + * Adds magic attack modifications based on status changes + * @param bl: Object to change matk [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param matk: Initial matk + * @return modified matk with cap_value(matk,0,USHRT_MAX) + */ static unsigned short status_calc_matk(struct block_list *bl, struct status_change *sc, int matk) { if(!sc || !sc->count) @@ -5379,12 +5383,12 @@ static unsigned short status_calc_matk(struct block_list *bl, struct status_chan } /** -* Adds critical modifications based on status changes -* @param bl: Object to change critical [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param critical: Initial critical -* @return modified critical with cap_value(critical,10,USHRT_MAX) -**/ + * Adds critical modifications based on status changes + * @param bl: Object to change critical [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param critical: Initial critical + * @return modified critical with cap_value(critical,10,USHRT_MAX) + */ static signed short status_calc_critical(struct block_list *bl, struct status_change *sc, int critical) { if(!sc || !sc->count) @@ -5417,12 +5421,12 @@ static signed short status_calc_critical(struct block_list *bl, struct status_ch } /** -* Adds hit modifications based on status changes -* @param bl: Object to change hit [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param hit: Initial hit -* @return modified hit with cap_value(hit,1,USHRT_MAX) -**/ + * Adds hit modifications based on status changes + * @param bl: Object to change hit [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param hit: Initial hit + * @return modified hit with cap_value(hit,1,USHRT_MAX) + */ static signed short status_calc_hit(struct block_list *bl, struct status_change *sc, int hit) { if(!sc || !sc->count) @@ -5468,12 +5472,12 @@ static signed short status_calc_hit(struct block_list *bl, struct status_change } /** -* Adds flee modifications based on status changes -* @param bl: Object to change flee [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param flee: Initial flee -* @return modified flee with cap_value(flee,1,USHRT_MAX) -**/ + * Adds flee modifications based on status changes + * @param bl: Object to change flee [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param flee: Initial flee + * @return modified flee with cap_value(flee,1,USHRT_MAX) + */ static signed short status_calc_flee(struct block_list *bl, struct status_change *sc, int flee) { if( bl->type == BL_PC ) { @@ -5570,12 +5574,12 @@ static signed short status_calc_flee(struct block_list *bl, struct status_change } /** -* Adds perfect flee modifications based on status changes -* @param bl: Object to change flee2 [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param flee2: Initial flee2 -* @return modified flee2 with cap_value(flee2,10,USHRT_MAX) -**/ + * Adds perfect flee modifications based on status changes + * @param bl: Object to change flee2 [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param flee2: Initial flee2 + * @return modified flee2 with cap_value(flee2,10,USHRT_MAX) + */ static signed short status_calc_flee2(struct block_list *bl, struct status_change *sc, int flee2) { if(!sc || !sc->count) @@ -5592,12 +5596,12 @@ static signed short status_calc_flee2(struct block_list *bl, struct status_chang } /** -* Adds defense (left-side) modifications based on status changes -* @param bl: Object to change def [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param def: Initial def -* @return modified def with cap_value(def,DEFTYPE_MIN,DEFTYPE_MAX) -**/ + * Adds defense (left-side) modifications based on status changes + * @param bl: Object to change def [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param def: Initial def + * @return modified def with cap_value(def,DEFTYPE_MIN,DEFTYPE_MAX) + */ static defType status_calc_def(struct block_list *bl, struct status_change *sc, int def) { if(!sc || !sc->count) @@ -5687,12 +5691,12 @@ static defType status_calc_def(struct block_list *bl, struct status_change *sc, } /** -* Adds defense (right-side) modifications based on status changes -* @param bl: Object to change def2 [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param def2: Initial def2 -* @return modified def2 with cap_value(def2,SHRT_MIN,SHRT_MAX) -**/ + * Adds defense (right-side) modifications based on status changes + * @param bl: Object to change def2 [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param def2: Initial def2 + * @return modified def2 with cap_value(def2,SHRT_MIN,SHRT_MAX) + */ static signed short status_calc_def2(struct block_list *bl, struct status_change *sc, int def2) { if(!sc || !sc->count) @@ -5756,12 +5760,12 @@ static signed short status_calc_def2(struct block_list *bl, struct status_change } /** -* Adds magic defense (left-side) modifications based on status changes -* @param bl: Object to change mdef [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param mdef: Initial mdef -* @return modified mdef with cap_value(mdef,DEFTYPE_MIN,DEFTYPE_MAX) -**/ + * Adds magic defense (left-side) modifications based on status changes + * @param bl: Object to change mdef [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param mdef: Initial mdef + * @return modified mdef with cap_value(mdef,DEFTYPE_MIN,DEFTYPE_MAX) + */ static defType status_calc_mdef(struct block_list *bl, struct status_change *sc, int mdef) { if(!sc || !sc->count) @@ -5815,12 +5819,12 @@ static defType status_calc_mdef(struct block_list *bl, struct status_change *sc, } /** -* Adds magic defense (right-side) modifications based on status changes -* @param bl: Object to change mdef2 [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param mdef2: Initial mdef2 -* @return modified mdef2 with cap_value(mdef2,SHRT_MIN,SHRT_MAX) -**/ + * Adds magic defense (right-side) modifications based on status changes + * @param bl: Object to change mdef2 [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param mdef2: Initial mdef2 + * @return modified mdef2 with cap_value(mdef2,SHRT_MIN,SHRT_MAX) + */ static signed short status_calc_mdef2(struct block_list *bl, struct status_change *sc, int mdef2) { if(!sc || !sc->count) @@ -5854,12 +5858,12 @@ static signed short status_calc_mdef2(struct block_list *bl, struct status_chang } /** -* Adds speed modifications based on status changes -* @param bl: Object to change speed [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param speed: Initial speed -* @return modified speed with cap_value(speed,10,USHRT_MAX) -**/ + * Adds speed modifications based on status changes + * @param bl: Object to change speed [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param speed: Initial speed + * @return modified speed with cap_value(speed,10,USHRT_MAX) + */ static unsigned short status_calc_speed(struct block_list *bl, struct status_change *sc, int speed) { TBL_PC* sd = BL_CAST(BL_PC, bl); @@ -6033,14 +6037,14 @@ static unsigned short status_calc_speed(struct block_list *bl, struct status_cha #ifdef RENEWAL_ASPD /** -* Renewal attack speed modifiers based on status changes -* This function only affects RENEWAL players and comes after base calculation -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param flag: flag&1 - fixed value [malufett] -* flag&2 - percentage value -* @return modified aspd -**/ + * Renewal attack speed modifiers based on status changes + * This function only affects RENEWAL players and comes after base calculation + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param flag: flag&1 - fixed value [malufett] + * flag&2 - percentage value + * @return modified aspd + */ static short status_calc_aspd(struct block_list *bl, struct status_change *sc, short flag) { int i, pots = 0, skills1 = 0, skills2 = 0; @@ -6166,14 +6170,14 @@ static short status_calc_aspd(struct block_list *bl, struct status_change *sc, s #endif /** -* Modifies ASPD by a number, rather than a percentage (10 = 1 ASPD) -* A subtraction reduces the delay, meaning an increase in ASPD -* This comes after the percentage changes and is based on status changes -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param aspd: Object's current ASPD -* @return modified aspd -**/ + * Modifies ASPD by a number, rather than a percentage (10 = 1 ASPD) + * A subtraction reduces the delay, meaning an increase in ASPD + * This comes after the percentage changes and is based on status changes + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param aspd: Object's current ASPD + * @return modified aspd + */ static short status_calc_fix_aspd(struct block_list *bl, struct status_change *sc, int aspd) { if (!sc || !sc->count) @@ -6193,14 +6197,14 @@ static short status_calc_fix_aspd(struct block_list *bl, struct status_change *s } /** -* Calculates an object's ASPD modifier based on status changes (alters amotion value) -* Note: The scale of aspd_rate is 1000 = 100% -* Note2: This only affects Homunculus, Mercenaries, and Pre-renewal Players -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param aspd_rate: Object's current ASPD -* @return modified aspd_rate -**/ + * Calculates an object's ASPD modifier based on status changes (alters amotion value) + * Note: The scale of aspd_rate is 1000 = 100% + * Note2: This only affects Homunculus, Mercenaries, and Pre-renewal Players + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param aspd_rate: Object's current ASPD + * @return modified aspd_rate + */ static short status_calc_aspd_rate(struct block_list *bl, struct status_change *sc, int aspd_rate) { int i; @@ -6336,13 +6340,13 @@ static short status_calc_aspd_rate(struct block_list *bl, struct status_change * } /** -* Modifies the damage delay time based on status changes -* The lower your delay, the quicker you can act after taking damage -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param dmotion: Object's current damage delay -* @return modified delay rate -**/ + * Modifies the damage delay time based on status changes + * The lower your delay, the quicker you can act after taking damage + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param dmotion: Object's current damage delay + * @return modified delay rate + */ static unsigned short status_calc_dmotion(struct block_list *bl, struct status_change *sc, int dmotion) { if( !sc || !sc->count || map_flag_gvg(bl->m) || map[bl->m].flag.battleground ) @@ -6358,12 +6362,12 @@ static unsigned short status_calc_dmotion(struct block_list *bl, struct status_c } /** -* Calculates a max HP based on status changes -* Values can either be percentages or fixed, based on how equations are formulated -* @param bl: Object's block_list data -* @param maxhp: Object's current max HP -* @return modified maxhp -**/ + * Calculates a max HP based on status changes + * Values can either be percentages or fixed, based on how equations are formulated + * @param bl: Object's block_list data + * @param maxhp: Object's current max HP + * @return modified maxhp + */ static unsigned int status_calc_maxhp(struct block_list *bl, uint64 maxhp) { int rate = 100; @@ -6377,12 +6381,12 @@ static unsigned int status_calc_maxhp(struct block_list *bl, uint64 maxhp) } /** -* Calculates a max SP based on status changes -* Values can either be percentages or fixed, bas ed on how equations are formulated -* @param bl: Object's block_list data -* @param maxsp: Object's current max SP -* @return modified maxsp -**/ + * Calculates a max SP based on status changes + * Values can either be percentages or fixed, bas ed on how equations are formulated + * @param bl: Object's block_list data + * @param maxsp: Object's current max SP + * @return modified maxsp + */ static unsigned int status_calc_maxsp(struct block_list *bl, uint64 maxsp) { int rate = 100; @@ -6396,12 +6400,12 @@ static unsigned int status_calc_maxsp(struct block_list *bl, uint64 maxsp) } /** -* Changes a player's element based on status changes -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param element: Object's current element -* @return new element -**/ + * Changes a player's element based on status changes + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param element: Object's current element + * @return new element + */ static unsigned char status_calc_element(struct block_list *bl, struct status_change *sc, int element) { if(!sc || !sc->count) @@ -6424,12 +6428,12 @@ static unsigned char status_calc_element(struct block_list *bl, struct status_ch } /** -* Changes a player's element level based on status changes -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param lv: Object's current element level -* @return new element level -**/ + * Changes a player's element level based on status changes + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param lv: Object's current element level + * @return new element level + */ static unsigned char status_calc_element_lv(struct block_list *bl, struct status_change *sc, int lv) { if(!sc || !sc->count) @@ -6454,12 +6458,12 @@ static unsigned char status_calc_element_lv(struct block_list *bl, struct status } /** -* Changes a player's attack element based on status changes -* @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] -* @param sc: Object's status change information -* @param element: Object's current attack element -* @return new attack element -**/ + * Changes a player's attack element based on status changes + * @param bl: Object to change aspd [PC|MOB|HOM|MER|ELEM] + * @param sc: Object's status change information + * @param element: Object's current attack element + * @return new attack element + */ unsigned char status_calc_attack_element(struct block_list *bl, struct status_change *sc, int element) { if(!sc || !sc->count) @@ -6494,12 +6498,12 @@ unsigned char status_calc_attack_element(struct block_list *bl, struct status_ch } /** -* Changes the mode of an object -* @param bl: Object whose mode to change [PC|MOB|PET|HOM|NPC] -* @param sc: Object's status change data -* @param mode: Original mode -* @return mode with cap_value(mode,0,USHRT_MAX) -**/ + * Changes the mode of an object + * @param bl: Object whose mode to change [PC|MOB|PET|HOM|NPC] + * @param sc: Object's status change data + * @param mode: Original mode + * @return mode with cap_value(mode,0,USHRT_MAX) + */ static unsigned short status_calc_mode(struct block_list *bl, struct status_change *sc, int mode) { if(!sc || !sc->count) @@ -6516,10 +6520,10 @@ static unsigned short status_calc_mode(struct block_list *bl, struct status_chan } /** -* Gets the name of the given bl -* @param bl: Object whose name to get [PC|MOB|PET|HOM|NPC] -* @return name or "Unknown" if any other bl->type than noted above -**/ + * Gets the name of the given bl + * @param bl: Object whose name to get [PC|MOB|PET|HOM|NPC] + * @return name or "Unknown" if any other bl->type than noted above + */ const char* status_get_name(struct block_list *bl) { nullpo_ret(bl); @@ -6534,10 +6538,10 @@ const char* status_get_name(struct block_list *bl) } /** -* Gets the class/sprite id of the given bl -* @param bl: Object whose class to get [PC|MOB|PET|HOM|MER|NPC|ELEM] -* @return class or 0 if any other bl->type than noted above -**/ + * Gets the class/sprite id of the given bl + * @param bl: Object whose class to get [PC|MOB|PET|HOM|MER|NPC|ELEM] + * @return class or 0 if any other bl->type than noted above + */ int status_get_class(struct block_list *bl) { nullpo_ret(bl); @@ -6554,10 +6558,10 @@ int status_get_class(struct block_list *bl) } /** -* Gets the base level of the given bl -* @param bl: Object whose base level to get [PC|MOB|PET|HOM|MER|NPC|ELEM] -* @return base level or 1 if any other bl->type than noted above -**/ + * Gets the base level of the given bl + * @param bl: Object whose base level to get [PC|MOB|PET|HOM|MER|NPC|ELEM] + * @return base level or 1 if any other bl->type than noted above + */ int status_get_lv(struct block_list *bl) { nullpo_ret(bl); @@ -6574,10 +6578,10 @@ int status_get_lv(struct block_list *bl) } /** -* Gets the regeneration info of the given bl -* @param bl: Object whose regen info to get [PC|HOM|MER|ELEM] -* @return regen data or NULL if any other bl->type than noted above -**/ + * Gets the regeneration info of the given bl + * @param bl: Object whose regen info to get [PC|HOM|MER|ELEM] + * @return regen data or NULL if any other bl->type than noted above + */ struct regen_data *status_get_regen_data(struct block_list *bl) { nullpo_retr(NULL, bl); @@ -6592,10 +6596,10 @@ struct regen_data *status_get_regen_data(struct block_list *bl) } /** -* Gets the status data of the given bl -* @param bl: Object whose status to get [PC|MOB|PET|HOM|MER|ELEM|NPC] -* @return status or "dummy_status" if any other bl->type than noted above -**/ + * Gets the status data of the given bl + * @param bl: Object whose status to get [PC|MOB|PET|HOM|MER|ELEM|NPC] + * @return status or "dummy_status" if any other bl->type than noted above + */ struct status_data *status_get_status_data(struct block_list *bl) { nullpo_retr(&dummy_status, bl); @@ -6614,10 +6618,10 @@ struct status_data *status_get_status_data(struct block_list *bl) } /** -* Gets the base status data of the given bl -* @param bl: Object whose status to get [PC|MOB|PET|HOM|MER|ELEM|NPC] -* @return base_status or NULL if any other bl->type than noted above -**/ + * Gets the base status data of the given bl + * @param bl: Object whose status to get [PC|MOB|PET|HOM|MER|ELEM|NPC] + * @return base_status or NULL if any other bl->type than noted above + */ struct status_data *status_get_base_status(struct block_list *bl) { nullpo_retr(NULL, bl); @@ -6635,10 +6639,10 @@ struct status_data *status_get_base_status(struct block_list *bl) } /** -* Gets the defense of the given bl -* @param bl: Object whose defense to get [PC|MOB|HOM|MER|ELEM] -* @return defense with cap_value(def, DEFTYPE_MIN, DEFTYPE_MAX) -**/ + * Gets the defense of the given bl + * @param bl: Object whose defense to get [PC|MOB|HOM|MER|ELEM] + * @return defense with cap_value(def, DEFTYPE_MIN, DEFTYPE_MAX) + */ defType status_get_def(struct block_list *bl) { struct unit_data *ud; @@ -6652,10 +6656,10 @@ defType status_get_def(struct block_list *bl) } /** -* Gets the walking speed of the given bl -* @param bl: Object whose speed to get [PC|MOB|PET|HOM|MER|ELEM|NPC] -* @return speed -**/ + * Gets the walking speed of the given bl + * @param bl: Object whose speed to get [PC|MOB|PET|HOM|MER|ELEM|NPC] + * @return speed + */ unsigned short status_get_speed(struct block_list *bl) { if(bl->type==BL_NPC)// Only BL with speed data but no status_data [Skotlex] @@ -6664,10 +6668,10 @@ unsigned short status_get_speed(struct block_list *bl) } /** -* Gets the party ID of the given bl -* @param bl: Object whose party ID to get [PC|MOB|PET|HOM|MER|SKILL|ELEM] -* @return party ID -**/ + * Gets the party ID of the given bl + * @param bl: Object whose party ID to get [PC|MOB|PET|HOM|MER|SKILL|ELEM] + * @return party ID + */ int status_get_party_id(struct block_list *bl) { nullpo_ret(bl); @@ -6707,10 +6711,10 @@ int status_get_party_id(struct block_list *bl) } /** -* Gets the guild ID of the given bl -* @param bl: Object whose guild ID to get [PC|MOB|PET|HOM|MER|SKILL|ELEM|NPC] -* @return guild ID -**/ + * Gets the guild ID of the given bl + * @param bl: Object whose guild ID to get [PC|MOB|PET|HOM|MER|SKILL|ELEM|NPC] + * @return guild ID + */ int status_get_guild_id(struct block_list *bl) { nullpo_ret(bl); @@ -6754,10 +6758,10 @@ int status_get_guild_id(struct block_list *bl) } /** -* Gets the guild emblem ID of the given bl -* @param bl: Object whose emblem ID to get [PC|MOB|PET|HOM|MER|SKILL|ELEM|NPC] -* @return guild emblem ID -**/ + * Gets the guild emblem ID of the given bl + * @param bl: Object whose emblem ID to get [PC|MOB|PET|HOM|MER|SKILL|ELEM|NPC] + * @return guild emblem ID + */ int status_get_emblem_id(struct block_list *bl) { nullpo_ret(bl); @@ -6802,10 +6806,10 @@ int status_get_emblem_id(struct block_list *bl) } /** -* Gets the race of a mob or pet -* @param bl: Object whose race to get [MOB|PET] -* @return race -**/ + * Gets the race of a mob or pet + * @param bl: Object whose race to get [MOB|PET] + * @return race + */ int status_get_race2(struct block_list *bl) { nullpo_ret(bl); @@ -6817,10 +6821,10 @@ int status_get_race2(struct block_list *bl) } /** -* Checks if an object is dead -* @param bl: Object to check [PC|MOB|HOM|MER|ELEM] -* @return 1: Is dead or 0: Is alive -**/ + * Checks if an object is dead + * @param bl: Object to check [PC|MOB|HOM|MER|ELEM] + * @return 1: Is dead or 0: Is alive + */ int status_isdead(struct block_list *bl) { nullpo_ret(bl); @@ -6828,10 +6832,10 @@ int status_isdead(struct block_list *bl) } /** -* Checks if an object is immune to magic -* @param bl: Object to check [PC|MOB|HOM|MER|ELEM] -* @return value of magic damage to be blocked -**/ + * Checks if an object is immune to magic + * @param bl: Object to check [PC|MOB|HOM|MER|ELEM] + * @return value of magic damage to be blocked + */ int status_isimmune(struct block_list *bl) { struct status_change *sc =status_get_sc(bl); @@ -6845,10 +6849,10 @@ int status_isimmune(struct block_list *bl) } /** -* Get view data of an object -* @param bl: Object whose view data to get [PC|MOB|PET|HOM|MER|ELEM|NPC] -* @return view data structure bl->vd -**/ + * Get view data of an object + * @param bl: Object whose view data to get [PC|MOB|PET|HOM|MER|ELEM|NPC] + * @return view data structure bl->vd + */ struct view_data* status_get_viewdata(struct block_list *bl) { nullpo_retr(NULL, bl); @@ -6865,12 +6869,12 @@ struct view_data* status_get_viewdata(struct block_list *bl) } /** -* Set view data of an object -* This function deals with class, mount, and item views -* SC views are set in clif_getareachar_unit() -* @param bl: Object whose view data to set [PC|MOB|PET|HOM|MER|ELEM|NPC] -* @param class_: class of the object -**/ + * Set view data of an object + * This function deals with class, mount, and item views + * SC views are set in clif_getareachar_unit() + * @param bl: Object whose view data to set [PC|MOB|PET|HOM|MER|ELEM|NPC] + * @param class_: class of the object + */ void status_set_viewdata(struct block_list *bl, int class_) { struct view_data* vd; @@ -7009,10 +7013,10 @@ void status_set_viewdata(struct block_list *bl, int class_) } /** -* Get status change data of an object -* @param bl: Object whose sc data to get [PC|MOB|HOM|MER|ELEM|NPC] -* @return status change data structure bl->sc -**/ + * Get status change data of an object + * @param bl: Object whose sc data to get [PC|MOB|HOM|MER|ELEM|NPC] + * @return status change data structure bl->sc + */ struct status_change *status_get_sc(struct block_list *bl) { if( bl ) @@ -7028,9 +7032,9 @@ struct status_change *status_get_sc(struct block_list *bl) } /** -* Initiate (memset) the status change data of an object -* @param bl: Object whose sc data to memset [PC|MOB|HOM|MER|ELEM|NPC] -**/ + * Initiate (memset) the status change data of an object + * @param bl: Object whose sc data to memset [PC|MOB|HOM|MER|ELEM|NPC] + */ void status_change_init(struct block_list *bl) { struct status_change *sc = status_get_sc(bl); @@ -7039,16 +7043,16 @@ void status_change_init(struct block_list *bl) } /** -* Applies SC defense to a given status change -* This function also determines whether or not the status change will be applied -* @param src: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] -* @param bl: Target of the status change -* @param type: Status change (SC_*) -* @param rate: Initial percentage rate of affecting bl -* @param tick: Initial duration that the status change affects bl -* @param flag: Value which determines what parts to calculate. See e_status_change_start_flags -* @return adjusted duration based on flag values -**/ + * Applies SC defense to a given status change + * This function also determines whether or not the status change will be applied + * @param src: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] + * @param bl: Target of the status change + * @param type: Status change (SC_*) + * @param rate: Initial percentage rate of affecting bl + * @param tick: Initial duration that the status change affects bl + * @param flag: Value which determines what parts to calculate. See e_status_change_start_flags + * @return adjusted duration based on flag values + */ int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_type type, int rate, int tick, unsigned char flag) { /// Resistance rate: 10000 = 100% @@ -7381,12 +7385,12 @@ int status_get_sc_def(struct block_list *src, struct block_list *bl, enum sc_typ } /** -* Applies SC effect to the player -* @param sd: Source to apply effect [PC] -* @param type: Status change (SC_*) -* @param dval1~3: Depends on type of status change -* Author: Ind -**/ + * Applies SC effect to the player + * @param sd: Source to apply effect [PC] + * @param type: Status change (SC_*) + * @param dval1~3: Depends on type of status change + * Author: Ind + */ void status_display_add(struct map_session_data *sd, enum sc_type type, int dval1, int dval2, int dval3) { struct sc_display_entry *entry; int i; @@ -7415,11 +7419,11 @@ void status_display_add(struct map_session_data *sd, enum sc_type type, int dval } /** -* Removes SC effect of the player -* @param sd: Source to remove effect [PC] -* @param type: Status change (SC_*) -* Author: Ind -**/ + * Removes SC effect of the player + * @param sd: Source to remove effect [PC] + * @param type: Status change (SC_*) + * Author: Ind + */ void status_display_remove(struct map_session_data *sd, enum sc_type type) { int i; @@ -7453,17 +7457,17 @@ void status_display_remove(struct map_session_data *sd, enum sc_type type) { } /** -* Applies SC defense to a given status change -* This function also determines whether or not the status change will be applied -* @param src: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] -* @param bl: Target of the status change (See: enum sc_type) -* @param type: Status change (SC_*) -* @param rate: Initial percentage rate of affecting bl (0~10000) -* @param val1~4: Depends on type of status change -* @param tick: Initial duration that the status change affects bl -* @param flag: Value which determines what parts to calculate. See e_status_change_start_flags -* @return adjusted duration based on flag values -**/ + * Applies SC defense to a given status change + * This function also determines whether or not the status change will be applied + * @param src: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] + * @param bl: Target of the status change (See: enum sc_type) + * @param type: Status change (SC_*) + * @param rate: Initial percentage rate of affecting bl (0~10000) + * @param val1~4: Depends on type of status change + * @param tick: Initial duration that the status change affects bl + * @param flag: Value which determines what parts to calculate. See e_status_change_start_flags + * @return adjusted duration based on flag values + */ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_type type,int rate,int val1,int val2,int val3,int val4,int tick,unsigned char flag) { struct map_session_data *sd = NULL; struct status_change* sc; @@ -10286,7 +10290,7 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty status_calc_pc(sd, SCO_NONE); } - // 1st thing to execute when loading status + // 1st thing to execute when loading status switch (type) { case SC_FULL_THROTTLE: status_percent_heal(bl,100,0); @@ -10361,16 +10365,16 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty } /** -* End all statuses except those listed -* TODO: May be useful for dispel instead resetting a list there -* @param src: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] -* @param type: Changes behaviour of the function -* 0: PC killed -> Place here statuses that do not dispel on death. -* 1: If for some reason status_change_end decides to still keep the status when quitting. -* 2: Do clif_changeoption() -* 3: Do not remove some permanent/time-independent effects -* @return 1: Success 0: Fail -**/ + * End all statuses except those listed + * TODO: May be useful for dispel instead resetting a list there + * @param src: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] + * @param type: Changes behaviour of the function + * 0: PC killed -> Place here statuses that do not dispel on death. + * 1: If for some reason status_change_end decides to still keep the status when quitting. + * 2: Do clif_changeoption() + * 3: Do not remove some permanent/time-independent effects + * @return 1: Success 0: Fail + */ int status_change_clear(struct block_list* bl, int type) { struct status_change* sc; @@ -10497,14 +10501,14 @@ int status_change_clear(struct block_list* bl, int type) } /** -* End a specific status after checking -* @param bl: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] -* @param type: Status change (SC_*) -* @param tid: Timer -* @param file: Used for dancing save -* @param line: Used for dancing save -* @return 1: Success 0: Fail -**/ + * End a specific status after checking + * @param bl: Source of the status change [PC|MOB|HOM|MER|ELEM|NPC] + * @param type: Status change (SC_*) + * @param tid: Timer + * @param file: Used for dancing save + * @param line: Used for dancing save + * @return 1: Success 0: Fail + */ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const char* file, int line) { struct map_session_data *sd; @@ -11233,13 +11237,13 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const } /** -* Special timer and heal for Kaahi status -* @param tid: Timer ID -* @param tick: How long before next call -* @param id: ID of character -* @param data: Information passed through the timer call -* @return 1: Success 0: Fail -**/ + * Special timer and heal for Kaahi status + * @param tid: Timer ID + * @param tick: How long before next call + * @param id: ID of character + * @param data: Information passed through the timer call + * @return 1: Success 0: Fail + */ int kaahi_heal_timer(int tid, unsigned int tick, int id, intptr_t data) { struct block_list *bl; @@ -11275,14 +11279,14 @@ int kaahi_heal_timer(int tid, unsigned int tick, int id, intptr_t data) } /** -* Resets timers for statuses -* Used with reoccuring status effects, such as dropping SP every 5 seconds -* @param tid: Timer ID -* @param tick: How long before next call -* @param id: ID of character -* @param data: Information passed through the timer call -* @return 1: Success 0: Fail -**/ + * Resets timers for statuses + * Used with reoccurring status effects, such as dropping SP every 5 seconds + * @param tid: Timer ID + * @param tick: How long before next call + * @param id: ID of character + * @param data: Information passed through the timer call + * @return 1: Success 0: Fail + */ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data) { enum sc_type type = (sc_type)data; @@ -11477,7 +11481,7 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data) if( sd && --(sce->val4) >= 0 ) { struct mob_data *boss_md = map_id2boss(sce->val1); if( boss_md && sd->bl.m == boss_md->bl.m ) { - clif_bossmapinfo(sd->fd, boss_md, 1); // Update X - Y on minimap + clif_bossmapinfo(sd->fd, boss_md, 1); // Update X, Y on minimap if (boss_md->bl.prev != NULL) { sc_timer_next(5000 + tick, status_change_timer, bl->id, data); return 0; @@ -12148,10 +12152,10 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data) } /** -* For each iteration of repetitive status -* @param bl: Object [PC|MOB|HOM|MER|ELEM] -* @param ap: va_list arguments (src, sce, type, tick) -**/ + * For each iteration of repetitive status + * @param bl: Object [PC|MOB|HOM|MER|ELEM] + * @param ap: va_list arguments (src, sce, type, tick) + */ int status_change_timer_sub(struct block_list* bl, va_list ap) { struct status_change* tsc; @@ -12223,13 +12227,13 @@ int status_change_timer_sub(struct block_list* bl, va_list ap) } /** -* Clears buffs/debuffs on an object -* @param bl: Object to clear [PC|MOB|HOM|MER|ELEM] -* @param type: Type to remove -* &1: Clear Buffs -* $2: Clear Debuffs -* &4: Specific debuffs with a refresh -**/ + * Clears buffs/debuffs on an object + * @param bl: Object to clear [PC|MOB|HOM|MER|ELEM] + * @param type: Type to remove + * &1: Clear Buffs + * $2: Clear Debuffs + * &4: Specific debuffs with a refresh + */ void status_change_clear_buffs (struct block_list* bl, int type) { int i; @@ -12400,11 +12404,11 @@ void status_change_clear_buffs (struct block_list* bl, int type) } /** -* Infect a user with status effects (SC_DEADLYINFECT) -* @param src: Object initiating change on bl [PC|MOB|HOM|MER|ELEM] -* @param bl: Object to change -* @return 1: Success 0: Fail -**/ + * Infect a user with status effects (SC_DEADLYINFECT) + * @param src: Object initiating change on bl [PC|MOB|HOM|MER|ELEM] + * @param bl: Object to change + * @return 1: Success 0: Fail + */ int status_change_spread( struct block_list *src, struct block_list *bl ) { int i, flag = 0; @@ -12501,12 +12505,12 @@ int status_change_spread( struct block_list *src, struct block_list *bl ) } /** -* Applying natural heal bonuses (sit, skill, homun, etc...) -* TODO: the va_list doesn't seem to be used, safe to remove? -* @param bl: Object applying bonuses to [PC|HOM|MER|ELEM] -* @param args: va_list arguments -* @return which regeneration bonuses have been applied (flag) -**/ + * Applying natural heal bonuses (sit, skill, homun, etc...) + * TODO: the va_list doesn't seem to be used, safe to remove? + * @param bl: Object applying bonuses to [PC|HOM|MER|ELEM] + * @param args: va_list arguments + * @return which regeneration bonuses have been applied (flag) + */ static unsigned int natural_heal_prev_tick,natural_heal_diff_tick; static int status_natural_heal(struct block_list* bl, va_list args) { @@ -12686,13 +12690,13 @@ static int status_natural_heal(struct block_list* bl, va_list args) } /** -* Natural heal main timer -* @param tid: Timer ID -* @param tick: Current tick (time) -* @param id: Object ID to heal -* @param data: data pushed through timer function -* @return 0 -**/ + * Natural heal main timer + * @param tid: Timer ID + * @param tick: Current tick (time) + * @param id: Object ID to heal + * @param data: data pushed through timer function + * @return 0 + */ static int status_natural_heal_timer(int tid, unsigned int tick, int id, intptr_t data) { natural_heal_diff_tick = DIFF_TICK(tick,natural_heal_prev_tick); @@ -12702,11 +12706,11 @@ static int status_natural_heal_timer(int tid, unsigned int tick, int id, intptr_ } /** -* Get the chance to upgrade a piece of equipment -* @param wlv: The weapon type of the item to refine (see see enum refine_type) -* @param refine: The target's refine level -* @return The chance to refine the item, in percent (0~100) -**/ + * Get the chance to upgrade a piece of equipment + * @param wlv: The weapon type of the item to refine (see see enum refine_type) + * @param refine: The target's refine level + * @return The chance to refine the item, in percent (0~100) + */ int status_get_refine_chance(enum refine_type wlv, int refine) { @@ -12717,12 +12721,12 @@ int status_get_refine_chance(enum refine_type wlv, int refine) } /** -* Read sizefix database for attack calculations -* @param fields: Fields passed from sv_readdb -* @param columns: Columns passed from sv_readdb function call -* @param current: Current row being read into atkmods array -* @return True -**/ + * Read sizefix database for attack calculations + * @param fields: Fields passed from sv_readdb + * @param columns: Columns passed from sv_readdb function call + * @param current: Current row being read into atkmods array + * @return True + */ static bool status_readdb_sizefix(char* fields[], int columns, int current) { unsigned int i; @@ -12734,12 +12738,12 @@ static bool status_readdb_sizefix(char* fields[], int columns, int current) } /** -* Read refine database for refining calculations -* @param fields: Fields passed from sv_readdb -* @param columns: Columns passed from sv_readdb function call -* @param current: Current row being read into refine_info array -* @return True -**/ + * Read refine database for refining calculations + * @param fields: Fields passed from sv_readdb + * @param columns: Columns passed from sv_readdb function call + * @param current: Current row being read into refine_info array + * @return True + */ static bool status_readdb_refine(char* fields[], int columns, int current) { int i, bonus_per_level, random_bonus, random_bonus_start_level; @@ -12774,10 +12778,10 @@ static bool status_readdb_refine(char* fields[], int columns, int current) } /** -* Read attribute fix database for attack calculations -* Function stores information in the attr_fix_table -* @return True -**/ + * Read attribute fix database for attack calculations + * Function stores information in the attr_fix_table + * @return True + */ static bool status_readdb_attrfix(const char *basedir,bool silent) { FILE *fp; @@ -12829,15 +12833,15 @@ static bool status_readdb_attrfix(const char *basedir,bool silent) } /** -* Sets defaults in tables and starts read db functions -* sv_readdb reads the file, outputting the information line-by-line to -* previous functions above, separating information by delimiter -* DBs being read: -* attr_fix.txt: Attribute adjustment table for attacks -* size_fix.txt: Size adjustment table for weapons -* refine_db.txt: Refining data table -* @return 0 -**/ + * Sets defaults in tables and starts read db functions + * sv_readdb reads the file, outputting the information line-by-line to + * previous functions above, separating information by delimiter + * DBs being read: + * attr_fix.txt: Attribute adjustment table for attacks + * size_fix.txt: Size adjustment table for weapons + * refine_db.txt: Refining data table + * @return 0 + */ int status_readdb(void) { int i, j, k; @@ -12894,8 +12898,8 @@ int status_readdb(void) } /** -* Status db init and destroy. -**/ + * Status db init and destroy. + */ int do_init_status(void) { add_timer_func_list(status_change_timer,"status_change_timer"); diff --git a/src/map/trade.c b/src/map/trade.c index 69475b4837..bc48a584b4 100644 --- a/src/map/trade.c +++ b/src/map/trade.c @@ -41,8 +41,7 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta return; } - if (target_sd->npc_id) - { //Trade fails if you are using an NPC. + if (target_sd->npc_id) { // Trade fails if you are using an NPC. clif_tradestart(sd, 2); return; } @@ -56,6 +55,7 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta if ( sd->trade_partner != 0 ) { // If a character tries to trade to another one then cancel the previous one struct map_session_data *previous_sd = map_id2sd(sd->trade_partner); + if( previous_sd ){ previous_sd->trade_partner = 0; clif_tradecancelled(previous_sd); @@ -69,8 +69,7 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta return; } - if (!pc_can_give_items(sd) || !pc_can_give_items(target_sd)) //check if both GMs are allowed to trade - { + if (!pc_can_give_items(sd) || !pc_can_give_items(target_sd)) { // check if both GMs are allowed to trade clif_displaymessage(sd->fd, msg_txt(sd,246)); clif_tradestart(sd, 2); // GM is not allowed to trade return; @@ -104,22 +103,22 @@ void trade_traderequest(struct map_session_data *sd, struct map_session_data *ta void trade_tradeack(struct map_session_data *sd, int type) { struct map_session_data *tsd; + nullpo_retv(sd); if (sd->state.trading || !sd->trade_partner) - return; //Already trading or no partner set. + return; // Already trading or no partner set. if ((tsd = map_id2sd(sd->trade_partner)) == NULL) { - clif_tradestart(sd, 1); // character does not exist + clif_tradestart(sd, 1); // Character does not exist sd->trade_partner=0; return; } - if (tsd->state.trading || tsd->trade_partner != sd->bl.id) - { + if (tsd->state.trading || tsd->trade_partner != sd->bl.id) { clif_tradestart(sd, 2); sd->trade_partner=0; - return; //Already trading or wrong partner. + return; // Already trading or wrong partner. } if (type == 4) { // Cancel @@ -145,10 +144,9 @@ void trade_tradeack(struct map_session_data *sd, int type) return; } - //Check if you can start trade. + // Check if you can start trade. if (sd->npc_id || sd->state.vending || sd->state.buyingstore || sd->state.storage_flag || - tsd->npc_id || tsd->state.vending || tsd->state.buyingstore || tsd->state.storage_flag) - { //Fail + tsd->npc_id || tsd->state.vending || tsd->state.buyingstore || tsd->state.storage_flag) { // Fail clif_tradestart(sd, 2); clif_tradestart(tsd, 2); sd->state.deal_locked = 0; @@ -158,7 +156,7 @@ void trade_tradeack(struct map_session_data *sd, int type) return; } - //Initiate trade + // Initiate trade sd->state.trading = 1; tsd->state.trading = 1; memset(&sd->deal, 0, sizeof(sd->deal)); @@ -183,8 +181,7 @@ int impossible_trade_check(struct map_session_data *sd) nullpo_retr(1, sd); - if(sd->deal.zeny > sd->status.zeny) - { + if(sd->deal.zeny > sd->status.zeny) { pc_setglobalreg(sd,"ZENY_HACKER",1); return -1; } @@ -192,9 +189,9 @@ int impossible_trade_check(struct map_session_data *sd) // get inventory of player memcpy(&inventory, &sd->status.inventory, sizeof(struct item) * MAX_INVENTORY); - // remove this part: arrows can be trade and equiped + // remove this part: arrows can be trade and equipped // re-added! [celest] - // remove equiped items (they can not be trade) + // remove equipped items (they can not be trade) for (i = 0; i < MAX_INVENTORY; i++) if (inventory[i].nameid > 0 && inventory[i].equip && !(inventory[i].equip & EQP_AMMO)) memset(&inventory[i], 0, sizeof(struct item)); @@ -203,9 +200,10 @@ int impossible_trade_check(struct map_session_data *sd) for(i = 0; i < 10; i++) { if (!sd->deal.item[i].amount) continue; + index = sd->deal.item[i].index; - if (inventory[index].amount < sd->deal.item[i].amount) - { // if more than the player have -> hack + + if (inventory[index].amount < sd->deal.item[i].amount) { // if more than the player have -> hack sprintf(message_to_gm, msg_txt(sd,538), sd->status.name, sd->status.account_id); // Hack on trade: character '%s' (account: %d) try to trade more items that he has. intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); sprintf(message_to_gm, msg_txt(sd,539), inventory[index].amount, inventory[index].nameid, sd->deal.item[i].amount); // This player has %d of a kind of item (id: %d), and try to trade %d of them. @@ -229,6 +227,7 @@ int impossible_trade_check(struct map_session_data *sd) intif_wis_message_to_gm(wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); return 1; } + inventory[index].amount -= sd->deal.item[i].amount; // remove item from inventory } return 0; @@ -247,7 +246,7 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd) struct item_data *data; int trade_i, i, n; - // check zenys value against hackers (Zeny was already checked on time of adding, but you never know when you lost some zeny since then. + // check zeny 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)) return 0; if(tsd->deal.zeny > tsd->status.zeny || (sd->status.zeny > MAX_ZENY - tsd->deal.zeny)) @@ -262,44 +261,54 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd) short amount; amount = sd->deal.item[trade_i].amount; + if (amount) { n = sd->deal.item[trade_i].index; + if (amount > inventory[n].amount) - return 0; //qty Exploit? + return 0; // Quantity Exploit? data = itemdb_search(inventory[n].nameid); i = MAX_INVENTORY; - if (itemdb_isstackable2(data)) { //Stackable item. + if (itemdb_isstackable2(data)) { // Stackable item. for(i = 0; i < MAX_INVENTORY; i++) if (inventory2[i].nameid == inventory[n].nameid && inventory2[i].card[0] == inventory[n].card[0] && inventory2[i].card[1] == inventory[n].card[1] && inventory2[i].card[2] == inventory[n].card[2] && inventory2[i].card[3] == inventory[n].card[3]) { if (inventory2[i].amount + amount > MAX_AMOUNT) return 0; + inventory2[i].amount += amount; inventory[n].amount -= amount; break; } } - if (i == MAX_INVENTORY) {// look for an empty slot. + if (i == MAX_INVENTORY) { // look for an empty slot. for(i = 0; i < MAX_INVENTORY && inventory2[i].nameid; i++); if (i == MAX_INVENTORY) return 0; + memcpy(&inventory2[i], &inventory[n], sizeof(struct item)); inventory2[i].amount = amount; inventory[n].amount -= amount; } } + amount = tsd->deal.item[trade_i].amount; + if (!amount) continue; + n = tsd->deal.item[trade_i].index; + if (amount > inventory2[n].amount) return 0; + // search if it's possible to add item (for full inventory) data = itemdb_search(inventory2[n].nameid); i = MAX_INVENTORY; + if (itemdb_isstackable2(data)) { for(i = 0; i < MAX_INVENTORY; i++) if (inventory[i].nameid == inventory2[n].nameid && @@ -307,15 +316,18 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd) inventory[i].card[2] == inventory2[n].card[2] && inventory[i].card[3] == inventory2[n].card[3]) { if (inventory[i].amount + amount > MAX_AMOUNT) return 0; + inventory[i].amount += amount; inventory2[n].amount -= amount; break; } } + if (i == MAX_INVENTORY) { for(i = 0; i < MAX_INVENTORY && inventory[i].nameid; i++); if (i == MAX_INVENTORY) return 0; + memcpy(&inventory[i], &inventory2[n], sizeof(struct item)); inventory[i].amount = amount; inventory2[n].amount -= amount; @@ -339,24 +351,23 @@ void trade_tradeadditem(struct map_session_data *sd, short index, short amount) int src_lv, dst_lv; nullpo_retv(sd); - if( !sd->state.trading || sd->state.deal_locked > 0 ) - return; //Can't add stuff. - if( (target_sd = map_id2sd(sd->trade_partner)) == NULL ) - { + if( !sd->state.trading || sd->state.deal_locked > 0 ) + return; // Can't add stuff. + + if( (target_sd = map_id2sd(sd->trade_partner)) == NULL ) { trade_tradecancel(sd); return; } - if( amount == 0 ) - { //Why do this.. ~.~ just send an ack, the item won't display on the trade window. + if( !amount ) { // Why do this.. ~.~ just send an ack, the item won't display on the trade window. clif_tradeitemok(sd, index, 0); return; } index -= 2; // 0 is for zeny, 1 is unknown. Gravity, go figure... - //Item checks... + // Item checks... if( index < 0 || index >= MAX_INVENTORY ) return; if( amount < 0 || amount > sd->status.inventory[index].amount ) @@ -365,16 +376,15 @@ void trade_tradeadditem(struct map_session_data *sd, short index, short amount) item = &sd->status.inventory[index]; src_lv = pc_get_group_level(sd); dst_lv = pc_get_group_level(target_sd); - if( !itemdb_cantrade(item, src_lv, dst_lv) && //Can't trade - (pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(item, src_lv, dst_lv)) ) //Can't partner-trade - { + + if( !itemdb_cantrade(item, src_lv, dst_lv) && // Can't trade + (pc_get_partner(sd) != target_sd || !itemdb_canpartnertrade(item, src_lv, dst_lv)) ) { // Can't partner-trade clif_displaymessage (sd->fd, msg_txt(sd,260)); clif_tradeitemok(sd, index+2, 1); return; } - if( item->expire_time ) - { // Rental System + if( item->expire_time ) { // Rental System clif_displaymessage (sd->fd, msg_txt(sd,260)); clif_tradeitemok(sd, index+2, 1); return; @@ -386,35 +396,31 @@ void trade_tradeadditem(struct map_session_data *sd, short index, short amount) return; } - //Locate a trade position + // Locate a trade position ARR_FIND( 0, 10, trade_i, sd->deal.item[trade_i].index == index || sd->deal.item[trade_i].amount == 0 ); - if( trade_i == 10 ) //No space left - { + if( trade_i == 10 ) { // No space left clif_tradeitemok(sd, index+2, 1); return; } trade_weight = sd->inventory_data[index]->weight * amount; - if( target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight ) - { //fail to add item -- the player was over weighted. + if( target_sd->weight + sd->deal.weight + trade_weight > target_sd->max_weight ) { // fail to add item -- the player was over weighted. clif_tradeitemok(sd, index+2, 1); return; } - if( sd->deal.item[trade_i].index == index ) - { //The same item as before is being readjusted. - if( sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount ) - { //packet deal exploit check + if( sd->deal.item[trade_i].index == index ) { // The same item as before is being readjusted. + if( sd->deal.item[trade_i].amount + amount > sd->status.inventory[index].amount ) { // packet deal exploit check amount = sd->status.inventory[index].amount - sd->deal.item[trade_i].amount; trade_weight = sd->inventory_data[index]->weight * amount; } + sd->deal.item[trade_i].amount += amount; - } - else - { //New deal item + } else { // New deal item sd->deal.item[trade_i].index = index; sd->deal.item[trade_i].amount = amount; } + sd->deal.weight += trade_weight; clif_tradeitemok(sd, index+2, 0); // Return the index as it was received @@ -431,19 +437,18 @@ void trade_tradeadditem(struct map_session_data *sd, short index, short amount) void trade_tradeaddzeny(struct map_session_data* sd, int amount) { struct map_session_data* target_sd; + nullpo_retv(sd); if( !sd->state.trading || sd->state.deal_locked > 0 ) return; //Can't add stuff. - if( (target_sd = map_id2sd(sd->trade_partner)) == NULL ) - { + if( (target_sd = map_id2sd(sd->trade_partner)) == NULL ) { trade_tradecancel(sd); return; } - if( amount < 0 || amount > sd->status.zeny || amount > MAX_ZENY - target_sd->status.zeny ) - { // invalid values, no appropriate packet for it => abort + if( amount < 0 || amount > sd->status.zeny || amount > MAX_ZENY - target_sd->status.zeny ) { // invalid values, no appropriate packet for it => abort trade_tradecancel(sd); return; } @@ -467,6 +472,7 @@ void trade_tradeok(struct map_session_data *sd) trade_tradecancel(sd); return; } + sd->state.deal_locked = 1; clif_tradeitemok(sd, 0, 0); clif_tradedeal_lock(sd, 0); @@ -484,8 +490,7 @@ void trade_tradecancel(struct map_session_data *sd) target_sd = map_id2sd(sd->trade_partner); - if(!sd->state.trading) - { // Not trade acepted + if(!sd->state.trading) { // Not trade accepted if( target_sd ) { target_sd->trade_partner = 0; clif_tradecancelled(target_sd); @@ -498,10 +503,12 @@ void trade_tradecancel(struct map_session_data *sd) for(trade_i = 0; trade_i < 10; trade_i++) { // give items back (only virtual) if (!sd->deal.item[trade_i].amount) continue; + clif_additem(sd, sd->deal.item[trade_i].index, sd->deal.item[trade_i].amount, 0); sd->deal.item[trade_i].index = 0; sd->deal.item[trade_i].amount = 0; } + if (sd->deal.zeny) { clif_updatestatus(sd, SP_ZENY); sd->deal.zeny = 0; @@ -527,6 +534,7 @@ void trade_tradecancel(struct map_session_data *sd) clif_updatestatus(target_sd, SP_ZENY); target_sd->deal.zeny = 0; } + target_sd->state.deal_locked = 0; target_sd->trade_partner = 0; target_sd->state.trading = 0; @@ -556,17 +564,19 @@ void trade_tradecommit(struct map_session_data *sd) if (tsd->state.deal_locked < 2) return; //Not yet time for trading. - //Now is a good time (to save on resources) to check that the trade can indeed be made and it's not exploitable. + // Now is a good time (to save on resources) to check that the trade can indeed be made and it's not exploitable. // check exploit (trade more items that you have) if (impossible_trade_check(sd)) { trade_tradecancel(sd); return; } + // check exploit (trade more items that you have) if (impossible_trade_check(tsd)) { trade_tradecancel(tsd); return; } + // check for full inventory (can not add traded items) if (!trade_check(sd,tsd)) { // check the both players trade_tradecancel(sd); @@ -574,12 +584,11 @@ void trade_tradecommit(struct map_session_data *sd) } // trade is accepted and correct. - for( trade_i = 0; trade_i < 10; trade_i++ ) - { + for( trade_i = 0; trade_i < 10; trade_i++ ) { int n; unsigned char flag = 0; - if (sd->deal.item[trade_i].amount) - { + + if (sd->deal.item[trade_i].amount) { n = sd->deal.item[trade_i].index; flag = pc_additem(tsd, &sd->status.inventory[n], sd->deal.item[trade_i].amount,LOG_TYPE_TRADE); @@ -590,8 +599,8 @@ void trade_tradecommit(struct map_session_data *sd) sd->deal.item[trade_i].index = 0; sd->deal.item[trade_i].amount = 0; } - if (tsd->deal.item[trade_i].amount) - { + + if (tsd->deal.item[trade_i].amount) { n = tsd->deal.item[trade_i].index; flag = pc_additem(sd, &tsd->status.inventory[n], tsd->deal.item[trade_i].amount,LOG_TYPE_TRADE); @@ -610,6 +619,7 @@ void trade_tradecommit(struct map_session_data *sd) sd->deal.zeny = 0; } + if ( tsd->deal.zeny) { pc_payzeny(tsd,tsd->deal.zeny,LOG_TYPE_TRADE, sd); pc_getzeny(sd ,tsd->deal.zeny,LOG_TYPE_TRADE, tsd); @@ -628,8 +638,7 @@ void trade_tradecommit(struct map_session_data *sd) clif_tradecompleted(tsd, 0); // save both player to avoid crash: they always have no advantage/disadvantage between the 2 players - if (save_settings&1) - { + if (save_settings&1) { chrif_save(sd,0); chrif_save(tsd,0); } diff --git a/src/map/unit.c b/src/map/unit.c index fef01374e7..7fb7ff366b 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -53,6 +53,7 @@ const short diry[8]={1,1,0,-1,-1,-1,0,1}; ///lookup to know where will move to y static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data); static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data); int unit_unattackable(struct block_list *bl); + /** * Get the unit_data related to the bl * @param bl : Object to get the unit_data from @@ -131,7 +132,6 @@ int unit_walktoxy_sub(struct block_list *bl) return 1; } - /** * Retrieve the direct master of a bl if one exists. * @param bl: char to get his master [HOM|ELEM|PET|MER] @@ -189,8 +189,7 @@ int unit_teleport_timer(int tid, unsigned int tick, int id, intptr_t data) if(msd && !check_distance_bl(&msd->bl, bl, data)) { *mast_tid = INVALID_TIMER; unit_warp(bl, msd->bl.m, msd->bl.x, msd->bl.y, CLR_TELEPORT ); - } - else // No timer needed + } else // No timer needed *mast_tid = INVALID_TIMER; } return 0; @@ -227,6 +226,7 @@ int unit_check_start_teleport_timer(struct block_list *sbl) // If there is a master and it's a valid type if(msd && max_dist) { int *msd_tid = unit_get_masterteleport_timer(sbl); + if(msd_tid == NULL) return 0; if (!check_distance_bl(&msd->bl, sbl, max_dist)) { if(*msd_tid == INVALID_TIMER || *msd_tid == 0) @@ -310,7 +310,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data map_foreachinmovearea(clif_insight, bl, AREA_SIZE, -dx, -dy, sd?BL_ALL:BL_PC, bl); ud->walktimer = INVALID_TIMER; - switch(bl->type){ + switch(bl->type) { case BL_PC: { if( sd->touching_id ) npc_touchnext_areanpc(sd,false); @@ -704,7 +704,7 @@ int unit_run(struct block_list *bl) } /** - * Char movement with wugdash + * Character movement with Warg Dash * @author [Jobbie/3CeAM] * @param bl: Object that is dashing * @param sd: Player @@ -1276,6 +1276,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui int combo = 0, range; nullpo_ret(src); + if(status_isdead(src)) return 0; // Do not continue source is dead @@ -1336,7 +1337,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui } if (target) target_id = target->id; - } else if (src->type==BL_HOM) + } else if (src->type == BL_HOM) switch(skill_id) { // Homun-auto-target skills. case HLIF_HEAL: case HLIF_AVOID: @@ -1481,14 +1482,14 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui ud->state.skillcastcancel = castcancel; - // temp: Used to signal force cast now. + // Combo: Used to signal force cast now. combo = 0; switch(skill_id) { case ALL_RESURRECTION: - if(battle_check_undead(tstatus->race,tstatus->def_ele)) { + if(battle_check_undead(tstatus->race,tstatus->def_ele)) combo = 1; - } else if (!status_isdead(target)) + else if (!status_isdead(target)) return 0; // Can't cast on non-dead characters. break; case MO_FINGEROFFENSIVE: @@ -1703,7 +1704,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui /** * Pneuma cannot be cancelled past this point, the client displays the animation even, * if we cancel it from nodamage_id, so it has to be here for it to not display the animation. - **/ + */ if( skill_id == AL_PNEUMA && map_getcell(src->m, skill_x, skill_y, CELL_CHKLANDPROTECTOR) ) { clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); return 0; @@ -2197,7 +2198,7 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t /** * Applied when you're unable to attack (e.g. out of ammo) * We should stop here otherwise timer keeps on and this happens endlessly - **/ + */ if( ud->attacktarget_lv == ATK_NONE ) return 1; diff --git a/src/map/vending.c b/src/map/vending.c index 87f017151d..a393011309 100755 --- a/src/map/vending.c +++ b/src/map/vending.c @@ -58,7 +58,8 @@ static void do_final_vending_autotrade(void); * Lookup to get the vending_db outside module * @return the vending_db */ -DBMap * vending_getdb(){ +DBMap * vending_getdb() +{ return vending_db; } @@ -66,7 +67,8 @@ DBMap * vending_getdb(){ * Create an unique vending shop id. * @return the next vending_id */ -static int vending_getuid(void){ +static int vending_getuid(void) +{ return ++vending_nextid; } @@ -80,7 +82,7 @@ void vending_closevending(struct map_session_data* sd) if( sd->state.vending ) { if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE vending_id = %d;", vending_items_db, sd->vender_id ) != SQL_SUCCESS || - Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", vendings_db, sd->vender_id ) != SQL_SUCCESS ){ + Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `id` = %d;", vendings_db, sd->vender_id ) != SQL_SUCCESS ) { Sql_ShowDebug(mmysql_handle); } @@ -106,8 +108,7 @@ void vending_vendinglistreq(struct map_session_data* sd, int id) if( !vsd->state.vending ) return; // not vending - if (!pc_can_give_items(sd) || !pc_can_give_items(vsd)) //check if both GMs are allowed to trade - { // GM is not allowed to trade + if (!pc_can_give_items(sd) || !pc_can_give_items(vsd)) { //check if both GMs are allowed to trade clif_displaymessage(sd->fd, msg_txt(sd,246)); return; } @@ -177,13 +178,11 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui vend_list[i] = j; z += ((double)vsd->vending[j].value * (double)amount); - if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY ) - { + if( z > (double)sd->status.zeny || z < 0. || z > (double)MAX_ZENY ) { clif_buyvending(sd, idx, amount, 1); // you don't have enough zeny return; } - if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max ) - { + if( z + (double)vsd->status.zeny > (double)MAX_ZENY && !battle_config.vending_over_max ) { clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // too much zeny = overflow return; @@ -200,8 +199,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui // if they try to add packets (example: get twice or more 2 apples if marchand has only 3 apples). // here, we check cumulative amounts - if( vending[j].amount < amount ) - { + if( vending[j].amount < amount ) { // send more quantity is not a hack (an other player can have buy items just before) clif_buyvending(sd, idx, vsd->vending[j].amount, 4); // not enough quantity return; @@ -236,12 +234,12 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui pc_additem(sd, &vsd->status.cart[idx], amount, LOG_TYPE_VENDING); vsd->vending[vend_list[i]].amount -= amount; - if( vsd->vending[vend_list[i]].amount ){ - if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vending[vend_list[i]].amount, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ){ + if( vsd->vending[vend_list[i]].amount ) { + if( Sql_Query( mmysql_handle, "UPDATE `%s` SET `amount` = %d WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vending[vend_list[i]].amount, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ) { Sql_ShowDebug( mmysql_handle ); } - }else{ - if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ){ + } else { + if( Sql_Query( mmysql_handle, "DELETE FROM `%s` WHERE `vending_id` = %d and `cartinventory_id` = %d", vending_items_db, vsd->vender_id, vsd->status.cart[idx].id ) != SQL_SUCCESS ) { Sql_ShowDebug( mmysql_handle ); } } @@ -270,6 +268,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui cursor++; } + vsd->vend_num = cursor; //Always save BOTH: customer (buyer) and vender @@ -299,7 +298,8 @@ void vending_purchasereq(struct map_session_data* sd, int aid, int uid, const ui * @param count : number of different items * @return 0 If success, 1 - Cannot open (die, not state.prevend, trading), 2 - No cart, 3 - Count issue, 4 - Cart data isn't saved yet, 5 - No valid item found */ -char vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) { +char vending_openvending(struct map_session_data* sd, const char* message, const uint8* data, int count) +{ int i, j; int vending_skill_lvl; char message_sql[MESSAGE_SIZE*2]; @@ -319,8 +319,7 @@ char vending_openvending(struct map_session_data* sd, const char* message, const } // check number of items in shop - if( count < 1 || count > MAX_VENDING || count > 2 + vending_skill_lvl ) - { // invalid item count + if( count < 1 || count > MAX_VENDING || count > 2 + vending_skill_lvl ) { // invalid item count clif_skill_fail(sd, MC_VENDING, USESKILL_FAIL_LEVEL, 0); return 3; } @@ -372,6 +371,7 @@ char vending_openvending(struct map_session_data* sd, const char* message, const clif_skill_fail(sd, MC_VENDING, USESKILL_FAIL_LEVEL, 0); // custom reply packet return 5; } + sd->state.prevend = 0; sd->state.vending = true; sd->vender_id = vending_getuid(); @@ -382,12 +382,12 @@ char vending_openvending(struct map_session_data* sd, const char* message, const if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`id`,`account_id`,`char_id`,`sex`,`map`,`x`,`y`,`title`,`autotrade`, `body_direction`, `head_direction`, `sit`) " "VALUES( %d, %d, %d, '%c', '%s', %d, %d, '%s', %d, '%d', '%d', '%d' );", - vendings_db, sd->vender_id, sd->status.account_id, sd->status.char_id, sd->status.sex == 0 ? 'F' : 'M', map[sd->bl.m].name, sd->bl.x, sd->bl.y, message_sql, sd->state.autotrade, sd->ud.dir, sd->head_dir, pc_issit(sd) ) != SQL_SUCCESS ){ + vendings_db, sd->vender_id, sd->status.account_id, sd->status.char_id, sd->status.sex == 0 ? 'F' : 'M', map[sd->bl.m].name, sd->bl.x, sd->bl.y, message_sql, sd->state.autotrade, sd->ud.dir, sd->head_dir, pc_issit(sd) ) != SQL_SUCCESS ) { Sql_ShowDebug(mmysql_handle); } for( i = 0; i < count; i++ ) { - if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`vending_id`,`index`,`cartinventory_id`,`amount`,`price`) VALUES( %d, %d, %d, %d, %d );", vending_items_db, sd->vender_id, i, sd->status.cart[sd->vending[i].index].id, sd->vending[i].amount, sd->vending[i].value ) != SQL_SUCCESS ){ + if( Sql_Query( mmysql_handle, "INSERT INTO `%s`(`vending_id`,`index`,`cartinventory_id`,`amount`,`price`) VALUES( %d, %d, %d, %d, %d );", vending_items_db, sd->vender_id, i, sd->status.cart[sd->vending[i].index].id, sd->vending[i].amount, sd->vending[i].value ) != SQL_SUCCESS ) { Sql_ShowDebug(mmysql_handle); } } @@ -406,7 +406,8 @@ char vending_openvending(struct map_session_data* sd, const char* message, const * @param nameid : item id * @return 0:not selling it, 1: yes */ -bool vending_search(struct map_session_data* sd, unsigned short nameid) { +bool vending_search(struct map_session_data* sd, unsigned short nameid) +{ int i; if( !sd->state.vending ) { // not vending @@ -421,15 +422,14 @@ bool vending_search(struct map_session_data* sd, unsigned short nameid) { return true; } - - /** * Searches for all items in a vending, that match given ids, price and possible cards. * @param sd : The vender session to search into * @param s : parameter of the search (see s_search_store_search) * @return Whether or not the search should be continued. */ -bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s) { +bool vending_searchall(struct map_session_data* sd, const struct s_search_store_search* s) +{ int i, c, slot; unsigned int idx, cidx; struct item* it; @@ -439,40 +439,38 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_ for( idx = 0; idx < s->item_count; idx++ ) { ARR_FIND( 0, sd->vend_num, i, sd->status.cart[sd->vending[i].index].nameid == (short)s->itemlist[idx] ); - if( i == sd->vend_num ) {// not found + if( i == sd->vend_num ) { // not found continue; } it = &sd->status.cart[sd->vending[i].index]; - if( s->min_price && s->min_price > sd->vending[i].value ) {// too low price + if( s->min_price && s->min_price > sd->vending[i].value ) { // too low price continue; } - if( s->max_price && s->max_price < sd->vending[i].value ) {// too high price + if( s->max_price && s->max_price < sd->vending[i].value ) { // too high price continue; } - if( s->card_count ) {// check cards - if( itemdb_isspecial(it->card[0]) ) {// something, that is not a carded + if( s->card_count ) { // check cards + if( itemdb_isspecial(it->card[0]) ) { // something, that is not a carded continue; } slot = itemdb_slot(it->nameid); for( c = 0; c < slot && it->card[c]; c ++ ) { ARR_FIND( 0, s->card_count, cidx, s->cardlist[cidx] == it->card[c] ); - if( cidx != s->card_count ) - {// found + if( cidx != s->card_count ) { // found break; } } - if( c == slot || !it->card[c] ) {// no card match + if( c == slot || !it->card[c] ) { // no card match continue; } } - if( !searchstore_result(s->search_sd, sd->vender_id, sd->status.account_id, sd->message, it->nameid, sd->vending[i].amount, sd->vending[i].value, it->card, it->refine) ) - {// result set full + if( !searchstore_result(s->search_sd, sd->vender_id, sd->status.account_id, sd->message, it->nameid, sd->vending[i].amount, sd->vending[i].value, it->card, it->refine) ) { // result set full return false; } } @@ -484,11 +482,12 @@ bool vending_searchall(struct map_session_data* sd, const struct s_search_store_ * Open vending for Autotrader * @param sd Player as autotrader */ -void vending_reopen( struct map_session_data* sd ){ +void vending_reopen( struct map_session_data* sd ) +{ nullpo_retv(sd); // Ready to open vending for this char - if ( autotrader_count > 0 && autotraders){ + if ( autotrader_count > 0 && autotraders) { uint16 i; uint8 *data, *p, fail = 0; uint16 j, count; @@ -530,12 +529,11 @@ void vending_reopen( struct map_session_data* sd ){ pc_cleareventtimer(sd); // Open the vending again - if( (fail = vending_openvending(sd, autotraders[i]->title, data, count)) == 0 ){ + if( (fail = vending_openvending(sd, autotraders[i]->title, data, count)) == 0 ) { // Set him to autotrade if (Sql_Query( mmysql_handle, "UPDATE `%s` SET `autotrade` = 1, `body_direction` = '%d', `head_direction` = '%d', `sit` = '%d' " "WHERE `id` = %d;", - vendings_db, autotraders[i]->dir, autotraders[i]->head_dir, autotraders[i]->sit, sd->vender_id ) != SQL_SUCCESS ) - { + vendings_db, autotraders[i]->dir, autotraders[i]->head_dir, autotraders[i]->sit, sd->vender_id ) != SQL_SUCCESS ) { Sql_ShowDebug( mmysql_handle ); } @@ -553,7 +551,7 @@ void vending_reopen( struct map_session_data* sd ){ ShowInfo("Loaded vending for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items at "CL_WHITE"%s (%d,%d)"CL_RESET"\n", sd->status.name, count, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y); - }else{ + } else { // Failed to open the vending, set him offline ShowError("Failed (%d) to load autotrade vending data for '"CL_WHITE"%s"CL_RESET"' with '"CL_WHITE"%d"CL_RESET"' items\n", fail, sd->status.name, count ); @@ -571,7 +569,8 @@ void vending_reopen( struct map_session_data* sd ){ /** * Initializing autotraders from table */ -void do_init_vending_autotrade( void ) { +void do_init_vending_autotrade(void) +{ if (battle_config.feature_autotrade) { uint16 i, items = 0; autotrader_count = autotrader_loaded_count = 0; @@ -583,13 +582,12 @@ void do_init_vending_autotrade( void ) { "FROM `%s` " "WHERE `autotrade` = 1 AND (SELECT COUNT(`vending_id`) FROM `%s` WHERE `vending_id` = `id`) > 0 " "ORDER BY `id`;", - vendings_db, vending_items_db ) != SQL_SUCCESS ) - { + vendings_db, vending_items_db ) != SQL_SUCCESS ) { Sql_ShowDebug(mmysql_handle); return; } - if( (autotrader_count = (uint16)Sql_NumRows(mmysql_handle)) > 0 ){ + if( (autotrader_count = (uint16)Sql_NumRows(mmysql_handle)) > 0 ) { // Init autotraders CREATE(autotraders, struct s_autotrade *, autotrader_count); @@ -637,7 +635,7 @@ void do_init_vending_autotrade( void ) { Sql_FreeResult(mmysql_handle); //Init items on vending list each autotrader - for (i = 0; i < autotrader_count; i++){ + for (i = 0; i < autotrader_count; i++) { struct s_autotrade *at = NULL; uint16 j; @@ -649,8 +647,7 @@ void do_init_vending_autotrade( void ) { "FROM `%s` " "WHERE `vending_id` = %d " "ORDER BY `index` ASC;", - vending_items_db, at->vendor_id ) ) - { + vending_items_db, at->vendor_id ) ) { Sql_ShowDebug(mmysql_handle); continue; } @@ -684,8 +681,7 @@ void do_init_vending_autotrade( void ) { // Everything is loaded fine, their entries will be reinserted once they are loaded if (Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vendings_db ) != SQL_SUCCESS || - Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vending_items_db ) != SQL_SUCCESS) - { + Sql_Query( mmysql_handle, "DELETE FROM `%s`;", vending_items_db ) != SQL_SUCCESS) { Sql_ShowDebug(mmysql_handle); } } @@ -694,8 +690,9 @@ void do_init_vending_autotrade( void ) { * Clear all autotraders * @author [Cydh] */ -void do_final_vending_autotrade(void) { - if (autotrader_count && autotraders){ +void do_final_vending_autotrade(void) +{ + if (autotrader_count && autotraders) { uint16 i = 0; while (i < autotrader_count) { //Free the autotrader if (autotraders[i] == NULL) @@ -723,7 +720,8 @@ void do_final_vending_autotrade(void) { * Initialise the vending module * called in map::do_init */ -void do_final_vending(void) { +void do_final_vending(void) +{ db_destroy(vending_db); do_final_vending_autotrade(); //Make sure everything is cleared [Cydh] } @@ -732,7 +730,8 @@ void do_final_vending(void) { * Destory the vending module * called in map::do_final */ -void do_init_vending(void) { +void do_init_vending(void) +{ vending_db = idb_alloc(DB_OPT_BASE); vending_nextid = 0; }