10 #include "tilereg-mon.h"
18 #include "tiledef-dngn.h"
19 #include "tiledef-icons.h"
20 #include "tiledef-player.h"
21 #include "tilereg-dgn.h"
26 MonsterRegion::MonsterRegion(const TileRegionInit
&init
) : GridRegion(init
)
30 void MonsterRegion::update()
36 const size_t max_mons
= mx
* my
;
41 get_monster_info(m_mon_info
);
42 std::sort(m_mon_info
.begin(), m_mon_info
.end(),
43 monster_info::less_than_wrapper
);
45 unsigned int num_mons
= std::min(max_mons
, m_mon_info
.size());
46 for (size_t i
= 0; i
< num_mons
; ++i
)
51 m_items
.push_back(desc
);
55 int MonsterRegion::handle_mouse(MouseEvent
&event
)
58 if (!mouse_pos(event
.px
, event
.py
, cx
, cy
))
60 place_cursor(NO_CURSOR
);
64 const coord_def
cursor(cx
, cy
);
67 if (mouse_control::current_mode() != MOUSE_MODE_COMMAND
)
71 unsigned int item_idx
= cursor_index();
72 const monster
* mon
= get_monster(item_idx
);
76 const coord_def
&gc
= mon
->position
;
77 tiles
.place_cursor(CURSOR_MOUSE
, gc
);
79 if (event
.event
!= MouseEvent::PRESS
)
82 if (event
.button
== MouseEvent::LEFT
)
84 m_last_clicked_item
= item_idx
;
85 return (tile_click_cell(gc
, event
.mod
));
87 else if (event
.button
== MouseEvent::RIGHT
)
89 full_describe_square(gc
);
91 return (CK_MOUSE_CMD
);
97 bool MonsterRegion::update_tip_text(std::string
&tip
)
99 if (m_cursor
== NO_CURSOR
)
102 unsigned int item_idx
= cursor_index();
103 const monster
* mon
= get_monster(item_idx
);
107 return (tile_dungeon_tip(mon
->position
, tip
));
110 bool MonsterRegion::update_tab_tip_text(std::string
&tip
, bool active
)
115 bool MonsterRegion::update_alt_text(std::string
&alt
)
117 if (m_cursor
== NO_CURSOR
)
120 unsigned int item_idx
= cursor_index();
121 if (m_last_clicked_item
>= 0
122 && item_idx
== (unsigned int) m_last_clicked_item
)
127 const monster
* mon
= get_monster(item_idx
);
131 const coord_def
&gc
= mon
->position
;
134 if (!you
.see_cell(gc
))
137 get_square_desc(gc
, inf
, true, false);
139 alt_desc_proc
proc(crawl_view
.msgsz
.x
, crawl_view
.msgsz
.y
);
140 process_description
<alt_desc_proc
>(proc
, inf
);
142 proc
.get_string(alt
);
147 const monster
* MonsterRegion::get_monster(unsigned int idx
) const
149 if (idx
>= m_items
.size())
152 const InventoryTile
&item
= m_items
[idx
];
153 if (item
.idx
>= static_cast<int>(m_mon_info
.size()))
156 return (m_mon_info
[item
.idx
].mon());
159 void MonsterRegion::pack_buffers()
162 const int num_floor
= tile_dngn_count(env
.tile_default
.floor
);
165 for (int y
= 0; y
< my
; y
++)
167 for (int x
= 0; x
< mx
; x
++)
169 bool cursor
= (i
< m_items
.size()) ?
170 (m_items
[i
].flag
& TILEI_FLAG_CURSOR
) : false;
172 const monster
* mon
= get_monster(i
++);
175 const coord_def gc
= mon
->position
;
176 const coord_def ep
= grid2show(gc
);
178 if (crawl_view
.in_los_bounds_g(gc
))
181 cell
.fg
= env
.tile_fg(ep
);
182 cell
.bg
= env
.tile_bg(ep
);
183 cell
.flv
= env
.tile_flv(gc
);
184 tile_apply_properties(gc
, cell
);
186 m_buf
.add(cell
, x
, y
);
189 m_buf
.add_icons_tile(TILEI_CURSOR
, x
, y
);
194 // Fill the rest of the space with out of sight floor tiles.
195 int tileidx
= env
.tile_default
.floor
+ m_flavour
[i
] % num_floor
;
196 m_buf
.add_dngn_tile(tileidx
, x
, y
);
197 m_buf
.add_icons_tile(TILEI_MESH
, x
, y
);
202 void MonsterRegion::draw_tag()
204 if (m_cursor
== NO_CURSOR
)
207 int curs_index
= cursor_index();
208 if (curs_index
>= (int)m_items
.size())
210 int idx
= m_items
[curs_index
].idx
;
214 const monster
* mon
= get_monster(idx
);
218 std::string desc
= mon
->name(DESC_CAP_A
);
219 draw_desc(desc
.c_str());
222 void MonsterRegion::activate()