summaryrefslogtreecommitdiff
path: root/src/map/pc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/pc.c')
-rw-r--r--src/map/pc.c185
1 files changed, 83 insertions, 102 deletions
diff --git a/src/map/pc.c b/src/map/pc.c
index 8fcac8826..3eabde647 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1308,7 +1308,7 @@ static int pc_bonus_addeff(struct s_addeffect* effect, int max, short id, short
return 1;
}
-static int pc_bonus_item_drop(struct s_add_drop *drop, short *count, short id, short group, int race, int rate)
+static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id, short group, int race, int rate)
{
int i;
//Apply config rate adjustment settings.
@@ -1325,7 +1325,7 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, short *count, short id, s
if (rate > -1)
rate = -1;
}
- for(i = 0; i < *count; i++) {
+ for(i = 0; i < max && (drop[i].id || drop[i].group); i++) {
if(
(id && drop[i].id == id) ||
(group && drop[i].group == group)
@@ -1345,16 +1345,15 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, short *count, short id, s
return 1;
}
}
- if(*count >= MAX_PC_BONUS) {
+ if(i == max) {
if (battle_config.error_log)
- ShowWarning("pc_bonus: Reached max (%d) number of added drops per character!\n", MAX_PC_BONUS);
+ ShowWarning("pc_bonus: Reached max (%d) number of added drops per character!\n", max);
return 0;
}
- drop[*count].id = id;
- drop[*count].group = group;
- drop[*count].race |= race;
- drop[*count].rate = rate;
- (*count)++;
+ drop[i].id = id;
+ drop[i].group = group;
+ drop[i].race |= race;
+ drop[i].rate = rate;
return 1;
}
@@ -1970,7 +1969,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ShowWarning("pc_bonus2 (Add Effect): %d is not supported.\n", type2);
break;
}
- pc_bonus_addeff(sd->addeff, MAX_PC_BONUS, type2,
+ pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), type2,
sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0,
ATF_SHORT|ATF_LONG|ATF_TARGET);
break;
@@ -1979,7 +1978,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
ShowWarning("pc_bonus2 (Add Effect2): %d is not supported.\n", type2);
break;
}
- pc_bonus_addeff(sd->addeff, MAX_PC_BONUS, type2,
+ pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), type2,
sd->state.lr_flag!=2?val:0, sd->state.lr_flag==2?val:0,
ATF_SHORT|ATF_LONG|ATF_SELF);
break;
@@ -2011,77 +2010,74 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
sd->magic_addsize[type2]+=val;
break;
case SP_ADD_DAMAGE_CLASS:
- if(!sd->state.lr_flag) {
- for(i=0;i<sd->right_weapon.add_damage_class_count;i++) {
- if(sd->right_weapon.add_damage_classid[i] == type2) {
- sd->right_weapon.add_damage_classrate[i] += val;
- break;
- }
- }
- if(i >= sd->right_weapon.add_damage_class_count && sd->right_weapon.add_damage_class_count < 10) {
- sd->right_weapon.add_damage_classid[sd->right_weapon.add_damage_class_count] = type2;
- sd->right_weapon.add_damage_classrate[sd->right_weapon.add_damage_class_count] += val;
- sd->right_weapon.add_damage_class_count++;
- }
- }
- else if(sd->state.lr_flag == 1) {
- for(i=0;i<sd->left_weapon.add_damage_class_count;i++) {
- if(sd->left_weapon.add_damage_classid[i] == type2) {
- sd->left_weapon.add_damage_classrate[i] += val;
- break;
- }
+ switch (sd->state.lr_flag) {
+ case 0: //Right hand
+ ARR_FIND(0, ARRAYLENGTH(sd->right_weapon.add_dmg), i, sd->right_weapon.add_dmg[i].rate == 0 || sd->right_weapon.add_dmg[i].class_ == type2);
+ if (i == ARRAYLENGTH(sd->right_weapon.add_dmg))
+ {
+ ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->right_weapon.add_dmg));
+ break;
}
- if(i >= sd->left_weapon.add_damage_class_count && sd->left_weapon.add_damage_class_count < 10) {
- sd->left_weapon.add_damage_classid[sd->left_weapon.add_damage_class_count] = type2;
- sd->left_weapon.add_damage_classrate[sd->left_weapon.add_damage_class_count] += val;
- sd->left_weapon.add_damage_class_count++;
+ sd->right_weapon.add_dmg[i].class_ = type2;
+ sd->right_weapon.add_dmg[i].rate += val;
+ if (!sd->right_weapon.add_dmg[i].rate) //Shift the rest of elements up.
+ memmove(&sd->right_weapon.add_dmg[i], &sd->right_weapon.add_dmg[i+1], sizeof(sd->right_weapon.add_dmg) - (i+1)*sizeof(sd->right_weapon.add_dmg[0]));
+ break;
+ case 1: //Left hand
+ ARR_FIND(0, ARRAYLENGTH(sd->left_weapon.add_dmg), i, sd->left_weapon.add_dmg[i].rate == 0 || sd->left_weapon.add_dmg[i].class_ == type2);
+ if (i == ARRAYLENGTH(sd->left_weapon.add_dmg))
+ {
+ ShowWarning("pc_bonus2: Reached max (%d) number of add Class dmg bonuses per character!\n", ARRAYLENGTH(sd->left_weapon.add_dmg));
+ break;
}
+ sd->left_weapon.add_dmg[i].class_ = type2;
+ sd->left_weapon.add_dmg[i].rate += val;
+ if (!sd->left_weapon.add_dmg[i].rate) //Shift the rest of elements up.
+ memmove(&sd->left_weapon.add_dmg[i], &sd->left_weapon.add_dmg[i+1], sizeof(sd->left_weapon.add_dmg) - (i+1)*sizeof(sd->left_weapon.add_dmg[0]));
+ break;
}
break;
case SP_ADD_MAGIC_DAMAGE_CLASS:
- if(sd->state.lr_flag != 2) {
- for(i=0;i<sd->add_mdmg_count;i++) {
- if(sd->add_mdmg[i].class_ == type2) {
- sd->add_mdmg[i].rate += val;
- break;
- }
- }
- if(i >= sd->add_mdmg_count && sd->add_mdmg_count < MAX_PC_BONUS) {
- sd->add_mdmg[sd->add_mdmg_count].class_ = type2;
- sd->add_mdmg[sd->add_mdmg_count].rate += val;
- sd->add_mdmg_count++;
- }
+ if(sd->state.lr_flag == 2)
+ break;
+ ARR_FIND(0, ARRAYLENGTH(sd->add_mdmg), i, sd->add_mdmg[i].rate == 0 || sd->add_mdmg[i].class_ == type2);
+ if (i == ARRAYLENGTH(sd->add_mdmg))
+ {
+ ShowWarning("pc_bonus2: Reached max (%d) number of add Class magic dmg bonuses per character!\n", ARRAYLENGTH(sd->add_mdmg));
+ break;
}
+ sd->add_mdmg[i].class_ = type2;
+ sd->add_mdmg[i].rate += val;
+ if (!sd->add_mdmg[i].rate) //Shift the rest of elements up.
+ memmove(&sd->add_mdmg[i], &sd->add_mdmg[i+1], sizeof(sd->add_mdmg) - (i+1)*sizeof(sd->add_mdmg[0]));
break;
case SP_ADD_DEF_CLASS:
- if(sd->state.lr_flag != 2) {
- for(i=0;i<sd->add_def_count;i++) {
- if(sd->add_def[i].class_ == type2) {
- sd->add_def[i].rate += val;
- break;
- }
- }
- if(i >= sd->add_def_count && sd->add_def_count < MAX_PC_BONUS) {
- sd->add_def[sd->add_def_count].class_ = type2;
- sd->add_def[sd->add_def_count].rate += val;
- sd->add_def_count++;
- }
+ if(sd->state.lr_flag == 2)
+ break;
+ ARR_FIND(0, ARRAYLENGTH(sd->add_def), i, sd->add_def[i].rate == 0 || sd->add_def[i].class_ == type2);
+ if (i == ARRAYLENGTH(sd->add_def))
+ {
+ ShowWarning("pc_bonus2: Reached max (%d) number of add Class def bonuses per character!\n", ARRAYLENGTH(sd->add_def));
+ break;
}
+ sd->add_def[i].class_ = type2;
+ sd->add_def[i].rate += val;
+ if (!sd->add_def[i].rate) //Shift the rest of elements up.
+ memmove(&sd->add_def[i], &sd->add_def[i+1], sizeof(sd->add_def) - (i+1)*sizeof(sd->add_def[0]));
break;
case SP_ADD_MDEF_CLASS:
- if(sd->state.lr_flag != 2) {
- for(i=0;i<sd->add_mdef_count;i++) {
- if(sd->add_mdef[i].class_ == type2) {
- sd->add_mdef[i].rate += val;
- break;
- }
- }
- if(i >= sd->add_mdef_count && sd->add_mdef_count < MAX_PC_BONUS) {
- sd->add_mdef[sd->add_mdef_count].class_ = type2;
- sd->add_mdef[sd->add_mdef_count].rate += val;
- sd->add_mdef_count++;
- }
+ if(sd->state.lr_flag == 2)
+ break;
+ ARR_FIND(0, ARRAYLENGTH(sd->add_mdef), i, sd->add_mdef[i].rate == 0 || sd->add_mdef[i].class_ == type2);
+ if (i == ARRAYLENGTH(sd->add_mdef))
+ {
+ ShowWarning("pc_bonus2: Reached max (%d) number of add Class mdef bonuses per character!\n", ARRAYLENGTH(sd->add_mdef));
+ break;
}
+ sd->add_mdef[i].class_ = type2;
+ sd->add_mdef[i].rate += val;
+ if (!sd->add_mdef[i].rate) //Shift the rest of elements up.
+ memmove(&sd->add_mdef[i], &sd->add_mdef[i+1], sizeof(sd->add_mdef) - (i+1)*sizeof(sd->add_mdef[0]));
break;
case SP_HP_DRAIN_RATE:
if(!sd->state.lr_flag) {
@@ -2200,7 +2196,7 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
break;
}
if(sd->state.lr_flag != 2)
- pc_bonus_addeff(sd->addeff2, MAX_PC_BONUS, type2, val, 0,
+ pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), type2, val, 0,
ATF_SHORT|ATF_LONG|ATF_TARGET);
break;
case SP_ADDEFF_WHENHIT_SHORT:
@@ -2278,21 +2274,6 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
}
break;
- case SP_ADD_DAMAGE_BY_CLASS:
- if(sd->state.lr_flag != 2) {
- for(i=0;i<sd->add_dmg_count;i++) {
- if(sd->add_dmg[i].class_ == type2) {
- sd->add_dmg[i].rate += val;
- break;
- }
- }
- if(i >= sd->add_dmg_count && sd->add_dmg_count < MAX_PC_BONUS) {
- sd->add_dmg[sd->add_dmg_count].class_ = type2;
- sd->add_dmg[sd->add_dmg_count].rate += val;
- sd->add_dmg_count++;
- }
- }
- break;
case SP_HP_LOSS_RATE:
if(sd->state.lr_flag != 2) {
sd->hp_loss.value = type2;
@@ -2329,9 +2310,9 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
break;
}
//Standard item bonus.
- for(i=0; i < MAX_PC_BONUS && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
- if(i == MAX_PC_BONUS) {
- ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", MAX_PC_BONUS);
+ for(i=0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid && sd->itemhealrate[i].nameid != type2; i++);
+ if(i == ARRAYLENGTH(sd->itemhealrate)) {
+ ShowWarning("pc_bonus2: Reached max (%d) number of item heal bonuses per character!\n", ARRAYLENGTH(sd->itemhealrate));
break;
}
sd->itemhealrate[i].nameid = type2;
@@ -2347,11 +2328,11 @@ int pc_bonus2(struct map_session_data *sd,int type,int type2,int val)
break;
case SP_ADD_MONSTER_DROP_ITEM:
if (sd->state.lr_flag != 2)
- pc_bonus_item_drop(sd->add_drop, &sd->add_drop_count, type2, 0, (1<<RC_BOSS)|(1<<RC_NONBOSS), val);
+ pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, (1<<RC_BOSS)|(1<<RC_NONBOSS), val);
break;
case SP_ADD_MONSTER_DROP_ITEMGROUP:
if (sd->state.lr_flag != 2)
- pc_bonus_item_drop(sd->add_drop, &sd->add_drop_count, 0, type2, (1<<RC_BOSS)|(1<<RC_NONBOSS), val);
+ pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, (1<<RC_BOSS)|(1<<RC_NONBOSS), val);
break;
case SP_SP_LOSS_RATE:
if(sd->state.lr_flag != 2) {
@@ -2401,15 +2382,15 @@ int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
switch(type){
case SP_ADD_MONSTER_DROP_ITEM:
if(sd->state.lr_flag != 2)
- pc_bonus_item_drop(sd->add_drop, &sd->add_drop_count, type2, 0, 1<<type3, val);
+ pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), type2, 0, 1<<type3, val);
break;
case SP_AUTOSPELL:
if(sd->state.lr_flag != 2)
- pc_bonus_autospell(sd->autospell, MAX_PC_BONUS, skill_get_inf(type2)&INF_SELF_SKILL?-type2:type2, type3, val, 0, current_equip_card_id);
+ pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), skill_get_inf(type2)&INF_SELF_SKILL?-type2:type2, type3, val, 0, current_equip_card_id);
break;
case SP_AUTOSPELL_WHENHIT:
if(sd->state.lr_flag != 2)
- pc_bonus_autospell(sd->autospell2, MAX_PC_BONUS, skill_get_inf(type2)&INF_SELF_SKILL?-type2:type2, type3, val, 0, current_equip_card_id);
+ pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), skill_get_inf(type2)&INF_SELF_SKILL?-type2:type2, type3, val, 0, current_equip_card_id);
break;
case SP_SP_DRAIN_RATE:
if(!sd->state.lr_flag) {
@@ -2452,7 +2433,7 @@ int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
break;
case SP_ADD_MONSTER_DROP_ITEMGROUP:
if (sd->state.lr_flag != 2)
- pc_bonus_item_drop(sd->add_drop, &sd->add_drop_count, 0, type2, 1<<type3, val);
+ pc_bonus_item_drop(sd->add_drop, ARRAYLENGTH(sd->add_drop), 0, type2, 1<<type3, val);
break;
case SP_ADDEFF:
@@ -2460,7 +2441,7 @@ int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
ShowWarning("pc_bonus3 (Add Effect): %d is not supported.\n", type2);
break;
}
- pc_bonus_addeff(sd->addeff, MAX_PC_BONUS, type2,
+ pc_bonus_addeff(sd->addeff, ARRAYLENGTH(sd->addeff), type2,
sd->state.lr_flag!=2?type3:0, sd->state.lr_flag==2?type3:0,
ATF_SHORT|ATF_LONG|(val?ATF_TARGET:ATF_SELF)|(val==2?ATF_SELF:0));
break;
@@ -2471,7 +2452,7 @@ int pc_bonus3(struct map_session_data *sd,int type,int type2,int type3,int val)
break;
}
if(sd->state.lr_flag != 2)
- pc_bonus_addeff(sd->addeff2, MAX_PC_BONUS, type2, type3, 0,
+ pc_bonus_addeff(sd->addeff2, ARRAYLENGTH(sd->addeff2), type2, type3, 0,
ATF_SHORT|ATF_LONG|(val?ATF_TARGET:ATF_SELF)|(val==2?ATF_SELF:0));
break;
@@ -2491,12 +2472,12 @@ int pc_bonus4(struct map_session_data *sd,int type,int type2,int type3,int type4
switch(type){
case SP_AUTOSPELL:
if(sd->state.lr_flag != 2)
- pc_bonus_autospell(sd->autospell, MAX_PC_BONUS, (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
+ pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
break;
case SP_AUTOSPELL_WHENHIT:
if(sd->state.lr_flag != 2)
- pc_bonus_autospell(sd->autospell2, MAX_PC_BONUS, (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
+ pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, 0, current_equip_card_id);
break;
default:
if(battle_config.error_log)
@@ -2514,12 +2495,12 @@ int pc_bonus5(struct map_session_data *sd,int type,int type2,int type3,int type4
switch(type){
case SP_AUTOSPELL:
if(sd->state.lr_flag != 2)
- pc_bonus_autospell(sd->autospell, MAX_PC_BONUS, (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
+ pc_bonus_autospell(sd->autospell, ARRAYLENGTH(sd->autospell), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
break;
case SP_AUTOSPELL_WHENHIT:
if(sd->state.lr_flag != 2)
- pc_bonus_autospell(sd->autospell2, MAX_PC_BONUS, (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
+ pc_bonus_autospell(sd->autospell2, ARRAYLENGTH(sd->autospell2), (val&1?type2:-type2), (val&2?-type3:type3), type4, type5, current_equip_card_id);
break;
default:
if(battle_config.error_log)
@@ -5453,7 +5434,7 @@ int pc_itemheal(struct map_session_data *sd,int itemid, int hp,int sp)
//Item Group bonuses
bonus += bonus*itemdb_group_bonus(sd, itemid)/100;
//Individual item bonuses.
- for(i = 0; i < MAX_PC_BONUS && sd->itemhealrate[i].nameid; i++)
+ for(i = 0; i < ARRAYLENGTH(sd->itemhealrate) && sd->itemhealrate[i].nameid; i++)
{
if (sd->itemhealrate[i].nameid == itemid) {
bonus += bonus*sd->itemhealrate[i].rate/100;