diff --git a/src/boe.actions.cpp b/src/boe.actions.cpp index d070e687..efd0baa7 100644 --- a/src/boe.actions.cpp +++ b/src/boe.actions.cpp @@ -2197,10 +2197,10 @@ void do_rest(long length, int hp_restore, int mp_restore) { cItem& item = univ.party[i].items[j]; if(item.ability != eItemAbil::OCCASIONAL_STATUS) continue; if(item.abil_data[1] < 0 || item.abil_data[1] > 15) continue; - if(item.magic_use_type < 2) continue; + if(!item.abil_group()) continue; if(get_ran(1,0,5) != 3) continue; int how_much = item.abil_data[0]; - if(item.magic_use_type % 2 == 1) how_much *= -1; + if(item.abil_harms()) how_much *= -1; if(isStatusNegative(eStatus(item.abil_data[1]))) how_much *= -1; univ.party.apply_status(eStatus(item.abil_data[1]), how_much); @@ -2319,10 +2319,10 @@ void increase_age() { cItem& item = univ.party[i].items[j]; if(item.ability != eItemAbil::OCCASIONAL_STATUS) continue; if(item.abil_data[1] < 0 || item.abil_data[1] > 15) continue; - if(item.magic_use_type < 2) continue; + if(!item.abil_group()) continue; if(get_ran(1,0,5) != 3) continue; int how_much = item.abil_data[0]; - if(item.magic_use_type % 2 == 1) how_much *= -1; + if(item.abil_harms()) how_much *= -1; eStatus status = eStatus(item.abil_data[1]); if(isStatusNegative(status)) how_much *= -1; diff --git a/src/boe.combat.cpp b/src/boe.combat.cpp index 36ecf8bc..e27b8d06 100644 --- a/src/boe.combat.cpp +++ b/src/boe.combat.cpp @@ -1898,10 +1898,10 @@ void combat_run_monst() { for(int j = 0; j < 24; j++) { cItem& item = univ.party[i].items[j]; if(item.ability != eItemAbil::OCCASIONAL_STATUS) continue; - if(item.magic_use_type > 1) continue; // Affects whole party, which is handled elsewhere + if(item.abil_group()) continue; // Affects whole party, which is handled elsewhere if(get_ran(1,0,10) != 5) continue; int how_much = item.abil_data[0]; - if(item.magic_use_type % 2 == 1) how_much *= -1; + if(item.abil_harms()) how_much *= -1; eStatus status = eStatus(item.abil_data[1]); if(isStatusNegative(status)) how_much *= -1; diff --git a/src/boe.specials.cpp b/src/boe.specials.cpp index e05545a7..971f05c6 100644 --- a/src/boe.specials.cpp +++ b/src/boe.specials.cpp @@ -542,9 +542,10 @@ void use_spec_item(short item) { void use_item(short pc,short item) { bool take_charge = true,inept_ok = false; - short level,i,j,item_use_code,str,type,r1; + short level,i,j,item_use_code,str,r1; short sp[3] = {}; // Dummy values to pass to run_special; not actually used eStatus status; + eItemUse type; eSpell spell; location user_loc; cCreature *which_m; @@ -619,6 +620,7 @@ void use_item(short pc,short item) { } } if(take_charge) { + cItem& the_item = univ.party[pc].items[item]; std::string name; if(!univ.party[pc].items[item].ident) name = univ.party[pc].items[item].name.c_str(); @@ -640,95 +642,95 @@ void use_item(short pc,short item) { switch(status) { case eStatus::BLESS_CURSE: play_sound(4); - if(type % 2 == 1) { + if(the_item.abil_harms()) { ASB(" You feel awkward."); str = str * -1; }else ASB(" You feel blessed."); - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::HASTE_SLOW: // TODO: Is this the right sound? play_sound(75); - if(type % 2 == 1) { + if(the_item.abil_harms()) { ASB(" You feel sluggish."); str = str * -1; }else ASB(" You feel speedy."); - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::INVULNERABLE: // TODO: Is this the right sound? play_sound(68); - if(type % 2 == 1) { + if(the_item.abil_harms()) { ASB(" You feel odd."); str = str * -1; }else ASB(" You feel protected."); - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::MAGIC_RESISTANCE: // TODO: Is this the right sound? play_sound(51); - if(type % 2 == 1) { + if(the_item.abil_harms()) { ASB(" You feel odd."); str = str * -1; }else ASB(" You feel protected."); - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::WEBS: - if(type % 2 == 1) + if(the_item.abil_harms()) ASB(" You feel sticky."); else { ASB(" Your skin tingles."); str = str * -1; } - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::INVISIBLE: // TODO: Is this the right sound? play_sound(43); - if(type % 2 == 1) { + if(the_item.abil_harms()) { ASB(" You feel exposed."); str = str * -1; }else ASB(" You feel obscure."); - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::MARTYRS_SHIELD: // TODO: Is this the right sound? play_sound(43); - if(type % 2 == 1) { + if(the_item.abil_harms()) { ASB(" You feel dull."); str = str * -1; }else ASB(" You start to glow slightly."); - if(type > 1) + if(the_item.abil_group()) univ.party.apply_status(status,str); else univ.party[pc].apply_status(status,str); break; case eStatus::POISON: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel better."); univ.party[pc].cure(str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel ill."); univ.party[pc].poison(str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel better."); univ.party.cure(str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel ill."); univ.party.poison(str); break; @@ -736,19 +738,19 @@ void use_item(short pc,short item) { break; case eStatus::DISEASE: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel healthy."); univ.party[pc].apply_status(eStatus::DISEASE,-1 * str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel sick."); univ.party[pc].disease(str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel healthy."); univ.party.apply_status(eStatus::DISEASE,-1 * str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel sick."); univ.party.disease(str); break; @@ -756,19 +758,19 @@ void use_item(short pc,short item) { break; case eStatus::DUMB: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel clear headed."); univ.party[pc].apply_status(eStatus::DUMB,-1 * str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel confused."); univ.party[pc].dumbfound(str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel clear headed."); univ.party.apply_status(eStatus::DUMB,-1 * str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel confused."); univ.party.dumbfound(str); break; @@ -776,19 +778,19 @@ void use_item(short pc,short item) { break; case eStatus::ASLEEP: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel alert."); univ.party[pc].apply_status(eStatus::ASLEEP,-1 * str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel very tired."); univ.party[pc].sleep(eStatus::ASLEEP,str + 1,200); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel alert."); univ.party.apply_status(eStatus::ASLEEP,-1 * str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel very tired."); univ.party.sleep(eStatus::ASLEEP,str + 1,200); break; @@ -796,19 +798,19 @@ void use_item(short pc,short item) { break; case eStatus::PARALYZED: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You find it easier to move."); univ.party[pc].apply_status(eStatus::PARALYZED,-1 * str * 100); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel very stiff."); univ.party[pc].sleep(eStatus::PARALYZED,str * 20 + 10,200); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all find it easier to move."); univ.party.apply_status(eStatus::PARALYZED,-1 * str * 100); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel very stiff."); univ.party.sleep(eStatus::PARALYZED,str * 20 + 10,200); break; @@ -816,19 +818,19 @@ void use_item(short pc,short item) { break; case eStatus::ACID: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" Your skin tingles pleasantly."); univ.party[pc].apply_status(eStatus::ACID,-1 * str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" Your skin burns!"); univ.party[pc].acid(str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all tingle pleasantly."); univ.party.apply_status(eStatus::ACID,-1 * str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" Everyone's skin burns!"); univ.party.acid(str); break; @@ -837,24 +839,24 @@ void use_item(short pc,short item) { } case eItemAbil::BLISS_DOOM: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel wonderful!"); univ.party[pc].heal(str * 20); univ.party[pc].apply_status(eStatus::BLESS_CURSE,str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel terrible."); drain_pc(pc,str * 5); damage_pc(pc,20 * str,eDamageType::UNBLOCKABLE,eRace::HUMAN,0); univ.party[pc].disease(2 * str); univ.party[pc].dumbfound(2 * str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" Everyone feels wonderful!"); univ.party.heal(str*20); univ.party.apply_status(eStatus::BLESS_CURSE,str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel terrible."); for(i = 0; i < 6; i++) { drain_pc(i,str * 5); @@ -867,19 +869,19 @@ void use_item(short pc,short item) { break; case eItemAbil::AFFECT_EXPERIENCE: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel much smarter."); award_xp(pc,str * 5); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel forgetful."); drain_pc(pc,str * 5); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel much smarter."); award_party_xp(str * 5); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel forgetful."); for(i = 0; i < 6; i++) drain_pc(i,str * 5); @@ -890,20 +892,20 @@ void use_item(short pc,short item) { // TODO: Is this the right sound? play_sound(68); switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel much smarter."); univ.party[pc].skill_pts += str; break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel forgetful."); univ.party[pc].skill_pts = max(0,univ.party[pc].skill_pts - str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel much smarter."); for(i = 0; i < 6; i++) univ.party[i].skill_pts += str; break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel forgetful."); for(i = 0; i < 6; i++) univ.party[i].skill_pts = max(0,univ.party[i].skill_pts - str); @@ -912,19 +914,19 @@ void use_item(short pc,short item) { break; case eItemAbil::AFFECT_HEALTH: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel better."); univ.party[pc].heal(str * 20); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel sick."); damage_pc(pc,20 * str,eDamageType::UNBLOCKABLE,eRace::HUMAN,0); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel better."); univ.party.heal(str * 20); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel sick."); hit_party(20 * str,eDamageType::UNBLOCKABLE); break; @@ -932,19 +934,19 @@ void use_item(short pc,short item) { break; case eItemAbil::AFFECT_SPELL_POINTS: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel energized."); univ.party[pc].restore_sp(str * 5); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel drained."); univ.party[pc].cur_sp = max(0,univ.party[pc].cur_sp - str * 5); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel energized."); univ.party.restore_sp(str * 5); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel drained."); for(i = 0; i < 6; i++) univ.party[i].cur_sp = max(0,univ.party[i].cur_sp - str * 5); @@ -952,7 +954,7 @@ void use_item(short pc,short item) { } break; case eItemAbil::LIGHT: - if(type % 2 == 0) { + if(!the_item.abil_harms()) { ASB(" You have more light."); increase_light(50 * str); } else { @@ -961,10 +963,33 @@ void use_item(short pc,short item) { } break; case eItemAbil::AFFECT_PARTY_STATUS: - switch(ePartyStatus(univ.party[pc].items[item].abil_data[1])) { + if(the_item.abil_harms()) { + ePartyStatus status = ePartyStatus(the_item.abil_data[1]); + i = univ.party.status[status]; + switch(status) { + case ePartyStatus::STEALTH: ASB(" Your footsteps become louder."); str *= 5; break; + case ePartyStatus::FIREWALK: ASB(" The chill recedes from your feet."); str *= 2; break; + case ePartyStatus::DETECT_LIFE: ASB(" Your vision of life becomes blurry."); break; + case ePartyStatus::FLIGHT: + if(i <= str) { + if(blocksMove(univ.scenario.ter_types[univ.out[univ.party.p_loc.x][univ.party.p_loc.y]].blockage)) { + add_string_to_buf(" You plummet to your deaths."); + slay_party(eMainStatus::DEAD); + print_buf(); + pause(150); + } else if(i > 1) { + add_string_to_buf(" You plummet to the ground."); + hit_party(get_ran(i,1,12), eDamageType::UNBLOCKABLE); + } else add_string_to_buf(" You land safely."); + } else add_string_to_buf(" You start to descend."); + break; + } + if(str > i) str = i; + str *= -1; + } else switch(ePartyStatus(the_item.abil_data[1])) { case ePartyStatus::STEALTH: ASB(" Your footsteps become quieter."); str *= 5; break; case ePartyStatus::FIREWALK: ASB(" You feel chilly."); str *= 2; break; - case ePartyStatus::DETECT_LIFE: ASB(" You detect life."); break; + case ePartyStatus::DETECT_LIFE: ASB(" You detect life."); break; case ePartyStatus::FLIGHT: if(univ.party.status[ePartyStatus::FLIGHT] > 0) { add_string_to_buf(" Not while already flying."); @@ -982,22 +1007,22 @@ void use_item(short pc,short item) { break; case eItemAbil::HEALTH_POISON: switch(type) { - case 0: + case eItemUse::HELP_ONE: ASB(" You feel wonderful."); univ.party[pc].heal(str*25); univ.party[pc].cure(str); break; - case 1: + case eItemUse::HARM_ONE: ASB(" You feel terrible."); damage_pc(pc, str*25, eDamageType::UNBLOCKABLE, eRace::UNKNOWN, 0); univ.party[pc].poison(str); break; - case 2: + case eItemUse::HELP_ALL: ASB(" You all feel wonderful."); univ.party.heal(str*25); univ.party.cure(str); break; - case 3: + case eItemUse::HARM_ALL: ASB(" You all feel terrible."); hit_party(str*25, eDamageType::UNBLOCKABLE); univ.party.poison(str); diff --git a/src/classes/item.cpp b/src/classes/item.cpp index c3c2cf34..ec09c0c6 100644 --- a/src/classes/item.cpp +++ b/src/classes/item.cpp @@ -61,6 +61,18 @@ short cItem::item_weight() const { return w; } +bool cItem::abil_harms() const { + if(magic_use_type == eItemUse::HARM_ONE || magic_use_type == eItemUse::HARM_ALL) + return true; + return false; +} + +bool cItem::abil_group() const { + if(magic_use_type == eItemUse::HELP_ALL || magic_use_type == eItemUse::HARM_ALL) + return true; + return false; +} + cItem::cItem(){ variety = eItemType::NO_ITEM; item_level = 0; @@ -69,7 +81,7 @@ cItem::cItem(){ protection = 0; charges = 0; weap_type = eSkill::INVALID; - magic_use_type = 0; + magic_use_type = eItemUse::HELP_ONE; graphic_num = 0; ability = eItemAbil::NONE; abil_data[0] = 0; @@ -80,34 +92,18 @@ cItem::cItem(){ special_class = 0; item_loc.x = 0; item_loc.y = 0; - full_name = ""; - name = ""; treas_class = 0; ident = property = magic = contained = false; cursed = concealed = enchanted = unsellable = false; } -cItem::cItem(long preset){ - ability = eItemAbil::NONE; - abil_data[0] = 0; - type_flag = 0; - is_special = 0; - special_class = 0; - item_loc.x = 0; - item_loc.y = 0; - treas_class = 0; - ident = property = magic = contained = false; - cursed = concealed = enchanted = unsellable = false; +cItem::cItem(long preset) : cItem() { switch(preset){ case 'nife': variety = eItemType::ONE_HANDED; item_level = 4; - awkward = 0; bonus = 1; - protection = 0; - charges = 0; weap_type = eSkill::EDGED_WEAPONS; - magic_use_type = 0; graphic_num = 55; value = 2; weight = 7; @@ -119,11 +115,6 @@ cItem::cItem(long preset){ variety = eItemType::SHIELD; item_level = 1; awkward = 1; - bonus = 0; - protection = 0; - charges = 0; - weap_type = eSkill::INVALID; - magic_use_type = 0; graphic_num = 75; value = 2; weight = 20; @@ -133,13 +124,7 @@ cItem::cItem(long preset){ break; case 'bow ': variety = eItemType::BOW; - item_level = 0; - awkward = 0; - bonus = 0; - protection = 0; - charges = 0; weap_type = eSkill::ARCHERY; - magic_use_type = 0; graphic_num = 10; value = 15; weight = 20; @@ -150,12 +135,7 @@ cItem::cItem(long preset){ case 'arrw': variety = eItemType::ARROW; item_level = 12; - awkward = 0; - bonus = 0; - protection = 0; charges = 12; - weap_type = eSkill::INVALID; - magic_use_type = 0; graphic_num = 57; missile = 3; value = 1; @@ -167,12 +147,7 @@ cItem::cItem(long preset){ case 'pole': variety = eItemType::TWO_HANDED; item_level = 9; - awkward = 0; - bonus = 0; - protection = 0; - charges = 0; weap_type = eSkill::POLE_WEAPONS; - magic_use_type = 0; graphic_num = 4; value = 10; weight = 20; @@ -183,12 +158,7 @@ cItem::cItem(long preset){ case 'helm': variety = eItemType::HELM; item_level = 1; - awkward = 0; - bonus = 0; - protection = 0; - charges = 0; weap_type = eSkill::INVALID; - magic_use_type = 0; graphic_num = 76; value = 6; weight = 15; @@ -199,12 +169,9 @@ cItem::cItem(long preset){ case 'rdsk': variety = eItemType::THROWN_MISSILE; item_level = 9; - awkward = 0; bonus = 1; - protection = 0; charges = 8; weap_type = eSkill::THROWN_MISSILES; - magic_use_type = 0; graphic_num = 59; missile = 7; value = 10; @@ -215,51 +182,21 @@ cItem::cItem(long preset){ break; case 'food': variety = eItemType::FOOD; - item_level = 0; - awkward = 0; - bonus = 0; - protection = 0; - charges = 0; - weap_type = eSkill::INVALID; - magic_use_type = 0; graphic_num = 72; - value = 0; - weight = 0; full_name = "Food"; name = "Food"; - ident = false; break; case 'spel': variety = eItemType::NON_USE_OBJECT; - item_level = 0; - awkward = 0; - bonus = 0; - protection = 0; - charges = 0; - weap_type = eSkill::INVALID; - magic_use_type = 0; graphic_num = 63; - value = 0; - weight = 0; - full_name = ""; - name = ""; - ident = false; break; case 'alch': variety = eItemType::POTION; - item_level = 0; - awkward = 0; - bonus = 0; - protection = 0; charges = 1; - weap_type = eSkill::INVALID; - magic_use_type = 0; graphic_num = 60; - value = 0; weight = 8; full_name = "Potion"; name = "Potion"; - ident = false; magic = true; break; } @@ -318,7 +255,7 @@ cItem::cItem(eAlchemy recipe) : cItem('alch') { ability = eItemAbil::AFFECT_STATUS; abil_data[0] = 4; abil_data[1] = int(eStatus::DISEASE); - magic_use_type = 2; + magic_use_type = eItemUse::HELP_ALL; break; case eAlchemy::POWER_WEAK: value = 100; @@ -428,7 +365,6 @@ void cItem::enchant_weapon(eEnchant enchant_type,short new_val) { ability = eItemAbil::AFFECT_STATUS; abil_data[0] = 5; abil_data[1] = int(eStatus::BLESS_CURSE); - magic_use_type = 0; charges = 8; break; } @@ -453,7 +389,7 @@ void cItem::append(legacy::item_record_type& old){ weap_type = eSkill::ARCHERY; else if(variety == eItemType::THROWN_MISSILE) weap_type = eSkill::THROWN_MISSILES; - magic_use_type = old.magic_use_type; + magic_use_type = eItemUse(old.magic_use_type); graphic_num = old.graphic_num; if(graphic_num >= 150) // custom item graphic graphic_num += 850; @@ -587,12 +523,12 @@ void cItem::append(legacy::item_record_type& old){ case 46: ability = eItemAbil::OCCASIONAL_STATUS; abil_data[1] = int(eStatus::BLESS_CURSE); - magic_use_type = 0; + magic_use_type = eItemUse::HELP_ONE; break; case 47: ability = eItemAbil::OCCASIONAL_STATUS; abil_data[1] = int(eStatus::HASTE_SLOW); - magic_use_type = 0; + magic_use_type = eItemUse::HELP_ONE; break; case 48: ability = eItemAbil::LIFE_SAVING; @@ -609,7 +545,7 @@ void cItem::append(legacy::item_record_type& old){ case 52: ability = eItemAbil::OCCASIONAL_STATUS; abil_data[1] = int(eStatus::DISEASE); - magic_use_type = 3; + magic_use_type = eItemUse::HARM_ALL; break; case 53: ability = eItemAbil::WILL; @@ -705,10 +641,10 @@ void cItem::append(legacy::item_record_type& old){ break; case 84: ability = eItemAbil::BLISS_DOOM; - if(magic_use_type == 1) - magic_use_type = 0; - else if(magic_use_type == 3) - magic_use_type = 2; + if(magic_use_type == eItemUse::HARM_ONE) + magic_use_type = eItemUse::HELP_ONE; + else if(magic_use_type == eItemUse::HARM_ALL) + magic_use_type = eItemUse::HELP_ALL; break; case 85: ability = eItemAbil::AFFECT_EXPERIENCE; @@ -724,33 +660,36 @@ void cItem::append(legacy::item_record_type& old){ break; case 89: ability = eItemAbil::BLISS_DOOM; - if(magic_use_type == 0) - magic_use_type = 1; - else if(magic_use_type == 2) - magic_use_type = 3; + if(magic_use_type == eItemUse::HELP_ONE) + magic_use_type = eItemUse::HARM_ONE; + else if(magic_use_type == eItemUse::HELP_ALL) + magic_use_type = eItemUse::HARM_ALL; break; case 90: ability = eItemAbil::LIGHT; - magic_use_type = 2; + magic_use_type = eItemUse::HELP_ALL; break; case 91: ability = eItemAbil::AFFECT_PARTY_STATUS; abil_data[1] = int(ePartyStatus::STEALTH); + magic_use_type = eItemUse::HELP_ALL; break; case 92: ability = eItemAbil::AFFECT_PARTY_STATUS; abil_data[1] = int(ePartyStatus::FIREWALK); + magic_use_type = eItemUse::HELP_ALL; break; case 93: ability = eItemAbil::AFFECT_PARTY_STATUS; abil_data[1] = int(ePartyStatus::FLIGHT); + magic_use_type = eItemUse::HELP_ALL; break; case 94: ability = eItemAbil::HEALTH_POISON; - if(magic_use_type == 1) - magic_use_type = 0; - else if(magic_use_type == 3) - magic_use_type = 2; + if(magic_use_type == eItemUse::HARM_ONE) + magic_use_type = eItemUse::HELP_ONE; + else if(magic_use_type == eItemUse::HARM_ALL) + magic_use_type = eItemUse::HELP_ALL; break; case 95: ability = eItemAbil::CALL_SPECIAL; @@ -1001,8 +940,8 @@ void cItem::append(legacy::item_record_type& old){ } std::string cItem::getAbilName() const { - bool harmful = magic_use_type % 2; - bool party = magic_use_type >= 2; + bool harmful = abil_harms(); + bool party = abil_group(); std::ostringstream sout; switch(ability) { case eItemAbil::NONE: sout << "No ability"; break; @@ -1246,7 +1185,7 @@ std::string cItem::getAbilName() const { sout << "Spell: " << (*cSpell::fromNum(abil_data[1])).name(); break; case eItemAbil::BLISS_DOOM: - if(magic_use_type >= 2) + if(party) sout << "Party "; sout << (harmful ? "Doom" : "Bliss"); break; @@ -1422,6 +1361,16 @@ std::ostream& operator << (std::ostream& out, eItemType e){ return out; } +std::ostream& operator << (std::ostream& out, eItemUse e){ + switch(e) { + case eItemUse::HELP_ONE: out << "help-one"; break; + case eItemUse::HELP_ALL: out << "harm-one"; break; + case eItemUse::HARM_ONE: out << "help-all"; break; + case eItemUse::HARM_ALL: out << "harm-all"; break; + } + return out; +} + std::ostream& operator << (std::ostream& out, eItemAbil e){ return out << (int) e; } @@ -1542,6 +1491,27 @@ std::istream& operator >> (std::istream& in, eItemType& e){ return in; } +std::istream& operator >> (std::istream& in, eItemUse& e){ + std::string key; + in >> key; + e = eItemUse::HELP_ONE; + try { + int i = boost::lexical_cast(key); + if(i > 0 && i < 4) + e = (eItemUse) i; + } catch(boost::bad_lexical_cast) { + if(key == "help-on") + e = eItemUse::HELP_ONE; + else if(key == "harm-one") + e = eItemUse::HARM_ONE; + else if(key == "help-all") + e = eItemUse::HELP_ALL; + else if(key == "harm-all") + e = eItemUse::HARM_ALL; + } + return in; +} + // TODO: Perhaps this should understand symbolic names as well? std::istream& operator >> (std::istream& in, eItemAbil& e){ int i; diff --git a/src/classes/item.h b/src/classes/item.h index 4f8bbfe0..31f96cab 100644 --- a/src/classes/item.h +++ b/src/classes/item.h @@ -17,6 +17,7 @@ namespace legacy { struct item_record_type; }; +enum class eItemUse {HELP_ONE, HARM_ONE, HELP_ALL, HARM_ALL}; enum class eEnchant {PLUS_ONE, PLUS_TWO, PLUS_THREE, SHOOT_FLAME, FLAMING, PLUS_FIVE, BLESSED}; class cItem { @@ -28,7 +29,7 @@ public: int protection; int charges; eSkill weap_type; - int magic_use_type; + eItemUse magic_use_type; unsigned short graphic_num; eItemAbil ability; unsigned int abil_data[2]; @@ -56,6 +57,8 @@ public: std::string getAbilName() const; void enchant_weapon(eEnchant enchant_type, short new_val); + bool abil_harms() const; + bool abil_group() const; cItem(); explicit cItem(long preset); @@ -71,6 +74,8 @@ std::istream& operator >> (std::istream& in, eItemType& e); std::istream& operator >> (std::istream& in, eItemAbil& e); std::ostream& operator << (std::ostream& out, eSkill e); std::istream& operator >> (std::istream& in, eSkill& e); +std::ostream& operator << (std::ostream& out, eItemUse e); +std::istream& operator >> (std::istream& in, eItemUse& e); class cSpecItem { public: diff --git a/src/scenedit/scen.core.cpp b/src/scenedit/scen.core.cpp index 499e1848..3b36169e 100644 --- a/src/scenedit/scen.core.cpp +++ b/src/scenedit/scen.core.cpp @@ -1571,7 +1571,7 @@ static void put_item_abils_in_dlog(cDialog& me, cItem& item, short which) { me["abilname"].setText("No ability"); else me["abilname"].setText(get_str("item-abilities", int(item.ability))); - dynamic_cast(me["use-type"]).setSelected("use" + std::to_string(item.magic_use_type)); + dynamic_cast(me["use-type"]).setSelected("use" + std::to_string(int(item.magic_use_type))); dynamic_cast(me["treasure"]).setSelected("type" + std::to_string(item.treas_class)); me["str1"].setTextToNum(item.abil_data[0]); me["str2"].setTextToNum(item.abil_data[1]); @@ -1640,7 +1640,7 @@ static void put_item_abils_in_dlog(cDialog& me, cItem& item, short which) { } static void save_item_abils(cDialog& me, cItem& item) { - item.magic_use_type = boost::lexical_cast(dynamic_cast(me["use-type"]).getSelected().substr(3)); + item.magic_use_type = boost::lexical_cast(dynamic_cast(me["use-type"]).getSelected().substr(3)); item.treas_class = boost::lexical_cast(dynamic_cast(me["treasure"]).getSelected().substr(4)); item.abil_data[0] = me["str1"].getTextAsNum(); item.abil_data[1] = me["str2"].getTextAsNum();