Changeset 130

Show
Ignore:
Timestamp:
05/12/07 09:39:43 (2 years ago)
Author:
takkaria
Message:
  • Make monster list display nicer, and allow displaying in the main term. Some Sangband code stolen. (closes #116)
  • Clean up the directory scanners a bit.
Files:

Legend:

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

    r120 r130  
    11901190} 
    11911191 
     1192static void do_cmd_monlist(void) 
     1193{ 
     1194        /* Save the screen and display the list */ 
     1195        screen_save(); 
     1196        display_monlist(); 
     1197 
     1198        /* Wait */ 
     1199        inkey(); 
     1200 
     1201        /* Return */ 
     1202        screen_load(); 
     1203} 
     1204 
    11921205/* 
    11931206 * Useful typedef. 
     
    12971310        { "Identify symbol",       '/', do_cmd_query_symbol }, 
    12981311        { "Character description", 'C', do_cmd_change_name }, 
     1312        { "Display monster list",  '[', do_cmd_monlist }, 
    12991313 
    13001314 
  • trunk/src/monster2.c

    r48 r130  
    554554void display_monlist(void) 
    555555{ 
    556         int idx, n; 
    557         int line = 0; 
     556        int i, n; 
     557        int line = 1, x = 0; 
     558        unsigned total_count = 0; 
     559 
     560        byte attr; 
    558561 
    559562        char *m_name; 
     
    563566        monster_race *r_ptr; 
    564567 
    565         u16b *race_counts; 
    566  
     568        u16b *race_count; 
     569 
     570 
     571        /* Clear the term if in a subwindow, set x otherwise */ 
     572        if (Term != angband_term[0]) 
     573                clear_from(0); 
     574        else 
     575            x = 13; 
    567576 
    568577        /* Allocate the array */ 
    569         C_MAKE(race_counts, z_info->r_max, u16b); 
    570  
    571         /* Iterate over mon_list */ 
    572         for (idx = 1; idx < mon_max; idx++) 
    573         { 
    574                 m_ptr = &mon_list[idx]; 
     578        C_MAKE(race_count, z_info->r_max, u16b); 
     579 
     580        /* Scan the monster list */ 
     581        for (i = 1; i < mon_max; i++) 
     582        { 
     583                m_ptr = &mon_list[i]; 
    575584 
    576585                /* Only visible monsters */ 
    577586                if (!m_ptr->ml) continue; 
    578587 
    579                 /* Bump the count for this race */ 
    580                 race_counts[m_ptr->r_idx]++; 
    581         } 
    582  
    583  
    584         /* Iterate over mon_list ( again :-/ ) */ 
    585         for (idx = 1; idx < mon_max; idx++) 
    586         { 
    587                 m_ptr = &mon_list[idx]; 
    588  
    589                 /* Only visible monsters */ 
    590                 if (!m_ptr->ml) continue; 
    591  
    592                 /* Do each race only once */ 
    593                 if (!race_counts[m_ptr->r_idx]) continue; 
    594  
    595                 /* Get monster race */ 
    596                 r_ptr = &r_info[m_ptr->r_idx]; 
    597  
    598                 /* Get the monster name */ 
     588                /* Bump the count for this race, and the total count */ 
     589                race_count[m_ptr->r_idx]++; 
     590                total_count++; 
     591        } 
     592 
     593        /* Note no visible monsters */ 
     594        if (!total_count) 
     595        { 
     596                /* Clear display and print note */ 
     597                c_prt(TERM_SLATE, "You see no monsters.", 0, 0); 
     598                if (Term == angband_term[0]) 
     599                    Term_addstr(-1, TERM_WHITE, "  (Press any key to continue.)"); 
     600 
     601                /* Free up memory */ 
     602                FREE(race_count); 
     603 
     604                /* Done */ 
     605                return; 
     606        } 
     607 
     608        /* Go over */ 
     609        for (i = 1; i < z_info->r_max; i++) 
     610        { 
     611                /* No monsters of this race are visible */ 
     612                if (!race_count[i]) continue; 
     613 
     614                /* Get monster race and name */ 
     615                r_ptr = &r_info[i]; 
    599616                m_name = r_name + r_ptr->name; 
    600617 
    601                 /* Obtain the length of the description */ 
    602                 n = strlen(m_name); 
    603  
    604                 /* Display the entry itself */ 
    605                 Term_putstr(0, line, n, TERM_WHITE, m_name); 
    606  
    607                 /* Append the "standard" attr/char info */ 
    608                 Term_addstr(-1, TERM_WHITE, " ('"); 
    609                 Term_addch(r_ptr->d_attr, r_ptr->d_char); 
    610                 Term_addstr(-1, TERM_WHITE, "')"); 
    611                 n += 6; 
    612  
    613                 /* Append the "optional" attr/char info */ 
    614                 Term_addstr(-1, TERM_WHITE, "/('"); 
    615  
    616                 Term_addch(r_ptr->x_attr, r_ptr->x_char); 
    617  
    618                 if (use_bigtile) 
    619                 { 
    620                         if (r_ptr->x_attr & 0x80) 
    621                                 Term_addch(255, -1); 
    622                         else 
    623                                 Term_addch(0, ' '); 
    624  
    625                         n++; 
    626                 } 
    627  
    628                 Term_addstr(-1, TERM_WHITE, "'):"); 
    629                 n += 7; 
    630  
    631                 /* Add race count */ 
    632                 sprintf(buf, "%d", race_counts[m_ptr->r_idx]); 
    633                 Term_addch(TERM_WHITE, '['); 
    634                 Term_addstr(strlen(buf), TERM_WHITE, buf); 
    635                 Term_addch(TERM_WHITE, ']'); 
    636                 n += strlen(buf) + 2; 
    637  
    638                 /* Don't do this race again */ 
    639                 race_counts[m_ptr->r_idx] = 0; 
    640  
    641                 /* Erase the rest of the line */ 
    642                 Term_erase(n, line, 255); 
    643  
    644                 /* Bump line counter */ 
     618                /* Display uniques in a special colour */ 
     619                if (r_ptr->flags1 & RF1_UNIQUE) 
     620                        attr = TERM_VIOLET; 
     621                else 
     622                        attr = TERM_WHITE; 
     623 
     624                /* Build the monster name */ 
     625                if (race_count[i] == 1) 
     626                        my_strcpy(buf, m_name, sizeof(buf)); 
     627                else 
     628                        strnfmt(buf, sizeof(buf), "%s (x%d) ", m_name, race_count[i]); 
     629 
     630                /* Display the pict */ 
     631                Term_putch(x, line, r_ptr->x_attr, r_ptr->x_char); 
     632                Term_putch(x + 1, line, TERM_WHITE, ' '); 
     633 
     634                /* Print and bump line counter */ 
     635                c_prt(attr, buf, line, x + 2); 
    645636                line++; 
    646637        } 
    647638 
     639        /* Clear a line for main-term display */ 
     640        prt("", line, x); 
     641 
     642        /* Message */ 
     643        prt(format("You can see %d monster%s:", 
     644                total_count, (total_count > 1 ? "s" : "")), 0, 0); 
     645        if (Term == angband_term[0]) 
     646            Term_addstr(-1, TERM_WHITE, "  (Press any key to continue.)"); 
     647 
    648648        /* Free the race counters */ 
    649         FREE(race_counts); 
    650  
    651         /* Erase the rest of the window */ 
    652         for (idx = line; idx < Term->hgt; idx++) 
    653         { 
    654                 /* Erase the line */ 
    655                 Term_erase(0, idx, 255); 
    656         } 
     649        FREE(race_count); 
    657650} 
    658651 
  • trunk/src/z-file.c

    r128 r130  
    827827{ 
    828828        WIN32_FIND_DATA fd; 
     829        HANDLE h; 
    829830        ang_dir *dir; 
    830  
     831         
     832        /* Try to open it */ 
     833        h = FindFirstFile(format("%s\\*", dirname), &fd); 
     834 
     835        /* Abort */ 
     836        if (h == INVALID_HANDLE_VALUE) 
     837                return NULL; 
     838 
     839        /* Allocate for the handle */ 
    831840        dir = ralloc(sizeof dir); 
    832841        if (!dir) return NULL; 
    833842 
    834         /* Try to open it */ 
    835         dir->h = FindFirstFile(format("%s\\*", dirname), &fd); 
    836  
    837         /* Abort */ 
    838         if (dir->h == INVALID_HANDLE_VALUE) 
    839         { 
    840                 FREE(dir); 
    841                 return NULL; 
    842         } 
    843  
    844         /* Remember this one */ 
     843        /* Remember details */ 
     844        dir->h = h; 
    845845        dir->first_file = string_make(fd.cFileName); 
    846846 
     
    917917{ 
    918918        ang_dir *dir; 
    919  
     919        DIR d; 
     920 
     921        /* Try to open the directory */ 
     922        d = opendir(dirname); 
     923        if (!dir->d) return NULL; 
     924 
     925        /* Allocate memory for the handle */ 
    920926        dir = ralloc(sizeof dir); 
    921927        if (!dir) return NULL; 
    922928 
    923         /* Try to open the directory */ 
    924         dir->d = opendir(dirname); 
    925         if (!dir->d) 
    926         { 
    927                 FREE(dir); 
    928                 return NULL; 
    929         } 
     929        /* Set up the handle */ 
     930        dir->d = d; 
    930931 
    931932        /* Success */