Convert C-style casts to static_cast

This commit is contained in:
Charles Dang 2018-05-13 22:36:50 +11:00
parent 36e83e646c
commit 0dc5656c32
43 changed files with 89 additions and 85 deletions

View file

@ -284,7 +284,7 @@ void protect_goal::add_targets(std::back_insert_iterator< std::vector< target >>
{ {
DBG_AI_GOAL << "side " << get_side() << ": in " << goal_type << ": found threat target. " << u.get_location() << " is a threat to "<< loc << '\n'; DBG_AI_GOAL << "side " << get_side() << ": in " << goal_type << ": found threat target. " << u.get_location() << " is a threat to "<< loc << '\n';
*target_list = target(u.get_location(), *target_list = target(u.get_location(),
value_ * double(radius_ - distance) / value_ * static_cast<double>(radius_ - distance) /
radius_, target::TYPE::THREAT); radius_, target::TYPE::THREAT);
} }
} }

View file

@ -1211,7 +1211,7 @@ double readonly_context_impl::power_projection(const map_location& loc, const mo
} }
// The 0.5 power avoids underestimating too much the damage of a wounded unit. // The 0.5 power avoids underestimating too much the damage of a wounded unit.
int64_t hp = int(std::sqrt(double(un.hitpoints()) / un.max_hitpoints()) * 1000); int64_t hp = static_cast<int>(std::sqrt(static_cast<double>(un.hitpoints()) / un.max_hitpoints()) * 1000);
int64_t most_damage = 0; int64_t most_damage = 0;
for(const attack_type& att : un.attacks()) { for(const attack_type& att : un.attacks()) {
int damage = att.damage() * att.num_attacks() * (100 + tod_modifier); int damage = att.damage() * att.num_attacks() * (100 + tod_modifier);

View file

@ -65,8 +65,8 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
uses_leader = false; uses_leader = false;
target_value = defend_it->cost(); target_value = defend_it->cost();
target_value += (double(defend_it->experience())/ target_value += (static_cast<double>(defend_it->experience())/
double(defend_it->max_experience()))*target_value; static_cast<double>(defend_it->max_experience()))*target_value;
target_starting_damage = defend_it->max_hitpoints() - target_starting_damage = defend_it->max_hitpoints() -
defend_it->hitpoints(); defend_it->hitpoints();
@ -166,7 +166,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
double cost = up->cost(); double cost = up->cost();
const bool on_village = map.is_village(m->second); const bool on_village = map.is_village(m->second);
// Up to double the value of a unit based on experience // Up to double the value of a unit based on experience
cost += (double(up->experience()) / up->max_experience())*cost; cost += (static_cast<double>(up->experience()) / up->max_experience())*cost;
resources_used += cost; resources_used += cost;
avg_losses += cost * prob_died; avg_losses += cost * prob_died;
@ -182,7 +182,7 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
avg_damage_taken -= game_config::poison_amount*2 * prob_survived; avg_damage_taken -= game_config::poison_amount*2 * prob_survived;
} }
terrain_quality += (double(bc->get_defender_stats().chance_to_hit)/100.0)*cost * (on_village ? 0.5 : 1.0); terrain_quality += (static_cast<double>(bc->get_defender_stats().chance_to_hit)/100.0)*cost * (on_village ? 0.5 : 1.0);
double advance_prob = 0.0; double advance_prob = 0.0;
// The reward for advancing a unit is to get a 'negative' loss of that unit // The reward for advancing a unit is to get a 'negative' loss of that unit

View file

@ -1472,7 +1472,7 @@ double retreat_phase::evaluate()
const map_location& hex = itors.first->second; const map_location& hex = itors.first->second;
const int defense = i->defense_modifier(resources::gameboard->map().get_terrain(hex)); const int defense = i->defense_modifier(resources::gameboard->map().get_terrain(hex));
const double our_power = power_projection(hex,get_dstsrc()); const double our_power = power_projection(hex,get_dstsrc());
const double their_power = power_projection(hex,get_enemy_dstsrc()) * double(defense)/100.0; const double their_power = power_projection(hex,get_enemy_dstsrc()) * static_cast<double>(defense)/100.0;
const double rating = our_power - their_power; const double rating = our_power - their_power;
if(rating > best_rating) { if(rating > best_rating) {
best_pos = hex; best_pos = hex;

View file

@ -641,7 +641,7 @@ void move_to_targets_phase::access_points(const move_map& srcdst, const map_loca
const std::pair<move_map::const_iterator,move_map::const_iterator> locs = srcdst.equal_range(u); const std::pair<move_map::const_iterator,move_map::const_iterator> locs = srcdst.equal_range(u);
for(move_map::const_iterator i = locs.first; i != locs.second; ++i) { for(move_map::const_iterator i = locs.first; i != locs.second; ++i) {
const map_location& loc = i->second; const map_location& loc = i->second;
if (int(distance_between(loc,dst)) <= u_it->total_movement()) { if (static_cast<int>(distance_between(loc,dst)) <= u_it->total_movement()) {
pathfind::shortest_path_calculator calc(*u_it, current_team(), resources::gameboard->teams(), map_); pathfind::shortest_path_calculator calc(*u_it, current_team(), resources::gameboard->teams(), map_);
const pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*u_it, current_team()); const pathfind::teleport_map allowed_teleports = pathfind::get_teleport_locations(*u_it, current_team());
pathfind::plain_route rt = a_star_search(loc, dst, u_it->total_movement(), calc, map_.w(), map_.h(), &allowed_teleports); pathfind::plain_route rt = a_star_search(loc, dst, u_it->total_movement(), calc, map_.w(), map_.h(), &allowed_teleports);
@ -849,7 +849,7 @@ double move_to_targets_phase::rate_group(const std::set<map_location>& group, co
} }
const int rating = (defense*best_attack*un.hitpoints())/(100*un.max_hitpoints()); const int rating = (defense*best_attack*un.hitpoints())/(100*un.max_hitpoints());
strength += double(rating); strength += static_cast<double>(rating);
} }
return strength; return strength;

View file

@ -164,7 +164,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
assert(threats.empty() == false); assert(threats.empty() == false);
const double value = threat/double(threats.size()); const double value = threat/static_cast<double>(threats.size());
for(std::set<map_location>::const_iterator i = threats.begin(); i != threats.end(); ++i) { for(std::set<map_location>::const_iterator i = threats.begin(); i != threats.end(); ++i) {
LOG_AI << "found threat target... " << *i << " with value: " << value << "\n"; LOG_AI << "found threat target... " << *i << " with value: " << value << "\n";
targets.emplace_back(*i,value,target::TYPE::THREAT); targets.emplace_back(*i,value,target::TYPE::THREAT);

View file

@ -234,7 +234,7 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
} }
static const std::size_t NDIRECTIONS = map_location::NDIRECTIONS; static const std::size_t NDIRECTIONS = map_location::NDIRECTIONS;
unsigned int difference = std::abs(int(preferred - n)); unsigned int difference = std::abs(static_cast<int>(preferred - n));
if(difference > NDIRECTIONS/2) { if(difference > NDIRECTIONS/2) {
difference = NDIRECTIONS - difference; difference = NDIRECTIONS - difference;
} }

View file

@ -625,7 +625,7 @@ DEFINE_WFL_FUNCTION(calculate_outcome, 3, 4)
while (it != hp_dist.end()) { while (it != hp_dist.end()) {
if (*it != 0) { if (*it != 0) {
hitLeft.emplace_back(i); hitLeft.emplace_back(i);
prob.emplace_back(int(*it*10000)); prob.emplace_back(static_cast<int>(*it*10000));
} }
++it; ++it;
++i; ++i;
@ -649,7 +649,7 @@ DEFINE_WFL_FUNCTION(calculate_outcome, 3, 4)
while (it != hp_dist.end()) { while (it != hp_dist.end()) {
if (*it != 0) { if (*it != 0) {
hitLeft.emplace_back(i); hitLeft.emplace_back(i);
prob.emplace_back(int(*it*10000)); prob.emplace_back(static_cast<int>(*it*10000));
} }
++it; ++it;
++i; ++i;

View file

@ -62,7 +62,7 @@ void ai_testing::log_turn(const char* msg, unsigned int side)
DBG_AI_TESTING << msg << "_INCOME " << side << ": " << _income << std::endl; DBG_AI_TESTING << msg << "_INCOME " << side << ": " << _income << std::endl;
config c; config c;
c["side"] = int(side); c["side"] = static_cast<int>(side);
c["turn"] = _turn_number; c["turn"] = _turn_number;
c["event"] = msg; c["event"] = msg;
c["units"] = _units; c["units"] = _units;

View file

@ -2510,7 +2510,7 @@ void combatant::print(const char label[], unsigned int battle, unsigned int figh
// TODO: add this to the stream... no idea how to convert it properly... // TODO: add this to the stream... no idea how to convert it properly...
printf("#%06u: (%02u) %s%*c %u-%d; %uhp; %02u%% to hit; %.2f%% unscathed; ", battle, fighter, label, printf("#%06u: (%02u) %s%*c %u-%d; %uhp; %02u%% to hit; %.2f%% unscathed; ", battle, fighter, label,
int(strlen(label)) - 12, ':', u_.swarm_max, u_.damage, u_.hp, u_.chance_to_hit, untouched * 100.0); static_cast<int>(strlen(label)) - 12, ':', u_.swarm_max, u_.damage, u_.hp, u_.chance_to_hit, untouched * 100.0);
if(u_.drains) { if(u_.drains) {
ss << "drains, "; ss << "drains, ";

View file

@ -241,7 +241,11 @@ struct color_t
inline std::ostream& operator<<(std::ostream& s, const color_t& c) inline std::ostream& operator<<(std::ostream& s, const color_t& c)
{ {
s << int(c.r) << " " << int(c.g) << " " << int(c.b) << " " << int(c.a) << std::endl; s << static_cast<int>(c.r) << " "
<< static_cast<int>(c.g) << " "
<< static_cast<int>(c.b) << " "
<< static_cast<int>(c.a) << std::endl;
return s; return s;
} }

View file

@ -61,7 +61,7 @@ std::string deprecated_message(
break; break;
default: // Not impossible, in case level was given an invalid value from a cast. default: // Not impossible, in case level was given an invalid value from a cast.
utils::string_map err_params {{"level", std::to_string(int(level))}}; utils::string_map err_params {{"level", std::to_string(static_cast<int>(level))}};
// Note: This message is duplicated in data/lua/core.lua // Note: This message is duplicated in data/lua/core.lua
// Any changes should be mirrorred there. // Any changes should be mirrorred there.

View file

@ -1054,7 +1054,7 @@ bool display::set_zoom(unsigned int amount, const bool validate_value_and_set_in
const SDL_Rect& area = map_area(); const SDL_Rect& area = map_area();
// Turn the zoom factor to a double in order to avoid rounding errors. // Turn the zoom factor to a double in order to avoid rounding errors.
double zoom_factor = double(new_zoom) / double(zoom_); double zoom_factor = static_cast<double>(new_zoom) / static_cast<double>(zoom_);
xpos_ = std::round(((xpos_ + area.w / 2) * zoom_factor) - (area.w / 2)); xpos_ = std::round(((xpos_ + area.w / 2) * zoom_factor) - (area.w / 2));
ypos_ = std::round(((ypos_ + area.h / 2) * zoom_factor) - (area.h / 2)); ypos_ = std::round(((ypos_ + area.h / 2) * zoom_factor) - (area.h / 2));

View file

@ -326,7 +326,7 @@ public:
/** Returns the current zoom factor. */ /** Returns the current zoom factor. */
double get_zoom_factor() const double get_zoom_factor() const
{ {
return double(zoom_) / double(game_config::tile_size); return static_cast<double>(zoom_) / static_cast<double>(game_config::tile_size);
} }
/** /**

View file

@ -1069,7 +1069,7 @@ void editor_controller::show_menu(const std::vector<config>& items_arg, int xloc
active_menu_ = editor::UNIT_FACING; active_menu_ = editor::UNIT_FACING;
auto pos = items.erase(items.begin()); auto pos = items.erase(items.begin());
int dir = 0; int dir = 0;
std::generate_n(std::inserter<std::vector<config>>(items, pos), int(map_location::NDIRECTIONS), [&dir]() -> config { std::generate_n(std::inserter<std::vector<config>>(items, pos), static_cast<int>(map_location::NDIRECTIONS), [&dir]() -> config {
return config {"label", map_location::write_translated_direction(map_location::DIRECTION(dir++))}; return config {"label", map_location::write_translated_direction(map_location::DIRECTION(dir++))};
}); });
} }

View file

@ -71,7 +71,7 @@ static std::string do_interpolation(const std::string &str, const variable_set&
// For the next iteration of the loop, search for more '$' // For the next iteration of the loop, search for more '$'
// (not from the same place because sometimes the '$' is not replaced) // (not from the same place because sometimes the '$' is not replaced)
rfind_dollars_sign_from = int(var_begin_loc) - 1; rfind_dollars_sign_from = static_cast<int>(var_begin_loc) - 1;
const std::string::iterator var_begin = res.begin() + var_begin_loc; const std::string::iterator var_begin = res.begin() + var_begin_loc;

View file

@ -472,7 +472,7 @@ WML_HANDLER_FUNCTION(recall,, cfg)
vconfig unit_filter_cfg(temp_config); vconfig unit_filter_cfg(temp_config);
const vconfig & leader_filter = cfg.child("secondary_unit"); const vconfig & leader_filter = cfg.child("secondary_unit");
for(int index = 0; index < int(resources::gameboard->teams().size()); ++index) { for(int index = 0; index < static_cast<int>(resources::gameboard->teams().size()); ++index) {
LOG_NG << "for side " << index + 1 << "...\n"; LOG_NG << "for side " << index + 1 << "...\n";
const std::string player_id = resources::gameboard->teams()[index].save_id(); const std::string player_id = resources::gameboard->teams()[index].save_id();

View file

@ -161,7 +161,7 @@ void game_state::place_sides_in_preferred_locations(const config& level)
std::set<int> placed; std::set<int> placed;
std::set<map_location> positions_taken; std::set<map_location> positions_taken;
for (std::vector<placing_info>::const_iterator i = placings.begin(); i != placings.end() && int(placed.size()) != side_num - 1; ++i) { for (std::vector<placing_info>::const_iterator i = placings.begin(); i != placings.end() && static_cast<int>(placed.size()) != side_num - 1; ++i) {
if(placed.count(i->side) == 0 && positions_taken.count(i->pos) == 0) { if(placed.count(i->side) == 0 && positions_taken.count(i->pos) == 0) {
placed.insert(i->side); placed.insert(i->side);
positions_taken.insert(i->pos); positions_taken.insert(i->pos);

View file

@ -104,8 +104,8 @@ cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_ma
uint32_t seed = randomseed.get_ptr() ? *randomseed.get_ptr() : seed_rng::next_seed(); uint32_t seed = randomseed.get_ptr() ? *randomseed.get_ptr() : seed_rng::next_seed();
rng_.seed(seed); rng_.seed(seed);
LOG_NG << "creating random cave with seed: " << seed << '\n'; LOG_NG << "creating random cave with seed: " << seed << '\n';
flipx_ = int(rng_() % 100) < params.flipx_chance_; flipx_ = static_cast<int>(rng_() % 100) < params.flipx_chance_;
flipy_ = int(rng_() % 100) < params.flipy_chance_; flipy_ = static_cast<int>(rng_() % 100) < params.flipy_chance_;
LOG_NG << "creating scenario....\n"; LOG_NG << "creating scenario....\n";
generate_chambers(); generate_chambers();
@ -135,7 +135,7 @@ void cave_map_generator::cave_map_generator_job::build_chamber(map_location loc,
adjacent_loc_array_t adj; adjacent_loc_array_t adj;
get_adjacent_tiles(loc,adj.data()); get_adjacent_tiles(loc,adj.data());
for(std::size_t n = 0; n < adj.size(); ++n) { for(std::size_t n = 0; n < adj.size(); ++n) {
if(int(rng_() % 100) < (100l - static_cast<long>(jagged))) { if(static_cast<int>(rng_() % 100) < (100l - static_cast<long>(jagged))) {
build_chamber(adj[n],locs,size-1,jagged); build_chamber(adj[n],locs,size-1,jagged);
} }
} }
@ -146,7 +146,7 @@ void cave_map_generator::cave_map_generator_job::generate_chambers()
for (const config &ch : params.cfg_.child_range("chamber")) for (const config &ch : params.cfg_.child_range("chamber"))
{ {
// If there is only a chance of the chamber appearing, deal with that here. // If there is only a chance of the chamber appearing, deal with that here.
if (ch.has_attribute("chance") && int(rng_() % 100) < ch["chance"].to_int()) { if (ch.has_attribute("chance") && static_cast<int>(rng_() % 100) < ch["chance"].to_int()) {
continue; continue;
} }
@ -301,7 +301,7 @@ double passage_path_calculator::cost(const map_location& loc, const double) cons
} }
if(windiness_ > 1) { if(windiness_ > 1) {
res *= double(rng_()%windiness_); res *= static_cast<double>(rng_()%windiness_);
} }
return res; return res;
@ -310,7 +310,7 @@ double passage_path_calculator::cost(const map_location& loc, const double) cons
void cave_map_generator::cave_map_generator_job::place_passage(const passage& p) void cave_map_generator::cave_map_generator_job::place_passage(const passage& p)
{ {
const std::string& chance = p.cfg["chance"]; const std::string& chance = p.cfg["chance"];
if(!chance.empty() && int(rng_()%100) < std::stoi(chance)) { if(!chance.empty() && static_cast<int>(rng_()%100) < std::stoi(chance)) {
return; return;
} }
@ -341,7 +341,7 @@ void cave_map_generator::cave_map_generator_job::set_terrain(map_location loc, c
if(c == params.clear_ || c == params.wall_ || c == params.village_) { if(c == params.clear_ || c == params.wall_ || c == params.village_) {
// Change this terrain. // Change this terrain.
if ( t == params.clear_ && int(rng_() % 1000) < params.village_density_ ) if ( t == params.clear_ && static_cast<int>(rng_() % 1000) < params.village_density_ )
// Override with a village. // Override with a village.
c = params.village_; c = params.village_;
else else

View file

@ -299,14 +299,14 @@ height_map default_map_generator_job::generate_height_map(std::size_t width, std
// Is this a negative hill? (i.e. a valley) // Is this a negative hill? (i.e. a valley)
bool is_valley = false; bool is_valley = false;
int x1 = island_size > 0 ? center_x - island_size + (rng_()%(island_size*2)) : int(rng_()%width); int x1 = island_size > 0 ? center_x - island_size + (rng_()%(island_size*2)) : static_cast<int>(rng_()%width);
int y1 = island_size > 0 ? center_y - island_size + (rng_()%(island_size*2)) : int(rng_()%height); int y1 = island_size > 0 ? center_y - island_size + (rng_()%(island_size*2)) : static_cast<int>(rng_()%height);
// We have to check whether this is actually a valley // We have to check whether this is actually a valley
if(island_size != 0) { if(island_size != 0) {
const std::size_t diffx = std::abs(x1 - int(center_x)); const std::size_t diffx = std::abs(x1 - static_cast<int>(center_x));
const std::size_t diffy = std::abs(y1 - int(center_y)); const std::size_t diffy = std::abs(y1 - static_cast<int>(center_y));
const std::size_t dist = std::size_t(std::sqrt(double(diffx*diffx + diffy*diffy))); const std::size_t dist = std::size_t(std::sqrt(static_cast<double>(diffx*diffx + diffy*diffy)));
is_valley = dist > island_size; is_valley = dist > island_size;
} }
@ -322,7 +322,7 @@ height_map default_map_generator_job::generate_height_map(std::size_t width, std
const int xdiff = (x2-x1); const int xdiff = (x2-x1);
const int ydiff = (y2-y1); const int ydiff = (y2-y1);
const int hill_height = radius - int(std::sqrt(double(xdiff*xdiff + ydiff*ydiff))); const int hill_height = radius - static_cast<int>(std::sqrt(static_cast<double>(xdiff*xdiff + ydiff*ydiff)));
if(hill_height > 0) { if(hill_height > 0) {
if(is_valley) { if(is_valley) {
@ -993,7 +993,7 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
dst.x += data.width/3 - 1; dst.x += data.width/3 - 1;
dst.y += data.height/3 - 1; dst.y += data.height/3 - 1;
if(data.link_castles && road < int(castles.size() * castles.size())) { if(data.link_castles && road < static_cast<int>(castles.size() * castles.size())) {
const std::size_t src_castle = road/castles.size(); const std::size_t src_castle = road/castles.size();
const std::size_t dst_castle = road%castles.size(); const std::size_t dst_castle = road%castles.size();
if(src_castle >= dst_castle) { if(src_castle >= dst_castle) {

View file

@ -572,7 +572,7 @@ void file_dialog::sync_bookmarks_bar(window& window)
} }
current_bookmark_ = -1; current_bookmark_ = -1;
} else { } else {
const int new_selection = int(std::distance(bookmark_paths_.begin(), it.base()) - 1); const int new_selection = static_cast<int>(std::distance(bookmark_paths_.begin(), it.base()) - 1);
if(new_selection != current_bookmark_) { if(new_selection != current_bookmark_) {
assert(unsigned(new_selection) < bookmarks_bar.get_item_count()); assert(unsigned(new_selection) < bookmarks_bar.get_item_count());
if(current_bookmark_ >= 0) { if(current_bookmark_ >= 0) {
@ -686,7 +686,7 @@ void file_dialog::on_bookmark_del_cmd(window& window)
assert(user_bookmarks_begin_ >= 0 assert(user_bookmarks_begin_ >= 0
&& current_bookmark_ >= 0 && current_bookmark_ >= 0
&& current_bookmark_ >= user_bookmarks_begin_ && current_bookmark_ >= user_bookmarks_begin_
&& current_bookmark_ < int(bookmark_paths_.size())); && current_bookmark_ < static_cast<int>(bookmark_paths_.size()));
listbox& bookmarks_bar = find_widget<listbox>(&window, "bookmarks", false); listbox& bookmarks_bar = find_widget<listbox>(&window, "bookmarks", false);
desktop::remove_user_bookmark(current_bookmark_ - user_bookmarks_begin_); desktop::remove_user_bookmark(current_bookmark_ - user_bookmarks_begin_);

View file

@ -239,7 +239,7 @@ void slider::signal_handler_left_button_up(const event::ui_event event, bool& ha
static t_string default_value_label_generator(const std::vector<t_string>& value_labels, int item_position, int max) static t_string default_value_label_generator(const std::vector<t_string>& value_labels, int item_position, int max)
{ {
assert(int(value_labels.size()) == max); assert(static_cast<int>(value_labels.size()) == max);
assert(item_position < max && item_position >= 0); assert(item_position < max && item_position >= 0);
return value_labels[item_position]; return value_labels[item_position];
} }

View file

@ -47,7 +47,7 @@ std::string hexencode_hash(const std::array<uint8_t, len>& input) {
std::ostringstream sout; std::ostringstream sout;
sout << std::hex; sout << std::hex;
for(uint8_t c : input) { for(uint8_t c : input) {
sout << int(c); sout << static_cast<int>(c);
} }
return sout.str(); return sout.str();
} }

View file

@ -263,9 +263,9 @@ public:
} else if(key == "height") { } else if(key == "height") {
return variant(h); return variant(h);
} else if(key == "u") { } else if(key == "u") {
return variant(p.x / float(w)); return variant(p.x / static_cast<float>(w));
} else if(key == "v") { } else if(key == "v") {
return variant(p.y / float(h)); return variant(p.y / static_cast<float>(h));
} }
return variant(); return variant();

View file

@ -459,12 +459,12 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
if(current_paths_.destinations.contains(adj[n])) { if(current_paths_.destinations.contains(adj[n])) {
static const std::size_t NDIRECTIONS = map_location::NDIRECTIONS; static const std::size_t NDIRECTIONS = map_location::NDIRECTIONS;
unsigned int difference = std::abs(int(preferred - n)); unsigned int difference = std::abs(static_cast<int>(preferred - n));
if(difference > NDIRECTIONS / 2) { if(difference > NDIRECTIONS / 2) {
difference = NDIRECTIONS - difference; difference = NDIRECTIONS - difference;
} }
unsigned int second_difference = std::abs(int(second_preferred - n)); unsigned int second_difference = std::abs(static_cast<int>(second_preferred - n));
if(second_difference > NDIRECTIONS / 2) { if(second_difference > NDIRECTIONS / 2) {
second_difference = NDIRECTIONS - second_difference; second_difference = NDIRECTIONS - second_difference;
} }
@ -1145,7 +1145,7 @@ bool mouse_handler::unit_in_cycle(unit_map::const_iterator it)
return false; return false;
} }
if(current_team().is_enemy(int(gui().viewing_team() + 1)) && it->invisible(it->get_location())) { if(current_team().is_enemy(static_cast<int>(gui().viewing_team() + 1)) && it->invisible(it->get_location())) {
return false; return false;
} }

View file

@ -153,7 +153,7 @@ plain_route a_star_search(const map_location& src, const map_location& dst,
if (calc.cost(dst, 0) >= stop_at) { if (calc.cost(dst, 0) >= stop_at) {
LOG_PF << "aborted A* search because Start or Dest is invalid\n"; LOG_PF << "aborted A* search because Start or Dest is invalid\n";
plain_route locRoute; plain_route locRoute;
locRoute.move_cost = int(calc.getNoPathValue()); locRoute.move_cost = static_cast<int>(calc.getNoPathValue());
return locRoute; return locRoute;
} }

View file

@ -365,7 +365,7 @@ void play_controller::init_managers()
void play_controller::fire_preload() void play_controller::fire_preload()
{ {
// Run initialization scripts, even if loading from a snapshot. // Run initialization scripts, even if loading from a snapshot.
gamestate().gamedata_.get_variable("turn_number") = int(turn()); gamestate().gamedata_.get_variable("turn_number") = static_cast<int>(turn());
pump().fire("preload"); pump().fire("preload");
} }
@ -385,7 +385,7 @@ void play_controller::fire_prestart()
pump().fire("prestart"); pump().fire("prestart");
// prestart event may modify start turn with WML, reflect any changes. // prestart event may modify start turn with WML, reflect any changes.
gamestate().gamedata_.get_variable("turn_number") = int(turn()); gamestate().gamedata_.get_variable("turn_number") = static_cast<int>(turn());
} }
void play_controller::fire_start() void play_controller::fire_start()
@ -394,7 +394,7 @@ void play_controller::fire_start()
pump().fire("start"); pump().fire("start");
// start event may modify start turn with WML, reflect any changes. // start event may modify start turn with WML, reflect any changes.
gamestate().gamedata_.get_variable("turn_number") = int(turn()); gamestate().gamedata_.get_variable("turn_number") = static_cast<int>(turn());
check_objectives(); check_objectives();
@ -714,7 +714,7 @@ bool play_controller::is_team_visible(int team_num, bool observer) const
int play_controller::find_last_visible_team() const int play_controller::find_last_visible_team() const
{ {
assert(current_side() <= int(gamestate().board_.teams().size())); assert(current_side() <= static_cast<int>(gamestate().board_.teams().size()));
const int num_teams = gamestate().board_.teams().size(); const int num_teams = gamestate().board_.teams().size();
const bool is_observer = this->is_observer(); const bool is_observer = this->is_observer();
@ -1171,7 +1171,7 @@ void play_controller::play_turn()
int last_player_number = gamestate_->player_number_; int last_player_number = gamestate_->player_number_;
int next_player_number = gamestate_->next_player_number_; int next_player_number = gamestate_->next_player_number_;
while(gamestate_->player_number_ <= int(gamestate().board_.teams().size())) { while(gamestate_->player_number_ <= static_cast<int>(gamestate().board_.teams().size())) {
gamestate_->next_player_number_ = gamestate_->player_number_ + 1; gamestate_->next_player_number_ = gamestate_->player_number_ + 1;
next_player_number = gamestate_->next_player_number_; next_player_number = gamestate_->next_player_number_;
last_player_number = gamestate_->player_number_; last_player_number = gamestate_->player_number_;
@ -1190,7 +1190,7 @@ void play_controller::play_turn()
// ignore any changes to next_player_number_ that happen after the [end_turn] is sent to the server, // ignore any changes to next_player_number_ that happen after the [end_turn] is sent to the server,
// otherwise we will get OOS. // otherwise we will get OOS.
next_player_number = gamestate_->next_player_number_; next_player_number = gamestate_->next_player_number_;
assert(next_player_number <= 2 * int(gamestate().board_.teams().size())); assert(next_player_number <= 2 * static_cast<int>(gamestate().board_.teams().size()));
if(is_regular_game_end()) { if(is_regular_game_end()) {
return; return;
} }

View file

@ -892,7 +892,7 @@ void save_sample_rate(const unsigned int rate)
if (sample_rate() == rate) if (sample_rate() == rate)
return; return;
prefs["sample_rate"] = int(rate); prefs["sample_rate"] = static_cast<int>(rate);
// If audio is open, we have to re set sample rate // If audio is open, we have to re set sample rate
sound::reset_sound(); sound::reset_sound();

View file

@ -820,7 +820,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
{ {
int val = countdown_update["value"]; int val = countdown_update["value"];
int tval = countdown_update["team"]; int tval = countdown_update["team"];
if (tval <= 0 || tval > int(resources::gameboard->teams().size())) { if (tval <= 0 || tval > static_cast<int>(resources::gameboard->teams().size())) {
std::stringstream errbuf; std::stringstream errbuf;
errbuf << "Illegal countdown update \n" errbuf << "Illegal countdown update \n"
<< "Received update for :" << tval << " Current user :" << "Received update for :" << tval << " Current user :"

View file

@ -103,7 +103,7 @@ config replay_helper::get_attack(const map_location& a, const map_location& b,
move["defender_type"] = defender_type_id; move["defender_type"] = defender_type_id;
move["attacker_lvl"] = attacker_lvl; move["attacker_lvl"] = attacker_lvl;
move["defender_lvl"] = defender_lvl; move["defender_lvl"] = defender_lvl;
move["turn"] = int(turn); move["turn"] = static_cast<int>(turn);
move["tod"] = t.id; move["tod"] = t.id;
/* /*
add_unit_checksum(a,current_); add_unit_checksum(a,current_);

View file

@ -582,7 +582,7 @@ static config unit_moves(reports::context & rc, const unit* u)
std::ostringstream str, tooltip; std::ostringstream str, tooltip;
double movement_frac = 1.0; double movement_frac = 1.0;
if (u->side() == rc.screen().playing_side()) { if (u->side() == rc.screen().playing_side()) {
movement_frac = double(u->movement_left()) / std::max<int>(1, u->total_movement()); movement_frac = static_cast<double>(u->movement_left()) / std::max<int>(1, u->total_movement());
if (movement_frac > 1.0) if (movement_frac > 1.0)
movement_frac = 1.0; movement_frac = 1.0;
} }
@ -627,7 +627,7 @@ static config unit_moves(reports::context & rc, const unit* u)
} }
} }
int grey = 128 + int((255 - 128) * movement_frac); int grey = 128 + static_cast<int>((255 - 128) * movement_frac);
color_t c = color_t(grey, grey, grey); color_t c = color_t(grey, grey, grey);
str << span_color(c) << u->movement_left() << '/' << u->total_movement() << naps; str << span_color(c) << u->movement_left() << '/' << u->total_movement() << naps;
return text_report(str.str(), tooltip.str()); return text_report(str.str(), tooltip.str());
@ -724,7 +724,7 @@ static int attack_info(reports::context & rc, const attack_type &at, config &res
// specials are calculated, but for an unusual case, simple brevity // specials are calculated, but for an unusual case, simple brevity
// trumps complexities. // trumps complexities.
if ( max_attacks != base_attacks ) { if ( max_attacks != base_attacks ) {
int attack_diff = int(max_attacks) - int(base_attacks); int attack_diff = static_cast<int>(max_attacks) - static_cast<int>(base_attacks);
tooltip << '\t' << _("Specials: ") << utils::signed_value(attack_diff) << '\n'; tooltip << '\t' << _("Specials: ") << utils::signed_value(attack_diff) << '\n';
} }
} }

View file

@ -1654,7 +1654,7 @@ int game_lua_kernel::intf_find_path(lua_State *L)
lua_rawget(L, arg); lua_rawget(L, arg);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {
int i = luaL_checkinteger(L, -1); int i = luaL_checkinteger(L, -1);
if (i >= 1 && i <= int(teams().size())) viewing_side = i; if (i >= 1 && i <= static_cast<int>(teams().size())) viewing_side = i;
else see_all = true; else see_all = true;
} }
lua_pop(L, 1); lua_pop(L, 1);
@ -1751,7 +1751,7 @@ int game_lua_kernel::intf_find_reach(lua_State *L)
lua_rawget(L, arg); lua_rawget(L, arg);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1)) {
int i = luaL_checkinteger(L, -1); int i = luaL_checkinteger(L, -1);
if (i >= 1 && i <= int(teams().size())) viewing_side = i; if (i >= 1 && i <= static_cast<int>(teams().size())) viewing_side = i;
else see_all = true; else see_all = true;
} }
lua_pop(L, 1); lua_pop(L, 1);
@ -1905,7 +1905,7 @@ int game_lua_kernel::intf_find_cost_map(lua_State *L)
if (!lua_isnil(L, -1)) if (!lua_isnil(L, -1))
{ {
int i = luaL_checkinteger(L, -1); int i = luaL_checkinteger(L, -1);
if (i >= 1 && i <= int(teams().size())) if (i >= 1 && i <= static_cast<int>(teams().size()))
{ {
viewing_side = i; viewing_side = i;
see_all = false; see_all = false;
@ -2521,7 +2521,7 @@ int game_lua_kernel::intf_simulate_combat(lua_State *L)
++arg_num; ++arg_num;
if (lua_isnumber(L, arg_num)) { if (lua_isnumber(L, arg_num)) {
att_w = lua_tointeger(L, arg_num) - 1; att_w = lua_tointeger(L, arg_num) - 1;
if (att_w < 0 || att_w >= int(att.attacks().size())) if (att_w < 0 || att_w >= static_cast<int>(att.attacks().size()))
return luaL_argerror(L, arg_num, "weapon index out of bounds"); return luaL_argerror(L, arg_num, "weapon index out of bounds");
++arg_num; ++arg_num;
} }
@ -2530,7 +2530,7 @@ int game_lua_kernel::intf_simulate_combat(lua_State *L)
++arg_num; ++arg_num;
if (lua_isnumber(L, arg_num)) { if (lua_isnumber(L, arg_num)) {
def_w = lua_tointeger(L, arg_num) - 1; def_w = lua_tointeger(L, arg_num) - 1;
if (def_w < 0 || def_w >= int(def.attacks().size())) if (def_w < 0 || def_w >= static_cast<int>(def.attacks().size()))
return luaL_argerror(L, arg_num, "weapon index out of bounds"); return luaL_argerror(L, arg_num, "weapon index out of bounds");
++arg_num; ++arg_num;
} }
@ -3312,7 +3312,7 @@ int game_lua_kernel::intf_delay(lua_State *L)
do { do {
play_controller_.play_slice(false); play_controller_.play_slice(false);
CVideo::delay(10); CVideo::delay(10);
} while (int(final - SDL_GetTicks()) > 0); } while (static_cast<int>(final - SDL_GetTicks()) > 0);
return 0; return 0;
} }

View file

@ -217,8 +217,8 @@ static int intf_name_generator(lua_State *L)
static int intf_random(lua_State *L) static int intf_random(lua_State *L)
{ {
if (lua_isnoneornil(L, 1)) { if (lua_isnoneornil(L, 1)) {
double r = double(randomness::generator->next_random()); double r = static_cast<double>(randomness::generator->next_random());
double r_max = double(std::numeric_limits<uint32_t>::max()); double r_max = static_cast<double>(std::numeric_limits<uint32_t>::max());
lua_push(L, r / (r_max + 1)); lua_push(L, r / (r_max + 1));
return 1; return 1;
} }

View file

@ -712,9 +712,9 @@ surface adjust_surface_color(const surface &surf, int red, int green, int blue)
g = (*beg) >> 8; g = (*beg) >> 8;
b = (*beg) >> 0; b = (*beg) >> 0;
r = std::max<int>(0,std::min<int>(255,int(r)+red)); r = std::max<int>(0,std::min<int>(255,static_cast<int>(r)+red));
g = std::max<int>(0,std::min<int>(255,int(g)+green)); g = std::max<int>(0,std::min<int>(255,static_cast<int>(g)+green));
b = std::max<int>(0,std::min<int>(255,int(b)+blue)); b = std::max<int>(0,std::min<int>(255,static_cast<int>(b)+blue));
*beg = (alpha << 24) + (r << 16) + (g << 8) + b; *beg = (alpha << 24) + (r << 16) + (g << 8) + b;
} }
@ -1208,7 +1208,7 @@ surface adjust_surface_alpha_add(const surface &surf, int amount)
g = (*beg) >> 8; g = (*beg) >> 8;
b = (*beg); b = (*beg);
alpha = uint8_t(std::max<int>(0,std::min<int>(255,int(alpha) + amount))); alpha = uint8_t(std::max<int>(0,std::min<int>(255,static_cast<int>(alpha) + amount)));
*beg = (alpha << 24) + (r << 16) + (g << 8) + b; *beg = (alpha << 24) + (r << 16) + (g << 8) + b;
} }

View file

@ -480,7 +480,7 @@ std::string urlencode(const std::string &str)
res << '%'; res << '%';
res.width(2); res.width(2);
res << int(c); res << static_cast<int>(c);
} }
return res.str(); return res.str();

View file

@ -166,7 +166,7 @@ void fuh::set_is_moderator(const std::string& name, const bool& is_moderator) {
if(!user_exists(name)) return; if(!user_exists(name)) return;
try { try {
write_detail(name, "user_is_moderator", int(is_moderator)); write_detail(name, "user_is_moderator", static_cast<int>(is_moderator));
} catch (const sql_error& e) { } catch (const sql_error& e) {
ERR_UH << "Could not set is_moderator for user '" << name << "' :" << e.message << std::endl; ERR_UH << "Could not set is_moderator for user '" << name << "' :" << e.message << std::endl;
} }
@ -292,7 +292,7 @@ std::time_t fuh::get_registrationdate(const std::string& user) {
void fuh::set_lastlogin(const std::string& user, const std::time_t& lastlogin) { void fuh::set_lastlogin(const std::string& user, const std::time_t& lastlogin) {
try { try {
write_detail(user, "user_lastvisit", int(lastlogin)); write_detail(user, "user_lastvisit", static_cast<int>(lastlogin));
} catch (const sql_error& e) { } catch (const sql_error& e) {
ERR_UH << "Could not set last visit for user '" << user << "' :" << e.message << std::endl; ERR_UH << "Could not set last visit for user '" << user << "' :" << e.message << std::endl;
} }

View file

@ -741,7 +741,7 @@ void validate_side(int side)
return; return;
} }
if(side < 1 || side > int(resources::gameboard->teams().size())) { if(side < 1 || side > static_cast<int>(resources::gameboard->teams().size())) {
throw game::game_error("invalid side(" + std::to_string(side) + ") found in unit definition"); throw game::game_error("invalid side(" + std::to_string(side) + ") found in unit definition");
} }
} }

View file

@ -562,14 +562,14 @@ void terrain_builder::rotate(terrain_constraint& ret, int angle)
for(rule_imagelist::iterator itor = ret.images.begin(); itor != ret.images.end(); ++itor) { for(rule_imagelist::iterator itor = ret.images.begin(); itor != ret.images.end(); ++itor) {
double vx, vy, rx, ry; double vx, vy, rx, ry;
vx = double(itor->basex) - double(tilewidth_) / 2; vx = static_cast<double>(itor->basex) - static_cast<double>(tilewidth_) / 2;
vy = double(itor->basey) - double(tilewidth_) / 2; vy = static_cast<double>(itor->basey) - static_cast<double>(tilewidth_) / 2;
rx = xyrotations[angle].xx * vx + xyrotations[angle].xy * vy; rx = xyrotations[angle].xx * vx + xyrotations[angle].xy * vy;
ry = xyrotations[angle].yx * vx + xyrotations[angle].yy * vy; ry = xyrotations[angle].yx * vx + xyrotations[angle].yy * vy;
itor->basex = int(rx + tilewidth_ / 2); itor->basex = static_cast<int>(rx + tilewidth_ / 2);
itor->basey = int(ry + tilewidth_ / 2); itor->basey = static_cast<int>(ry + tilewidth_ / 2);
// std::cerr << "Rotation: from " << vx << ", " << vy << " to " << itor->basex << // std::cerr << "Rotation: from " << vx << ", " << vy << " to " << itor->basex <<
// ", " << itor->basey << "\n"; // ", " << itor->basey << "\n";

View file

@ -1269,7 +1269,7 @@ effect::effect(const unit_ability_list& list, int def, bool backstab)
effect_list_.push_back(val.second); effect_list_.push_back(val.second);
} }
composite_value_ = int((value_set + addition) * multiplier / divisor); composite_value_ = static_cast<int>((value_set + addition) * multiplier / divisor);
} }
} // end namespace unit_abilities } // end namespace unit_abilities

View file

@ -338,7 +338,7 @@ void unit_drawer::redraw_unit(const unit & u) const
double unit_energy = 0.0; double unit_energy = 0.0;
if(max_hitpoints > 0) { if(max_hitpoints > 0) {
unit_energy = double(hitpoints)/double(max_hitpoints); unit_energy = static_cast<double>(hitpoints)/static_cast<double>(max_hitpoints);
} }
const int bar_shift = static_cast<int>(-5*zoom_factor); const int bar_shift = static_cast<int>(-5*zoom_factor);
@ -355,7 +355,7 @@ void unit_drawer::redraw_unit(const unit & u) const
); );
if(experience > 0 && can_advance) { if(experience > 0 && can_advance) {
const double filled = double(experience) / double(max_experience); const double filled = static_cast<double>(experience) / static_cast<double>(max_experience);
const int xp_bar_height = static_cast<int>(max_experience * u.xp_bar_scaling() / std::max<int>(u.level(),1)); const int xp_bar_height = static_cast<int>(max_experience * u.xp_bar_scaling() / std::max<int>(u.level(),1));
// XP bar // XP bar

View file

@ -1047,7 +1047,7 @@ static color_t hp_color_impl(int hitpoints, int max_hitpoints)
color_t energy_color {0,0,0,255}; color_t energy_color {0,0,0,255};
if(max_hitpoints > 0) { if(max_hitpoints > 0) {
unit_energy = double(hitpoints)/double(max_hitpoints); unit_energy = static_cast<double>(hitpoints)/static_cast<double>(max_hitpoints);
} }
if(1.0 == unit_energy) { if(1.0 == unit_energy) {

View file

@ -356,7 +356,7 @@ vconfig::all_children_iterator& vconfig::all_children_iterator::operator++()
config::const_child_itors range = vinfo.as_array(); config::const_child_itors range = vinfo.as_array();
if (++inner_index_ < int(range.size())) if (++inner_index_ < static_cast<int>(range.size()))
{ {
return *this; return *this;
} }

View file

@ -479,7 +479,7 @@ static void draw_numbers(const map_location& hex, side_actions::numbers_t number
std::string number_text = std::to_string(number); std::string number_text = std::to_string(number);
std::size_t font_size; std::size_t font_size;
if (int(i) == main_number) font_size = 19; if (static_cast<int>(i) == main_number) font_size = 19;
else if (secondary_numbers.find(i)!=secondary_numbers.end()) font_size = 17; else if (secondary_numbers.find(i)!=secondary_numbers.end()) font_size = 17;
else font_size = 15; else font_size = 15;