diff options
-rw-r--r-- | crawl-ref/source/describe.cc | 203 | ||||
-rw-r--r-- | crawl-ref/source/it_use2.cc | 9 | ||||
-rw-r--r-- | crawl-ref/source/item_use.cc | 58 | ||||
-rw-r--r-- | crawl-ref/source/item_use.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/randart.cc | 95 | ||||
-rw-r--r-- | crawl-ref/source/randart.h | 12 |
6 files changed, 259 insertions, 120 deletions
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 4622e7907f..1e09d0d758 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -162,162 +162,184 @@ void print_description( const std::string &d ) //--------------------------------------------------------------- static void randart_descrip( std::string &description, const item_def &item ) { +#define known_proprt(prop) (proprt[(prop)] && known[(prop)]) + unsigned int old_length = description.length(); - randart_properties_t proprt; - randart_wpn_properties( item, proprt ); + randart_properties_t proprt; + randart_known_props_t known; + randart_wpn_properties( item, proprt, known ); - if (proprt[ RAP_AC ]) + if (known_proprt( RAP_AC )) { description += "$It affects your AC ("; append_value(description, proprt[ RAP_AC ], true); description += ")."; } - if (proprt[ RAP_EVASION ]) + if (known_proprt( RAP_EVASION )) { description += "$It affects your evasion ("; append_value(description, proprt[ RAP_EVASION ], true); description += ")."; } - if (proprt[ RAP_STRENGTH ]) + if (known_proprt( RAP_STRENGTH )) { description += "$It affects your strength ("; append_value(description, proprt[ RAP_STRENGTH ], true); description += ")."; } - if (proprt[ RAP_INTELLIGENCE ]) + if (known_proprt( RAP_INTELLIGENCE )) { description += "$It affects your intelligence ("; append_value(description, proprt[ RAP_INTELLIGENCE ], true); description += ")."; } - if (proprt[ RAP_DEXTERITY ]) + if (known_proprt( RAP_DEXTERITY )) { description += "$It affects your dexterity ("; append_value(description, proprt[ RAP_DEXTERITY ], true); description += ")."; } - if (proprt[ RAP_ACCURACY ]) + if (known_proprt( RAP_ACCURACY )) { description += "$It affects your accuracy ("; append_value(description, proprt[ RAP_ACCURACY ], true); description += ")."; } - if (proprt[ RAP_DAMAGE ]) + if (known_proprt( RAP_DAMAGE )) { description += "$It affects your damage-dealing abilities ("; append_value(description, proprt[ RAP_DAMAGE ], true); description += ")."; } - if (proprt[ RAP_FIRE ] < -2) - description += "$It makes you extremely vulnerable to fire. "; - else if (proprt[ RAP_FIRE ] == -2) - description += "$It makes you very vulnerable to fire. "; - else if (proprt[ RAP_FIRE ] == -1) - description += "$It makes you vulnerable to fire. "; - else if (proprt[ RAP_FIRE ] == 1) - description += "$It protects you from fire. "; - else if (proprt[ RAP_FIRE ] == 2) - description += "$It greatly protects you from fire. "; - else if (proprt[ RAP_FIRE ] > 2) - description += "$It renders you almost immune to fire. "; - - if (proprt[ RAP_COLD ] < -2) - description += "$It makes you extremely vulnerable to cold. "; - else if (proprt[ RAP_COLD ] == -2) - description += "$It makes you very vulnerable to cold. "; - else if (proprt[ RAP_COLD ] == -1) - description += "$It makes you vulnerable to cold. "; - else if (proprt[ RAP_COLD ] == 1) - description += "$It protects you from cold. "; - else if (proprt[ RAP_COLD ] == 2) - description += "$It greatly protects you from cold. "; - else if (proprt[ RAP_COLD ] > 2) - description += "$It renders you almost immune to cold. "; - - if (proprt[ RAP_ELECTRICITY ]) + if (known_proprt( RAP_FIRE )) + { + if (proprt[ RAP_FIRE ] < -2) + description += "$It makes you extremely vulnerable to fire. "; + else if (proprt[ RAP_FIRE ] == -2) + description += "$It makes you very vulnerable to fire. "; + else if (proprt[ RAP_FIRE ] == -1) + description += "$It makes you vulnerable to fire. "; + else if (proprt[ RAP_FIRE ] == 1) + description += "$It protects you from fire. "; + else if (proprt[ RAP_FIRE ] == 2) + description += "$It greatly protects you from fire. "; + else if (proprt[ RAP_FIRE ] > 2) + description += "$It renders you almost immune to fire. "; + } + + if (known_proprt( RAP_COLD )) + { + if (proprt[ RAP_COLD ] < -2) + description += "$It makes you extremely vulnerable to cold. "; + else if (proprt[ RAP_COLD ] == -2) + description += "$It makes you very vulnerable to cold. "; + else if (proprt[ RAP_COLD ] == -1) + description += "$It makes you vulnerable to cold. "; + else if (proprt[ RAP_COLD ] == 1) + description += "$It protects you from cold. "; + else if (proprt[ RAP_COLD ] == 2) + description += "$It greatly protects you from cold. "; + else if (proprt[ RAP_COLD ] > 2) + description += "$It renders you almost immune to cold. "; + } + + if (known_proprt( RAP_ELECTRICITY )) description += "$It insulates you from electricity. "; - if (proprt[ RAP_POISON ]) + if (known_proprt( RAP_POISON )) description += "$It protects you from poison. "; - if (proprt[ RAP_NEGATIVE_ENERGY ] == 1) - description += "$It partially protects you from negative energy. "; - else if (proprt[ RAP_NEGATIVE_ENERGY ] == 2) - description += "$It protects you from negative energy. "; - else if (proprt[ RAP_NEGATIVE_ENERGY ] > 2) - description += "$It renders you almost immune to negative energy. "; + if (known_proprt( RAP_NEGATIVE_ENERGY )) + { + if (proprt[ RAP_NEGATIVE_ENERGY ] == 1) + description += "$It partially protects you from negative energy. "; + else if (proprt[ RAP_NEGATIVE_ENERGY ] == 2) + description += "$It protects you from negative energy. "; + else if (proprt[ RAP_NEGATIVE_ENERGY ] > 2) + description += "$It renders you almost immune to " + "negative energy. "; + } - if (proprt[ RAP_MAGIC ]) + if (known_proprt( RAP_MAGIC )) description += "$It increases your resistance to enchantments. "; - if (proprt[ RAP_STEALTH ] < 0) + if (known_proprt( RAP_STEALTH )) { - if (proprt[ RAP_STEALTH ] < -20) - description += "$It makes you much less stealthy. "; - else - description += "$It makes you less stealthy. "; - } - else if (proprt[ RAP_STEALTH ] > 0) - { - if (proprt[ RAP_STEALTH ] > 20) - description += "$It makes you much more stealthy. "; - else - description += "$It makes you more stealthy. "; + if (proprt[ RAP_STEALTH ] < 0) + { + if (proprt[ RAP_STEALTH ] < -20) + description += "$It makes you much less stealthy. "; + else + description += "$It makes you less stealthy. "; + } + else if (proprt[ RAP_STEALTH ] > 0) + { + if (proprt[ RAP_STEALTH ] > 20) + description += "$It makes you much more stealthy. "; + else + description += "$It makes you more stealthy. "; + } } - if (proprt[ RAP_EYESIGHT ]) + if (known_proprt( RAP_EYESIGHT )) description += "$It enhances your eyesight. "; - if (proprt[ RAP_INVISIBLE ]) + if (known_proprt( RAP_INVISIBLE )) description += "$It lets you turn invisible. "; - if (proprt[ RAP_LEVITATE ]) + if (known_proprt( RAP_LEVITATE )) description += "$It lets you levitate. "; - if (proprt[ RAP_BLINK ]) + if (known_proprt( RAP_BLINK )) description += "$It lets you blink. "; - if (proprt[ RAP_CAN_TELEPORT ]) + if (known_proprt( RAP_CAN_TELEPORT )) description += "$It lets you teleport. "; - if (proprt[ RAP_BERSERK ]) + if (known_proprt( RAP_BERSERK )) description += "$It lets you go berserk. "; - if (proprt[ RAP_MAPPING ]) + if (known_proprt( RAP_MAPPING )) description += "$It lets you sense your surroundings. "; - if (proprt[ RAP_NOISES ]) + if (known_proprt( RAP_NOISES )) description += "$It makes noises. "; - if (proprt[ RAP_PREVENT_SPELLCASTING ]) + if (known_proprt( RAP_PREVENT_SPELLCASTING )) description += "$It prevents spellcasting. "; - if (proprt[ RAP_CAUSE_TELEPORTATION ]) + if (known_proprt( RAP_CAUSE_TELEPORTATION )) description += "$It causes teleportation. "; - if (proprt[ RAP_PREVENT_TELEPORTATION ]) + if (known_proprt( RAP_PREVENT_TELEPORTATION )) description += "$It prevents most forms of teleportation. "; - if (proprt[ RAP_ANGRY ]) + if (known_proprt( RAP_ANGRY )) description += "$It makes you angry. "; - if (proprt[ RAP_METABOLISM ] >= 3) - description += "$It greatly speeds your metabolism. "; - else if (proprt[ RAP_METABOLISM ]) - description += "$It speeds your metabolism. "; + if (known_proprt( RAP_METABOLISM )) + { + if (proprt[ RAP_METABOLISM ] >= 3) + description += "$It greatly speeds your metabolism. "; + else if (proprt[ RAP_METABOLISM ]) + description += "$It speeds your metabolism. "; + } - if (proprt[ RAP_MUTAGENIC ] > 3) - description += "$It glows with mutagenic radiation."; - else if (proprt[ RAP_MUTAGENIC ]) - description += "$It emits mutagenic radiation."; + if (known_proprt( RAP_MUTAGENIC )) + { + if (proprt[ RAP_MUTAGENIC ] > 3) + description += "$It glows with mutagenic radiation."; + else if (proprt[ RAP_MUTAGENIC ]) + description += "$It emits mutagenic radiation."; + } if (old_length != description.length()) description += "$"; @@ -331,6 +353,7 @@ static void randart_descrip( std::string &description, const item_def &item ) description += "$"; } } +#undef known_proprt } static const char *trap_names[] = @@ -1196,15 +1219,13 @@ static std::string describe_weapon( const item_def &item, bool verbose) if (is_random_artefact( item )) { - if (item_ident( item, ISFLAG_KNOW_PROPERTIES )) - { - unsigned int old_length = description.length(); - randart_descrip( description, item ); + unsigned int old_length = description.length(); + randart_descrip( description, item ); - if (description.length() == old_length) - description += "$"; - } - else if (item_type_known(item)) + if (description.length() == old_length) + description += "$"; + else if (!item_ident( item, ISFLAG_KNOW_PROPERTIES ) + && item_type_known(item)) { description += "$This weapon may have some hidden properties.$"; } @@ -1793,10 +1814,12 @@ static std::string describe_armour( const item_def &item, bool verbose ) if (is_random_artefact( item )) { - if (item_ident( item, ISFLAG_KNOW_PROPERTIES )) - randart_descrip( description, item ); - else if (item_type_known(item)) + randart_descrip( description, item ); + if (!item_ident( item, ISFLAG_KNOW_PROPERTIES ) + && item_type_known(item)) + { description += "$This armour may have some hidden properties.$"; + } } else { @@ -2753,9 +2776,9 @@ static std::string describe_jewellery( const item_def &item, bool verbose) // randart properties if (is_random_artefact( item )) { - if (item_ident( item, ISFLAG_KNOW_PROPERTIES )) - randart_descrip( description, item ); - else if (item_type_known(item)) + randart_descrip( description, item ); + if (!item_ident( item, ISFLAG_KNOW_PROPERTIES ) + && item_type_known(item)) { if (item.sub_type >= AMU_RAGE) description += "$This amulet may have hidden properties.$"; diff --git a/crawl-ref/source/it_use2.cc b/crawl-ref/source/it_use2.cc index 8f55fe42d8..832e7bfe2a 100644 --- a/crawl-ref/source/it_use2.cc +++ b/crawl-ref/source/it_use2.cc @@ -601,15 +601,14 @@ void unuse_randart(const item_def &item) { ASSERT( is_random_artefact( item ) ); - const bool ident = fully_identified(item); - randart_properties_t proprt; - randart_wpn_properties( item, proprt ); + randart_known_props_t known; + randart_wpn_properties( item, proprt, known ); if (proprt[RAP_AC]) { you.redraw_armour_class = 1; - if (!ident) + if (!known[RAP_AC]) { mprf("You feel less %s.", proprt[RAP_AC] > 0? "well-protected" : "vulnerable"); @@ -619,7 +618,7 @@ void unuse_randart(const item_def &item) if (proprt[RAP_EVASION]) { you.redraw_evasion = 1; - if (!ident) + if (!known[RAP_EVASION]) { mprf("You feel less %s.", proprt[RAP_EVASION] > 0? "nimble" : "awkward"); diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index aeca7119d9..ea900bd501 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -3945,35 +3945,39 @@ void use_randart(unsigned char item_wield_2) use_randart( you.inv[ item_wield_2 ] ); } -void use_randart(const item_def &item) +void use_randart(item_def &item) { +#define unknown_proprt(prop) (proprt[(prop)] && !known[(prop)]) + ASSERT( is_random_artefact( item ) ); const bool alreadyknown = item_type_known(item); const bool dangerous = player_in_a_dangerous_place(); - const bool ident = fully_identified(item); - randart_properties_t proprt; - randart_wpn_properties( item, proprt ); + randart_properties_t proprt; + randart_known_props_t known; + randart_wpn_properties( item, proprt, known ); - // Give messages for stat changes, possibly only if !identified + // Only give property messages for previously unknown properties. if (proprt[RAP_AC]) { you.redraw_armour_class = 1; - if (!ident) + if (!known[RAP_AC]) { mprf("You feel %s.", proprt[RAP_AC] > 0? "well-protected" : "more vulnerable"); + randart_wpn_learn_prop(item, RAP_AC); } } if (proprt[RAP_EVASION]) { you.redraw_evasion = 1; - if (!ident) + if (!known[RAP_EVASION]) { mprf("You feel somewhat %s.", proprt[RAP_EVASION] > 0? "nimbler" : "more awkward"); + randart_wpn_learn_prop(item, RAP_EVASION); } } @@ -3983,24 +3987,41 @@ void use_randart(const item_def &item) modify_stat( STAT_INTELLIGENCE, proprt[RAP_INTELLIGENCE], false, item ); modify_stat( STAT_DEXTERITY, proprt[RAP_DEXTERITY], false, item ); + int stat_props[3] = {RAP_STRENGTH, RAP_INTELLIGENCE, RAP_DEXTERITY}; + for (int i = 0; i < 3; i++) + if (unknown_proprt(stat_props[i])) + randart_wpn_learn_prop(item, stat_props[i]); // For evokable stuff, check whether other equipped items yield - // the same ability. If not, give a message. - // Do NOT give all these messages if the randart is identified. - if (!ident) + // the same ability. If not, and if the ability granted hasn't + // already been discovered, give a message. + if (unknown_proprt(RAP_LEVITATE) + && !items_give_ability(item.link, RAP_LEVITATE)) { - if (proprt[RAP_LEVITATE] && !items_give_ability(item.link, RAP_LEVITATE)) - mpr("You feel buoyant."); + mpr("You feel buoyant."); + randart_wpn_learn_prop(item, RAP_LEVITATE); + } - if (proprt[RAP_INVISIBLE] && !you.duration[DUR_INVIS]) - mpr("You become transparent for a moment."); + if (unknown_proprt(RAP_INVISIBLE) && !you.duration[DUR_INVIS]) + { + mpr("You become transparent for a moment."); + randart_wpn_learn_prop(item, RAP_INVISIBLE); + } - if (proprt[RAP_CAN_TELEPORT] && !items_give_ability(item.link, RAP_CAN_TELEPORT)) - mpr("You feel slightly jumpy."); + if (unknown_proprt(RAP_CAN_TELEPORT) + && !items_give_ability(item.link, RAP_CAN_TELEPORT)) + { + mpr("You feel slightly jumpy."); + randart_wpn_learn_prop(item, RAP_CAN_TELEPORT); + } - if (proprt[RAP_BERSERK] && !items_give_ability(item.link, RAP_BERSERK)) - mpr("You feel a brief urge to hack something to bits."); + if (unknown_proprt(RAP_BERSERK) + && !items_give_ability(item.link, RAP_BERSERK)) + { + mpr("You feel a brief urge to hack something to bits."); + randart_wpn_learn_prop(item, RAP_BERSERK); } + if (proprt[RAP_NOISES]) you.special_wield = SPWLD_NOISE; @@ -4010,6 +4031,7 @@ void use_randart(const item_def &item) // there is a dangerous monster nearby... xom_is_stimulated(255); } +#undef unknown_proprt } bool wearing_slot(int inv_slot) diff --git a/crawl-ref/source/item_use.h b/crawl-ref/source/item_use.h index 0f564ba452..a529e283f1 100644 --- a/crawl-ref/source/item_use.h +++ b/crawl-ref/source/item_use.h @@ -152,7 +152,7 @@ void wield_effects(int item_wield_2, bool showMsgs); * called from: delay.cc item_use.cc it_use2.cc * *********************************************************************** */ void use_randart( unsigned char item_wield_2 ); -void use_randart(const item_def &item); +void use_randart(item_def &item); bool puton_item(int slot, bool prompt_finger = true); diff --git a/crawl-ref/source/randart.cc b/crawl-ref/source/randart.cc index 87c82bb468..5b4e70e7ca 100644 --- a/crawl-ref/source/randart.cc +++ b/crawl-ref/source/randart.cc @@ -27,6 +27,8 @@ #include "itemprop.h" #include "stuff.h" +#define KNOWN_PROPS_KEY "randart_known_props" + /* The initial generation of a randart is very simple - it occurs in dungeon.cc and consists of giving it a few random things - plus & plus2 @@ -879,9 +881,28 @@ static long calc_seed( const item_def &item ) } void randart_wpn_properties( const item_def &item, - randart_properties_t &proprt ) + randart_properties_t &proprt, + randart_known_props_t &known) { ASSERT( is_random_artefact( item ) ); + ASSERT( item.props.exists( KNOWN_PROPS_KEY ) ); + const CrawlStoreValue &_val = item.props[KNOWN_PROPS_KEY]; + ASSERT( _val.get_type() == SV_VEC ); + const CrawlVector &known_vec = _val.get_vector(); + ASSERT( known_vec.get_type() == SV_BOOL ); + ASSERT( known_vec.size() == RA_PROPERTIES); + ASSERT( known_vec.get_max_size() == RA_PROPERTIES); + + if ( item_ident( item, ISFLAG_KNOW_PROPERTIES ) ) + { + for (vec_size i = 0; i < RA_PROPERTIES; i++) + known[i] = (bool) true; + } + else + { + for (vec_size i = 0; i < RA_PROPERTIES; i++) + known[i] = known_vec[i]; + } const object_class_type aclass = item.base_type; const int atype = item.sub_type; @@ -1347,13 +1368,55 @@ void randart_wpn_properties( const item_def &item, proprt[RAP_CURSED] = 1; } +void randart_wpn_properties( const item_def &item, + randart_properties_t &proprt ) +{ + randart_known_props_t known; + + randart_wpn_properties(item, proprt, known); +} + +int randart_wpn_property( const item_def &item, int prop, bool &_known ) +{ + randart_properties_t proprt; + randart_known_props_t known; + + randart_wpn_properties( item, proprt, known ); + + _known = known[prop]; + + return ( proprt[prop] ); +} + int randart_wpn_property( const item_def &item, int prop ) { - randart_properties_t proprt; + bool known; - randart_wpn_properties( item, proprt ); + return randart_wpn_property( item, prop, known ); +} - return (proprt[prop]); +void randart_wpn_learn_prop( item_def &item, int prop ) +{ + ASSERT( is_random_artefact( item ) ); + ASSERT( item.props.exists( KNOWN_PROPS_KEY ) ); + CrawlStoreValue &_val = item.props[KNOWN_PROPS_KEY]; + ASSERT( _val.get_type() == SV_VEC ); + CrawlVector &known_vec = _val.get_vector(); + ASSERT( known_vec.get_type() == SV_BOOL ); + ASSERT( known_vec.size() == RA_PROPERTIES); + ASSERT( known_vec.get_max_size() == RA_PROPERTIES); + + if ( item_ident( item, ISFLAG_KNOW_PROPERTIES ) ) + return; + else + known_vec[prop] = (bool) true; +} + +bool randart_wpn_known_prop( const item_def &item, int prop ) +{ + bool known; + randart_wpn_property( item, prop, known ); + return known; } std::string randart_name( const item_def &item ) @@ -1732,9 +1795,31 @@ bool make_item_randart( item_def &item ) return (false); } - item.flags |= ISFLAG_RANDART; + if (item.flags & ISFLAG_RANDART) + { + return (true); + } + + if (item.flags & ISFLAG_UNRANDART) + { +#if DEBUG + mprf(MSGCH_DIAGNOSTICS, "Trying to turn '%s' from an unrandart to" + "a randart.", item.name(DESC_PLAIN, false, true).c_str()); +#endif + return (false); + } + + item.flags |= ISFLAG_RANDART; item.special = (random_int() & RANDART_SEED_MASK); + ASSERT(!item.props.exists( KNOWN_PROPS_KEY )); + + item.props[KNOWN_PROPS_KEY].new_vector(SV_BOOL).resize(RA_PROPERTIES); + CrawlVector &known = item.props[KNOWN_PROPS_KEY]; + known.set_max_size(RA_PROPERTIES); + for (vec_size i = 0; i < RA_PROPERTIES; i++) + known[i] = (bool) false; + return (true); } diff --git a/crawl-ref/source/randart.h b/crawl-ref/source/randart.h index f57151b6de..45a8ac286a 100644 --- a/crawl-ref/source/randart.h +++ b/crawl-ref/source/randart.h @@ -94,16 +94,26 @@ bool does_unrandart_exist(int whun); * *********************************************************************** */ int find_okay_unrandart(unsigned char aclass, unsigned char atype = OBJ_RANDOM); -typedef FixedVector< int, RA_PROPERTIES > randart_properties_t; +typedef FixedVector< int, RA_PROPERTIES > randart_properties_t; +typedef FixedVector< bool, RA_PROPERTIES > randart_known_props_t; /* *********************************************************************** * called from: describe - fight - it_use2 - item_use - player * *********************************************************************** */ void randart_wpn_properties( const item_def &item, + randart_properties_t &proprt, + randart_known_props_t &known ); + +void randart_wpn_properties( const item_def &item, randart_properties_t &proprt ); +int randart_wpn_property( const item_def &item, int prop, + bool &known ); + int randart_wpn_property( const item_def &item, int prop ); +void randart_wpn_learn_prop( item_def &item, int prop ); +bool randart_wpn_known_prop( item_def &item, int prop ); /* *********************************************************************** * called from: dungeon |