From 914e4acb0353c4d24e5beeebb7074217505db5d1 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Sun, 2 Sep 2007 13:33:06 +0000 Subject: Implementing patch 1783079 (improved inscriptions) by zelgadis. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2044 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 6 ++++ crawl-ref/source/debug.cc | 5 +++ crawl-ref/source/it_use3.cc | 5 +++ crawl-ref/source/itemname.cc | 8 ++++- crawl-ref/source/itemprop.cc | 7 +++- crawl-ref/source/items.cc | 86 +++++++++++++++++++++++++++++++++----------- crawl-ref/source/items.h | 4 +++ crawl-ref/source/newgame.cc | 4 +++ 8 files changed, 103 insertions(+), 22 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index f05e7d19d8..69d5fa5115 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -961,6 +961,9 @@ static void input() if (need_to_autopickup()) autopickup(); + if (need_to_autoinscribe()) + autoinscribe(); + handle_delay(); const coord_def cwhere = grid2view(you.pos()); @@ -1010,6 +1013,9 @@ static void input() c_input_reset(false, true); } + if (need_to_autoinscribe()) + autoinscribe(); + if (you.turn_is_over) { if ( apply_berserk_penalty ) diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index 7a721d72d3..a205576898 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -830,6 +830,11 @@ void create_spec_object() if (!(type_wanted = atoi(specs))) { mpr( "No such item." ); + + // Clean up item + mitm[thing_created].base_type = OBJ_UNASSIGNED; + mitm[thing_created].quantity = 0; + return; } type_wanted--; diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc index 5b363a44ba..38b54860be 100644 --- a/crawl-ref/source/it_use3.cc +++ b/crawl-ref/source/it_use3.cc @@ -28,6 +28,7 @@ #include "effects.h" #include "fight.h" #include "food.h" +#include "invent.h" #include "items.h" #include "it_use2.h" #include "itemname.h" @@ -325,6 +326,10 @@ bool evoke_wielded( void ) item_def& wpn = you.inv[wield]; bool unevokable = false; + // Check inscriptions. + if ( !check_warning_inscriptions(wpn, OPER_EVOKE) ) + return false; + switch (wpn.base_type) { case OBJ_WEAPONS: diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index 1237d50d04..400a77da24 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -1559,7 +1559,13 @@ void set_ident_type( object_class_type basetype, int subtype, const item_type_id_type idt = objtype_to_idtype(basetype); if ( idt != NUM_IDTYPE ) - type_ids[idt][subtype] = setting; + { + if (type_ids[idt][subtype] != setting) + { + type_ids[idt][subtype] = setting; + request_autoinscribe(); + } + } } item_type_id_state_type get_ident_type(object_class_type basetype, int subtype) diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc index 4526448db4..dfd2020310 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -494,7 +494,12 @@ bool item_is_critical(const item_def &item) void set_ident_flags( item_def &item, unsigned long flags ) { - item.flags |= flags; + if ((item.flags & flags) != flags) + { + item.flags |= flags; + request_autoinscribe(); + } + if (notes_are_active() && !(item.flags & ISFLAG_NOTED_ID) && fully_identified(item) && is_interesting_item(item)) { diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 8e31712f24..3f71d29434 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -71,9 +71,11 @@ static bool invisible_to_player( const item_def& item ); static void item_list_on_square( std::vector& items, int obj, bool force_squelch = false ); static void autoinscribe_item( item_def& item ); -static void autoinscribe_items(); +static void autoinscribe_floor_items(); +static void autoinscribe_inventory(); -static bool will_autopickup = false; +static bool will_autopickup = false; +static bool will_autoinscribe = false; // Used to be called "unlink_items", but all it really does is make // sure item coordinates are correct to the stack they're in. -- bwr @@ -625,7 +627,6 @@ void item_check(bool verbose) { describe_floor(); - autoinscribe_items(); origin_set(you.x_pos, you.y_pos); std::ostream& strm = msg::streams(MSGCH_FLOOR_ITEMS); @@ -1664,8 +1665,13 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer ) mprf("You drop %s.", quant_name(you.inv[item_dropped], quant_drop, DESC_NOCAP_A).c_str()); - if ( grid_destroys_items(my_grid) && !silenced(you.pos()) ) - mprf(MSGCH_SOUND, grid_item_destruction_message(my_grid)); + if ( grid_destroys_items(my_grid) ) + { + if( !silenced(you.pos()) ) + mprf(MSGCH_SOUND, grid_item_destruction_message(my_grid)); + } + else if (strstr(you.inv[item_dropped].inscription.c_str(), "=s") != 0) + stashes.add_stash(); dec_inv_item_quantity( item_dropped, quant_drop ); you.turn_is_over = true; @@ -2622,7 +2628,7 @@ void handle_time( long time_delta ) static void autoinscribe_item( item_def& item ) { std::string iname = item.name(DESC_INVENTORY); - + /* if there's an inscription already, do nothing */ if ( item.inscription.size() > 0 ) return; @@ -2631,13 +2637,65 @@ static void autoinscribe_item( item_def& item ) { if ( Options.autoinscriptions[i].first.matches(iname) ) { + // Don't autoinscribe dropped items on ground with + // "=g". If the item matches a rule which adds "=g", + // "=g" got added to it before it was dropped, and + // then the user explictly removed it because they + // don't want to autopickup it again. + std::string str = Options.autoinscriptions[i].second; + if ((item.flags & ISFLAG_DROPPED) + && (item.x != -1 || item.y != -1)) + { + str = replace_all(str, "=g", ""); + } + // Note that this might cause the item inscription to // pass 80 characters. - item.inscription += Options.autoinscriptions[i].second; + item.inscription += str; } } } +static void autoinscribe_floor_items() +{ + int o, next; + o = igrd[you.x_pos][you.y_pos]; + + while (o != NON_ITEM) + { + next = mitm[o].link; + autoinscribe_item( mitm[o] ); + o = next; + } +} + +static void autoinscribe_inventory() +{ + for (int i = 0; i < ENDOFPACK; i++) + { + if (is_valid_item(you.inv[i])) + autoinscribe_item( you.inv[i] ); + } +} + +bool need_to_autoinscribe() +{ + return will_autoinscribe; +} + +void request_autoinscribe(bool do_inscribe) +{ + will_autoinscribe = do_inscribe; +} + +void autoinscribe() +{ + autoinscribe_floor_items(); + autoinscribe_inventory(); + + will_autoinscribe = false; +} + static inline std::string autopickup_item_name(const item_def &item) { return userdef_annotate_item(STASH_LUA_SEARCH_ANNOTATE, &item, true) @@ -2668,19 +2726,6 @@ static bool is_forced_autopickup(const item_def &item, std::string &iname) return false; } -static void autoinscribe_items() -{ - int o, next; - o = igrd[you.x_pos][you.y_pos]; - - while (o != NON_ITEM) - { - next = mitm[o].link; - autoinscribe_item( mitm[o] ); - o = next; - } -} - bool item_needs_autopickup(const item_def &item) { if (strstr(item.inscription.c_str(), "=g") != 0) @@ -2804,6 +2849,7 @@ static void do_autopickup() void autopickup() { + autoinscribe_floor_items(); do_autopickup(); item_check(false); } diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h index d5953b523b..6d970ab454 100644 --- a/crawl-ref/source/items.h +++ b/crawl-ref/source/items.h @@ -152,4 +152,8 @@ void autopickup(); int find_free_slot(const item_def &i); bool is_rune(const item_def &item); +bool need_to_autoinscribe(); +void request_autoinscribe(bool do_inscribe = true); +void autoinscribe(); + #endif diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 6e34bec11f..bc6f3fcc82 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -848,6 +848,10 @@ game_start: } } + // Apply autoinscribe rules to inventory. + request_autoinscribe(); + autoinscribe(); + // Brand items as original equipment. origin_set_inventory(origin_set_startequip); -- cgit v1.2.3-54-g00ecf