| 2215 | | |
|---|
| | 2215 | /* |
|---|
| | 2216 | * Display visible monsters in a window |
|---|
| | 2217 | */ |
|---|
| | 2218 | static void handle_mons_list(game_event_type type, game_event_data *data, void *user) |
|---|
| | 2219 | { |
|---|
| | 2220 | xtra_win_data *xd = &xdata[3]; |
|---|
| | 2221 | int i, max; |
|---|
| | 2222 | int line = 1, x = 0; |
|---|
| | 2223 | int cur_x; |
|---|
| | 2224 | unsigned total_count = 0, disp_count = 0; |
|---|
| | 2225 | |
|---|
| | 2226 | byte attr; |
|---|
| | 2227 | |
|---|
| | 2228 | char *m_name; |
|---|
| | 2229 | char buf[80]; |
|---|
| | 2230 | char str[80]; |
|---|
| | 2231 | |
|---|
| | 2232 | monster_type *m_ptr; |
|---|
| | 2233 | monster_race *r_ptr; |
|---|
| | 2234 | |
|---|
| | 2235 | u16b *race_count; |
|---|
| | 2236 | |
|---|
| | 2237 | if (!xd) return; |
|---|
| | 2238 | |
|---|
| | 2239 | xd->buf = gtk_text_buffer_new(NULL); |
|---|
| | 2240 | gtk_text_view_set_buffer(GTK_TEXT_VIEW (xd->text_view), xd->buf); |
|---|
| | 2241 | |
|---|
| | 2242 | init_color_tags(xd); |
|---|
| | 2243 | |
|---|
| | 2244 | /* Allocate the array */ |
|---|
| | 2245 | race_count = C_ZNEW(z_info->r_max, u16b); |
|---|
| | 2246 | |
|---|
| | 2247 | /* Scan the monster list */ |
|---|
| | 2248 | for (i = 1; i < mon_max; i++) |
|---|
| | 2249 | { |
|---|
| | 2250 | m_ptr = &mon_list[i]; |
|---|
| | 2251 | |
|---|
| | 2252 | /* Only visible monsters */ |
|---|
| | 2253 | if (!m_ptr->ml) continue; |
|---|
| | 2254 | |
|---|
| | 2255 | /* Bump the count for this race, and the total count */ |
|---|
| | 2256 | race_count[m_ptr->r_idx]++; |
|---|
| | 2257 | total_count++; |
|---|
| | 2258 | } |
|---|
| | 2259 | |
|---|
| | 2260 | /* Note no visible monsters */ |
|---|
| | 2261 | if (!total_count) |
|---|
| | 2262 | { |
|---|
| | 2263 | /* Print note */ |
|---|
| | 2264 | strnfmt(str, sizeof(str), "You see no monsters."); |
|---|
| | 2265 | text_view_print(xd, str, TERM_SLATE); |
|---|
| | 2266 | |
|---|
| | 2267 | /* Free up memory */ |
|---|
| | 2268 | FREE(race_count); |
|---|
| | 2269 | |
|---|
| | 2270 | /* Done */ |
|---|
| | 2271 | return; |
|---|
| | 2272 | } |
|---|
| | 2273 | |
|---|
| | 2274 | strnfmt(str, sizeof(str), "You can see %d monster%s:", total_count, PLURAL(total_count)); |
|---|
| | 2275 | text_view_print(xd, str, 1); |
|---|
| | 2276 | |
|---|
| | 2277 | /* Go over in reverse order (so we show harder monsters first) */ |
|---|
| | 2278 | for (i = z_info->r_max - 1; (i > 0) && (line < max); i--) |
|---|
| | 2279 | { |
|---|
| | 2280 | monster_lore *l_ptr = &l_list[i]; |
|---|
| | 2281 | |
|---|
| | 2282 | /* No monsters of this race are visible */ |
|---|
| | 2283 | if (!race_count[i]) continue; |
|---|
| | 2284 | |
|---|
| | 2285 | /* Reset position */ |
|---|
| | 2286 | cur_x = x; |
|---|
| | 2287 | |
|---|
| | 2288 | /* Note that these have been displayed */ |
|---|
| | 2289 | disp_count += race_count[i]; |
|---|
| | 2290 | |
|---|
| | 2291 | /* Get monster race and name */ |
|---|
| | 2292 | r_ptr = &r_info[i]; |
|---|
| | 2293 | m_name = r_name + r_ptr->name; |
|---|
| | 2294 | |
|---|
| | 2295 | /* Display uniques in a special colour */ |
|---|
| | 2296 | if (r_ptr->flags[0] & RF0_UNIQUE) |
|---|
| | 2297 | attr = TERM_VIOLET; |
|---|
| | 2298 | else if (l_ptr->tkills && (r_ptr->level > p_ptr->depth)) |
|---|
| | 2299 | attr = TERM_RED; |
|---|
| | 2300 | else |
|---|
| | 2301 | attr = TERM_WHITE; |
|---|
| | 2302 | |
|---|
| | 2303 | /* Build the monster name */ |
|---|
| | 2304 | if (race_count[i] == 1) |
|---|
| | 2305 | my_strcpy(buf, m_name, sizeof(buf)); |
|---|
| | 2306 | else |
|---|
| | 2307 | strnfmt(buf, sizeof(buf), "%s (x%d) ", m_name, race_count[i]); |
|---|
| | 2308 | |
|---|
| | 2309 | text_view_print(xd, buf, attr); |
|---|
| | 2310 | line++; |
|---|
| | 2311 | } |
|---|
| | 2312 | |
|---|
| | 2313 | /* Free the race counters */ |
|---|
| | 2314 | FREE(race_count); |
|---|
| | 2315 | } |
|---|
| | 2316 | #ifdef Old_version |
|---|