Changeset 254

Show
Ignore:
Timestamp:
07/03/07 17:29:00 (1 year ago)
Author:
ajps
Message:

Fixes to some store oddities, and making it clearer when knowledge menu items won't do anything. All going towards #170.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd4.c

    r252 r254  
    574574                { 
    575575                        display_visual_list(g_name_len + 3, 7, browser_rows-1, 
    576                                    wid - (g_name_len + 3), attr_top, char_left); 
     576                                                    wid - (g_name_len + 3), attr_top, char_left); 
    577577                        place_visual_list_cursor(g_name_len + 3, 7, *o_funcs.xattr(oid),  
    578578                                                                                *o_funcs.xchar(oid), attr_top, char_left); 
     
    10641064} 
    10651065 
     1066static int count_known_monsters(void) 
     1067{ 
     1068        int m_count = 0; 
     1069        int i; 
     1070        size_t j; 
     1071 
     1072        for (i = 0; i < z_info->r_max; i++) 
     1073        { 
     1074                monster_race *r_ptr = &r_info[i]; 
     1075                if (!cheat_know && !l_list[i].sights) continue; 
     1076                if (!r_ptr->name) continue; 
     1077 
     1078                if (r_ptr->flags1 & RF1_UNIQUE) m_count++; 
     1079 
     1080                for (j = 1; j < N_ELEMENTS(monster_group) - 1; j++) 
     1081                { 
     1082                        const char *pat = monster_group[j].chars; 
     1083                        if (strchr(pat, r_ptr->d_char)) m_count++; 
     1084                } 
     1085        } 
     1086 
     1087        return m_count; 
     1088} 
     1089 
    10661090/* 
    10671091 * Display known monsters. 
    10681092 */ 
    1069 static void do_cmd_knowledge_monsters(void
     1093static void do_cmd_knowledge_monsters(void *obj, const char *name
    10701094{ 
    10711095        group_funcs r_funcs = {N_ELEMENTS(monster_group), FALSE, race_name, 
     
    12071231 
    12081232 
     1233/* If 'artifacts' is NULL, it counts the number of known artifacts, otherwise 
     1234   it collects the list of known artifacts into 'artifacts' as well. */ 
     1235static int collect_known_artifacts(int *artifacts, size_t artifacts_len) 
     1236{ 
     1237        int a_count = 0; 
     1238        int i, j; 
     1239 
     1240        if (artifacts) 
     1241                assert(artifacts_len >= z_info->a_max); 
     1242 
     1243        for (j = 0; j < z_info->a_max; j++) 
     1244        { 
     1245                /* If the artifact has been created (or we're cheating) */ 
     1246                if ((cheat_xtra || a_info[j].cur_num) && a_info[j].name) 
     1247                { 
     1248                        bool valid = TRUE; 
     1249 
     1250                        for (i = 0; !cheat_xtra && i < z_info->o_max; i++) 
     1251                        { 
     1252                                int a = o_list[i].name1; 
     1253 
     1254                                /* If we haven't actually identified the artifact yet */ 
     1255                                if (a && a == j && !object_known_p(&o_list[i])) 
     1256                                { 
     1257                                        valid = FALSE; 
     1258                                } 
     1259                        } 
     1260 
     1261                        if (valid) 
     1262                        { 
     1263                                if (artifacts) 
     1264                                        artifacts[a_count++] = j; 
     1265                                else 
     1266                                        a_count++; 
     1267                        } 
     1268                } 
     1269        } 
     1270 
     1271        return a_count; 
     1272} 
     1273 
    12091274/* 
    12101275 * Display known artifacts 
    12111276 */ 
    1212 static void do_cmd_knowledge_artifacts(void
     1277static void do_cmd_knowledge_artifacts(void *obj, const char *name
    12131278{ 
    12141279        /* HACK -- should be TV_MAX */ 
     
    12161281        member_funcs art_f = {display_artifact, desc_art_fake, 0, 0, 0, 0, 0}; 
    12171282 
    1218  
    12191283        int *artifacts; 
    12201284        int a_count = 0; 
    1221         int i, j; 
    12221285 
    12231286        C_MAKE(artifacts, z_info->a_max, int); 
    1224          
     1287 
    12251288        /* Collect valid artifacts */ 
    1226         for (i = 0; i < z_info->a_max; i++) 
    1227         { 
    1228                 if ((cheat_xtra || a_info[i].cur_num) && a_info[i].name) 
    1229                         artifacts[a_count++] = i; 
    1230         } 
    1231         for (i = 0; !cheat_xtra && i < z_info->o_max; i++) 
    1232         { 
    1233                 int a = o_list[i].name1; 
    1234                 if (a && !object_known_p(&o_list[i])) 
    1235                 { 
    1236                         for (j = 0; j < a_count && a != artifacts[j]; j++); 
    1237                         a_count -= 1; 
    1238                         for (; j < a_count; j++)  
    1239                                 artifacts[j] = artifacts[j+1]; 
    1240                 } 
    1241         } 
     1289        a_count = collect_known_artifacts(artifacts, z_info->a_max); 
    12421290 
    12431291        display_knowledge("artifacts", artifacts, a_count, obj_f, art_f, 0); 
     
    13401388 * Display known ego_items 
    13411389 */ 
    1342 static void do_cmd_knowledge_ego_items(void
     1390static void do_cmd_knowledge_ego_items(void *obj, const char *name
    13431391{ 
    13441392        group_funcs obj_f = 
     
    15941642 * Display known objects 
    15951643 */ 
    1596 static void do_cmd_knowledge_objects(void
     1644static void do_cmd_knowledge_objects(void *obj, const char *name
    15971645{ 
    15981646        group_funcs kind_f = {TV_GOLD, FALSE, kind_name, o_cmp_tval, obj2gid, 0}; 
     
    16701718 * Interact with feature visuals. 
    16711719 */ 
    1672 static void do_cmd_knowledge_features(void
     1720static void do_cmd_knowledge_features(void *obj, const char *name
    16731721{ 
    16741722        group_funcs fkind_f = {N_ELEMENTS(feature_group_text), FALSE, 
     
    16961744 
    16971745 
    1698 void do_cmd_knowledge_home()  
     1746void do_cmd_knowledge_home()  
    16991747{ 
    17001748        /* TODO */ 
     
    30233071 
    30243072                if (ESCAPE == c.key) break; 
    3025                 if (c.key == ARROW_LEFT || c.key == ARROW_RIGHT) continue; 
     3073               if (c.key == ARROW_LEFT || c.key == ARROW_RIGHT) continue; 
    30263074                evt = macro_actions[cursor].id; 
    30273075 
     
    40084056 
    40094057 
    4010 void do_cmd_self_knowledge(void *obj, const char *name) 
     4058static void do_cmd_self_knowledge(void *obj, const char *name) 
    40114059{ 
    40124060        /* display self knowledge we already know about. */ 
     
    40194067static menu_item knowledge_actions[] = 
    40204068{ 
    4021         {{0, "Display artifact knowledge", (action_f)do_cmd_knowledge_artifacts, 0}, '1'}, 
    4022         {{0, "Display monster knowledge", (action_f)do_cmd_knowledge_monsters, 0}, '2'}, 
    4023         {{0, "Display ego item knowledge", (action_f)do_cmd_knowledge_ego_items, 0}, '3'}, 
    4024         {{0, "Display object knowledge", (action_f)do_cmd_knowledge_objects, 0}, '4'}, 
    4025         {{0, "Display feature knowledge", (action_f)do_cmd_knowledge_features, 0}, '5'}, 
     4069        {{0, "Display object knowledge", do_cmd_knowledge_objects, 0}, '1'}, 
     4070        {{0, "Display artifact knowledge", do_cmd_knowledge_artifacts, 0}, '2'}, 
     4071        {{0, "Display ego item knowledge", do_cmd_knowledge_ego_items, 0}, '3'}, 
     4072        {{0, "Display monster knowledge", do_cmd_knowledge_monsters, 0}, '4'}, 
     4073        {{0, "Display feature knowledge", do_cmd_knowledge_features, 0}, '5'}, 
    40264074        {{0, "Display self-knowledge", do_cmd_self_knowledge, 0}, '6'}, 
    40274075}; 
     
    40364084{ 
    40374085        int cursor = 0; 
     4086        int i; 
    40384087        event_type c = EVENT_EMPTY; 
    40394088        region knowledge_region = { 0, 0, -1, 11 }; 
     4089 
     4090        /* Grey out menu items that won't display anything */ 
     4091        if (collect_known_artifacts(NULL, 0) > 0) 
     4092                knowledge_actions[1].flags = 0; 
     4093        else 
     4094                knowledge_actions[1].flags = MN_GREYED; 
     4095 
     4096        knowledge_actions[2].flags = MN_GREYED; 
     4097        for (i = 0; i < z_info->e_max; i++) 
     4098        { 
     4099                if (e_info[i].everseen || cheat_xtra) 
     4100                { 
     4101                        knowledge_actions[2].flags = 0; 
     4102                        break; 
     4103                } 
     4104        } 
     4105 
     4106        if (count_known_monsters() > 0) 
     4107                knowledge_actions[3].flags = 0; 
     4108        else 
     4109                knowledge_actions[3].flags = MN_GREYED; 
    40404110 
    40414111        screen_save(); 
  • trunk/src/store.c

    r239 r254  
    20472047        const char *prompt = "Sell which item? "; 
    20482048 
     2049        /* Clear all current messages */ 
     2050        msg_flag = FALSE; 
     2051        prt("", 0, 0); 
     2052 
    20492053        if (store_current == STORE_HOME) 
    20502054                prompt = "Drop which item? "; 
     
    25722576 
    25732577 
    2574     /*** Set up state ***/ 
     2578       /*** Set up state ***/ 
    25752579 
    25762580        /* XXX Take note of the store number from the terrain feature */ 
     
    25792583 
    25802584 
    2581     /*** Display ***/ 
     2585       /*** Display ***/ 
    25822586 
    25832587        /* Save current screen (ie. dungeon) */ 
     
    26022606 
    26032607        /* Calculate the positions of things and redraw */ 
     2608        store_flags = STORE_INIT_CHANGE; 
    26042609        store_display_recalc(); 
    2605         store_flags = STORE_INIT_CHANGE; 
    26062610        store_redraw(); 
    26072611 
     
    26122616        while (!leave) 
    26132617        { 
    2614                 /* Keep track of stock and number of rows */ 
     2618                /* As many rows in the menus as there are items in the store */ 
    26152619                menu.count = st_ptr->stock_num; 
    2616                 items_region.page_rows = scr_places_y[LOC_ITEMS_END] - scr_places_y[LOC_ITEMS_START] + 1; 
    26172620 
    26182621                /* These two can't intersect! */ 
     
    26242627                        cursor = menu.count - 1; 
    26252628 
    2626                 if (menu.count >= menu.active.page_rows) 
    2627                         items_region.page_rows += 1; 
     2629                items_region.page_rows = scr_places_y[LOC_MORE] - scr_places_y[LOC_ITEMS_START]; 
    26282630 
    26292631                /* Init the menu structure */ 
    26302632                menu_init2(&menu, find_menu_skin(MN_SCROLL), cur_menu, &items_region); 
    26312633 
    2632                 if (menu.count >= menu.active.page_rows) 
     2634                if (menu.count > items_region.page_rows) 
    26332635                        menu.prompt = "  -more-"; 
    26342636                else 
  • trunk/src/ui.h

    r166 r254  
    230230        MN_DISABLED             = 0x0100000,    /* Neither action nor selection is permitted */ 
    231231        MN_GRAYED               = 0x0200000,    /* Row is displayed with CURS_UNKNOWN colors */ 
     232        MN_GREYED               = 0x0200000,    /* Row is displayed with CURS_UNKNOWN colors */ 
    232233        MN_SELECTED             = 0x0400000,    /* Row is currently selected */ 
    233234        MN_SELECTABLE   = 0x0800000,    /* Row is permitted to be selected */