diff options
author | Enne Walker <ennewalker@users.sourceforge.net> | 2010-04-19 20:00:06 -0400 |
---|---|---|
committer | Enne Walker <ennewalker@users.sourceforge.net> | 2010-04-25 19:33:13 -0400 |
commit | 8305dc11a61b732984b4bf2a2f8c8f48af84630e (patch) | |
tree | 9f605e327b60ab79111ae7c25bec938ed2261a0b /crawl-ref/source/tilereg-map.cc | |
parent | edacdc0db313c0f5385631dfcf560f1fdf8e7c8a (diff) | |
download | crawl-ref-8305dc11a61b732984b4bf2a2f8c8f48af84630e.tar.gz crawl-ref-8305dc11a61b732984b4bf2a2f8c8f48af84630e.zip |
Split tilereg.h/cc into multiple files.
No functional changes, just rearranging and exposing functions where
needed.
Diffstat (limited to 'crawl-ref/source/tilereg-map.cc')
-rw-r--r-- | crawl-ref/source/tilereg-map.cc | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/crawl-ref/source/tilereg-map.cc b/crawl-ref/source/tilereg-map.cc new file mode 100644 index 0000000000..23ebad028d --- /dev/null +++ b/crawl-ref/source/tilereg-map.cc @@ -0,0 +1,330 @@ +/* + * File: tilereg-map.cc + * + * Created by: ennewalker on Sat Jan 5 01:33:53 2008 UTC + */ + +#include "AppHdr.h" + +#ifdef USE_TILE + +#include "tilereg-map.h" + +#include "cio.h" +#include "food.h" +#include "libutil.h" +#include "misc.h" +#include "options.h" +#include "tilesdl.h" +#include "travel.h" +#include "viewgeom.h" + +const VColour map_colours[MAX_MAP_COL] = +{ + VColour( 0, 0, 0, 255), // BLACK + VColour(128, 128, 128, 255), // DKGREY + VColour(160, 160, 160, 255), // MDGREY + VColour(192, 192, 192, 255), // LTGREY + VColour(255, 255, 255, 255), // WHITE + + VColour( 0, 64, 255, 255), // BLUE (actually cyan-blue) + VColour(128, 128, 255, 255), // LTBLUE + VColour( 0, 32, 128, 255), // DKBLUE (maybe too dark) + + VColour( 0, 255, 0, 255), // GREEN + VColour(128, 255, 128, 255), // LTGREEN + VColour( 0, 128, 0, 255), // DKGREEN + + VColour( 0, 255, 255, 255), // CYAN + VColour( 64, 255, 255, 255), // LTCYAN (maybe too pale) + VColour( 0, 128, 128, 255), // DKCYAN + + VColour(255, 0, 0, 255), // RED + VColour(255, 128, 128, 255), // LTRED (actually pink) + VColour(128, 0, 0, 255), // DKRED + + VColour(192, 0, 255, 255), // MAGENTA (actually blue-magenta) + VColour(255, 128, 255, 255), // LTMAGENTA + VColour( 96, 0, 128, 255), // DKMAGENTA + + VColour(255, 255, 0, 255), // YELLOW + VColour(255, 255, 64, 255), // LTYELLOW (maybe too pale) + VColour(128, 128, 0, 255), // DKYELLOW + + VColour(165, 91, 0, 255), // BROWN +}; + +MapRegion::MapRegion(int pixsz) : + m_buf(NULL), + m_dirty(true), + m_far_view(false) +{ + ASSERT(pixsz > 0); + + dx = pixsz; + dy = pixsz; + clear(); + init_colours(); +} + +void MapRegion::on_resize() +{ + delete[] m_buf; + + int size = mx * my; + m_buf = new unsigned char[size]; + memset(m_buf, 0, sizeof(unsigned char) * size); +} + +void MapRegion::init_colours() +{ + // TODO enne - the options array for colours should be + // tied to the map feature enumeration to avoid this function. + m_colours[MF_UNSEEN] = (map_colour)Options.tile_unseen_col; + m_colours[MF_FLOOR] = (map_colour)Options.tile_floor_col; + m_colours[MF_WALL] = (map_colour)Options.tile_wall_col; + m_colours[MF_MAP_FLOOR] = (map_colour)Options.tile_floor_col; // TODO enne + m_colours[MF_MAP_WALL] = (map_colour)Options.tile_mapped_wall_col; + m_colours[MF_DOOR] = (map_colour)Options.tile_door_col; + m_colours[MF_ITEM] = (map_colour)Options.tile_item_col; + m_colours[MF_MONS_FRIENDLY] = (map_colour)Options.tile_friendly_col; + m_colours[MF_MONS_PEACEFUL] = (map_colour)Options.tile_peaceful_col; + m_colours[MF_MONS_NEUTRAL] = (map_colour)Options.tile_neutral_col; + m_colours[MF_MONS_HOSTILE] = (map_colour)Options.tile_monster_col; + m_colours[MF_MONS_NO_EXP] = (map_colour)Options.tile_plant_col; + m_colours[MF_STAIR_UP] = (map_colour)Options.tile_upstairs_col; + m_colours[MF_STAIR_DOWN] = (map_colour)Options.tile_downstairs_col; + m_colours[MF_STAIR_BRANCH] = (map_colour)Options.tile_feature_col; + m_colours[MF_FEATURE] = (map_colour)Options.tile_feature_col; + m_colours[MF_WATER] = (map_colour)Options.tile_water_col; + m_colours[MF_LAVA] = (map_colour)Options.tile_lava_col; + m_colours[MF_TRAP] = (map_colour)Options.tile_trap_col; + m_colours[MF_EXCL_ROOT] = (map_colour)Options.tile_excl_centre_col; + m_colours[MF_EXCL] = (map_colour)Options.tile_excluded_col; + m_colours[MF_PLAYER] = (map_colour)Options.tile_player_col; +} + +MapRegion::~MapRegion() +{ + delete[] m_buf; +} + +void MapRegion::pack_buffers() +{ + m_buf_map.clear(); + m_buf_lines.clear(); + + for (int x = m_min_gx; x <= m_max_gx; x++) + for (int y = m_min_gy; y <= m_max_gy; y++) + { + map_feature f = (map_feature)m_buf[x + y * mx]; + map_colour c = m_colours[f]; + + float pos_x = x - m_min_gx; + float pos_y = y - m_min_gy; + m_buf_map.add(pos_x, pos_y, pos_x + 1, pos_y + 1, map_colours[c]); + } + + // Draw window box. + if (m_win_start.x == -1 && m_win_end.x == -1) + return; + + int c = (int)Options.tile_window_col; + float pos_sx = (m_win_start.x - m_min_gx); + float pos_sy = (m_win_start.y - m_min_gy); + float pos_ex = (m_win_end.x - m_min_gx) + 1 / (float)dx; + float pos_ey = (m_win_end.y - m_min_gy) + 1 / (float)dy; + + m_buf_lines.add_square(pos_sx, pos_sy, pos_ex, pos_ey, map_colours[c]); +} + +void MapRegion::render() +{ + if (m_min_gx > m_max_gx || m_min_gy > m_max_gy) + return; + +#ifdef DEBUG_TILES_REDRAW + cprintf("rendering MapRegion\n"); +#endif + if (m_dirty) + { + pack_buffers(); + m_dirty = false; + } + + set_transform(); + m_buf_map.draw(NULL, NULL); + m_buf_lines.draw(NULL, NULL); +} + +void MapRegion::recenter() +{ + // adjust offsets to center map + ox = (wx - dx * (m_max_gx - m_min_gx)) / 2; + oy = (wy - dy * (m_max_gy - m_min_gy)) / 2; +#if 0 + // Not needed? (jpeg) + m_dirty = true; +#endif +} + +void MapRegion::set(int gx, int gy, map_feature f) +{ + ASSERT((unsigned int)f <= (unsigned char)~0); + m_buf[gx + gy * mx] = f; + + if (f == MF_UNSEEN) + return; + + // Get map extents + m_min_gx = std::min(m_min_gx, gx); + m_max_gx = std::max(m_max_gx, gx); + m_min_gy = std::min(m_min_gy, gy); + m_max_gy = std::max(m_max_gy, gy); + + recenter(); +} + +void MapRegion::update_bounds() +{ + int min_gx = m_min_gx; + int max_gx = m_max_gx; + int min_gy = m_min_gy; + int max_gy = m_max_gy; + + m_min_gx = GXM; + m_max_gx = 0; + m_min_gy = GYM; + m_max_gy = 0; + + for (int x = min_gx; x <= max_gx; x++) + for (int y = min_gy; y <= max_gy; y++) + { + map_feature f = (map_feature)m_buf[x + y * mx]; + if (f == MF_UNSEEN) + continue; + + m_min_gx = std::min(m_min_gx, x); + m_max_gx = std::max(m_max_gx, x); + m_min_gy = std::min(m_min_gy, y); + m_max_gy = std::max(m_max_gy, y); + } + + recenter(); +#if 0 + // Not needed? (jpeg) + m_dirty = true; +#endif +} + +void MapRegion::set_window(const coord_def &start, const coord_def &end) +{ + m_win_start = start; + m_win_end = end; + + m_dirty = true; +} + +void MapRegion::clear() +{ + m_min_gx = GXM; + m_max_gx = 0; + m_min_gy = GYM; + m_max_gy = 0; + + m_win_start.x = -1; + m_win_start.y = -1; + m_win_end.x = -1; + m_win_end.y = -1; + + recenter(); + + if (m_buf) + memset(m_buf, 0, sizeof(*m_buf) * mx * my); + + m_buf_map.clear(); + m_buf_lines.clear(); +} + +int MapRegion::handle_mouse(MouseEvent &event) +{ + if (mouse_control::current_mode() != MOUSE_MODE_COMMAND) + return 0; + + int cx; + int cy; + if (!mouse_pos(event.px, event.py, cx, cy)) + { + if (m_far_view) + { + m_far_view = false; + tiles.load_dungeon(crawl_view.vgrdc); + return 0; + } + return 0; + } + + const int x = event.px - sx; + const int y = event.py - sy; + if (x < 0 || x > wx || y < 0 || y > wy) + return (0); + + const coord_def gc(m_min_gx + cx, m_min_gy + cy); + + tiles.place_cursor(CURSOR_MOUSE, gc); + + switch (event.event) + { + case MouseEvent::MOVE: + if (m_far_view) + tiles.load_dungeon(gc); + return 0; + case MouseEvent::PRESS: + if (event.button == MouseEvent::LEFT) + { + if (event.mod & MOD_SHIFT) + { + // Start autotravel, or give an appropriate message. + do_explore_cmd(); + return (CK_MOUSE_CMD); + } + else + return (click_travel(gc, event.mod & MOD_CTRL)); + } + else if (event.button == MouseEvent::RIGHT) + { + m_far_view = true; + tiles.load_dungeon(gc); + } + return 0; + case MouseEvent::RELEASE: + if ((event.button == MouseEvent::RIGHT) && m_far_view) + { + m_far_view = false; + tiles.load_dungeon(crawl_view.vgrdc); + } + return (0); + default: + return (0); + } +} + +bool MapRegion::update_tip_text(std::string& tip) +{ + if (mouse_control::current_mode() != MOUSE_MODE_COMMAND) + return (false); + + if (!player_in_mappable_area()) + return (false); + + tip = "[L-Click] Travel / [R-Click] View"; + if (you.level_type != LEVEL_LABYRINTH + && (you.hunger_state > HS_STARVING || you_min_hunger()) + && i_feel_safe()) + { + tip += "\n[Shift-L-Click] Autoexplore"; + } + return (true); +} + +#endif |