Fix a bunch of MSVC2015 compiler warnings about hiding declarations

This commit still doesn't fix all of them. I decided to leave alone
cases where variables with the same name are assigned in multiple
conditions of the same if...else if...else statement, and cases where a
scope logging macro is used multiple times in the same scope. In any
case, this commit greatly reduces the warning count on MSVC2015 and makes
new warnings much easier to spot.
This commit is contained in:
Jyrki Vesterinen 2016-10-05 23:30:57 +03:00
parent 5d347bb61b
commit af733360a8
69 changed files with 322 additions and 336 deletions

View file

@ -72,9 +72,9 @@ void addon_info::read(const config& cfg)
this->uploads = cfg["uploads"];
this->type = get_addon_type(cfg["type"].str());
const config::const_child_itors& locales = cfg.child_range("translation");
const config::const_child_itors& locales_as_configs = cfg.child_range("translation");
for(const config& locale : locales) {
for(const config& locale : locales_as_configs) {
this->locales.push_back(locale["language"].str());
}

View file

@ -215,19 +215,19 @@ addon_op_result do_resolve_addon_dependencies(CVideo& v, addons_client& client,
cursor_setter.reset(new cursor::setter(cursor::WAIT));
for(const std::string& dep : missing_deps) {
const addon_info& addon = addon_at(dep, addons);
const addon_info& missing_addon = addon_at(dep, addons);
const std::string& display_size = size_display_string(addon.size);
const std::string& display_type = addon.display_type();
const std::string& display_icon = addon.display_icon();
const std::string& display_version = addon.version.str();
const std::string& display_size = size_display_string(missing_addon.size);
const std::string& display_type = missing_addon.display_type();
const std::string& display_icon = missing_addon.display_icon();
const std::string& display_version = missing_addon.version.str();
const std::string& display_title = font::word_wrap_text(addon.display_title(), font::SIZE_NORMAL, 150, -1, 2);
std::string display_author = addon.author;
const std::string& display_title = font::word_wrap_text(missing_addon.display_title(), font::SIZE_NORMAL, 150, -1, 2);
std::string display_author = missing_addon.author;
utils::ellipsis_truncate(display_author, 14);
// Add negative sizes to reverse the sort order.
sort_sizes.push_back(-addon.size);
sort_sizes.push_back(-missing_addon.size);
// NOTE: NULL_MARKUP used to escape abuse of formatting chars in add-on titles
options.push_back(IMAGE_PREFIX + display_icon + sep +
@ -263,10 +263,10 @@ addon_op_result do_resolve_addon_dependencies(CVideo& v, addons_client& client,
std::vector<std::string> failed_titles;
for(const std::string& dep : missing_deps) {
const addon_info& addon = addon_at(dep, addons);
const addon_info& missing_addon = addon_at(dep, addons);
if(!try_fetch_addon(v, client, addon)) {
failed_titles.push_back(addon.title);
if(!try_fetch_addon(v, client, missing_addon)) {
failed_titles.push_back(missing_addon.title);
} else {
result.wml_changed = true;
}

View file

@ -1178,14 +1178,14 @@ void readonly_context_impl::recalculate_move_maps() const
if (i.valid()) {
map_location loc = i->get_location();
srcdst_.erase(loc);
for(move_map::iterator i = dstsrc_.begin(); i != dstsrc_.end(); ) {
if(i->second == loc) {
dstsrc_.erase(i++);
for(move_map::iterator it = dstsrc_.begin(); it != dstsrc_.end(); ) {
if(it->second == loc) {
it = dstsrc_.erase(it);
} else {
++i;
++it;
}
}
///@todo 1.9: shall possible moves be modified as well ?
///@todo: shall possible moves be modified as well ?
}
}
move_maps_valid_ = true;

View file

@ -1031,7 +1031,7 @@ void get_villages_phase::dispatch_complex(
for(u = 0; u < unit_count; ++u) {
std::cerr << units[u];
for(size_t v = 0; v < village_count; ++v) {
for(v = 0; v < village_count; ++v) {
std::cerr << '\t' << matrix[u][v];
}
std::cerr << "\t" << villages_per_unit[u] << '\n';
@ -1174,9 +1174,8 @@ void get_villages_phase::dispatch_complex(
moves.insert(moves.end(), best_result.begin(), best_result.end());
// Clean up the reachmap for dispatched units.
for(std::vector<std::pair<map_location, map_location> >::const_iterator
itor = best_result.begin(); itor != best_result.end(); ++itor) {
reachmap.erase(itor->second);
for(const auto& unit_village_pair : best_result) {
reachmap.erase(unit_village_pair.second);
}
// Try to dispatch whatever is left
@ -1215,9 +1214,8 @@ void get_villages_phase::dispatch_complex(
// clean up the reachmap we need to test whether the leader is still there
// and if so remove him manually to get him dispatched.
for(std::vector<std::pair<map_location, map_location> >::const_iterator
itor = best_result.begin(); itor != best_result.end(); ++itor) {
reachmap.erase(itor->second);
for(const auto& unit_village_pair : best_result) {
reachmap.erase(unit_village_pair.second);
}
treachmap::iterator unit = reachmap.find(leader_loc_);
if(unit != reachmap.end()) {
@ -1258,9 +1256,8 @@ void get_villages_phase::dispatch_complex(
// clean up the reachmap we need to test whether the leader is still there
// and if so remove him manually to get him dispatched.
for(std::vector<std::pair<map_location, map_location> >::const_iterator
itor = best_result.begin(); itor != best_result.end(); ++itor) {
reachmap.erase(itor->second);
for(const auto& unit_village_pair : best_result) {
reachmap.erase(unit_village_pair.second);
}
treachmap::iterator unit = reachmap.find(leader_loc_);
if(unit != reachmap.end()) {

View file

@ -844,8 +844,8 @@ double move_to_targets_phase::rate_group(const std::set<map_location>& group, co
int best_attack = 0;
for(const attack_type& a : un.attacks()) {
const int strength = a.num_attacks() * a.damage();
best_attack = std::max<int>(strength,best_attack);
const int attack_strength = a.num_attacks() * a.damage();
best_attack = std::max<int>(attack_strength, best_attack);
}
const int rating = (defense*best_attack*un.hitpoints())/(100*un.max_hitpoints());

View file

@ -1663,8 +1663,8 @@ bool recruitment::is_enemy_in_radius(const map_location& loc, int radius) const
if (surrounding.empty()) {
return false;
}
for (const map_location& loc : surrounding) {
const unit_map::const_iterator& enemy_it = units.find(loc);
for (const map_location& l : surrounding) {
const unit_map::const_iterator& enemy_it = units.find(l);
if(enemy_it == units.end()) {
continue;
}

View file

@ -97,16 +97,16 @@ void move_candidate_action::evaluate(ai::formula_ai* ai, unit_map& units)
candidate_action_filters::const_iterator me_filter = filter_map_.find("me");
std::vector<variant> res;
std::vector<variant> unit_vector;
for(unit_map::unit_iterator i = units.begin() ; i != units.end() ; ++i)
{
if (i->side() == ai->get_side() && i->movement_left() > 0) {
res.push_back(variant(new unit_callable(*i)));
unit_vector.push_back(variant(new unit_callable(*i)));
}
}
variant my_units(&res);
variant my_units(&unit_vector);
variant filtered_units;
try {

View file

@ -569,7 +569,7 @@ const std::string manager::internal_evaluate_command( side_number side, const st
if (cmd.size()==3){
//!add_ai side file
if (cmd.at(0)=="!add_ai"){
side_number side = lexical_cast<side_number>(cmd.at(1));
side = std::stoi(cmd.at(1));
std::string file = cmd.at(2);
if (add_ai_for_side_from_file(side,file,false)){
return std::string("AI MANAGER: added [")+manager::get_active_ai_identifier_for_side(side)+std::string("] AI for side ")+std::to_string(side)+std::string(" from file ")+file;
@ -579,7 +579,7 @@ const std::string manager::internal_evaluate_command( side_number side, const st
}
//!replace_ai side file
if (cmd.at(0)=="!replace_ai"){
side_number side = lexical_cast<side_number>(cmd.at(1));
side = std::stoi(cmd.at(1));
std::string file = cmd.at(2);
if (add_ai_for_side_from_file(side,file,true)){
return std::string("AI MANAGER: added [")+manager::get_active_ai_identifier_for_side(side)+std::string("] AI for side ")+std::to_string(side)+std::string(" from file ")+file;
@ -591,7 +591,7 @@ const std::string manager::internal_evaluate_command( side_number side, const st
} else if (cmd.size()==2){
//!remove_ai side
if (cmd.at(0)=="!remove_ai"){
side_number side = lexical_cast<side_number>(cmd.at(1));
side = std::stoi(cmd.at(1));
remove_ai_for_side(side);
return std::string("AI MANAGER: made an attempt to remove AI for side ")+std::to_string(side);
}

View file

@ -50,9 +50,9 @@ std::map<uint32_t, uint32_t> recolor_range(const color_range& new_range, const s
for(std::vector< uint32_t >::const_iterator temp_rgb2 = old_rgb.begin();
temp_rgb2 != old_rgb.end(); ++temp_rgb2)
{
uint16_t old_r=((*temp_rgb2) & 0X00FF0000)>>16;
uint16_t old_g=((*temp_rgb2) & 0X0000FF00)>>8;
uint16_t old_b=((*temp_rgb2) & 0X000000FF);
old_r=((*temp_rgb2) & 0X00FF0000)>>16;
old_g=((*temp_rgb2) & 0X0000FF00)>>8;
old_b=((*temp_rgb2) & 0X000000FF);
const uint16_t old_avg = (( old_r + old_g + old_b) / 3);
// Calculate new color

View file

@ -1528,7 +1528,6 @@ std::string config::hash() const
static const char hash_string[] =
"+-,.<>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char hash_str[hash_length + 1];
std::string::const_iterator c;
unsigned int i;
for(i = 0; i != hash_length; ++i) {
@ -1539,12 +1538,12 @@ std::string config::hash() const
i = 0;
for (const attribute &val : values)
{
for (c = val.first.begin(); c != val.first.end(); ++c) {
for (std::string::const_iterator c = val.first.begin(); c != val.first.end(); ++c) {
hash_str[i] ^= *c;
if (++i == hash_length) i = 0;
}
std::string base_str = val.second.t_str().base_str();
for (c = base_str.begin(); c != base_str.end(); ++c) {
for (std::string::const_iterator c = base_str.begin(); c != base_str.end(); ++c) {
hash_str[i] ^= *c;
if (++i == hash_length) i = 0;
}

View file

@ -86,28 +86,28 @@ void config_cache::clear_defines()
defines_map_["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str());
}
void config_cache::get_config(const std::string& path, config& cfg)
void config_cache::get_config(const std::string& file_path, config& cfg)
{
load_configs(path, cfg);
load_configs(file_path, cfg);
}
void config_cache::write_file(std::string path, const config& cfg)
void config_cache::write_file(std::string file_path, const config& cfg)
{
filesystem::scoped_ostream stream = filesystem::ostream_file(path);
filesystem::scoped_ostream stream = filesystem::ostream_file(file_path);
config_writer writer(*stream, true, game_config::cache_compression_level);
writer.write(cfg);
}
void config_cache::write_file(std::string path, const preproc_map& defines)
void config_cache::write_file(std::string file_path, const preproc_map& defines)
{
if(defines.empty()) {
if(filesystem::file_exists(path)) {
filesystem::delete_directory(path);
if(filesystem::file_exists(file_path)) {
filesystem::delete_directory(file_path);
}
return;
}
filesystem::scoped_ostream stream = filesystem::ostream_file(path);
filesystem::scoped_ostream stream = filesystem::ostream_file(file_path);
config_writer writer(*stream, true, game_config::cache_compression_level);
// Write all defines to stream.
@ -116,9 +116,9 @@ void config_cache::write_file(std::string path, const preproc_map& defines)
}
}
void config_cache::read_file(const std::string& path, config& cfg)
void config_cache::read_file(const std::string& file_path, config& cfg)
{
filesystem::scoped_istream stream = filesystem::istream_file(path);
filesystem::scoped_istream stream = filesystem::istream_file(file_path);
read_gz(cfg, *stream);
}
@ -132,19 +132,19 @@ void config_cache::add_defines_map_diff(preproc_map& defines_map)
return config_cache_transaction::instance().add_defines_map_diff(defines_map);
}
void config_cache::read_configs(const std::string& path, config& cfg, preproc_map& defines_map)
void config_cache::read_configs(const std::string& file_path, config& cfg, preproc_map& defines_map)
{
//read the file and then write to the cache
filesystem::scoped_istream stream = preprocess_file(path, &defines_map);
filesystem::scoped_istream stream = preprocess_file(file_path, &defines_map);
read(cfg, *stream);
}
void config_cache::read_cache(const std::string& path, config& cfg)
void config_cache::read_cache(const std::string& file_path, config& cfg)
{
static const std::string extension = ".gz";
std::stringstream defines_string;
defines_string << path;
defines_string << file_path;
bool is_valid = true;
@ -252,12 +252,12 @@ void config_cache::read_cache(const std::string& path, config& cfg)
add_defines_map_diff(copy_map);
}
void config_cache::read_defines_file(const std::string& path)
void config_cache::read_defines_file(const std::string& file_path)
{
config cfg;
read_file(path, cfg);
read_file(file_path, cfg);
DBG_CACHE << "Reading cached defines from: " << path << "\n";
DBG_CACHE << "Reading cached defines from: " << file_path << "\n";
// use static preproc_define::read_pair(config) to make a object
// and pass that object config_cache_transaction::insert_to_active method
@ -271,21 +271,21 @@ void config_cache::read_defines_queue()
{
const std::vector<std::string>& files = config_cache_transaction::instance().get_define_files();
for(const std::string &path : files) {
read_defines_file(path);
for(const std::string &p : files) {
read_defines_file(p);
}
}
void config_cache::load_configs(const std::string& path, config& cfg)
void config_cache::load_configs(const std::string& config_path, config& cfg)
{
// Make sure that we have fake transaction if no real one is going on
fake_transaction fake;
if (use_cache_) {
read_cache(path, cfg);
read_cache(config_path, cfg);
} else {
preproc_map copy_map(make_copy_map());
read_configs(path, cfg, copy_map);
read_configs(config_path, cfg, copy_map);
add_defines_map_diff(copy_map);
}
}
@ -377,22 +377,22 @@ bool config_cache::delete_cache_files(const std::vector<std::string>& paths,
const bool delete_everything = exclude_pattern.empty();
bool status = true;
for(const std::string& path : paths)
for(const std::string& file_path : paths)
{
if(!delete_everything) {
const std::string& fn = filesystem::base_name(path);
const std::string& fn = filesystem::base_name(file_path);
if(utils::wildcard_string_match(fn, exclude_pattern)) {
LOG_CACHE << "delete_cache_files(): skipping " << path
LOG_CACHE << "delete_cache_files(): skipping " << file_path
<< " excluded by '" << exclude_pattern << "'\n";
continue;
}
}
LOG_CACHE << "delete_cache_files(): deleting " << path << '\n';
if(!filesystem::delete_directory(path)) {
LOG_CACHE << "delete_cache_files(): deleting " << file_path << '\n';
if(!filesystem::delete_directory(file_path)) {
ERR_CACHE << "delete_cache_files(): could not delete "
<< path << '\n';
<< file_path << '\n';
status = false;
}
}

View file

@ -593,7 +593,6 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int index, bool press)
{
const int zoom_amount = 4;
hotkey::HOTKEY_COMMAND command = cmd.id;
SCOPE_ED;
using namespace hotkey;

View file

@ -81,13 +81,13 @@ void terrain_palette::setup(const config& cfg)
{
if (group_names.find(group["id"]) == group_names.end()) {
config cfg;
cfg["id"] = group["id"];
cfg["name"] = group["name"];
config group_cfg;
group_cfg["id"] = group["id"];
group_cfg["name"] = group["name"];
cfg["icon"] = "icons/terrain/terrain_" + group["icon"].str();
cfg["core"] = group["core"];
groups_.push_back(item_group(cfg));
group_cfg["icon"] = "icons/terrain/terrain_" + group["icon"].str();
group_cfg["core"] = group["core"];
groups_.push_back(item_group(group_cfg));
group_names.insert(groups_.back().id);
}

View file

@ -580,8 +580,8 @@ void pump()
}
}
const handler_list& event_handlers = event_contexts.front().handlers;
for(auto handler : event_handlers) {
const handler_list& global_handlers = event_contexts.front().handlers;
for(auto handler : global_handlers) {
handler->handle_event(event);
}
@ -589,8 +589,6 @@ void pump()
const handler_list& event_handlers = event_contexts.back().handlers;
//events may cause more event handlers to be added and/or removed,
//so we must use indexes instead of iterators here.
for(auto handler : event_handlers) {
handler->handle_event(event);
}

View file

@ -362,9 +362,12 @@ floating_label_context::floating_label_context()
floating_label_context::~floating_label_context()
{
const std::set<int>& labels = label_contexts.top();
for(std::set<int>::const_iterator i = labels.begin(); i != labels.end(); ) {
remove_floating_label(*i++);
const std::set<int>& context = label_contexts.top();
while (!context.empty())
{
// Remove_floating_label removes the passed label from the context.
// This loop removes a different label in every iteration.
remove_floating_label(*context.begin());
}
label_contexts.pop();

View file

@ -864,7 +864,7 @@ static surface render_text(const std::string& text, int fontsize, const SDL_Colo
for(std::vector< std::vector<surface> >::iterator i = surfaces.begin(),
i_end = surfaces.end(); i != i_end; ++i) {
size_t xpos = 0;
size_t height = 0;
height = 0;
for(std::vector<surface>::iterator j = i->begin(),
j_end = i->end(); j != j_end; ++j) {

View file

@ -1117,17 +1117,17 @@ expression_ptr parse_expression(const token* i1, const token* i2, function_symbo
int n = std::stoi(std::string(i1->begin,dot));
iterator end = i1->end;
iterator literal_end = i1->end;
if( end - dot > 4)
end = dot + 4;
if(literal_end - dot > 4)
literal_end = dot + 4;
++dot;
int f = 0;
int multiplicator = 100;
while( dot != end) {
while(dot != literal_end) {
f += (*dot - 48)*multiplicator;
multiplicator /= 10;
++dot;
@ -1140,7 +1140,7 @@ expression_ptr parse_expression(const token* i1, const token* i2, function_symbo
} else if(i1->type == TOKEN_IDENTIFIER &&
(i1+1)->type == TOKEN_LPARENS &&
(i2-1)->type == TOKEN_RPARENS) {
const token* begin = i1, *end = i2; //these are used for error reporting
const token* function_call_begin = i1, *function_call_end = i2; //these are used for error reporting
int nleft = 0, nright = 0;
for(const token* i = i1; i != i2; ++i) {
if(i->type == TOKEN_LPARENS) {
@ -1157,7 +1157,7 @@ expression_ptr parse_expression(const token* i1, const token* i2, function_symbo
return create_function(std::string(i1->begin,i1->end),args,symbols);
}
catch(formula_error& e) {
throw formula_error(e.type, tokens_to_string(begin,end), *i1->filename, i1->line_number);
throw formula_error(e.type, tokens_to_string(function_call_begin, function_call_end), *i1->filename, i1->line_number);
}
}
}
@ -1216,9 +1216,9 @@ formula_ptr formula::create_optional_formula(const std::string& str, function_sy
return formula_ptr(new formula(str, symbols));
}
formula::formula(const std::string& str, function_symbol_table* symbols) :
formula::formula(const std::string& text, function_symbol_table* symbols) :
expr_(),
str_(str),
str_(text),
symbols_(symbols),
managing_symbols(symbols == nullptr)
{
@ -1229,7 +1229,7 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :
}
std::vector<token> tokens;
std::string::const_iterator i1 = str.begin(), i2 = str.end();
std::string::const_iterator i1 = text.begin(), i2 = text.end();
//set true when 'fai' keyword is found
bool fai_keyword = false;

View file

@ -183,17 +183,17 @@ namespace { // Support functions
if (route.steps.empty()) {
WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring complexities" << std::endl;
pathfind::emergency_path_calculator calc(fake_unit, *game_map);
pathfind::emergency_path_calculator emergency_calc(fake_unit, *game_map);
route = pathfind::a_star_search(src, dst, 10000, calc,
route = pathfind::a_star_search(src, dst, 10000, emergency_calc,
game_map->w(), game_map->h());
if(route.steps.empty()) {
// This would occur when trying to do a MUF of a unit
// over locations which are unreachable to it (infinite movement
// costs). This really cannot fail.
WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring terrain" << std::endl;
pathfind::dummy_path_calculator calc(fake_unit, *game_map);
route = a_star_search(src, dst, 10000, calc, game_map->w(), game_map->h());
pathfind::dummy_path_calculator dummy_calc(fake_unit, *game_map);
route = a_star_search(src, dst, 10000, dummy_calc, game_map->w(), game_map->h());
assert(!route.steps.empty());
}
}
@ -688,8 +688,8 @@ WML_HANDLER_FUNCTION(set_variables,, cfg)
{
//merge children into one
config merged_children;
for (const config &cfg : data) {
merged_children.append(cfg);
for (const config &ch : data) {
merged_children.append(ch);
}
data = {merged_children};
}

View file

@ -65,7 +65,6 @@ namespace builtin_conditions {
}
}
if(cfg["search_recall_list"].to_bool()) {
const unit_filter ufilt(cfg, resources::filter_con);
for(const team& team : resources::gameboard->teams()) {
if(counts == default_counts && match_count) {
break;

View file

@ -538,7 +538,7 @@ bool t_pump::operator()()
unit::clear_status_caches();
{ // Block for context::scoped
context::scoped evc(impl_->contexts_, false);
context::scoped inner_evc(impl_->contexts_, false);
if ( resources::lua_kernel->run_event(ev) ) {
++impl_->internal_wml_tracking;
}

View file

@ -127,16 +127,16 @@ static std::unique_ptr<twesnothd_connection> open_connection(CVideo& video, cons
}
std::unique_ptr<twesnothd_connection> sock;
const int pos = h.find_first_of(":");
const int colon_index = h.find_first_of(":");
std::string host;
unsigned int port;
if(pos == -1) {
if(colon_index == -1) {
host = h;
port = 15000;
} else {
host = h.substr(0, pos);
port = lexical_cast_default<unsigned int>(h.substr(pos + 1), 15000);
host = h.substr(0, colon_index);
port = lexical_cast_default<unsigned int>(h.substr(colon_index + 1), 15000);
}
// shown_hosts is used to prevent the client being locked in a redirect

View file

@ -591,11 +591,11 @@ void gamebrowser::populate_game_item_map_info(gamebrowser::game_item & item, con
// Don't throw the rendered minimaps away
std::vector<minimap_cache_item> minimap_cache;
for(std::vector<game_item>::iterator oldgame = games_.begin(); oldgame != games_.end(); ++oldgame) {
minimap_cache_item item;
item.map_data = oldgame->map_data;
item.mini_map = oldgame->mini_map;
item.map_info_size = oldgame->map_info_size;
minimap_cache.push_back(item);
minimap_cache_item cache_item;
cache_item.map_data = oldgame->map_data;
cache_item.mini_map = oldgame->mini_map;
cache_item.map_info_size = oldgame->map_info_size;
minimap_cache.push_back(cache_item);
}
item.map_data = game["map_data"].str();
@ -1288,12 +1288,12 @@ void lobby::process_event_impl(const process_event_data & data)
}
config response;
config& join = response.add_child("join");
join["id"] = game.id;
join["observe"] = observe;
config& join_data = response.add_child("join");
join_data["id"] = game.id;
join_data["observe"] = observe;
if(!password.empty()) {
join["password"] = password;
join_data["password"] = password;
}
send_to_server(response);

View file

@ -1167,8 +1167,8 @@ static void encounter_recallable_units(const std::vector<team>& teams){
void encounter_map_terrain(const gamemap& map)
{
map.for_each_loc([&](const map_location& loc) {
const t_translation::t_terrain t = map.get_terrain(loc);
preferences::encountered_terrains().insert(t);
const t_translation::t_terrain terrain = map.get_terrain(loc);
preferences::encountered_terrains().insert(terrain);
for (t_translation::t_terrain t : map.underlying_union_terrain(loc)) {
preferences::encountered_terrains().insert(t);
}

View file

@ -335,17 +335,17 @@ height_map default_map_generator_job::generate_height_map(size_t width, size_t h
const int xdiff = (x2-x1);
const int ydiff = (y2-y1);
const int height = radius - int(std::sqrt(double(xdiff*xdiff + ydiff*ydiff)));
const int hill_height = radius - int(std::sqrt(double(xdiff*xdiff + ydiff*ydiff)));
if(height > 0) {
if(hill_height > 0) {
if(is_valley) {
if(height > res[x2][y2]) {
if(hill_height > res[x2][y2]) {
res[x2][y2] = 0;
} else {
res[x2][y2] -= height;
res[x2][y2] -= hill_height;
}
} else {
res[x2][y2] += height;
res[x2][y2] += hill_height;
}
}
}
@ -772,9 +772,8 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
}
terrain_map terrain(data.width, data.height, grassland);
size_t x, y;
for(x = 0; x != heights.size(); ++x) {
for(y = 0; y != heights[x].size(); ++y) {
for(size_t x = 0; x != heights.size(); ++x) {
for(size_t y = 0; y != heights[x].size(); ++y) {
for(auto i : height_conversion) {
if(i.convert_terrain(heights[x][y])) {
terrain[x][y] = i.convert_to();
@ -905,8 +904,8 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
ticks = SDL_GetTicks();
// Iterate over every flatland tile, and determine what type of flatland it is, based on our [convert] tags.
for(x = 0; x != static_cast<unsigned>(data.width); ++x) {
for(y = 0; y != static_cast<unsigned>(data.height); ++y) {
for(int x = 0; x != data.width; ++x) {
for(int y = 0; y != data.height; ++y) {
for(auto i : converters) {
if(i.convert_terrain(terrain[x][y],heights[x][y],temperature_map[x][y])) {
terrain[x][y] = i.convert_to();
@ -1152,20 +1151,20 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
starting_positions.insert(t_translation::tstarting_positions::value_type(std::to_string(player), coord));
terrain[x][y] = t_translation::HUMAN_KEEP;
const int castles[13][2] = {
const int castle_array[13][2] = {
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}, {-1, 1},
{-2, 1}, {-2, 0}, {-2, -1}, {-1, -2}, {0, -2}, {1, -2}
};
for(int i = 0; i < data.castle_size - 1; i++) {
terrain[x+castles[i][0]][y+castles[i][1]] = t_translation::HUMAN_CASTLE;
terrain[x+ castle_array[i][0]][y+ castle_array[i][1]] = t_translation::HUMAN_CASTLE;
}
// Remove all labels under the castle tiles
if(labels != nullptr) {
labels->erase(map_location(x-data.width/3,y-data.height/3));
for(int i = 0; i < data.castle_size - 1; i++) {
labels->erase(map_location(x+castles[i][0]-data.width/3, y+castles[i][1]-data.height/3));
labels->erase(map_location(x+ castle_array[i][0]-data.width/3, y+ castle_array[i][1]-data.height/3));
}
}
}
@ -1178,8 +1177,8 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
* roads could split a forest)
*/
if(misc_labels != nullptr) {
for(x = static_cast<unsigned>(data.width) / 3; x < (static_cast<unsigned>(data.width) / 3)*2; x++) {
for(y = static_cast<unsigned>(data.height) / 3; y < (static_cast<unsigned>(data.height) / 3) * 2;y++) {
for(int x = data.width / 3; x < (data.width / 3)*2; x++) {
for(int y = data.height / 3; y < (data.height / 3) * 2;y++) {
//check the terrain of the tile
const map_location loc(x - data.width / 3, y - data.height / 3);
const t_translation::t_terrain terr = terrain[x][y];

View file

@ -1058,23 +1058,23 @@ void timage::draw(surface& canvas,
local_variables.add("image_width", variant(w ? w : image_->w));
local_variables.add("image_height", variant(h ? h : image_->h));
const unsigned x = x_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(x) >= 0,
const unsigned clip_x = x_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(clip_x) >= 0,
_("Image doesn't fit on canvas."),
formatter() << "Image '" << name
<< "', x = " << static_cast<int>(x)
<< "', x = " << static_cast<int>(clip_x)
<< ".");
const unsigned y = y_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(y) >= 0,
const unsigned clip_y = y_(local_variables);
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(clip_y) >= 0,
_("Image doesn't fit on canvas."),
formatter() << "Image '" << name
<< "', y = " << static_cast<int>(y)
<< "', y = " << static_cast<int>(clip_y)
<< ".");
// Copy the data to local variables to avoid overwriting the originals.
SDL_Rect src_clip = src_clip_;
SDL_Rect dst_clip = sdl::create_rect(x, y, 0, 0);
SDL_Rect dst_clip = sdl::create_rect(clip_x, clip_y, 0, 0);
surface surf;
// Test whether we need to scale and do the scaling if needed.

View file

@ -470,9 +470,9 @@ void thandler::disconnect(tdispatcher* dispatcher)
}
/***** Set proper state for the other dispatchers. *****/
for(auto dispatcher : dispatchers_)
for(auto d : dispatchers_)
{
dynamic_cast<twidget&>(*dispatcher).set_is_dirty(true);
dynamic_cast<twidget&>(*d).set_is_dirty(true);
}
activate();

View file

@ -36,7 +36,7 @@ struct ttimer
};
/** Ids for the timers. */
static size_t id = 0;
static size_t next_timer_id = 0;
/** The active timers. */
static std::map<size_t, ttimer> timers;
@ -118,12 +118,12 @@ size_t add_timer(const Uint32 interval,
DBG_GUI_E << "Adding timer.\n";
do {
++id;
} while(id == 0 || timers.find(id) != timers.end());
++next_timer_id;
} while(next_timer_id == 0 || timers.find(next_timer_id) != timers.end());
ttimer timer;
timer.sdl_id = SDL_AddTimer(
interval, timer_callback, reinterpret_cast<void*>(id));
interval, timer_callback, reinterpret_cast<void*>(next_timer_id));
if(timer.sdl_id == 0) {
WRN_GUI_E << "Failed to create an sdl timer." << std::endl;
return 0;
@ -135,10 +135,10 @@ size_t add_timer(const Uint32 interval,
timer.callback = callback;
timers.insert(std::make_pair(id, timer));
timers.insert(std::make_pair(next_timer_id, timer));
DBG_GUI_E << "Added timer " << id << ".\n";
return id;
DBG_GUI_E << "Added timer " << next_timer_id << ".\n";
return next_timer_id;
}
bool remove_timer(const size_t id)

View file

@ -575,10 +575,10 @@ void tlua_interpreter::controller::tab()
std::string text = text_entry->get_value();
std::string prefix;
size_t idx = text.find_last_of(" (");
if (idx != std::string::npos) {
prefix = text.substr(0, idx+1);
text = text.substr(idx+1);
size_t prefix_end_pos = text.find_last_of(" (");
if (prefix_end_pos != std::string::npos) {
prefix = text.substr(0, prefix_end_pos + 1);
text = text.substr(prefix_end_pos + 1);
}
std::vector<std::string> matches;

View file

@ -147,12 +147,12 @@ void tmp_options_helper::display_custom_options(std::string&& type, const config
std::vector<std::string> combo_values;
config::const_child_itors items = menu_button_option.child_range("item");
for(auto item : items) {
for(auto i : items) {
// Comboboxes expect this key to be 'label' not 'name'
item["label"] = item["name"];
i["label"] = i["name"];
combo_items.push_back(item);
combo_values.push_back(item["value"]);
combo_items.push_back(i);
combo_values.push_back(i["value"]);
}
if(combo_items.empty()) {

View file

@ -610,12 +610,12 @@ void tpreferences::post_build(twindow& window)
std::vector<std::string> option_ids;
for(const config& choice : option.child_range("option")) {
config option;
option["label"] = choice["name"];
config menu_item;
menu_item["label"] = choice["name"];
if(choice.has_attribute("description")) {
option["details"] = std::string("<span color='#777'>") + choice["description"] + "</span>";
menu_item["details"] = std::string("<span color='#777'>") + choice["description"] + "</span>";
}
menu_data.push_back(option);
menu_data.push_back(menu_item);
option_ids.push_back(choice["id"]);
}

View file

@ -72,7 +72,7 @@ tcontrol::tcontrol(const implementation::tbuilder_control& builder,
const std::string& control_type)
: twidget(builder)
, definition_(builder.definition)
, label_(builder.label)
, label_(builder.label_string)
, use_markup_(false)
, use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
, tooltip_(builder.tooltip)
@ -438,8 +438,8 @@ void tcontrol::definition_load_configuration(const std::string& control_type)
update_canvas();
}
tpoint tcontrol::get_best_text_size(const tpoint& minimum_size,
const tpoint& maximum_size) const
tpoint tcontrol::get_best_text_size(tpoint minimum_size,
tpoint maximum_size) const
{
log_scope2(log_gui_layout, LOG_SCOPE_HEADER);
@ -488,7 +488,7 @@ tpoint tcontrol::get_best_text_size(const tpoint& minimum_size,
if(renderer_.is_truncated() && !can_wrap()) {
// FIXME if maximum size is defined we should look at that
// but also we don't adjust for the extra text space yet!!!
const tpoint maximum_size(config_->max_width, config_->max_height);
maximum_size = tpoint(config_->max_width, config_->max_height);
renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x
: -1);
}
@ -651,7 +651,7 @@ namespace implementation
tbuilder_control::tbuilder_control(const config& cfg)
: tbuilder_widget(cfg)
, definition(cfg["definition"])
, label(cfg["label"].t_str())
, label_string(cfg["label"].t_str())
, tooltip(cfg["tooltip"].t_str())
, help(cfg["help"].t_str())
, use_tooltip_on_label_overflow(true)
@ -664,7 +664,7 @@ tbuilder_control::tbuilder_control(const config& cfg)
VALIDATE_WITH_DEV_MESSAGE(
help.empty() || !tooltip.empty(),
_("Found a widget with a helptip and without a tooltip."),
formatter() << "id '" << id << "' label '" << label
formatter() << "id '" << id << "' label '" << label_string
<< "' helptip '" << help << "'.");
@ -679,7 +679,7 @@ void tbuilder_control::init_control(tcontrol* control) const
control->set_id(id);
control->set_definition(definition);
control->set_linked_group(linked_group);
control->set_label(label);
control->set_label(label_string);
control->set_tooltip(tooltip);
control->set_help_message(help);
control->set_use_tooltip_on_label_overflow(use_tooltip_on_label_overflow);

View file

@ -468,8 +468,8 @@ private:
*
* @returns The best size.
*/
tpoint get_best_text_size(const tpoint& minimum_size,
const tpoint& maximum_size = {0, 0}) const;
tpoint get_best_text_size(tpoint minimum_size,
tpoint maximum_size = {0, 0}) const;
/**
* Contains a helper cache for the rendering.
@ -528,7 +528,7 @@ public:
/** Parameters for the control. */
std::string definition;
t_string label;
t_string label_string;
t_string tooltip;
t_string help;
bool use_tooltip_on_label_overflow;

View file

@ -1139,25 +1139,25 @@ char compile_assert[0];
result = new tgenerator<minimum, \
maximum, \
policy::placement::thorizontal_list, \
select>; \
select_action>; \
break; \
case tgenerator_::vertical_list: \
result = new tgenerator<minimum, \
maximum, \
policy::placement::tvertical_list, \
select>; \
select_action>; \
break; \
case tgenerator_::grid: \
result = new tgenerator<minimum, \
maximum, \
policy::placement::tmatrix, \
select>; \
select_action>; \
break; \
case tgenerator_::independent: \
result = new tgenerator<minimum, \
maximum, \
policy::placement::tindependent, \
select>; \
select_action>; \
break; \
default: \
assert(false); \
@ -1169,10 +1169,10 @@ char compile_assert[0];
#else
#define GENERATE_SELECT \
if(select) { \
typedef policy::select_action::tselect select; \
typedef policy::select_action::tselect select_action; \
GENERATE_PLACEMENT \
} else { \
typedef policy::select_action::tshow select; \
typedef policy::select_action::tshow select_action; \
GENERATE_PLACEMENT \
}
#endif

View file

@ -136,7 +136,7 @@ twidget* tbuilder_password_box::build() const
// A password box doesn't have a label but a text.
// It also has no history.
widget->set_value(label);
widget->set_value(label_string);
DBG_GUI_G << "Window builder: placed password box '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -143,36 +143,35 @@ tbuilder_scrollbar_panel::tbuilder_scrollbar_panel(const config& cfg)
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
, grid(nullptr)
{
const config& definition = cfg.child("definition");
const config& grid_definition = cfg.child("definition");
VALIDATE(definition, _("No list defined."));
grid = std::make_shared<tbuilder_grid>(definition);
VALIDATE(grid_definition, _("No list defined."));
grid = std::make_shared<tbuilder_grid>(grid_definition);
assert(grid);
}
twidget* tbuilder_scrollbar_panel::build() const
{
tscrollbar_panel* widget = new tscrollbar_panel();
tscrollbar_panel* panel = new tscrollbar_panel();
init_control(widget);
init_control(panel);
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
panel->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
panel->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
DBG_GUI_G << "Window builder: placed scrollbar_panel '" << id
<< "' with definition '" << definition << "'.\n";
std::shared_ptr<const tscrollbar_panel_definition::tresolution> conf
= std::static_pointer_cast<const tscrollbar_panel_definition::
tresolution>(
widget->config());
= std::static_pointer_cast<const tscrollbar_panel_definition::tresolution>(
panel->config());
assert(conf);
widget->init_grid(conf->grid);
widget->finalize_setup();
panel->init_grid(conf->grid);
panel->finalize_setup();
/*** Fill the content grid. ***/
tgrid* content_grid = widget->content_grid();
tgrid* content_grid = panel->content_grid();
assert(content_grid);
const unsigned rows = grid->rows;
@ -198,7 +197,7 @@ twidget* tbuilder_scrollbar_panel::build() const
}
}
return widget;
return panel;
}
} // namespace implementation

View file

@ -492,7 +492,7 @@ twidget* tbuilder_text_box::build() const
init_control(widget);
// A textbox doesn't have a label but a text
widget->set_value(label);
widget->set_value(label_string);
if(!history.empty()) {
widget->set_history(history);

View file

@ -375,8 +375,8 @@ const twidget* ttree_view_node::find(const std::string& id,
void ttree_view_node::impl_populate_dirty_list(
twindow& caller, const std::vector<twidget*>& call_stack)
{
std::vector<twidget*> child_call_stack = call_stack;
grid_.populate_dirty_list(caller, child_call_stack);
std::vector<twidget*> my_call_stack = call_stack;
grid_.populate_dirty_list(caller, my_call_stack);
if(is_folded()) {
return;

View file

@ -747,22 +747,18 @@ void twindow::draw()
}
}
if(dirty_list_.empty()) {
if(preferences::use_color_cursors() || sunset_) {
surface& frame_buffer = get_video_surface();
if (dirty_list_.empty()) {
if (sunset_) {
/** @todo should probably be moved to event::thandler::draw. */
static unsigned i = 0;
if (++i % sunset_ == 0) {
SDL_Rect r = sdl::create_rect(
0, 0, frame_buffer->w, frame_buffer->h);
const Uint32 color
= SDL_MapRGBA(frame_buffer->format, 0, 0, 0, SDL_ALPHA_OPAQUE);
if(sunset_) {
/** @todo should probably be moved to event::thandler::draw. */
static unsigned i = 0;
if(++i % sunset_ == 0) {
SDL_Rect r = sdl::create_rect(
0, 0, frame_buffer->w, frame_buffer->h);
const Uint32 color
= SDL_MapRGBA(frame_buffer->format, 0, 0, 0, SDL_ALPHA_OPAQUE);
sdl::fill_rect_alpha(r, color, 1, frame_buffer);
update_rect(r);
}
sdl::fill_rect_alpha(r, color, 1, frame_buffer);
update_rect(r);
}
}
return;

View file

@ -242,11 +242,11 @@ bool halo_impl::effect::render()
const clip_rect_setter clip_setter(screen, &clip_rect);
if(buffer_ == nullptr || buffer_->w != rect.w || buffer_->h != rect.h) {
SDL_Rect rect = rect_;
buffer_.assign(get_surface_portion(screen,rect));
SDL_Rect rect2 = rect_;
buffer_.assign(get_surface_portion(screen,rect2));
} else {
SDL_Rect rect = rect_;
sdl_copy_portion(screen,&rect,buffer_,nullptr);
SDL_Rect rect2 = rect_;
sdl_copy_portion(screen,&rect2,buffer_,nullptr);
}
sdl_blit(surf_,nullptr,screen,&rect);

View file

@ -101,7 +101,7 @@ help_manager::~help_manager()
{
game_cfg = nullptr;
// map = nullptr;
toplevel.clear();
default_toplevel.clear();
hidden_sections.clear();
// These last numbers must be reset so that the content is regenerated.
// Upon next start.
@ -116,7 +116,7 @@ help_manager::~help_manager()
*/
void show_help(CVideo& video, const std::string& show_topic, int xloc, int yloc)
{
show_help(video, toplevel, show_topic, xloc, yloc);
show_help(video, default_toplevel, show_topic, xloc, yloc);
}
/**
@ -126,7 +126,7 @@ void show_help(CVideo& video, const std::string& show_topic, int xloc, int yloc)
*/
void show_unit_help(CVideo& video, const std::string& show_topic, bool has_variations, bool hidden, int xloc, int yloc)
{
show_help(video, toplevel,
show_help(video, default_toplevel,
hidden_symbol(hidden) + (has_variations ? ".." : "") + unit_prefix + show_topic, xloc, yloc);
}
@ -137,7 +137,7 @@ void show_unit_help(CVideo& video, const std::string& show_topic, bool has_varia
*/
void show_terrain_help(CVideo& video, const std::string& show_topic, bool hidden, int xloc, int yloc)
{
show_help(video, toplevel, hidden_symbol(hidden) + terrain_prefix + show_topic, xloc, yloc);
show_help(video, default_toplevel, hidden_symbol(hidden) + terrain_prefix + show_topic, xloc, yloc);
}
@ -147,7 +147,7 @@ void show_terrain_help(CVideo& video, const std::string& show_topic, bool hidden
*/
void show_variation_help(CVideo& video, const std::string& unit, const std::string &variation, bool hidden, int xloc, int yloc)
{
show_help(video, toplevel, hidden_symbol(hidden) + variation_prefix + unit + "_" + variation, xloc, yloc);
show_help(video, default_toplevel, hidden_symbol(hidden) + variation_prefix + unit + "_" + variation, xloc, yloc);
}
/**

View file

@ -62,7 +62,7 @@ namespace help {
const config *game_cfg = nullptr;
// The default toplevel.
help::section toplevel;
help::section default_toplevel;
// All sections and topics not referenced from the default toplevel.
help::section hidden_sections;
@ -394,9 +394,9 @@ std::vector<topic> generate_weapon_special_topics(const bool sort_generated)
std::map<t_string, std::string> special_description;
std::map<t_string, std::set<std::string, string_less> > special_units;
for (const unit_type_data::unit_type_map::value_type &i : unit_types.types())
for (const unit_type_data::unit_type_map::value_type &type_mapping : unit_types.types())
{
const unit_type &type = i.second;
const unit_type &type = type_mapping.second;
// Only show the weapon special if we find it on a unit that
// detailed description should be shown about.
if (description_type(type) != FULL_DESCRIPTION)
@ -494,9 +494,9 @@ std::vector<topic> generate_ability_topics(const bool sort_generated)
// should have a full description, if so, add this units abilities
// for display. We do not want to show abilities that the user has
// not encountered yet.
for (const unit_type_data::unit_type_map::value_type &i : unit_types.types())
for (const unit_type_data::unit_type_map::value_type &type_mapping : unit_types.types())
{
const unit_type &type = i.second;
const unit_type &type = type_mapping.second;
if (description_type(type) == FULL_DESCRIPTION) {
std::vector<t_string> const* abil_vecs[2];
@ -1380,7 +1380,7 @@ std::string get_first_word(const std::string &s)
void generate_contents()
{
toplevel.clear();
default_toplevel.clear();
hidden_sections.clear();
if (game_cfg != nullptr) {
const config *help_config = &game_cfg->child("help");
@ -1388,7 +1388,7 @@ void generate_contents()
help_config = &dummy_cfg;
}
try {
toplevel = parse_config(help_config);
default_toplevel = parse_config(help_config);
// Create a config object that contains everything that is
// not referenced from the toplevel element. Read this
// config and save these sections and topics so that they
@ -1400,7 +1400,7 @@ void generate_contents()
for (const config &section : help_config->child_range("section"))
{
const std::string id = section["id"];
if (find_section(toplevel, id) == nullptr) {
if (find_section(default_toplevel, id) == nullptr) {
// This section does not exist referenced from the
// toplevel. Hence, add it to the hidden ones if it
// is not referenced from another section.
@ -1417,7 +1417,7 @@ void generate_contents()
for (const config &topic : help_config->child_range("topic"))
{
const std::string id = topic["id"];
if (find_topic(toplevel, id) == nullptr) {
if (find_topic(default_toplevel, id) == nullptr) {
if (!topic_is_referenced(id, *help_config)) {
if (ss.str() != "") {
ss << ",";

View file

@ -316,7 +316,7 @@ tdata_cache load_terrain_types_data();
extern const config *game_cfg;
// The default toplevel.
extern help::section toplevel;
extern help::section default_toplevel;
// All sections and topics not referenced from the default toplevel.
extern help::section hidden_sections;

View file

@ -184,7 +184,7 @@ int help_menu::process()
display_visible_items();
} else if (x >= text_start){
// click on title open the topic associated to this section
chosen_topic_ = find_topic(toplevel, ".."+sec->id );
chosen_topic_ = find_topic(default_toplevel, ".."+sec->id );
}
} else if (selected_item_.t != nullptr) {
/// Choose a topic if it is clicked.

View file

@ -471,14 +471,14 @@ std::vector<config> command_executor::get_menu_images(display& disp, const std::
std::string label(item.begin(), item.begin() + item.find_last_not_of(' ') + 1);
// TODO: To away with the fugly markup, both '=' and 0x01
size_t i = label.find_first_of('=');
if(i != std::string::npos)
result.back()["label"] = label.substr(i + 1);
size_t separator_pos = label.find_first_of('=');
if(separator_pos != std::string::npos)
result.back()["label"] = label.substr(separator_pos + 1);
else {
i = label.find_first_of(1);
if(i != std::string::npos) {
result.back()["details"] = label.substr(i + 1);
result.back()["image"] = label.substr(1, i - 1);
separator_pos = label.find_first_of(1);
if(separator_pos != std::string::npos) {
result.back()["details"] = label.substr(separator_pos + 1);
result.back()["image"] = label.substr(1, separator_pos - 1);
} else {
result.back()["label"] = label;
}

View file

@ -119,8 +119,8 @@ struct map_location {
void set_wml_x(int v) { x = v - 1; }
void set_wml_y(int v) { y = v - 1; }
//on purpose these functions don't take map_location objects, if you use map_location objects to store 'differences' between 2 locations use vector_sum().
void add(int x, int y) { this->x += x; this->y += y; }
map_location plus(int x, int y) const { return map_location(this->x + x, this->y + y); }
void add(int x_diff, int y_diff) { x += x_diff; y += y_diff; }
map_location plus(int x_diff, int y_diff) const { return map_location(x + x_diff, y + y_diff); }
int x, y;

View file

@ -443,9 +443,9 @@ std::vector<map_location> gamemap::parse_location_range(const std::string &x, co
yrange.second = ymax;
}
for(int x = xrange.first; x <= xrange.second; ++x) {
for(int y = yrange.first; y <= yrange.second; ++y) {
res.push_back(map_location(x-1,y-1));
for(int x2 = xrange.first; x2 <= xrange.second; ++x2) {
for(int y2 = yrange.first; y2 <= yrange.second; ++y2) {
res.push_back(map_location(x2-1,y2-1));
}
}
}

View file

@ -191,7 +191,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
for(const t_translation::t_terrain& underlying_terrain : underlying_terrains) {
const std::string& terrain_id = tdata.get_terrain_info(underlying_terrain).id();
std::map<std::string, color_range>::const_iterator it = game_config::team_rgb_range.find(terrain_id);
it = game_config::team_rgb_range.find(terrain_id);
if (it == game_config::team_rgb_range.end())
continue;

View file

@ -733,17 +733,17 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
wb::future_map_if_active planned_unit_map; //lasts for whole method
unit_map::iterator u = find_unit(selected_hex_);
unit_map::iterator unit = find_unit(selected_hex_);
if (selected_hex_.valid() && u.valid() && !u->get_hidden()) {
if (selected_hex_.valid() && unit.valid() && !unit->get_hidden()) {
next_unit_ = u->get_location();
next_unit_ = unit->get_location();
{
current_paths_ = pathfind::paths(*u, false, true, viewing_team(), path_turns_);
current_paths_ = pathfind::paths(*unit, false, true, viewing_team(), path_turns_);
}
if(highlight) {
show_attack_options(u);
show_attack_options(unit);
gui().highlight_reach(current_paths_);
}
// the highlight now comes from selection
@ -752,11 +752,11 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
gui().set_route(nullptr);
// selection have impact only if we are not observing and it's our unit
if ((!commands_disabled || pc_.get_whiteboard()->is_active()) && u->side() == gui().viewing_side()) {
if (!(browse || pc_.get_whiteboard()->unit_has_actions(&*u)))
if ((!commands_disabled || pc_.get_whiteboard()->is_active()) && unit->side() == gui().viewing_side()) {
if (!(browse || pc_.get_whiteboard()->unit_has_actions(&*unit)))
{
sound::play_UI_sound("select-unit.wav");
u->anim_comp().set_selecting();
unit->anim_comp().set_selecting();
if(fire_event) {
// ensure unit map is back to normal while event is fired
wb::real_map srum;
@ -768,7 +768,7 @@ void mouse_handler::select_hex(const map_location& hex, const bool browse, const
return;
}
if (selected_hex_.valid() && !u) {
if (selected_hex_.valid() && !unit) {
// compute unit in range of the empty selected_hex field
gui_->unhighlight_reach();

View file

@ -162,16 +162,15 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
set_scroll_start(event.x, event.y);
scroll_started_ = true;
map_location loc = gui().minimap_location_on(event.x,event.y);
map_location minimap_loc = gui().minimap_location_on(event.x,event.y);
minimap_scrolling_ = false;
if(loc.valid()) {
if(minimap_loc.valid()) {
simple_warp_ = false;
minimap_scrolling_ = true;
last_hex_ = loc;
gui().scroll_to_tile(loc,display::WARP,false);
last_hex_ = minimap_loc;
gui().scroll_to_tile(minimap_loc,display::WARP,false);
} else if(simple_warp_) {
// middle click not on minimap, check gamemap instead
loc = gui().hex_clicked_on(event.x,event.y);
if(loc.valid()) {
last_hex_ = loc;
gui().scroll_to_tile(loc,display::WARP,false);

View file

@ -76,15 +76,15 @@ map_location find_vacant_tile(const map_location& loc, VACANT_TILE_TYPE vacancy,
std::set<map_location> tiles_checking;
tiles_checking.swap(pending_tiles_to_check);
//Iterate over all the hexes we need to check
for (const map_location &loc : tiles_checking)
for (const map_location &l : tiles_checking)
{
// Skip shrouded locations.
if ( do_shroud && shroud_check->shrouded(loc) )
if ( do_shroud && shroud_check->shrouded(l) )
continue;
//If this area is not a castle but should, skip it.
if ( vacancy == VACANT_CASTLE && !map.is_castle(loc) ) continue;
if ( vacancy == VACANT_CASTLE && !map.is_castle(l) ) continue;
const bool pass_check_and_unreachable = pass_check
&& pass_check->movement_cost(map[loc]) == movetype::UNREACHABLE;
&& pass_check->movement_cost(map[l]) == movetype::UNREACHABLE;
//If the unit can't reach the tile and we have searched
//an area of at least radius 10 (arbitrary), skip the tile.
//Neccessary for cases such as an unreachable
@ -93,18 +93,18 @@ map_location find_vacant_tile(const map_location& loc, VACANT_TILE_TYPE vacancy,
//even if there's a reachable hex for distance==2.
if (pass_check_and_unreachable && distance > 10) continue;
//If the hex is empty and we do either no pass check or the hex is reachable, return it.
if (units.find(loc) == units.end() && !pass_check_and_unreachable) return loc;
if (units.find(l) == units.end() && !pass_check_and_unreachable) return l;
map_location adjs[6];
get_adjacent_tiles(loc,adjs);
for (const map_location &loc : adjs)
get_adjacent_tiles(l,adjs);
for (const map_location &l2 : adjs)
{
if (!map.on_board(loc)) continue;
if (!map.on_board(l2)) continue;
// Add the tile to be checked if it hasn't already been and
// isn't being checked.
if (tiles_checked.find(loc) == tiles_checked.end() &&
tiles_checking.find(loc) == tiles_checking.end())
if (tiles_checked.find(l2) == tiles_checked.end() &&
tiles_checking.find(l2) == tiles_checking.end())
{
pending_tiles_to_check.insert(loc);
pending_tiles_to_check.insert(l2);
}
}
}

View file

@ -164,7 +164,7 @@ config teleport_group::to_config() const {
teleport_map::teleport_map(
const std::vector<teleport_group>& groups
, const unit& u
, const unit& unit
, const team &viewing_team
, const bool see_all
, const bool ignore_units
@ -182,8 +182,8 @@ teleport_map::teleport_map(
continue;
}
group.get_teleport_pair(locations, u, ignore_units);
if (!see_all && !group.always_visible() && viewing_team.is_enemy(u.side())) {
group.get_teleport_pair(locations, unit, ignore_units);
if (!see_all && !group.always_visible() && viewing_team.is_enemy(unit.side())) {
teleport_pair filter_locs;
for (const map_location &loc : locations.first) {
if(!viewing_team.fogged(loc))

View file

@ -127,7 +127,7 @@ bool persist_file_context::clear_var(const std::string &global, bool immediate)
} else {
if (immediate) {
cfg_ = bak;
config *active = get_node(cfg_, namespace_);
active = get_node(cfg_, namespace_);
if (active != nullptr) {
active->clear_children("variables");
active->remove_attribute("variables");

View file

@ -74,7 +74,7 @@ playsingle_controller::playsingle_controller(const config& level,
const config& game_config, const tdata_cache & tdata,
CVideo& video, bool skip_replay)
: play_controller(level, state_of_game, game_config, tdata, video, skip_replay)
, cursor_setter(cursor::NORMAL)
, cursor_setter_(cursor::NORMAL)
, textbox_info_()
, replay_sender_(*resources::recorder)
, network_reader_([this](config& cfg) {return recieve_from_wesnothd(cfg);})

View file

@ -77,10 +77,8 @@ protected:
virtual void do_idle_notification();
virtual void play_network_turn();
virtual void init_gui() override;
void store_recalls();
void store_gold(bool obs = false);
const cursor::setter cursor_setter;
const cursor::setter cursor_setter_;
gui::floating_textbox textbox_info_;
replay_network_sender replay_sender_;

View file

@ -101,16 +101,16 @@ static void verify(const unit_map& units, const config& cfg) {
errbuf.clear();
}
config cfg;
u->write(cfg);
config u_cfg;
u->write(u_cfg);
bool is_ok = true;
static const std::string fields[] = {"type","hitpoints","experience","side",""};
for(const std::string* str = fields; str->empty() == false; ++str) {
if (cfg[*str] != un[*str]) {
if (u_cfg[*str] != un[*str]) {
errbuf << "ERROR IN FIELD '" << *str << "' for unit at "
<< loc << " data source: '" << un[*str]
<< "' local: '" << cfg[*str] << "'\n";
<< "' local: '" << u_cfg[*str] << "'\n";
is_ok = false;
}
}
@ -626,10 +626,10 @@ void replay::add_config(const config& cfg, MARK_SENT mark)
{
for (const config &cmd : cfg.child_range("command"))
{
config &cfg = base_->insert_command(base_->size());
cfg = cmd;
config &cmd_cfg = base_->insert_command(base_->size());
cmd_cfg = cmd;
if(mark == MARK_AS_SENT) {
cfg["sent"] = true;
cmd_cfg["sent"] = true;
}
}
}

View file

@ -533,9 +533,9 @@ static config unit_defense(reports::context & rc, const unit* u, const map_locat
revert = false;
} else {
int t_def = 100 - u->defense_modifier(t);
SDL_Color color = int_to_color(game_config::red_to_green(t_def));
SDL_Color t_color = int_to_color(game_config::red_to_green(t_def));
tooltip << '\t' << map.get_terrain_info(t).description() << ": "
<< span_color(color) << t_def << '%' << naps
<< span_color(t_color) << t_def << '%' << naps
<< (revert ? _("maximum^max.") : _("minimum^min.")) << '\n';
}
}
@ -774,8 +774,8 @@ static int attack_info(reports::context & rc, const attack_type &at, config &res
typedef std::pair<int, std::set<std::string> > resist_units;
for (const resist_units &resist : resistances) {
int damage = round_damage(specials_damage, damage_multiplier * resist.first, damage_divisor);
tooltip << "<b>" << damage << "</b> "
int damage_with_resistance = round_damage(specials_damage, damage_multiplier * resist.first, damage_divisor);
tooltip << "<b>" << damage_with_resistance << "</b> "
<< "<i>(" << utils::signed_percent(resist.first-100) << ")</i> : "
<< utils::join(resist.second, ", ") << '\n';
}

View file

@ -1652,18 +1652,18 @@ error:
int game_lua_kernel::intf_find_cost_map(lua_State *L)
{
int arg = 1;
unit* u = luaW_tounit(L, arg, true);
unit* unit = luaW_tounit(L, arg, true);
vconfig filter = vconfig::unconstructed_vconfig();
luaW_tovconfig(L, arg, filter);
std::vector<const unit*> real_units;
std::vector<const ::unit*> real_units;
typedef std::vector<std::tuple<map_location, int, std::string> > unit_type_vector;
unit_type_vector fake_units;
if (u) // 1. arg - unit
if (unit) // 1. arg - unit
{
real_units.push_back(u);
real_units.push_back(unit);
}
else if (!filter.null()) // 1. arg - filter
{
@ -1761,7 +1761,7 @@ int game_lua_kernel::intf_find_cost_map(lua_State *L)
pathfind::full_cost_map cost_map(
ignore_units, !ignore_teleport, viewing_team, see_all, ignore_units);
for (const unit* const u : real_units)
for (const ::unit* const u : real_units)
{
cost_map.add_unit(*u, use_max_moves);
}
@ -3365,7 +3365,6 @@ int game_lua_kernel::intf_kill(lua_State *L)
if((cfg_x.empty() || cfg_x == "recall")
&& (cfg_y.empty() || cfg_y == "recall"))
{
const unit_filter ufilt(cfg, &game_state_);
//remove the unit from the corresponding team's recall list
for(std::vector<team>::iterator pi = teams().begin();
pi!=teams().end(); ++pi)

View file

@ -434,16 +434,18 @@ surface scale_surface(const surface &surf, int w, int h, bool optimize)
const fixed_t e = 0x000000FF & xsrc;
const fixed_t s = 0x000000FF & ysrc;
const fixed_t n = 0xFF - s;
const fixed_t w = 0xFF - e;
// Not called "w" to avoid hiding a function parameter
// (would cause a compiler warning in MSVC2015 with /W4)
const fixed_t we = 0xFF - e;
pix[0] = *src_word; // northwest
pix[1] = *(src_word + dx); // northeast
pix[2] = *(src_word + dy); // southwest
pix[3] = *(src_word + dx + dy); // southeast
bilin[0] = n*w;
bilin[0] = n*we;
bilin[1] = n*e;
bilin[2] = s*w;
bilin[2] = s*we;
bilin[3] = s*e;
int loc;
@ -1941,8 +1943,9 @@ surface blend_surface(
surface rotate_any_surface(const surface& surf, float angle, int zoom, int offset, bool optimize)
{
int src_w, src_h, dst_w, dst_h;
float min_x, max_x, min_y, max_y, sine, cosine;
float min_x, min_y, sine, cosine;
{
float max_x, max_y;
// convert angle to radiant (angle * 2 * PI) / 360
const float radians = angle * boost::math::constants::pi<float>() / 180;
cosine = static_cast<float>(cos(radians));

View file

@ -189,33 +189,32 @@ std::vector< std::string > square_parenthetical_split(std::string const &val,
for (size_t i=0; i < square_left.size(); i++) {
std::string tmp_val(square_left[i]+1,square_right[i]);
std::vector< std::string > tmp = split(tmp_val);
std::vector<std::string>::const_iterator itor = tmp.begin();
for(; itor != tmp.end(); ++itor) {
size_t found_tilde = (*itor).find_first_of('~');
for(const std::string& piece : tmp) {
size_t found_tilde = piece.find_first_of('~');
if (found_tilde == std::string::npos) {
size_t found_asterisk = (*itor).find_first_of('*');
size_t found_asterisk = piece.find_first_of('*');
if (found_asterisk == std::string::npos) {
std::string tmp = (*itor);
square_expansion.push_back(strip(tmp));
std::string tmp2(piece);
square_expansion.push_back(strip(tmp2));
}
else { //'*' multiple expansion
std::string s_begin = (*itor).substr(0,found_asterisk);
std::string s_begin = piece.substr(0,found_asterisk);
s_begin = strip(s_begin);
std::string s_end = (*itor).substr(found_asterisk+1);
std::string s_end = piece.substr(found_asterisk+1);
s_end = strip(s_end);
for (int ast=std::stoi(s_end); ast>0; --ast)
square_expansion.push_back(s_begin);
}
}
else { //expand number range
std::string s_begin = (*itor).substr(0,found_tilde);
std::string s_begin = piece.substr(0,found_tilde);
s_begin = strip(s_begin);
int begin = std::stoi(s_begin);
size_t padding = 0, padding_end = 0;
while (padding<s_begin.size() && s_begin[padding]=='0') {
padding++;
}
std::string s_end = (*itor).substr(found_tilde+1);
std::string s_end = piece.substr(found_tilde+1);
s_end = strip(s_end);
int end = std::stoi(s_end);
while (padding_end<s_end.size() && s_end[padding_end]=='0') {
@ -238,8 +237,8 @@ std::vector< std::string > square_parenthetical_split(std::string const &val,
}
}
if (i*square_expansion.size() != (i+1)*size_square_exp ) {
std::string tmp(i1, i2);
ERR_GENERAL << "Square bracket lengths do not match up: "+tmp+"" << std::endl;
std::string tmp2(i1, i2);
ERR_GENERAL << "Square bracket lengths do not match up: " << tmp2 << std::endl;
return res;
}
size_square_exp = square_expansion.size();

View file

@ -162,8 +162,8 @@ void positional_source::update(unsigned int time, const display &disp)
}
int distance_volume = DISTANCE_SILENT;
for(std::vector<map_location>::iterator i = locations_.begin(); i != locations_.end(); ++i) {
int v = calculate_volume(*i, disp);
for(const map_location& l : locations_) {
int v = calculate_volume(l, disp);
if(v < distance_volume) {
distance_volume = v;
}

View file

@ -419,7 +419,7 @@ static std::vector<std::string> get_variations(const std::string& base, const st
for (const std::string& v : vars) {
res.push_back(base);
std::string::size_type pos = 0;
pos = 0;
while ((pos = res.back().find("@V", pos)) != std::string::npos) {
res.back().replace(pos, 2, v);
pos += v.size();

View file

@ -317,9 +317,9 @@ void create_terrain_maps(const config::const_child_itors &cfgs,
t_translation::t_list& terrain_list,
std::map<t_translation::t_terrain, terrain_type>& letter_to_terrain)
{
for (const config &t : cfgs)
for (const config &terrain_data : cfgs)
{
terrain_type terrain(t);
terrain_type terrain(terrain_data);
DBG_G << "create_terrain_maps: " << terrain.number() << " "
<< terrain.id() << " " << terrain.name() << " : " << terrain.editor_group() << "\n";

View file

@ -228,7 +228,7 @@ bool basic_unit_filter_impl::matches(const unit & u, const map_location& loc, co
scoped_xy_unit auto_store("this_unit", loc, fc_.get_disp_context().units());
if (u2) {
const map_location& loc2 = u2->get_location();
scoped_xy_unit auto_store("other_unit", loc2, fc_.get_disp_context().units());
scoped_xy_unit u2_auto_store("other_unit", loc2, fc_.get_disp_context().units());
matches = internal_matches_filter(u, loc, u2);
} else {
matches = internal_matches_filter(u, loc, u2);

View file

@ -863,12 +863,12 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
text_color = display::rgb(cfg["red"], cfg["green"], cfg["blue"]);
}
resources::screen->scroll_to_tile(u->get_location(), game_display::ONSCREEN, true, false);
vconfig t_filter = cfg.child("facing");
vconfig t_filter_data = cfg.child("facing");
map_location secondary_loc = map_location::null_location();
if(!t_filter.empty()) {
terrain_filter filter(t_filter, resources::filter_con);
if(!t_filter_data.empty()) {
terrain_filter t_filter(t_filter_data, resources::filter_con);
std::set<map_location> locs;
filter.get_locations(locs);
t_filter.get_locations(locs);
if (!locs.empty() && u->get_location() != *locs.begin()) {
map_location::DIRECTION dir =u->get_location().get_relative_dir(*locs.begin());
u->set_facing(dir);

View file

@ -526,8 +526,8 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg)
//don't use the unit_type's attacks if this config has its own defined
if(config::const_child_itors cfg_range = cfg.child_range("attack")) {
attacks_.clear();
for (const config& cfg : cfg_range) {
attacks_.emplace_back(new attack_type(cfg));
for (const config& c : cfg_range) {
attacks_.emplace_back(new attack_type(c));
}
}

View file

@ -97,7 +97,6 @@ context_free_grammar_generator::context_free_grammar_generator(const std::map<st
if(key == "!" || key =="(" || key == ")") {
throw name_generator_invalid_exception("[context_free_grammar_generator] Parsing error: nonterminals (, ! and ) may not be overridden");
}
std::string buf;
for(std::string str : rule.second) {
nonterminals_[key].possibilities_.emplace_back();
std::vector<std::string>* filled = &nonterminals_[key].possibilities_.back();

View file

@ -152,9 +152,9 @@ config vconfig::get_parsed_config() const
try
{
config::const_child_itors range = as_nonempty_range(vname);
for (const config& child : range)
for (const config& ch : range)
{
res.add_child(name, vconfig(child).get_parsed_config());
res.add_child(name, vconfig(ch).get_parsed_config());
}
}
catch(const invalid_variablename_exception&)
@ -194,9 +194,9 @@ vconfig::child_list vconfig::get_children(const std::string& key) const
try
{
config::const_child_itors range = as_nonempty_range(insert_cfg["variable"]);
for (const config& child : range)
for (const config& ch : range)
{
res.push_back(vconfig(child, true));
res.push_back(vconfig(ch, true));
}
}
catch(const invalid_variablename_exception&)

View file

@ -93,13 +93,13 @@ void mapbuilder::build_map()
return;
}
bool end = false;
for(size_t turn=0; !end; ++turn) {
end = true;
bool stop = false;
for(size_t turn=0; !stop; ++turn) {
stop = true;
for (team &side : resources::gameboard->teams()) {
side_actions &actions = *side.get_side_actions();
if(turn < actions.num_turns() && team_has_visible_plan(side)) {
end = false;
stop = false;
side_actions::iterator it = actions.turn_begin(turn), next = it, end = actions.turn_end(turn);
while(it != end) {
std::advance(next, 1);

View file

@ -974,11 +974,11 @@ void menu::draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
int fs = style_->get_font_size();
int style = TTF_STYLE_NORMAL;
int w = rect.w - (xpos - rect.x) - 2 * style_->get_thickness();
std::string::const_iterator i_beg = to_show.begin(), i_end = to_show.end(),
i = font::parse_markup(i_beg, i_end, &fs, nullptr, &style);
if (i != i_end) {
std::string tmp(i, i_end);
to_show.erase(i - i_beg, i_end - i_beg);
std::string::const_iterator it2_beg = to_show.begin(), it2_end = to_show.end(),
it2 = font::parse_markup(it2_beg, it2_end, &fs, nullptr, &style);
if (it2 != it2_end) {
std::string tmp(it2, it2_end);
to_show.erase(it2 - it2_beg, it2_end - it2_beg);
to_show += font::make_text_ellipsis(tmp, fs, w, style);
}
}