File: tilereg-mon.cc

package info (click to toggle)
crawl 2%3A0.7.1-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 30,420 kB
  • ctags: 23,018
  • sloc: cpp: 244,317; ansic: 16,144; perl: 2,214; makefile: 984; python: 488; objc: 250; ruby: 200; sh: 140
file content (224 lines) | stat: -rw-r--r-- 5,054 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 *  File:       tilereg-mon.cc
 */

#include "AppHdr.h"

#ifdef USE_TILE
#include <algorithm>

#include "tilereg-mon.h"

#include "cio.h"
#include "directn.h"
#include "env.h"
#include "libutil.h"
#include "monster.h"
#include "stuff.h"
#include "tiledef-dngn.h"
#include "tiledef-player.h"
#include "tilereg-dgn.h"
#include "tilepick.h"
#include "tileview.h"
#include "viewgeom.h"

MonsterRegion::MonsterRegion(const TileRegionInit &init) : GridRegion(init)
{
}

void MonsterRegion::update()
{
    m_items.clear();
    m_mon_info.clear();
    m_dirty = true;

    const size_t max_mons = mx * my;

    if (max_mons == 0)
        return;

    get_monster_info(m_mon_info);
    std::sort(m_mon_info.begin(), m_mon_info.end(),
              monster_info::less_than_wrapper);

    unsigned int num_mons = std::min(max_mons, m_mon_info.size());
    for (size_t i = 0; i < num_mons; ++i)
    {
        InventoryTile desc;
        desc.idx = i;

        m_items.push_back(desc);
    }
}

int MonsterRegion::handle_mouse(MouseEvent &event)
{
    int cx, cy;
    if (!mouse_pos(event.px, event.py, cx, cy))
    {
        place_cursor(NO_CURSOR);
        return (0);
    }

    const coord_def cursor(cx, cy);
    place_cursor(cursor);

    if (mouse_control::current_mode() != MOUSE_MODE_COMMAND)
        return (0);


    unsigned int item_idx = cursor_index();
    const monsters *mon = get_monster(item_idx);
    if (!mon)
        return (0);

    const coord_def &gc = mon->position;
    tiles.place_cursor(CURSOR_MOUSE, gc);

    if (event.event != MouseEvent::PRESS)
        return (0);

    if (event.button == MouseEvent::LEFT)
    {
        m_last_clicked_item = item_idx;
        return (tile_click_cell(gc, event.mod));
    }
    else if (event.button == MouseEvent::RIGHT)
    {
        full_describe_square(gc);
        redraw_screen();
        return (CK_MOUSE_CMD);
    }

    return (0);
}

bool MonsterRegion::update_tip_text(std::string &tip)
{
    if (m_cursor == NO_CURSOR)
        return (false);

    unsigned int item_idx = cursor_index();
    const monsters *mon = get_monster(item_idx);
    if (!mon)
        return (false);

    return (tile_dungeon_tip(mon->position, tip));
}

bool MonsterRegion::update_tab_tip_text(std::string &tip, bool active)
{
    return (false);
}

bool MonsterRegion::update_alt_text(std::string &alt)
{
    if (m_cursor == NO_CURSOR)
        return (false);

    unsigned int item_idx = cursor_index();
    if (m_last_clicked_item >= 0
        && item_idx == (unsigned int) m_last_clicked_item)
    {
        return (false);
    }

    const monsters *mon = get_monster(item_idx);
    if (!mon)
        return (false);

    const coord_def &gc = mon->position;

    describe_info inf;
    if (!you.see_cell(gc))
        return (false);

    get_square_desc(gc, inf, true, false);

    alt_desc_proc proc(crawl_view.msgsz.x, crawl_view.msgsz.y);
    process_description<alt_desc_proc>(proc, inf);

    proc.get_string(alt);

    return (true);
}

const monsters *MonsterRegion::get_monster(unsigned int idx) const
{
    if (idx >= m_items.size())
        return (NULL);

    const InventoryTile &item = m_items[idx];
    if (item.idx >= static_cast<int>(m_mon_info.size()))
        return (NULL);

    return (m_mon_info[item.idx].m_mon);
}

void MonsterRegion::pack_buffers()
{
    const int num_floor = tile_dngn_count(env.tile_default.floor);

    unsigned int i = 0;
    for (int y = 0; y < my; y++)
    {
        for (int x = 0; x < mx; x++)
        {
            bool cursor = (i < m_items.size()) ?
                (m_items[i].flag & TILEI_FLAG_CURSOR) : false;

            const monsters *mon = get_monster(i++);
            if (mon)
            {
                const coord_def gc = mon->position;
                const coord_def ep = view2show(grid2view(gc));

                if (crawl_view.in_grid_los(gc))
                {
                    packed_cell cell;
                    cell.fg = env.tile_fg(ep);
                    cell.bg = env.tile_bg(ep);
                    cell.flv = env.tile_flv(gc);
                    tile_apply_properties(gc, &cell.fg, &cell.bg);

                    m_buf.add(cell, x, y);

                    if (cursor)
                        m_buf.add_main_tile(TILE_CURSOR, x, y);
                    continue;
                }
            }

            // Fill the rest of the space with out of sight floor tiles.
            int tileidx = env.tile_default.floor + m_flavour[i] % num_floor;
            m_buf.add_dngn_tile(tileidx, x, y);
            m_buf.add_main_tile(TILE_MESH, x, y);
        }
    }
}

void MonsterRegion::draw_tag()
{
    if (m_cursor == NO_CURSOR)
        return;

    int curs_index = cursor_index();
    if (curs_index >= (int)m_items.size())
        return;
    int idx = m_items[curs_index].idx;
    if (idx == -1)
        return;

    const monsters *mon = get_monster(idx);
    if (!mon)
        return;

    std::string desc = mon->name(DESC_CAP_A);
    draw_desc(desc.c_str());
}

void MonsterRegion::activate()
{
}

#endif