Fixed some warnings on -Wall
This commit is contained in:
parent
becd928424
commit
16d35b0b17
11 changed files with 54 additions and 73 deletions
|
@ -445,7 +445,7 @@ void attack(display& gui, const gamemap& map,
|
|||
|
||||
int tower_owner(const gamemap::location& loc, std::vector<team>& teams)
|
||||
{
|
||||
for(int i = 0; i != teams.size(); ++i) {
|
||||
for(size_t i = 0; i != teams.size(); ++i) {
|
||||
if(teams[i].owns_tower(loc))
|
||||
return i;
|
||||
}
|
||||
|
@ -457,13 +457,13 @@ int tower_owner(const gamemap::location& loc, std::vector<team>& teams)
|
|||
void get_tower(const gamemap::location& loc, std::vector<team>& teams,
|
||||
int team_num)
|
||||
{
|
||||
for(int i = 0; i != teams.size(); ++i) {
|
||||
if(i != team_num && teams[i].owns_tower(loc)) {
|
||||
for(size_t i = 0; i != teams.size(); ++i) {
|
||||
if(int(i) != team_num && teams[i].owns_tower(loc)) {
|
||||
teams[i].lose_tower(loc);
|
||||
}
|
||||
}
|
||||
|
||||
if(team_num >= 0 && team_num < teams.size())
|
||||
if(size_t(team_num) < teams.size())
|
||||
teams[team_num].get_tower(loc);
|
||||
}
|
||||
|
||||
|
@ -674,11 +674,7 @@ unit get_advanced_unit(const game_data& info,
|
|||
info.unit_types.find(advance_to);
|
||||
std::map<gamemap::location,unit>::iterator un = units.find(loc);
|
||||
if(new_type != info.unit_types.end() && un != units.end()) {
|
||||
const int side = un->second.side();
|
||||
|
||||
unit new_unit(&(new_type->second),un->second);
|
||||
|
||||
return new_unit;
|
||||
return unit(&(new_type->second),un->second);
|
||||
} else {
|
||||
throw gamestatus::game_error("Could not find the unit being advanced"
|
||||
" to: " + advance_to);
|
||||
|
|
|
@ -234,7 +234,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
|
||||
const int towers = map.towers().size();
|
||||
int taken_towers = 0;
|
||||
for(int j = 0; j != teams.size(); ++j) {
|
||||
for(size_t j = 0; j != teams.size(); ++j) {
|
||||
taken_towers += teams[j].towers();
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ void do_move(display& disp, const gamemap& map, const game_data& gameinfo,
|
|||
continue;
|
||||
|
||||
bool want_tower = true;
|
||||
for(int j = 0; j != teams.size(); ++j) {
|
||||
for(size_t j = 0; j != teams.size(); ++j) {
|
||||
if(!current_team.is_enemy(j+1) && teams[j].owns_tower(i->first)) {
|
||||
want_tower = false;
|
||||
break;
|
||||
|
|
|
@ -66,7 +66,7 @@ void do_analysis(
|
|||
rating_to_beat = best_res = maximum(best_res,cur_rating);
|
||||
}
|
||||
|
||||
for(int i = 0; i != units.size(); ++i) {
|
||||
for(size_t i = 0; i != units.size(); ++i) {
|
||||
const location current_unit = units[i];
|
||||
units.erase(units.begin() + i);
|
||||
|
||||
|
@ -161,12 +161,10 @@ int choose_weapon(const gamemap& map, std::map<location,unit>& units,
|
|||
++cache_hits;
|
||||
cur_stats = cache_itor->stats;
|
||||
|
||||
if(!(cache_itor->weapon >= 0 &&
|
||||
cache_itor->weapon < itor->second.attacks().size())) {
|
||||
if(!(size_t(cache_itor->weapon) < itor->second.attacks().size())) {
|
||||
}
|
||||
|
||||
assert(cache_itor->weapon >= 0 &&
|
||||
cache_itor->weapon < itor->second.attacks().size());
|
||||
assert(size_t(cache_itor->weapon) < itor->second.attacks().size());
|
||||
return cache_itor->weapon;
|
||||
}
|
||||
|
||||
|
@ -181,7 +179,7 @@ int choose_weapon(const gamemap& map, std::map<location,unit>& units,
|
|||
const std::vector<attack_type>& attacks = itor->second.attacks();
|
||||
assert(!attacks.empty());
|
||||
|
||||
for(int a = 0; a != attacks.size(); ++a) {
|
||||
for(size_t a = 0; a != attacks.size(); ++a) {
|
||||
const battle_stats stats = evaluate_battle_stats(map,att,def,a,units,
|
||||
status,info,terrain,false);
|
||||
|
||||
|
@ -198,7 +196,7 @@ int choose_weapon(const gamemap& map, std::map<location,unit>& units,
|
|||
}
|
||||
}
|
||||
|
||||
assert(current_choice >= 0 && current_choice < attacks.size());
|
||||
assert(size_t(current_choice) < attacks.size());
|
||||
|
||||
battle.stats = cur_stats;
|
||||
battle.weapon = current_choice;
|
||||
|
@ -256,7 +254,7 @@ void attack_analysis::analyze(const gamemap& map,
|
|||
int defenderxp = 0;
|
||||
|
||||
int defhp = target_hp;
|
||||
for(int i = 0; i != movements.size() && defhp; ++i) {
|
||||
for(size_t i = 0; i != movements.size() && defhp; ++i) {
|
||||
const battle_stats& stat = stats[i];
|
||||
int atthp = hitpoints[i];
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ std::vector<target> find_targets(
|
|||
t != towers.end(); ++t) {
|
||||
assert(map.on_board(*t));
|
||||
bool get_tower = true;
|
||||
for(int i = 0; i != teams.size(); ++i) {
|
||||
for(size_t i = 0; i != teams.size(); ++i) {
|
||||
if(!tm.is_enemy(i+1) && teams[i].owns_tower(*t)) {
|
||||
get_tower = false;
|
||||
break;
|
||||
|
@ -157,7 +157,7 @@ std::vector<target> find_targets(
|
|||
}
|
||||
|
||||
assert(new_values.size() == targets.size());
|
||||
for(int n = 0; n != new_values.size(); ++n) {
|
||||
for(size_t n = 0; n != new_values.size(); ++n) {
|
||||
std::cerr << "target value: " << targets[n].value << " -> " << new_values[n] << "\n";
|
||||
targets[n].value = new_values[n];
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
|
||||
//if this is the beginning of a pre-processing definition
|
||||
static const std::string hash_define("#define");
|
||||
if(data.end() - i > hash_define.size() &&
|
||||
if(size_t(data.end() - i) > hash_define.size() &&
|
||||
std::equal(hash_define.begin(),hash_define.end(),i)) {
|
||||
|
||||
i += hash_define.size();
|
||||
|
@ -179,7 +179,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
std::stringstream value;
|
||||
for(i = end+1; i != data.end(); ++i) {
|
||||
static const std::string hash_enddef("#enddef");
|
||||
if(data.end() - i > hash_enddef.size() &&
|
||||
if(size_t(data.end() - i) > hash_enddef.size() &&
|
||||
std::equal(hash_enddef.begin(),hash_enddef.end(),i)) {
|
||||
i += hash_enddef.size();
|
||||
break;
|
||||
|
@ -197,7 +197,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
static const std::string hash_else("#else");
|
||||
static const std::string hash_endif("#endif");
|
||||
|
||||
if(data.end() - i > hash_ifdef.size() &&
|
||||
if(size_t(data.end() - i) > hash_ifdef.size() &&
|
||||
std::equal(hash_ifdef.begin(),hash_ifdef.end(),i)) {
|
||||
i += hash_ifdef.size();
|
||||
while(i != data.end() && isspace(*i))
|
||||
|
@ -215,7 +215,7 @@ void internal_preprocess_file(const std::string& fname,
|
|||
//anyway.
|
||||
const std::string symbol(i,end);
|
||||
if(defines_map.count(symbol) == 0) {
|
||||
while(data.end() - i > hash_endif.size() &&
|
||||
while(size_t(data.end() - i) > hash_endif.size() &&
|
||||
!std::equal(hash_endif.begin(),hash_endif.end(),i) &&
|
||||
!std::equal(hash_else.begin(),hash_else.end(),i)) {
|
||||
++i;
|
||||
|
@ -231,9 +231,9 @@ void internal_preprocess_file(const std::string& fname,
|
|||
|
||||
//if we come across a #else, it must mean that we found a #ifdef
|
||||
//earlier, and we should ignore until #endif
|
||||
if(data.end() - i > hash_else.size() &&
|
||||
if(size_t(data.end() - i) > hash_else.size() &&
|
||||
std::equal(hash_else.begin(),hash_else.end(),i)) {
|
||||
while(data.end() - i > hash_endif.size() &&
|
||||
while(size_t(data.end() - i) > hash_endif.size() &&
|
||||
!std::equal(hash_endif.begin(),hash_endif.end(),i)) {
|
||||
++i;
|
||||
}
|
||||
|
|
10
src/game.cpp
10
src/game.cpp
|
@ -51,7 +51,7 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
|
|||
type = "scenario";
|
||||
const std::vector<config*>& scenarios = game_config.children[type];
|
||||
|
||||
for(int i = state.scenario; i < scenarios.size(); ++i) {
|
||||
for(size_t i = size_t(state.scenario); i < scenarios.size(); ++i) {
|
||||
std::vector<config*>& story = scenarios[i]->children["story"];
|
||||
|
||||
try {
|
||||
|
@ -196,11 +196,11 @@ int play_game(int argc, char** argv)
|
|||
<< "x" << resolution.second << "x16 "
|
||||
<< "is not supported\n";
|
||||
|
||||
if(video_flags == FULL_SCREEN && argc == 0)
|
||||
if((video_flags&FULL_SCREEN) != 0 && argc == 0)
|
||||
std::cerr << "Try running the program with the -windowed option "
|
||||
<< "using a 16bpp X windows setting\n";
|
||||
|
||||
if(video_flags == 0 && argc == 0)
|
||||
if((video_flags&FULL_SCREEN) == 0 && argc == 0)
|
||||
std::cerr << "Try running with the -fullscreen option\n";
|
||||
|
||||
return 0;
|
||||
|
@ -331,7 +331,7 @@ int play_game(int argc, char** argv)
|
|||
if(res == -1)
|
||||
continue;
|
||||
|
||||
assert(res >= 0 && res < options.size());
|
||||
assert(size_t(res) < options.size());
|
||||
|
||||
state.difficulty = difficulties[res];
|
||||
defines_map.clear();
|
||||
|
@ -359,7 +359,7 @@ int play_game(int argc, char** argv)
|
|||
const int res = gui::show_dialog(disp,NULL,"",
|
||||
string_table["language_button"] + ":",
|
||||
gui::OK_CANCEL,&langs);
|
||||
if(res >= 0 && res < langs.size()) {
|
||||
if(size_t(res) < langs.size()) {
|
||||
set_language(langs[res], game_config);
|
||||
preferences::set_locale(langs[res]);
|
||||
}
|
||||
|
|
|
@ -501,7 +501,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
}
|
||||
|
||||
if(options.empty() == false) {
|
||||
assert(option_chosen >= 0 && option_chosen < menu_items.size());
|
||||
assert(size_t(option_chosen) < menu_items.size());
|
||||
std::vector<config*>& events = *option_events[option_chosen];
|
||||
for(std::vector<config*>::iterator ev = events.begin();
|
||||
ev != events.end(); ++ev) {
|
||||
|
|
|
@ -105,10 +105,8 @@ void show_intro(display& screen, config& data)
|
|||
int mousex, mousey;
|
||||
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
|
||||
|
||||
const bool right_button = mouse_flags&SDL_BUTTON_RMASK;
|
||||
const bool left_button = mouse_flags&SDL_BUTTON_LMASK;
|
||||
|
||||
|
||||
if(key[KEY_ESCAPE] ||
|
||||
skip_button.process(mousex,mousey,left_button))
|
||||
return;
|
||||
|
|
|
@ -143,8 +143,8 @@ gamemap::gamemap(config& cfg, const std::string& data) : tiles_(1)
|
|||
if(tiles_.empty())
|
||||
throw incorrect_format_exception("empty map");
|
||||
|
||||
for(int n = 0; n != tiles_.size(); ++n) {
|
||||
if(tiles_[n].size() != this->y()) {
|
||||
for(size_t n = 0; n != tiles_.size(); ++n) {
|
||||
if(tiles_[n].size() != size_t(this->y())) {
|
||||
tiles_.erase(tiles_.begin()+n);
|
||||
--n;
|
||||
}
|
||||
|
|
49
src/menu.cpp
49
src/menu.cpp
|
@ -109,9 +109,9 @@ void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
|||
} //end namespace gui
|
||||
|
||||
namespace {
|
||||
const int max_menu_items = 18;
|
||||
const int menu_font_size = 16;
|
||||
const int menu_cell_padding = 10;
|
||||
const size_t max_menu_items = 18;
|
||||
const size_t menu_font_size = 16;
|
||||
const size_t menu_cell_padding = 10;
|
||||
|
||||
class menu
|
||||
{
|
||||
|
@ -135,8 +135,8 @@ class menu
|
|||
const std::vector<int>& column_widths() const
|
||||
{
|
||||
if(column_widths_.empty()) {
|
||||
for(int row = 0; row != items_.size(); ++row) {
|
||||
for(int col = 0; col != items_[row].size(); ++col) {
|
||||
for(size_t row = 0; row != items_.size(); ++row) {
|
||||
for(size_t col = 0; col != items_[row].size(); ++col) {
|
||||
static const SDL_Rect area =
|
||||
{0,0,display_->x(),display_->y()};
|
||||
|
||||
|
@ -161,10 +161,6 @@ class menu
|
|||
if(rect.w == 0)
|
||||
return;
|
||||
|
||||
short* const dstptr = reinterpret_cast<short*>(
|
||||
display_->video().getSurface()->pixels) +
|
||||
rect.y*display_->x() + x_;
|
||||
|
||||
if(buffer_.get() != NULL) {
|
||||
const int ypos = items_start()+(item-first_item_on_screen_)*rect.h;
|
||||
SDL_Rect srcrect = {0,ypos,rect.w,rect.h};
|
||||
|
@ -172,8 +168,6 @@ class menu
|
|||
display_->video().getSurface(),&rect);
|
||||
}
|
||||
|
||||
short* dst = dstptr;
|
||||
|
||||
gui::draw_solid_tinted_rectangle(x_,rect.y,width(),rect.h,
|
||||
item == selected_ ? 150:0,0,0,
|
||||
0.7,display_->video().getSurface());
|
||||
|
@ -183,7 +177,7 @@ class menu
|
|||
const std::vector<int>& widths = column_widths();
|
||||
|
||||
int xpos = rect.x;
|
||||
for(int i = 0; i != items_[item].size(); ++i) {
|
||||
for(size_t i = 0; i != items_[item].size(); ++i) {
|
||||
font::draw_text(display_,area,menu_font_size,font::NORMAL_COLOUR,
|
||||
items_[item][i],xpos,rect.y);
|
||||
xpos += widths[i];
|
||||
|
@ -193,7 +187,7 @@ class menu
|
|||
void draw() {
|
||||
drawn_ = true;
|
||||
|
||||
for(int i = 0; i != items_.size(); ++i)
|
||||
for(size_t i = 0; i != items_.size(); ++i)
|
||||
draw_item(i);
|
||||
|
||||
display_->video().update(x_,y_,width(),height());
|
||||
|
@ -201,7 +195,7 @@ class menu
|
|||
|
||||
int hit(int x, int y) const {
|
||||
if(x > x_ && x < x_ + width() && y > y_ && y < y_ + height()){
|
||||
for(int i = 0; i != items_.size(); ++i) {
|
||||
for(size_t i = 0; i != items_.size(); ++i) {
|
||||
const SDL_Rect& rect = get_item_rect(i);
|
||||
if(y > rect.y && y < rect.y + rect.h)
|
||||
return i;
|
||||
|
@ -217,7 +211,7 @@ class menu
|
|||
{
|
||||
const SDL_Rect empty_rect = {0,0,0,0};
|
||||
if(item < first_item_on_screen_ ||
|
||||
item >= first_item_on_screen_ + max_menu_items) {
|
||||
size_t(item) >= first_item_on_screen_ + max_menu_items) {
|
||||
return empty_rect;
|
||||
}
|
||||
|
||||
|
@ -289,9 +283,8 @@ public:
|
|||
|
||||
int height() const {
|
||||
if(height_ == -1) {
|
||||
const SDL_Rect area = { 0, 0, display_->x(), display_->y() };
|
||||
height_ = 0;
|
||||
for(int i = 0; i != items_.size() && i != max_menu_items; ++i) {
|
||||
for(size_t i = 0; i != items_.size() && i != max_menu_items; ++i) {
|
||||
height_ += get_item_rect(i).h;
|
||||
}
|
||||
|
||||
|
@ -334,7 +327,7 @@ public:
|
|||
|
||||
int process(int x, int y, bool button,bool up_arrow,bool down_arrow,
|
||||
bool page_up, bool page_down) {
|
||||
if(items_.size() > max_menu_items) {
|
||||
if(items_.size() > size_t(max_menu_items)) {
|
||||
const bool up = uparrow_.process(x,y,button);
|
||||
if(up && first_item_on_screen_ > 0) {
|
||||
itemRects_.clear();
|
||||
|
@ -344,7 +337,8 @@ public:
|
|||
}
|
||||
|
||||
const bool down = downarrow_.process(x,y,button);
|
||||
if(down && first_item_on_screen_ + max_menu_items < items_.size()) {
|
||||
if(down &&
|
||||
size_t(first_item_on_screen_+max_menu_items) < items_.size()) {
|
||||
itemRects_.clear();
|
||||
++first_item_on_screen_;
|
||||
draw();
|
||||
|
@ -361,9 +355,9 @@ public:
|
|||
draw();
|
||||
}
|
||||
|
||||
if(down_arrow && !click_selects_ && selected_ < items_.size()-1) {
|
||||
if(down_arrow && !click_selects_ && selected_ < int(items_.size()-1)) {
|
||||
++selected_;
|
||||
if(selected_ - first_item_on_screen_ == max_menu_items) {
|
||||
if(size_t(selected_ - first_item_on_screen_) == max_menu_items) {
|
||||
itemRects_.clear();
|
||||
++first_item_on_screen_;
|
||||
}
|
||||
|
@ -384,7 +378,7 @@ public:
|
|||
|
||||
if(page_down && !click_selects_) {
|
||||
selected_ += max_menu_items;
|
||||
if(selected_ >= items_.size())
|
||||
if(size_t(selected_) >= items_.size())
|
||||
selected_ = items_.size()-1;
|
||||
|
||||
first_item_on_screen_ = selected_ - (max_menu_items-1);
|
||||
|
@ -474,7 +468,6 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
menu menu_(disp,menu_items,type == MESSAGE);
|
||||
|
||||
const int border_size = 6;
|
||||
const short text_colour = 0xFFFF;
|
||||
const short border_colour = 0xF000;
|
||||
int nlines = 1;
|
||||
int longest_line = 0;
|
||||
|
@ -626,7 +619,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
|
||||
const int button_hpadding = total_width - button_widths;
|
||||
int button_offset = 0;
|
||||
for(int button_num = 0; button_num != buttons.size(); ++button_num) {
|
||||
for(size_t button_num = 0; button_num != buttons.size(); ++button_num) {
|
||||
const int padding_amount = button_hpadding/(buttons.size()+1);
|
||||
buttons[button_num].set_x(xloc + padding_amount*(button_num+1) +
|
||||
button_offset);
|
||||
|
@ -732,7 +725,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
if(first_time)
|
||||
selection = 0;
|
||||
|
||||
if(selection >= 0 && selection < units.size()) {
|
||||
if(size_t(selection) < units.size()) {
|
||||
SDL_Surface* const screen = disp.video().getSurface();
|
||||
if(unit_details_rect.w > 0) {
|
||||
SDL_FillRect(screen,&unit_details_rect,0);
|
||||
|
@ -796,7 +789,7 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
if(menu_.height() == 0) {
|
||||
return button_it - buttons.begin();
|
||||
} else if(buttons.size() <= 1 ||
|
||||
button_it - buttons.begin() != buttons.size()-1) {
|
||||
size_t(button_it-buttons.begin()) != buttons.size()-1) {
|
||||
return menu_.selection();
|
||||
} else {
|
||||
return -1;
|
||||
|
@ -846,9 +839,6 @@ TITLE_RESULT show_title(display& screen)
|
|||
language_button.set_y(400);
|
||||
quit_button.set_y(450);
|
||||
|
||||
bool right_button = true;
|
||||
bool left_button = true;
|
||||
|
||||
tutorial_button.draw();
|
||||
new_button.draw();
|
||||
load_button.draw();
|
||||
|
@ -863,7 +853,6 @@ TITLE_RESULT show_title(display& screen)
|
|||
int mousex, mousey;
|
||||
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
|
||||
|
||||
const bool right_button = mouse_flags&SDL_BUTTON_RMASK;
|
||||
const bool left_button = mouse_flags&SDL_BUTTON_LMASK;
|
||||
|
||||
if(tutorial_button.process(mousex,mousey,left_button))
|
||||
|
|
|
@ -60,7 +60,7 @@ void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
|||
}
|
||||
|
||||
res = 0;
|
||||
while(res != sides.size()) {
|
||||
while(size_t(res) != sides.size()) {
|
||||
std::vector<std::string> sides_list;
|
||||
for(std::vector<config*>::iterator sd = sides.begin();
|
||||
sd != sides.end(); ++sd) {
|
||||
|
@ -78,7 +78,7 @@ void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
|||
res = gui::show_dialog(disp,NULL,"",string_table["configure_sides"],
|
||||
gui::MESSAGE,&sides_list);
|
||||
|
||||
if(res >= 0 && res < sides.size()) {
|
||||
if(size_t(res) < sides.size()) {
|
||||
std::vector<std::string> choices;
|
||||
|
||||
for(int n = 0; n != 2; ++n) {
|
||||
|
@ -96,12 +96,12 @@ void play_multiplayer(display& disp, game_data& units_data, config& cfg,
|
|||
string_table["choose_side"],
|
||||
gui::MESSAGE,&choices);
|
||||
if(result >= 0) {
|
||||
sides[res]->values["controller"] = (result >= choices.size()/2)
|
||||
? "ai" : "human";
|
||||
if(result >= choices.size()/2)
|
||||
sides[res]->values["controller"] =
|
||||
(result >= int(choices.size())/2) ? "ai" : "human";
|
||||
if(result >= int(choices.size())/2)
|
||||
result -= choices.size()/2;
|
||||
|
||||
assert(result < possible_sides.size());
|
||||
assert(result < int(possible_sides.size()));
|
||||
|
||||
std::map<std::string,std::string>& values =
|
||||
possible_sides[result]->values;
|
||||
|
|
Loading…
Add table
Reference in a new issue