Skip to content

Commit

Permalink
Convert a bunch more C-style casts I missed in 0dc5656 to static_cast
Browse files Browse the repository at this point in the history
(cherry picked from commit cb43d8b)
  • Loading branch information
Vultraz authored and gfgtdf committed Oct 28, 2018
1 parent d22d6ea commit 00a1edd
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/actions/move.cpp
Expand Up @@ -139,7 +139,7 @@ void move_unit_spectator::set_unit(const unit_map::const_iterator &u)
game_events::pump_result_t get_village(const map_location& loc, int side, bool *action_timebonus, bool fire_event)
{
std::vector<team> &teams = resources::gameboard->teams();
team *t = unsigned(side - 1) < teams.size() ? &teams[side - 1] : nullptr;
team *t = static_cast<unsigned>(side - 1) < teams.size() ? &teams[side - 1] : nullptr;
if (t && t->owns_village(loc)) {
return game_events::pump_result_t();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ai/simulated_actions.cpp
Expand Up @@ -185,7 +185,7 @@ bool simulated_synced_command(){
// Helper functions.
void helper_check_village(const map_location& loc, int side){
std::vector<team> &teams = resources::gameboard->teams();
team *t = unsigned(side - 1) < teams.size() ? &teams[side - 1] : nullptr;
team *t = static_cast<unsigned>(side - 1) < teams.size() ? &teams[side - 1] : nullptr;
if(t && t->owns_village(loc)){
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/build_info.cpp
Expand Up @@ -70,9 +70,9 @@ std::string format_version(unsigned a, unsigned b, unsigned c)

std::string format_version(const SDL_version& v)
{
return formatter() << unsigned(v.major) << '.'
<< unsigned(v.minor) << '.'
<< unsigned(v.patch);
return formatter() << static_cast<unsigned>(v.major) << '.'
<< static_cast<unsigned>(v.minor) << '.'
<< static_cast<unsigned>(v.patch);
}

#ifndef __APPLE__
Expand Down
2 changes: 1 addition & 1 deletion src/generators/default_map_generator_job.cpp
Expand Up @@ -675,7 +675,7 @@ static void flood_name(const map_location& start, const std::string& name, std::
for(n = 0; n < 6; n++) {
//we do not care for tiles outside the middle part
//cast to unsigned to skip x < 0 || y < 0 as well.
if(unsigned(adj[n].x) >= width / 3 || unsigned(adj[n].y) >= height / 3) {
if(static_cast<unsigned>(adj[n].x) >= width / 3 || static_cast<unsigned>(adj[n].y) >= height / 3) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/drop_down_menu.cpp
Expand Up @@ -173,7 +173,7 @@ void drop_down_menu::pre_show(window& window)
}
}

if(selected_item_ >= 0 && unsigned(selected_item_) < list.get_item_count()) {
if(selected_item_ >= 0 && static_cast<unsigned>(selected_item_) < list.get_item_count()) {
list.select_row(selected_item_);
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/editor/generate_map.cpp
Expand Up @@ -73,7 +73,7 @@ void editor_generate_map::do_generator_selected(window& window)
listbox& list = find_widget<listbox>(&window, "generators_list", false);
const int current = list.get_selected_row();

if(current == -1 || unsigned(current) > map_generators_.size()) {
if(current == -1 || static_cast<unsigned>(current) > map_generators_.size()) {
return; // shouldn't happen!
}

Expand Down
12 changes: 6 additions & 6 deletions src/gui/dialogs/file_dialog.cpp
Expand Up @@ -565,17 +565,17 @@ void file_dialog::sync_bookmarks_bar(window& window)

if(it == bookmark_paths_.rend()) {
if(current_bookmark_ >= 0) {
bookmarks_bar.select_row(unsigned(current_bookmark_), false);
bookmarks_bar.select_row(static_cast<unsigned>(current_bookmark_), false);
}
current_bookmark_ = -1;
} else {
const int new_selection = static_cast<int>(std::distance(bookmark_paths_.begin(), it.base()) - 1);
if(new_selection != current_bookmark_) {
assert(unsigned(new_selection) < bookmarks_bar.get_item_count());
assert(static_cast<unsigned>(new_selection) < bookmarks_bar.get_item_count());
if(current_bookmark_ >= 0) {
bookmarks_bar.select_row(unsigned(current_bookmark_), false);
bookmarks_bar.select_row(static_cast<unsigned>(current_bookmark_), false);
}
bookmarks_bar.select_row(unsigned(new_selection), true);
bookmarks_bar.select_row(static_cast<unsigned>(new_selection), true);
current_bookmark_ = new_selection;
}
}
Expand Down Expand Up @@ -627,13 +627,13 @@ void file_dialog::on_bookmark_selected(window& window)
if(current_bookmark_ >= 0) {
// Don't allow the user to deselect the selected bookmark. That wouldn't
// make any sense.
bookmarks_bar.select_row(unsigned(current_bookmark_));
bookmarks_bar.select_row(static_cast<unsigned>(current_bookmark_));
}

return;
}

assert(unsigned(new_selection) < bookmark_paths_.size());
assert(static_cast<unsigned>(new_selection) < bookmark_paths_.size());
current_bookmark_ = new_selection;
set_path(bookmark_paths_[new_selection]);
refresh_fileview(window);
Expand Down
2 changes: 1 addition & 1 deletion src/image_modifications.cpp
Expand Up @@ -561,7 +561,7 @@ surface o_modification::operator()(const surface& src) const
g = (*beg) >> 8;
b = (*beg);

alpha = std::min<unsigned>(unsigned(fxpmult(alpha,amount)), 255);
alpha = std::min<unsigned>(static_cast<unsigned>(fxpmult(alpha,amount)), 255);
*beg = (alpha << 24) + (r << 16) + (g << 8) + b;
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripting/game_lua_kernel.cpp
Expand Up @@ -2280,7 +2280,7 @@ int game_lua_kernel::intf_put_recall_unit(lua_State *L)
lua_unit *lu = nullptr;
unit_ptr u = unit_ptr();
int side = lua_tointeger(L, 2);
if (unsigned(side) > teams().size()) side = 0;
if (static_cast<unsigned>(side) > teams().size()) side = 0;

if(luaW_isunit(L, 1)) {
lu = luaW_checkunit_ref(L, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/lua_gui2.cpp
Expand Up @@ -808,7 +808,7 @@ int intf_set_dialog_canvas(lua_State* L)
}

std::vector<gui2::canvas> &cv = c->get_canvases();
if(i < 1 || unsigned(i) > cv.size()) {
if(i < 1 || static_cast<unsigned>(i) > cv.size()) {
return luaL_argerror(L, 1, "out of bounds");
}

Expand Down
8 changes: 4 additions & 4 deletions src/sdl/utils.cpp
Expand Up @@ -1157,9 +1157,9 @@ surface brighten_image(const surface &surf, fixed_t amount)
g = (*beg) >> 8;
b = (*beg);

r = std::min<unsigned>(unsigned(fxpmult(r, amount)),255);
g = std::min<unsigned>(unsigned(fxpmult(g, amount)),255);
b = std::min<unsigned>(unsigned(fxpmult(b, amount)),255);
r = std::min<unsigned>(static_cast<unsigned>(fxpmult(r, amount)),255);
g = std::min<unsigned>(static_cast<unsigned>(fxpmult(g, amount)),255);
b = std::min<unsigned>(static_cast<unsigned>(fxpmult(b, amount)),255);

*beg = (alpha << 24) + (r << 16) + (g << 8) + b;
}
Expand Down Expand Up @@ -1360,7 +1360,7 @@ surface submerge_alpha(const surface &surf, int depth, float alpha_base, float a
int d = (beg-limit)/nsurf->w; // current depth in pixels
float a = alpha_base - d * alpha_delta;
fixed_t amount = ftofxp(a<0?0:a);
alpha = std::min<unsigned>(unsigned(fxpmult(alpha,amount)),255);
alpha = std::min<unsigned>(static_cast<unsigned>(fxpmult(alpha,amount)),255);
*beg = (alpha << 24) + (r << 16) + (g << 8) + b;
}

Expand Down
2 changes: 1 addition & 1 deletion src/soundsource.cpp
Expand Up @@ -131,7 +131,7 @@ bool positional_source::is_global() const

void positional_source::update(unsigned int time, const display &disp)
{
if (time - last_played_ < unsigned(min_delay_) || sound::is_sound_playing(id_))
if (time - last_played_ < static_cast<unsigned>(min_delay_) || sound::is_sound_playing(id_))
return;

int i = randomness::rng::default_instance().get_random_int(1, 100);
Expand Down
2 changes: 1 addition & 1 deletion src/units/unit.cpp
Expand Up @@ -1661,7 +1661,7 @@ std::vector<config> unit::get_modification_advances() const
continue;
}

if(modification_count("advancement", adv["id"]) >= unsigned(adv["max_times"].to_int(1))) {
if(modification_count("advancement", adv["id"]) >= static_cast<unsigned>(adv["max_times"].to_int(1))) {
continue;
}

Expand Down

0 comments on commit 00a1edd

Please sign in to comment.