Simplify some stuff with references
This commit is contained in:
@@ -2277,30 +2277,31 @@ bool damage_pc(cPlayer& which_pc,short how_much,eDamageType damage_type,eRace ty
|
||||
if(damage_type == eDamageType::WEAPON || damage_type == eDamageType::UNDEAD || damage_type == eDamageType::DEMON) {
|
||||
how_much -= minmax(-5,5,which_pc.status[eStatus::BLESS_CURSE]);
|
||||
for(short i = 0; i < which_pc.items.size(); i++) {
|
||||
if((which_pc.items[i].variety != eItemType::NO_ITEM) && (which_pc.equip[i])) {
|
||||
if((*which_pc.items[i].variety).is_armour) {
|
||||
r1 = get_ran(1,1,which_pc.items[i].item_level);
|
||||
const cItem& item = which_pc.items[i];
|
||||
if(item.variety != eItemType::NO_ITEM && which_pc.equip[i]) {
|
||||
if((*item.variety).is_armour) {
|
||||
r1 = get_ran(1,1,item.item_level);
|
||||
how_much -= r1;
|
||||
|
||||
// bonus for magical items
|
||||
if(which_pc.items[i].bonus > 0) {
|
||||
r1 = get_ran(1,1,which_pc.items[i].bonus);
|
||||
if(item.bonus > 0) {
|
||||
r1 = get_ran(1,1,item.bonus);
|
||||
how_much -= r1;
|
||||
how_much -= which_pc.items[i].bonus / 2;
|
||||
how_much -= item.bonus / 2;
|
||||
}
|
||||
if(which_pc.items[i].bonus < 0) {
|
||||
how_much = how_much - which_pc.items[i].bonus;
|
||||
if(item.bonus < 0) {
|
||||
how_much = how_much - item.bonus;
|
||||
}
|
||||
r1 = get_ran(1,1,100);
|
||||
if(r1 < hit_chance[which_pc.skill(eSkill::DEFENSE)] - 20)
|
||||
how_much -= 1;
|
||||
}
|
||||
if(which_pc.items[i].protection > 0) {
|
||||
r1 = get_ran(1,1,which_pc.items[i].protection);
|
||||
if(item.protection > 0) {
|
||||
r1 = get_ran(1,1,item.protection);
|
||||
how_much -= r1;
|
||||
}
|
||||
if(which_pc.items[i].protection < 0) {
|
||||
r1 = get_ran(1,1,-1 * which_pc.items[i].protection);
|
||||
if(item.protection < 0) {
|
||||
r1 = get_ran(1,1,-1 * item.protection);
|
||||
how_much += r1;
|
||||
}
|
||||
}
|
||||
|
@@ -305,29 +305,27 @@ void put_item_screen(short screen_num) {
|
||||
dest_rect.left += 36;
|
||||
dest_rect.top -= 2;
|
||||
|
||||
if(univ.party[pc].items[i_num].variety == eItemType::NO_ITEM) {
|
||||
|
||||
}
|
||||
else {
|
||||
const cPlayer& who = univ.party[pc];
|
||||
const cItem& item = who.items[i_num];
|
||||
|
||||
if(item.variety != eItemType::NO_ITEM) {
|
||||
style.font = FONT_PLAIN;
|
||||
if(univ.party[pc].equip[i_num]) {
|
||||
if(who.equip[i_num]) {
|
||||
style.italic = true;
|
||||
if(univ.party[pc].items[i_num].variety == eItemType::ONE_HANDED || univ.party[pc].items[i_num].variety == eItemType::TWO_HANDED)
|
||||
if(item.variety == eItemType::ONE_HANDED || item.variety == eItemType::TWO_HANDED)
|
||||
style.colour = sf::Color::Magenta;
|
||||
else if((*univ.party[pc].items[i_num].variety).is_armour)
|
||||
else if((*item.variety).is_armour)
|
||||
style.colour = sf::Color::Green;
|
||||
else style.colour = sf::Color::Blue;
|
||||
} else style.colour = sf::Color::Black;
|
||||
|
||||
sout.str("");
|
||||
if(!univ.party[pc].items[i_num].ident)
|
||||
sout << univ.party[pc].items[i_num].name << " ";
|
||||
if(!item.ident)
|
||||
sout << item.name << " ";
|
||||
else { /// Don't place # of charges when Sell button up and space tight
|
||||
sout << univ.party[pc].items[i_num].full_name << ' ';
|
||||
// TODO: Why are bashing weapons excluded from this?
|
||||
if(univ.party[pc].items[i_num].charges > 0 && univ.party[pc].items[i_num].ability != eItemAbil::MESSAGE
|
||||
&& (stat_screen_mode == MODE_INVEN || stat_screen_mode == MODE_SHOP))
|
||||
sout << '(' << int(univ.party[pc].items[i_num].charges) << ')';
|
||||
sout << item.full_name << ' ';
|
||||
if(item.charges > 0 && item.ability != eItemAbil::MESSAGE && (stat_screen_mode == MODE_INVEN || stat_screen_mode == MODE_SHOP))
|
||||
sout << '(' << int(item.charges) << ')';
|
||||
}
|
||||
dest_rect.left -= 2;
|
||||
win_draw_string(item_stats_gworld,dest_rect,sout.str(),eTextMode::WRAP,style);
|
||||
@@ -350,7 +348,7 @@ void put_item_screen(short screen_num) {
|
||||
((is_town()) || (is_out()) || ((is_combat()) && (pc == univ.cur_pc)))) { // place give and drop and use
|
||||
place_item_button(1,i,2,0);
|
||||
place_item_button(2,i,3,0);
|
||||
if(abil_chart[univ.party[pc].items[i_num].ability]) // place use if can
|
||||
if(abil_chart[item.ability]) // place use if can
|
||||
place_item_button(0,i,1,0);
|
||||
}
|
||||
}
|
||||
@@ -375,58 +373,50 @@ void place_buy_button(short position,short pc_num,short item_num) {
|
||||
// TODO: This is now duplicated here and in start_town_mode()
|
||||
short aug_cost[10] = {4,7,10,8, 15,15,10, 0,0,0};
|
||||
|
||||
if(univ.party[pc_num].items[item_num].variety == eItemType::NO_ITEM)
|
||||
const cPlayer& pc = univ.party[pc_num];
|
||||
const cItem& item = pc.items[item_num];
|
||||
|
||||
if(item.variety == eItemType::NO_ITEM)
|
||||
return;
|
||||
|
||||
dest_rect = item_buttons[position][5];
|
||||
|
||||
val_to_place = (univ.party[pc_num].items[item_num].charges > 0) ?
|
||||
univ.party[pc_num].items[item_num].charges * univ.party[pc_num].items[item_num].value :
|
||||
univ.party[pc_num].items[item_num].value;
|
||||
val_to_place = (item.charges > 0) ?
|
||||
item.charges * item.value :
|
||||
item.value;
|
||||
val_to_place = val_to_place / 2;
|
||||
|
||||
switch(stat_screen_mode) {
|
||||
case MODE_IDENTIFY:
|
||||
if(!univ.party[pc_num].items[item_num].ident) {
|
||||
if(!item.ident) {
|
||||
item_area_button_active[position][5] = true;
|
||||
source_rect = button_sources[0];
|
||||
val_to_place = shop_identify_cost;
|
||||
}
|
||||
break;
|
||||
case MODE_SELL_WEAP:
|
||||
if((*univ.party[pc_num].items[item_num].variety).is_weapon &&
|
||||
(!univ.party[pc_num].equip[item_num]) &&
|
||||
(univ.party[pc_num].items[item_num].ident) && (val_to_place > 0) &&
|
||||
(!univ.party[pc_num].items[item_num].unsellable)) {
|
||||
if((*item.variety).is_weapon && !pc.equip[item_num] && item.ident && val_to_place > 0 && !item.unsellable) {
|
||||
item_area_button_active[position][5] = true;
|
||||
source_rect = button_sources[1];
|
||||
}
|
||||
break;
|
||||
case MODE_SELL_ARMOR:
|
||||
if((*univ.party[pc_num].items[item_num].variety).is_armour &&
|
||||
(!univ.party[pc_num].equip[item_num]) &&
|
||||
(univ.party[pc_num].items[item_num].ident) && (val_to_place > 0) &&
|
||||
(!univ.party[pc_num].items[item_num].unsellable)) {
|
||||
if((*item.variety).is_armour && !pc.equip[item_num] && item.ident && val_to_place > 0 && !item.unsellable) {
|
||||
item_area_button_active[position][5] = true;
|
||||
source_rect = button_sources[1];
|
||||
}
|
||||
break;
|
||||
case MODE_SELL_ANY:
|
||||
if((val_to_place > 0) && (univ.party[pc_num].items[item_num].ident) &&
|
||||
(!univ.party[pc_num].equip[item_num]) &&
|
||||
(!univ.party[pc_num].items[item_num].unsellable)) {
|
||||
if(!pc.equip[item_num] && item.ident && val_to_place > 0 && !item.unsellable) {
|
||||
item_area_button_active[position][5] = true;
|
||||
source_rect = button_sources[1];
|
||||
}
|
||||
break;
|
||||
case MODE_ENCHANT:
|
||||
if((univ.party[pc_num].items[item_num].variety == eItemType::ONE_HANDED || univ.party[pc_num].items[item_num].variety == eItemType::TWO_HANDED) &&
|
||||
(univ.party[pc_num].items[item_num].ident) &&
|
||||
univ.party[pc_num].items[item_num].ability == eItemAbil::NONE &&
|
||||
(!univ.party[pc_num].items[item_num].magic)) {
|
||||
if((item.variety == eItemType::ONE_HANDED || item.variety == eItemType::TWO_HANDED) && item.ident && item.ability == eItemAbil::NONE && !item.magic) {
|
||||
item_area_button_active[position][5] = true;
|
||||
source_rect = button_sources[2];
|
||||
val_to_place = max(aug_cost[shop_identify_cost] * 100,univ.party[pc_num].items[item_num].value * (5 + aug_cost[shop_identify_cost]));
|
||||
val_to_place = max(aug_cost[shop_identify_cost] * 100, item.value * (5 + aug_cost[shop_identify_cost]));
|
||||
}
|
||||
break;
|
||||
case MODE_INVEN: case MODE_SHOP:
|
||||
|
@@ -544,7 +544,8 @@ bool cPlayer::give_item(cItem item, int flags) {
|
||||
}
|
||||
|
||||
bool cPlayer::equip_item(int which_item, bool do_print) {
|
||||
if((*items[which_item].variety).equip_count == 0) {
|
||||
const cItem& item = items[which_item];
|
||||
if((*item.variety).equip_count == 0) {
|
||||
if(do_print && print_result)
|
||||
print_result("Equip: Can't equip this item.");
|
||||
return false;
|
||||
@@ -552,13 +553,12 @@ bool cPlayer::equip_item(int which_item, bool do_print) {
|
||||
unsigned short num_this_type = 0, hands_occupied = 0;
|
||||
for(int i = 0; i < items.size(); i++)
|
||||
if(equip[i]) {
|
||||
if(items[i].variety == items[which_item].variety)
|
||||
if(items[i].variety == item.variety)
|
||||
num_this_type++;
|
||||
hands_occupied += (*items[i].variety).num_hands;
|
||||
}
|
||||
|
||||
|
||||
eItemCat equip_item_type = (*items[which_item].variety).exclusion;
|
||||
eItemCat equip_item_type = (*item.variety).exclusion;
|
||||
// Now if missile is already equipped, no more missiles
|
||||
if(equip_item_type != eItemCat::MISC) {
|
||||
for(int i = 0; i < items.size(); i++)
|
||||
@@ -572,11 +572,11 @@ bool cPlayer::equip_item(int which_item, bool do_print) {
|
||||
}
|
||||
|
||||
size_t hands_free = 2 - hands_occupied;
|
||||
if(hands_free < (*items[which_item].variety).num_hands) {
|
||||
if(hands_free < (*item.variety).num_hands) {
|
||||
if(do_print && print_result)
|
||||
print_result("Equip: Not enough free hands");
|
||||
return false;
|
||||
} else if((*items[which_item].variety).equip_count <= num_this_type) {
|
||||
} else if((*item.variety).equip_count <= num_this_type) {
|
||||
if(do_print && print_result)
|
||||
print_result("Equip: Can't equip another");
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user