Changeset 556

Show
Ignore:
Timestamp:
09/14/07 15:00:48 (1 year ago)
Author:
takkaria
Message:

Refactor the object information code so it makes more sense. (closes #363)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd-obj.c

    r527 r556  
    6767static void obj_examine(object_type *o_ptr, int item) 
    6868{ 
    69     object_info_screen(o_ptr); 
     69        text_out_hook = text_out_to_screen; 
     70        screen_save(); 
     71 
     72        object_info_header(o_ptr); 
     73        if (!object_info_known(o_ptr)) 
     74                text_out("This item does not seem to possess any special abilities."); 
     75 
     76        text_out_c(TERM_L_BLUE, "\n\n[Press any key to continue]\n"); 
     77        (void)anykey(); 
     78       
     79        screen_load(); 
    7080} 
    7181 
  • trunk/src/cmd4.c

    r552 r556  
    12311231        handle_stuff(); 
    12321232 
    1233         /* Save the screen */ 
     1233        text_out_hook = text_out_to_screen; 
    12341234        screen_save(); 
    12351235 
    12361236        Term_gotoxy(0, 0); 
    1237         object_info_screen(o_ptr); 
    1238  
    1239         /* Load the screen */ 
     1237        object_info_header(o_ptr); 
     1238        if (!object_info_known(o_ptr)) 
     1239                text_out("This item does not seem to possess any special abilities."); 
     1240 
     1241        text_out_c(TERM_L_BLUE, "\n\n[Press any key to continue]\n"); 
     1242        (void)anykey(); 
     1243       
    12401244        screen_load(); 
    12411245} 
     
    14061410        /* List ego flags */ 
    14071411        dummy.name2 = e_idx; 
    1408         object_info_out_flags = object_flags; 
    1409         object_info_out(&dummy); 
     1412        object_info_full(&dummy); 
    14101413 
    14111414        if (e_ptr->xtra) 
     
    15921595        handle_stuff(); 
    15931596 
    1594         /* Save the screen */ 
     1597        /* Describe */ 
     1598        text_out_hook = text_out_to_screen; 
    15951599        screen_save(); 
    15961600 
    1597         /* Describe */ 
    15981601        Term_gotoxy(0,0); 
    1599         object_info_screen(o_ptr); 
    1600  
    1601         /* Load the screen */ 
     1602        object_info_header(o_ptr); 
     1603        if (!object_info_known(o_ptr)) 
     1604                text_out("This item does not seem to possess any special abilities."); 
     1605 
     1606        text_out_c(TERM_L_BLUE, "\n\n[Press any key to continue]\n"); 
     1607        (void)anykey(); 
     1608       
    16021609        screen_load(); 
    16031610} 
  • trunk/src/externs.h

    r544 r556  
    237237extern bool (*get_mon_num_hook)(int r_idx); 
    238238extern bool (*get_obj_num_hook)(int k_idx); 
    239 extern void (*object_info_out_flags)(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    240239extern ang_file *text_out_file; 
    241240extern void (*text_out_hook)(byte a, cptr str); 
     
    394393 
    395394/* obj-info.c */ 
    396 extern bool object_info_out(const object_type *o_ptr); 
    397 extern void object_info_screen(const object_type *o_ptr); 
     395extern void object_info_header(const object_type *o_ptr); 
     396extern bool object_info_known(const object_type *o_ptr); 
     397extern bool object_info_full(const object_type *o_ptr); 
    398398 
    399399/* object1.c */ 
  • trunk/src/files.c

    r532 r556  
    18801880        } 
    18811881 
     1882 
     1883        /* Set the indent/wrap */ 
     1884        text_out_indent = 3; 
     1885        text_out_wrap = 72; 
     1886 
    18821887        /* Dump the equipment */ 
    18831888        if (p_ptr->equip_cnt) 
     
    18871892                { 
    18881893                        object_desc(o_name, sizeof(o_name), &inventory[i], TRUE, 3); 
    1889                         file_putf(fp, "%c) %s\n", 
    1890                                 index_to_label(i), o_name); 
    1891  
    1892                         /* Describe random object attributes */ 
    1893                         identify_random_gen(&inventory[i]); 
     1894 
     1895                        file_putf(fp, "%c) %s\n", index_to_label(i), o_name); 
     1896                        object_info_known(&inventory[i]); 
    18941897                } 
    18951898                file_putf(fp, "\n\n"); 
     
    19031906 
    19041907                object_desc(o_name, sizeof(o_name), &inventory[i], TRUE, 3); 
    1905                 file_putf(fp, "%c) %s\n", 
    1906                         index_to_label(i), o_name); 
    1907  
    1908                 /* Describe random object attributes */ 
    1909                 identify_random_gen(&inventory[i]); 
     1908 
     1909                file_putf(fp, "%c) %s\n", index_to_label(i), o_name); 
     1910                object_info_known(&inventory[i]); 
    19101911        } 
    19111912        file_putf(fp, "\n\n"); 
     
    19241925                        file_putf(fp, "%c) %s\n", I2A(i), o_name); 
    19251926 
    1926                         /* Describe random object attributes */ 
    1927                         identify_random_gen(&st_ptr->stock[i]); 
     1927                        object_info_known(&st_ptr->stock[i]); 
    19281928                } 
    19291929 
     
    19311931                file_putf(fp, "\n\n"); 
    19321932        } 
     1933 
     1934        text_out_indent = text_out_wrap = 0; 
    19331935 
    19341936 
     
    29292931{ 
    29302932        int item; 
    2931  
    2932         object_type *o_ptr; 
    2933  
    29342933        cptr q, s; 
    29352934 
     
    29422941        s = "You have nothing to examine."; 
    29432942 
    2944         while (TRUE) 
    2945         { 
    2946                 if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP))) return; 
    2947  
    2948                 /* Get the item */ 
    2949                 o_ptr = &inventory[item]; 
    2950  
    2951                 /* Fully known */ 
    2952                 o_ptr->ident |= (IDENT_KNOWN); 
     2943        while (get_item(&item, q, s, (USE_INVEN | USE_EQUIP))) 
     2944        { 
     2945                object_type *o_ptr = &inventory[item]; 
     2946 
     2947                /* "Know" */ 
     2948                o_ptr->ident |= IDENT_KNOWN; 
    29532949 
    29542950                /* Describe */ 
    2955                 object_info_screen(o_ptr); 
     2951                text_out_hook = text_out_to_screen; 
     2952                screen_save(); 
     2953                Term_gotoxy(0, 0); 
     2954 
     2955                object_info_header(o_ptr); 
     2956                if (!object_info_known(o_ptr)) 
     2957                        text_out("This item does not possess any special abilities."); 
     2958 
     2959                text_out_c(TERM_L_BLUE, "\n\n[Press any key to continue]\n"); 
     2960                (void)anykey(); 
     2961       
     2962                screen_load(); 
    29562963        } 
    29572964} 
  • trunk/src/obj-info.c

    r555 r556  
    684684 * Output object information 
    685685 */ 
    686 bool object_info_out(const object_type *o_ptr) 
     686bool object_info_out(const object_type *o_ptr, 
     687                     void (*flags)(const object_type *, u32b *, u32b *, u32b *)) 
    687688{ 
    688689        u32b f1, f2, f3; 
     
    690691 
    691692        /* Grab the object flags */ 
    692         object_info_out_flags(o_ptr, &f1, &f2, &f3); 
     693        flags(o_ptr, &f1, &f2, &f3); 
    693694 
    694695 
     
    729730 * Return TRUE if an object description was displayed. 
    730731 */ 
    731 static bool screen_out_head(const object_type *o_ptr) 
     732void object_info_header(const object_type *o_ptr) 
    732733{ 
    733734        char *o_name; 
     
    750751            object_known_p(o_ptr) && a_info[o_ptr->name1].text) 
    751752        { 
    752                 p_text_out(a_text + a_info[o_ptr->name1].text); 
     753                text_out("\n\n"); 
     754                text_out(a_text + a_info[o_ptr->name1].text); 
    753755        } 
    754756 
     
    760762                if (k_info[o_ptr->k_idx].text) 
    761763                { 
    762                         p_text_out(k_text + k_info[o_ptr->k_idx].text); 
     764                        text_out("\n\n"); 
     765                        text_out(k_text + k_info[o_ptr->k_idx].text); 
    763766                        did_desc = TRUE; 
    764767                } 
     
    767770                if (o_ptr->name2 && object_known_p(o_ptr) && e_info[o_ptr->name2].text) 
    768771                { 
    769                         if (did_desc) p_text_out("  "); 
    770                         p_text_out(e_text + e_info[o_ptr->name2].text); 
     772                        if (did_desc) text_out("  "); 
     773                        else text_out("\n\n"); 
     774 
     775                        text_out(e_text + e_info[o_ptr->name2].text); 
    771776                } 
    772777        } 
    773778 
    774         else 
    775         { 
    776                 return FALSE; 
    777         } 
    778  
    779         return TRUE; 
    780 
    781  
    782  
    783 /* 
    784  * Place an item description on the screen. 
    785  */ 
    786 void object_info_screen(const object_type *o_ptr) 
    787 
    788         bool has_description, has_info; 
    789  
    790         /* Redirect output to the screen */ 
    791         text_out_hook = text_out_to_screen; 
    792  
    793         /* Save the screen */ 
    794         screen_save(); 
     779        return; 
     780
     781 
     782 
     783bool object_info_known(const object_type *o_ptr) 
     784
     785        bool has_info = FALSE; 
     786 
     787        has_info = object_info_out(o_ptr, object_flags_known); 
    795788 
    796789        new_paragraph = TRUE; 
    797         has_description = screen_out_head(o_ptr); 
    798         object_info_out_flags = object_flags_known; 
    799  
    800         /* Dump the info */ 
    801         has_info = object_info_out(o_ptr); 
    802  
    803         /* Dump origin info */ 
    804         new_paragraph = TRUE; 
    805         describe_origin(o_ptr); 
     790        if (describe_origin(o_ptr)) has_info = TRUE; 
    806791 
    807792        new_paragraph = TRUE; 
    808793        if (!object_known_p(o_ptr)) 
     794        { 
    809795                p_text_out("You do not know the full extent of this item's powers."); 
    810         else if (!has_description && !has_info) 
    811                 p_text_out("This item does not seem to possess any special abilities."); 
    812  
    813         new_paragraph = TRUE; 
    814         text_out_c(TERM_L_BLUE, "\n\n[Press any key to continue]\n"); 
    815  
    816         /* Wait for input */ 
    817         (void)anykey(); 
    818  
    819         /* Load the screen */ 
    820         screen_load(); 
    821  
    822         /* Hack -- Browse book, then prompt for a command */ 
    823         if (o_ptr->tval == cp_ptr->spell_book) 
    824         { 
    825                 /* Call the aux function */ 
    826                 do_cmd_browse_aux(o_ptr); 
    827         } 
    828 
     796                has_info = TRUE; 
     797        } 
     798 
     799        return has_info; 
     800
     801 
     802bool object_info_full(const object_type *o_ptr) 
     803
     804        return object_info_out(o_ptr, object_flags); 
     805
  • trunk/src/object1.c

    r532 r556  
    16371637 
    16381638/* 
    1639  * Describe an item's random attributes for "character dumps" 
    1640  */ 
    1641 void identify_random_gen(const object_type *o_ptr) 
    1642 { 
    1643         /* Set hooks for character dump */ 
    1644         object_info_out_flags = object_flags_known; 
    1645  
    1646         /* Set the indent/wrap */ 
    1647         text_out_indent = 3; 
    1648         text_out_wrap = 72; 
    1649  
    1650         /* Dump the info */ 
    1651         if (object_info_out(o_ptr)) 
    1652                 text_out("\n"); 
    1653  
    1654         /* Reset indent/wrap */ 
    1655         text_out_indent = 0; 
    1656         text_out_wrap = 0; 
    1657 } 
    1658  
    1659  
    1660 /* 
    16611639 * Convert an inventory index into a one character label. 
    16621640 * 
  • trunk/src/store.c

    r542 r556  
    23042304        object_type *o_ptr; 
    23052305 
    2306         if(item < 0) return; 
     2306        if (item < 0) return; 
    23072307 
    23082308        /* Get the actual object */ 
     
    23122312        Term_erase(0, 0, 255); 
    23132313        Term_gotoxy(0, 0); 
    2314         object_info_screen(o_ptr); 
     2314        object_info_full(o_ptr); 
     2315 
     2316        /* Hack -- Browse book, then prompt for a command */ 
     2317        if (o_ptr->tval == cp_ptr->spell_book) 
     2318        { 
     2319                /* Call the aux function */ 
     2320                do_cmd_browse_aux(o_ptr); 
     2321        } 
    23152322} 
    23162323 
  • trunk/src/variable.c

    r529 r556  
    737737 
    738738 
    739 void (*object_info_out_flags)(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    740  
    741739 
    742740/* 
  • trunk/src/wizard1.c

    r531 r556  
    453453        text_out_file = fh; 
    454454 
    455         /* Set object_info_out() hook */ 
    456         object_info_out_flags = object_flags; 
    457  
    458455        /* Dump the header */ 
    459456        spoiler_underline(format("Artifact Spoilers for %s %s", 
     
    496493 
    497494                        /* Write out the artifact description to the spoiler file */ 
    498                         object_info_out(i_ptr); 
     495                        object_info_full(i_ptr); 
    499496 
    500497                        /*