void game_display::draw_movement_info(const map_location& loc) { // Search if there is a mark here pathfind::marked_route::mark_map::iterator w = route_.marks.find(loc); boost::shared_ptr<wb::manager> wb = wb_.lock(); // Don't use empty route or the first step (the unit will be there) if(w != route_.marks.end() && !route_.steps.empty() && route_.steps.front() != loc) { const unit_map::const_iterator un = (wb && wb->get_temp_move_unit().valid()) ? wb->get_temp_move_unit() : dc_->units().find(route_.steps.front()); if(un != dc_->units().end()) { // Display the def% of this terrain int def = 100 - un->defense_modifier(get_map().get_terrain(loc)); std::stringstream def_text; def_text << def << "%"; SDL_Color color = int_to_color(game_config::red_to_green(def, false)); // simple mark (no turn point) use smaller font int def_font = w->second.turns > 0 ? 18 : 16; draw_text_in_hex(loc, LAYER_MOVE_INFO, def_text.str(), def_font, color); int xpos = get_location_x(loc); int ypos = get_location_y(loc); if (w->second.invisible) { drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos, image::get_image("misc/hidden.png", image::SCALED_TO_HEX)); } if (w->second.zoc) { drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos, image::get_image("misc/zoc.png", image::SCALED_TO_HEX)); } if (w->second.capture) { drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos, image::get_image("misc/capture.png", image::SCALED_TO_HEX)); } //we display turn info only if different from a simple last "1" if (w->second.turns > 1 || (w->second.turns == 1 && loc != route_.steps.back())) { std::stringstream turns_text; turns_text << w->second.turns; draw_text_in_hex(loc, LAYER_MOVE_INFO, turns_text.str(), 17, font::NORMAL_COLOR, 0.5,0.8); } // The hex is full now, so skip the "show enemy moves" return; } } // When out-of-turn, it's still interesting to check out the terrain defs of the selected unit else if (selectedHex_.valid() && loc == mouseoverHex_) { const unit_map::const_iterator selectedUnit = resources::gameboard->find_visible_unit(selectedHex_,dc_->teams()[currentTeam_]); const unit_map::const_iterator mouseoveredUnit = resources::gameboard->find_visible_unit(mouseoverHex_,dc_->teams()[currentTeam_]); if(selectedUnit != dc_->units().end() && mouseoveredUnit == dc_->units().end()) { // Display the def% of this terrain int def = 100 - selectedUnit->defense_modifier(get_map().get_terrain(loc)); std::stringstream def_text; def_text << def << "%"; SDL_Color color = int_to_color(game_config::red_to_green(def, false)); // use small font int def_font = 16; draw_text_in_hex(loc, LAYER_MOVE_INFO, def_text.str(), def_font, color); } } if (!reach_map_.empty()) { reach_map::iterator reach = reach_map_.find(loc); if (reach != reach_map_.end() && reach->second > 1) { const std::string num = lexical_cast<std::string>(reach->second); draw_text_in_hex(loc, LAYER_MOVE_INFO, num, 16, font::YELLOW_COLOR); } } }
void game_display::draw_hex(const map_location& loc) { const bool on_map = get_map().on_board(loc); const bool is_shrouded = shrouded(loc); // const bool is_fogged = fogged(loc); const int xpos = get_location_x(loc); const int ypos = get_location_y(loc); // image::TYPE image_type = get_image_type(loc); display::draw_hex(loc); if(cursor::get() == cursor::WAIT) { // Interaction is disabled, so we don't need anything else return; } if(on_map && loc == mouseoverHex_) { tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM; const unit *u = resources::gameboard->get_visible_unit(loc, dc_->teams()[viewing_team()] ); if( u != NULL ) { hex_top_layer = LAYER_MOUSEOVER_TOP; } if(u == NULL) { drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-top.png~RC(magenta>gold)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png~RC(magenta>gold)", image::SCALED_TO_HEX)); } else if(dc_->teams()[currentTeam_].is_enemy(u->side())) { drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-enemy-top.png~RC(magenta>red)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-enemy-bottom.png~RC(magenta>red)", image::SCALED_TO_HEX)); } else if(dc_->teams()[currentTeam_].side() == u->side()) { drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-top.png~RC(magenta>green)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png~RC(magenta>green)", image::SCALED_TO_HEX)); } else { drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-top.png~RC(magenta>lightblue)", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png~RC(magenta>lightblue)", image::SCALED_TO_HEX)); } } // Draw reach_map information. // We remove the reachability mask of the unit // that we want to attack. if (!is_shrouded && !reach_map_.empty() && reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) { static const image::locator unreachable(game_config::images::unreachable); drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos, image::get_image(unreachable,image::SCALED_TO_HEX)); } if (boost::shared_ptr<wb::manager> w = wb_.lock()) { w->draw_hex(loc); if (!(w->is_active() && w->has_temp_move())) { // Footsteps indicating a movement path const std::vector<surface>& footstepImages = footsteps_images(loc, route_, dc_); if (!footstepImages.empty()) { drawing_buffer_add(LAYER_FOOTSTEPS, loc, xpos, ypos, footstepImages); } } } // Draw the attack direction indicator if(on_map && loc == attack_indicator_src_) { drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos, image::get_image("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX)); } else if (on_map && loc == attack_indicator_dst_) { drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos, image::get_image("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX)); } // Linger overlay unconditionally otherwise it might give glitches // so it's drawn over the shroud and fog. if(game_mode_ != RUNNING) { static const image::locator linger(game_config::images::linger); drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, xpos, ypos, image::get_image(linger, image::TOD_COLORED)); } if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) { static const image::locator selected(game_config::images::selected); drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos, image::get_image(selected, image::SCALED_TO_HEX)); } // Show def% and turn to reach info if(!is_shrouded && on_map) { draw_movement_info(loc); } if(game_config::debug) { int debugH = debugHighlights_[loc]; if (debugH) { std::string txt = lexical_cast<std::string>(debugH); draw_text_in_hex(loc, LAYER_MOVE_INFO, txt, 18, font::BAD_COLOR); } } //simulate_delay += 1; }
void game_display::draw_hex(const map_location& loc) { const bool on_map = get_map().on_board(loc); const bool is_shrouded = shrouded(loc); const bool is_fogged = fogged(loc); const int xpos = get_location_x(loc); const int ypos = get_location_y(loc); image::TYPE image_type = get_image_type(loc); display::draw_hex(loc); if(on_map && loc == mouseoverHex_) { tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM; if( get_visible_unit(loc, (*teams_)[viewing_team()] ) != NULL ) { hex_top_layer = LAYER_MOUSEOVER_TOP; } drawing_buffer_add( hex_top_layer, loc, xpos, ypos, image::get_image("misc/hover-hex-top.png", image::SCALED_TO_HEX)); drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png", image::SCALED_TO_HEX)); } if(!is_shrouded) { typedef overlay_map::const_iterator Itor; std::pair<Itor,Itor> overlays = overlays_.equal_range(loc); for( ; overlays.first != overlays.second; ++overlays.first) { if ((overlays.first->second.team_name == "" || overlays.first->second.team_name.find((*teams_)[playing_team()].team_name()) != std::string::npos) && !(is_fogged && !overlays.first->second.visible_in_fog)) { drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, image::get_image(overlays.first->second.image,image_type)); } } // village-control flags. drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, get_flag(loc)); } // Draw reach_map information. // We remove the reachability mask of the unit // that we want to attack. if (!is_shrouded && !reach_map_.empty() && reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) { static const image::locator unreachable(game_config::images::unreachable); drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos, image::get_image(unreachable,image::SCALED_TO_HEX)); } resources::whiteboard->draw_hex(loc); if (!(resources::whiteboard->is_active() && resources::whiteboard->has_temp_move())) { // Footsteps indicating a movement path const std::vector<surface>& footstepImages = footsteps_images(loc); if (footstepImages.size() != 0) { drawing_buffer_add(LAYER_FOOTSTEPS, loc, xpos, ypos, footstepImages); } } // Draw the attack direction indicator if(on_map && loc == attack_indicator_src_) { drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos, image::get_image("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX)); } else if (on_map && loc == attack_indicator_dst_) { drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos, image::get_image("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX)); } // Linger overlay unconditionally otherwise it might give glitches // so it's drawn over the shroud and fog. if(game_mode_ != RUNNING) { static const image::locator linger(game_config::images::linger); drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, xpos, ypos, image::get_image(linger, image::TOD_COLORED)); } if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) { static const image::locator selected(game_config::images::selected); drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos, image::get_image(selected, image::SCALED_TO_HEX)); } // Show def% and turn to reach info if(!is_shrouded && on_map) { draw_movement_info(loc); } if(game_config::debug) { int debugH = debugHighlights_[loc]; if (debugH) { std::string txt = lexical_cast<std::string>(debugH); draw_text_in_hex(loc, LAYER_MOVE_INFO, txt, 18, font::BAD_COLOR); } } //simulate_delay += 1; }