コード例 #1
0
ファイル: z-doc.c プロジェクト: Alkalinear/poschengband
vec_ptr doc_get_links(doc_ptr doc)
{
    vec_ptr          links = vec_alloc(NULL);
    int_map_iter_ptr iter;

    for (iter = int_map_iter_alloc(doc->links);
            int_map_iter_is_valid(iter);
            int_map_iter_next(iter) )
    {
        doc_link_ptr link = int_map_iter_current(iter);
        vec_add(links, link);
    }
    int_map_iter_free(iter);
    vec_sort(links, (vec_cmp_f)_compare_links);
    return links;
}
コード例 #2
0
ファイル: int-map.c プロジェクト: Alkalinear/poschengband
void int_map_iter_next(int_map_iter_ptr iter)
{
    assert(int_map_iter_is_valid(iter));

    iter->node = iter->node->next;
    if (!iter->node)
    {
        int prime = _primes[iter->map->prime_idx];
        int i;

        for (i = iter->bucket + 1; i < prime; i++)
        {
            iter->bucket = i;
            iter->node = iter->map->buckets[i];
            if (iter->node)
                break;
        }
    }
}
コード例 #3
0
ファイル: cmd3.c プロジェクト: NickMcConnell/poschengband
/* Idea borrowed from Vanilla 3.5, but recoded from scratch ... */
void do_cmd_list_monsters(void)
{
    int         i, ct_types, ct_total = 0;
    int_map_ptr info = int_map_alloc(free);
    
    /* Collect */
    for (i = 0; i < max_m_idx; i++)
    {
        const monster_type *m_ptr = &m_list[i];
        _mon_list_info_ptr  info_ptr;
        
        if (!m_ptr->ap_r_idx) continue;
        if (!m_ptr->ml) continue;

        info_ptr = int_map_find(info, m_ptr->ap_r_idx);
        if (!info_ptr)
        {
            info_ptr = malloc(sizeof(_mon_list_info_t));
            info_ptr->r_idx = m_ptr->ap_r_idx;
            info_ptr->ct_total = 0;
            info_ptr->ct_awake = 0;
            info_ptr->ct_los = 0;
            
            int_map_add(info, m_ptr->ap_r_idx, info_ptr);
        }

        assert(info_ptr);
        info_ptr->ct_total++;
        ct_total++;

        if (!MON_CSLEEP(m_ptr)) info_ptr->ct_awake++;
        if (projectable(py, px, m_ptr->fy, m_ptr->fx)) info_ptr->ct_los++;
    }
    
    ct_types = int_map_count(info);
    if (ct_types)
    {
        int_map_iter_ptr  iter;
        int              *order;
        int               cx, cy, row = 1, col;

        /* Sort */
        C_MAKE(order, ct_types, int);

        i = 0;
        for (iter = int_map_iter_alloc(info); 
                int_map_iter_is_valid(iter); 
                int_map_iter_next(iter))
        {
            _mon_list_info_ptr info_ptr = int_map_iter_current(iter);
            order[i++] = info_ptr->r_idx;
        }
        int_map_iter_free(iter);

        ang_sort_comp = _compare_r_level;
        ang_sort_swap = _swap_int;
        ang_sort(order, NULL, ct_types);

        /* Display */
        Term_get_size(&cx, &cy);
        col = cx - 52;
        screen_save();
        c_prt(TERM_WHITE, format("You see %d monster%s", ct_total, ct_total != 1 ? "s" : ""), 0, col);
        for (i = 0; i < ct_types; i++)
        {
            int                 r_idx = order[i];
            const monster_race *r_ptr = &r_info[r_idx];
            byte                attr = TERM_WHITE;
            _mon_list_info_ptr  info_ptr = int_map_find(info, r_idx);
            char                buf[100];

            assert(info_ptr);

            Term_erase(col - 1, row, 53);

            if (row >= cy - 2) 
            {
                c_prt(TERM_YELLOW, "...", row++, col+2);
                break;
            }

            if (r_ptr->flags1 & RF1_UNIQUE)
                attr = TERM_VIOLET;
            else if (r_ptr->level > base_level)
                attr = TERM_RED;                
            else if (!info_ptr->ct_awake)
                attr = TERM_L_UMBER;

            if (info_ptr->ct_total == 1)
                sprintf(buf, "%s", r_name + r_ptr->name);
            else if (!info_ptr->ct_awake)
                sprintf(buf, "%s (%d sleeping)", r_name + r_ptr->name, info_ptr->ct_total);
            else if (info_ptr->ct_awake == info_ptr->ct_total)
                sprintf(buf, "%s (%d awake)", r_name + r_ptr->name, info_ptr->ct_total);
            else
                sprintf(buf, "%s (%d awake, %d sleeping)", r_name + r_ptr->name, 
                    info_ptr->ct_awake, info_ptr->ct_total - info_ptr->ct_awake);

            Term_queue_bigchar(col, row, r_ptr->x_attr, r_ptr->x_char, 0, 0);
            c_put_str(attr, format(" %-50.50s", buf), row++, col+1);
        }
        Term_erase(col - 1, row, 53);
        c_prt(TERM_YELLOW, "Hit any key.", row, col+2);
        inkey();
        prt("", 0, 0);

        screen_load();

        C_KILL(order, ct_types, int);
    }
    else
        msg_print("You see no visible monsters.");

    int_map_free(info);
}
コード例 #4
0
ファイル: int-map.c プロジェクト: Alkalinear/poschengband
int int_map_iter_current_key(int_map_iter_ptr iter)
{
    assert(int_map_iter_is_valid(iter));
    return iter->node->key;
}
コード例 #5
0
ファイル: int-map.c プロジェクト: Alkalinear/poschengband
void * int_map_iter_current(int_map_iter_ptr iter)
{
    assert(int_map_iter_is_valid(iter));
    return iter->node->val;
}