When attempting to change video modes, if none are available...

...an error message will be displayed
This commit is contained in:
Dave White 2003-09-19 23:39:03 +00:00
parent a5e93584fa
commit 21f26373bb
16 changed files with 59 additions and 43 deletions

View File

@ -145,6 +145,9 @@ save_game="Save Game"
end_turn="End Turn"
full_or_windowed="Full Screen or Windowed?"
choose_resolution="Choose Resolution"
video_mode="Video Mode"
video_mode_unavailable="There are no alternative video modes available"
video_mode_fail="The video mode could not be changed. Your window manager must be set to 16 bits per pixel to run the game in windowed mode. Your display must support 1024x768x16 to run the game full screen."
display_type="Display:"
full_screen="Full Screen"

View File

@ -150,7 +150,7 @@ gamemap::location display::hex_clicked_on(int xclick, int yclick)
const double xtile = xpos_/(zoom_*0.75) +
static_cast<double>(xclick)/(zoom_*0.75) - 0.25;
const double ytile = ypos_/zoom_ + static_cast<double>(yclick)/zoom_
+ (is_odd(xtile) ? -0.5:0.0);
+ (is_odd(int(xtile)) ? -0.5:0.0);
return gamemap::location(static_cast<int>(xtile),static_cast<int>(ytile));
}

View File

@ -13,7 +13,4 @@
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
#define is_odd(x) (static_cast<unsigned int>(x) & 1)
#define is_even(x) (!is_odd(x))
#endif

View File

@ -12,6 +12,7 @@
*/
#include "game.hpp"
#include "map.hpp"
#include "util.hpp"
#include <algorithm>
#include <cassert>

View File

@ -12,6 +12,7 @@
*/
#include "game.hpp"
#include "pathfind.hpp"
#include "util.hpp"
#include <cmath>
#include <iostream>
@ -155,7 +156,7 @@ void find_routes(const gamemap& map, const game_data& gamedata,
}
//iterate over all adjacent tiles
for(int i = 0; i != locs.size(); ++i) {
for(size_t i = 0; i != locs.size(); ++i) {
const gamemap::location& currentloc = locs[i];
//check if the adjacent location is off the board

View File

@ -137,7 +137,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
std::vector<unit> units_list;
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,selected_hex,hex,
a,units,status,gameinfo);
@ -193,7 +193,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
string_table["choose_weapon"]+":\n",
gui::OK_CANCEL,&items,&units_list);
if(res >= 0 && res < attacks.size()) {
if(size_t(res) < attacks.size()) {
undo_stack.clear();
redo_stack.clear();
@ -208,7 +208,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
enemy = units.find(hex);
if(u == units.end() || enemy == units.end() ||
res >= u->second.attacks().size())
size_t(res) >= u->second.attacks().size())
continue;
gui.invalidate_all();

View File

@ -275,7 +275,7 @@ void show_preferences_dialog(display& disp)
grid_button.set_x(slider_left);
grid_button.set_y(sound_pos + 80 + 100);
gui::button resolution_button(disp,"Video Mode");
gui::button resolution_button(disp,string_table["video_mode"]);
resolution_button.set_x(slider_left);
resolution_button.set_y(sound_pos + 80 + 150);
@ -363,8 +363,10 @@ void show_video_mode_dialog(display& disp)
CVideo& video = disp.video();
SDL_Rect** modes = SDL_ListModes(video.getSurface()->format,FULL_SCREEN);
if(reinterpret_cast<int>(modes) == -1 || modes == NULL)
if(reinterpret_cast<int>(modes) == -1 || modes == NULL) {
gui::show_dialog(disp,NULL,"",string_table["video_mode_unavailable"]);
return;
}
for(int i = 0; modes[i] != NULL; ++i) {
if(modes[i]->w >= 1024 && modes[i]->h >= 768) {
@ -380,12 +382,15 @@ void show_video_mode_dialog(display& disp)
}
}
if(resolutions.size() < 2)
if(resolutions.size() < 2) {
gui::show_dialog(disp,NULL,"",string_table["video_mode_unavailable"]);
return;
}
const int result = gui::show_dialog(disp,NULL,"","Choose Resolution",
const int result = gui::show_dialog(disp,NULL,"",
string_table["choose_resolution"],
gui::MESSAGE,&options);
if(result >= 0 && result < resolutions.size()) {
if(size_t(result) < resolutions.size()) {
set_resolution(resolutions[result]);
}
}

View File

@ -294,7 +294,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const std::vector<std::string>& options =
u->second.type().advances_to();
if(val < 0 || val >= options.size()) {
if(size_t(val) >= options.size()) {
std::cerr << "illegal advancement type\n";
throw replay::error();
}
@ -436,7 +436,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
throw replay::error();
}
if(weapon_num < 0 || weapon_num >= u->second.attacks().size()) {
if(size_t(weapon_num) >= u->second.attacks().size()) {
std::cerr << "illegal weapon type in attack\n";
throw replay::error();
}

View File

@ -15,6 +15,7 @@
#include "game.hpp"
#include "sdl_utils.hpp"
#include "util.hpp"
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
{

View File

@ -42,9 +42,9 @@ bool compare_unit_values::operator()(const unit& a, const unit& b) const
}
//constructor for reading a unit
unit::unit(game_data& data, config& cfg) : moves_(0), facingLeft_(true),
unit::unit(game_data& data, config& cfg) : state_(STATE_NORMAL),
moves_(0), facingLeft_(true),
recruit_(false),
state_(STATE_NORMAL),
guardian_(false)
{
read(data,cfg);
@ -52,25 +52,25 @@ unit::unit(game_data& data, config& cfg) : moves_(0), facingLeft_(true),
//constructor for creating a new unit
unit::unit(const unit_type* t, int side, bool use_traits) :
type_(t), facingLeft_(side != 1), state_(STATE_NORMAL),
type_(t), state_(STATE_NORMAL),
hitpoints_(t->hitpoints()),
experience_(0), side_(side), moves_(0),
recruit_(false), attacks_(t->attacks()),
backupAttacks_(t->attacks()),
maxHitpoints_(t->hitpoints()),
backupMaxHitpoints_(t->hitpoints()),
maxMovement_(t->movement()),
backupMaxMovement_(t->movement()),
backupMaxHitpoints_(t->hitpoints()), experience_(0),
maxExperience_(t->experience_needed()),
backupMaxExperience_(t->experience_needed()),
side_(side), moves_(0), facingLeft_(side != 1),
maxMovement_(t->movement()),
backupMaxMovement_(t->movement()),
recruit_(false), attacks_(t->attacks()),
backupAttacks_(t->attacks()),
guardian_(false)
{
//calculate the unit's traits
std::vector<config*> traits = t->possible_traits();
const int num_traits = 2;
const size_t num_traits = 2;
if(use_traits && traits.size() >= num_traits) {
std::set<int> chosen_traits;
for(int i = 0; i != num_traits; ++i) {
for(size_t i = 0; i != num_traits; ++i) {
int num = recorder.get_random()%(traits.size()-i);
while(chosen_traits.count(num)) {
++num;
@ -98,18 +98,19 @@ unit::unit(const unit_type* t, int side, bool use_traits) :
//constructor for advancing a unit from a lower level
unit::unit(const unit_type* t, const unit& u) :
type_(t), facingLeft_(u.facingLeft_), state_(STATE_NORMAL),
type_(t), state_(STATE_NORMAL),
hitpoints_(t->hitpoints()),
experience_(0), side_(u.side()), moves_(u.moves_),
recruit_(u.recruit_), description_(u.description_),
role_(u.role_), statusFlags_(u.statusFlags_),
attacks_(t->attacks()), backupAttacks_(t->attacks()),
maxHitpoints_(t->hitpoints()),
backupMaxHitpoints_(t->hitpoints()),
maxMovement_(t->movement()),
backupMaxMovement_(t->movement()),
experience_(0),
maxExperience_(t->experience_needed()),
backupMaxExperience_(t->experience_needed()),
side_(u.side()), moves_(u.moves_), facingLeft_(u.facingLeft_),
maxMovement_(t->movement()),
backupMaxMovement_(t->movement()),
description_(u.description_), recruit_(u.recruit_),
role_(u.role_), statusFlags_(u.statusFlags_),
attacks_(t->attacks()), backupAttacks_(t->attacks()),
modifications_(u.modifications_),
traitsDescription_(u.traitsDescription_),
guardian_(false)

View File

@ -98,8 +98,6 @@ public:
private:
const unit_type* type_;
bool facingLeft_;
enum STATE { STATE_NORMAL, STATE_ATTACKING, STATE_DEFENDING };
STATE state_;
const attack_type* attackType_;
@ -114,6 +112,7 @@ private:
//is set to the number of moves left, and -1 if the unit has attacked
int moves_;
bool facingLeft_;
int maxMovement_, backupMaxMovement_;
std::string description_;

View File

@ -307,7 +307,7 @@ const std::map<std::string,std::string>& unit_movement_type::damage_table() cons
unit_type::unit_type(config& cfg, const movement_type_map& mv_types,
std::vector<config*>& traits)
: cfg_(cfg), possibleTraits_(traits), alpha_(1.0)
: cfg_(cfg), alpha_(1.0), possibleTraits_(traits)
{
if(has_ability("heals")) {
heals_ = game_config::healer_heals_per_turn;

View File

@ -29,4 +29,10 @@ T& maximum(T& a, T& b) { return a < b ? b : a; }
template<typename T>
const T& maximum(const T& a, const T& b) { return a < b ? b : a; }
template<typename T>
inline bool is_odd(T num) { return (static_cast<unsigned int>(num)&1) == 1; }
template<typename T>
inline bool is_even(T num) { return !is_odd(num); }
#endif

View File

@ -24,8 +24,9 @@ const int vertical_padding = 10;
button::button(display& disp, const std::string& label, button::TYPE type,
const std::string& button_image_name) :
label_(label), display_(&disp),
x_(0), y_(0), button_(true), state_(UNINIT),
image_(NULL), pressedImage_(NULL), type_(type)
image_(NULL), pressedImage_(NULL),
x_(0), y_(0), button_(true),
state_(UNINIT), type_(type)
{
SDL_Surface* button_image =
disp.getImage("buttons/button.png",display::UNSCALED);

View File

@ -20,8 +20,8 @@ namespace gui {
slider::slider(display& disp, SDL_Rect& rect, double value)
: disp_(disp), image_(disp.getImage("buttons/slider.png",display::UNSCALED)),
selectedImage_(disp.getImage("buttons/slider-selected.png",display::UNSCALED)),
area_(rect), buffer_(NULL), value_(value), drawn_(false),
clicked_(true), dragging_(false), highlight_(false)
buffer_(NULL), area_(rect), value_(value), drawn_(false),
highlight_(false), clicked_(true), dragging_(false)
{
background_changed();

View File

@ -23,9 +23,10 @@ const int font_size = 16;
textbox::textbox(display& disp, int width, const std::string& text)
: disp_(disp), text_(text), firstOnScreen_(0),
cursor_(text.size()), height_(-1), width_(width), x_(-1), y_(-1),
cursor_(text.size()), height_(-1), width_(width),
buffer_(NULL), x_(-1), y_(-1),
lastLArrow_(false), lastRArrow_(false),
lastDelete_(false), lastBackspace_(false), buffer_(NULL)
lastDelete_(false), lastBackspace_(false)
{
std::fill(previousKeyState_,
previousKeyState_+CHAR_LENGTH,false);
@ -83,7 +84,7 @@ void textbox::draw() const
static const SDL_Rect clip = {0,0,1024,768};
//draw the text
for(int i = firstOnScreen_; i < text_.size(); ++i) {
for(size_t i = firstOnScreen_; i < text_.size(); ++i) {
str[0] = text_[i];
const SDL_Rect area =
font::draw_text(NULL,clip,font_size,font::NORMAL_COLOUR,str,0,0);