From 00a1edd1499ee16c6936015439d9fdace18204ff Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Mon, 14 May 2018 00:07:27 +1100 Subject: [PATCH] Convert a bunch more C-style casts I missed in 0dc5656 to static_cast (cherry picked from commit cb43d8b35fb3e0b9d8d3dd0d802db294e0720c35) --- src/actions/move.cpp | 2 +- src/ai/simulated_actions.cpp | 2 +- src/build_info.cpp | 6 +++--- src/generators/default_map_generator_job.cpp | 2 +- src/gui/dialogs/drop_down_menu.cpp | 2 +- src/gui/dialogs/editor/generate_map.cpp | 2 +- src/gui/dialogs/file_dialog.cpp | 12 ++++++------ src/image_modifications.cpp | 2 +- src/scripting/game_lua_kernel.cpp | 2 +- src/scripting/lua_gui2.cpp | 2 +- src/sdl/utils.cpp | 8 ++++---- src/soundsource.cpp | 2 +- src/units/unit.cpp | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/actions/move.cpp b/src/actions/move.cpp index 96c20738fb06..c470c3318e20 100644 --- a/src/actions/move.cpp +++ b/src/actions/move.cpp @@ -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 &teams = resources::gameboard->teams(); - team *t = unsigned(side - 1) < teams.size() ? &teams[side - 1] : nullptr; + team *t = static_cast(side - 1) < teams.size() ? &teams[side - 1] : nullptr; if (t && t->owns_village(loc)) { return game_events::pump_result_t(); } diff --git a/src/ai/simulated_actions.cpp b/src/ai/simulated_actions.cpp index ef38df6f50a1..2fe5ad7ecd81 100644 --- a/src/ai/simulated_actions.cpp +++ b/src/ai/simulated_actions.cpp @@ -185,7 +185,7 @@ bool simulated_synced_command(){ // Helper functions. void helper_check_village(const map_location& loc, int side){ std::vector &teams = resources::gameboard->teams(); - team *t = unsigned(side - 1) < teams.size() ? &teams[side - 1] : nullptr; + team *t = static_cast(side - 1) < teams.size() ? &teams[side - 1] : nullptr; if(t && t->owns_village(loc)){ return; } diff --git a/src/build_info.cpp b/src/build_info.cpp index bd00c3d188cb..8b6de69e9e4b 100644 --- a/src/build_info.cpp +++ b/src/build_info.cpp @@ -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(v.major) << '.' + << static_cast(v.minor) << '.' + << static_cast(v.patch); } #ifndef __APPLE__ diff --git a/src/generators/default_map_generator_job.cpp b/src/generators/default_map_generator_job.cpp index aa8cc942ef2e..9bba896dad0b 100644 --- a/src/generators/default_map_generator_job.cpp +++ b/src/generators/default_map_generator_job.cpp @@ -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(adj[n].x) >= width / 3 || static_cast(adj[n].y) >= height / 3) { continue; } diff --git a/src/gui/dialogs/drop_down_menu.cpp b/src/gui/dialogs/drop_down_menu.cpp index a2f2b60046cf..e3fc5292ec05 100644 --- a/src/gui/dialogs/drop_down_menu.cpp +++ b/src/gui/dialogs/drop_down_menu.cpp @@ -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(selected_item_) < list.get_item_count()) { list.select_row(selected_item_); } diff --git a/src/gui/dialogs/editor/generate_map.cpp b/src/gui/dialogs/editor/generate_map.cpp index e30b256e22b3..df614560524d 100644 --- a/src/gui/dialogs/editor/generate_map.cpp +++ b/src/gui/dialogs/editor/generate_map.cpp @@ -73,7 +73,7 @@ void editor_generate_map::do_generator_selected(window& window) listbox& list = find_widget(&window, "generators_list", false); const int current = list.get_selected_row(); - if(current == -1 || unsigned(current) > map_generators_.size()) { + if(current == -1 || static_cast(current) > map_generators_.size()) { return; // shouldn't happen! } diff --git a/src/gui/dialogs/file_dialog.cpp b/src/gui/dialogs/file_dialog.cpp index 9a39342a5cc0..b2799f668e49 100644 --- a/src/gui/dialogs/file_dialog.cpp +++ b/src/gui/dialogs/file_dialog.cpp @@ -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(current_bookmark_), false); } current_bookmark_ = -1; } else { const int new_selection = static_cast(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(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(current_bookmark_), false); } - bookmarks_bar.select_row(unsigned(new_selection), true); + bookmarks_bar.select_row(static_cast(new_selection), true); current_bookmark_ = new_selection; } } @@ -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(current_bookmark_)); } return; } - assert(unsigned(new_selection) < bookmark_paths_.size()); + assert(static_cast(new_selection) < bookmark_paths_.size()); current_bookmark_ = new_selection; set_path(bookmark_paths_[new_selection]); refresh_fileview(window); diff --git a/src/image_modifications.cpp b/src/image_modifications.cpp index 37fb6aa9dfce..26b9ec876dd0 100644 --- a/src/image_modifications.cpp +++ b/src/image_modifications.cpp @@ -561,7 +561,7 @@ surface o_modification::operator()(const surface& src) const g = (*beg) >> 8; b = (*beg); - alpha = std::min(unsigned(fxpmult(alpha,amount)), 255); + alpha = std::min(static_cast(fxpmult(alpha,amount)), 255); *beg = (alpha << 24) + (r << 16) + (g << 8) + b; } diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 1f443056a8fc..ad69f78a00f3 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -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(side) > teams().size()) side = 0; if(luaW_isunit(L, 1)) { lu = luaW_checkunit_ref(L, 1); diff --git a/src/scripting/lua_gui2.cpp b/src/scripting/lua_gui2.cpp index 2de10fb32827..8c297457ee51 100644 --- a/src/scripting/lua_gui2.cpp +++ b/src/scripting/lua_gui2.cpp @@ -808,7 +808,7 @@ int intf_set_dialog_canvas(lua_State* L) } std::vector &cv = c->get_canvases(); - if(i < 1 || unsigned(i) > cv.size()) { + if(i < 1 || static_cast(i) > cv.size()) { return luaL_argerror(L, 1, "out of bounds"); } diff --git a/src/sdl/utils.cpp b/src/sdl/utils.cpp index 85bac5956660..6ca18229a36d 100644 --- a/src/sdl/utils.cpp +++ b/src/sdl/utils.cpp @@ -1157,9 +1157,9 @@ surface brighten_image(const surface &surf, fixed_t amount) g = (*beg) >> 8; b = (*beg); - r = std::min(unsigned(fxpmult(r, amount)),255); - g = std::min(unsigned(fxpmult(g, amount)),255); - b = std::min(unsigned(fxpmult(b, amount)),255); + r = std::min(static_cast(fxpmult(r, amount)),255); + g = std::min(static_cast(fxpmult(g, amount)),255); + b = std::min(static_cast(fxpmult(b, amount)),255); *beg = (alpha << 24) + (r << 16) + (g << 8) + b; } @@ -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(fxpmult(alpha,amount)),255); + alpha = std::min(static_cast(fxpmult(alpha,amount)),255); *beg = (alpha << 24) + (r << 16) + (g << 8) + b; } diff --git a/src/soundsource.cpp b/src/soundsource.cpp index 569e31abac31..1d0415f54104 100644 --- a/src/soundsource.cpp +++ b/src/soundsource.cpp @@ -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(min_delay_) || sound::is_sound_playing(id_)) return; int i = randomness::rng::default_instance().get_random_int(1, 100); diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 62511da8f23e..8a73701e2cd7 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1661,7 +1661,7 @@ std::vector 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(adv["max_times"].to_int(1))) { continue; }