diff --git a/data/terrain.cfg b/data/terrain.cfg index f45b187f55e..0f2af60f9cb 100644 --- a/data/terrain.cfg +++ b/data/terrain.cfg @@ -54,6 +54,9 @@ char=t red=200 green=200 blue=200 + +#make this not overlay nearby grassland (but will overlay other lower terrain) +no_overlay=true [/terrain] [terrain] diff --git a/images/terrain/flag-neutral-n.png b/images/terrain/flag-neutral-n.png new file mode 100644 index 00000000000..d3c3f413c6f Binary files /dev/null and b/images/terrain/flag-neutral-n.png differ diff --git a/images/terrain/flag-neutral-ne.png b/images/terrain/flag-neutral-ne.png new file mode 100644 index 00000000000..6bf7c1ca4a9 Binary files /dev/null and b/images/terrain/flag-neutral-ne.png differ diff --git a/images/terrain/flag-neutral-nw.png b/images/terrain/flag-neutral-nw.png new file mode 100644 index 00000000000..0357f59552a Binary files /dev/null and b/images/terrain/flag-neutral-nw.png differ diff --git a/images/terrain/flag-neutral-s.png b/images/terrain/flag-neutral-s.png new file mode 100644 index 00000000000..0e047a79c35 Binary files /dev/null and b/images/terrain/flag-neutral-s.png differ diff --git a/images/terrain/flag-neutral-se.png b/images/terrain/flag-neutral-se.png new file mode 100644 index 00000000000..1e0f7942fe0 Binary files /dev/null and b/images/terrain/flag-neutral-se.png differ diff --git a/images/terrain/flag-neutral-sw.png b/images/terrain/flag-neutral-sw.png new file mode 100644 index 00000000000..9a8b4ef9604 Binary files /dev/null and b/images/terrain/flag-neutral-sw.png differ diff --git a/images/terrain/flag-neutral.png b/images/terrain/flag-neutral.png index f3e60861ae1..55da38055a1 100644 Binary files a/images/terrain/flag-neutral.png and b/images/terrain/flag-neutral.png differ diff --git a/images/terrain/flag-team1.png b/images/terrain/flag-team1.png index 08bdfc5f128..19ed0e83d99 100644 Binary files a/images/terrain/flag-team1.png and b/images/terrain/flag-team1.png differ diff --git a/images/terrain/flag-team2.png b/images/terrain/flag-team2.png index 200abf59a35..a945ffb8a2d 100644 Binary files a/images/terrain/flag-team2.png and b/images/terrain/flag-team2.png differ diff --git a/images/terrain/flag-team3.png b/images/terrain/flag-team3.png index 6ba35d10973..a2495cec2ee 100644 Binary files a/images/terrain/flag-team3.png and b/images/terrain/flag-team3.png differ diff --git a/images/terrain/flag-team4.png b/images/terrain/flag-team4.png index e8a3f3d37e1..10deea4d6b6 100644 Binary files a/images/terrain/flag-team4.png and b/images/terrain/flag-team4.png differ diff --git a/images/terrain/flag-team5.png b/images/terrain/flag-team5.png index 08bdfc5f128..19ed0e83d99 100644 Binary files a/images/terrain/flag-team5.png and b/images/terrain/flag-team5.png differ diff --git a/images/terrain/flag-team6.png b/images/terrain/flag-team6.png index 08bdfc5f128..19ed0e83d99 100644 Binary files a/images/terrain/flag-team6.png and b/images/terrain/flag-team6.png differ diff --git a/src/config.cpp b/src/config.cpp index 0dac2571f55..9520df419aa 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -21,6 +21,7 @@ #include "config.hpp" #include "filesystem.hpp" +#include "game_config.hpp" #include "log.hpp" bool operator<(const line_source& a, const line_source& b) @@ -44,26 +45,8 @@ line_source get_line_source(const std::vector& line_src, int line) return res; } -} - -std::string read_file(const std::string& fname) +std::string read_file_internal(const std::string& fname) { - //if we have a path to the data -#ifdef WESNOTH_PATH - - //convert any filepath which is relative - if(!fname.empty() && fname[0] != '/' && WESNOTH_PATH[0] == '/') { - std::cerr << "trying to read file: '" << - (WESNOTH_PATH + std::string("/") + fname) << "'\n"; - const std::string& res = - read_file(WESNOTH_PATH + std::string("/") + fname); - if(!res.empty()) { - std::cerr << "success\n"; - return res; - } - } -#endif - std::ifstream file(fname.c_str()); std::string res; char c; @@ -75,6 +58,26 @@ std::string read_file(const std::string& fname) return res; } +} //end anon namespace + +std::string read_file(const std::string& fname) +{ + //if we have a path to the data, + //convert any filepath which is relative + if(!fname.empty() && fname[0] != '/' && !game_config::path.empty()) { + std::cerr << "trying to read file: '" << + game_config::path << "/" << fname << "'\n"; + const std::string& res = + read_file_internal(game_config::path + "/" + fname); + if(!res.empty()) { + std::cerr << "success\n"; + return res; + } + } + + return read_file_internal(fname); +} + void write_file(const std::string& fname, const std::string& data) { std::ofstream file(fname.c_str()); diff --git a/src/display.cpp b/src/display.cpp index b6a798b38ef..1d8f66aab64 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1288,10 +1288,15 @@ std::vector display::getAdjacentTerrain(int x, int y, std::vector::const_iterator terrain = std::find(precedence.begin(),precedence.end(),current_terrain); - if(terrain == precedence.end()) + if(terrain == precedence.end()) { terrain = precedence.begin(); - else + } else { ++terrain; + while(terrain != precedence.end() && + map_.get_terrain_info(*terrain).equal_precedence()) { + ++terrain; + } + } for(; terrain != precedence.end(); ++terrain){ //find somewhere that doesn't have overlap to use as a starting point @@ -1442,11 +1447,11 @@ SDL_Surface* display::getImage(const std::string& filename, const std::string images_filename = images_path + filename; SDL_Surface* surf = NULL; -#ifdef WESNOTH_PATH - const std::string& fullpath = WESNOTH_PATH + std::string("/") + - images_filename; - surf = IMG_Load(fullpath.c_str()); -#endif + if(game_config::path.empty() == false) { + const std::string& fullpath = game_config::path + "/" + + images_filename; + surf = IMG_Load(fullpath.c_str()); + } if(surf == NULL) surf = IMG_Load(images_filename.c_str()); diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 1ccd4140980..cbaa881febe 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -39,6 +39,7 @@ #include #include "filesystem.hpp" +#include "game_config.hpp" namespace { const mode_t AccessMode = 00770; @@ -55,18 +56,15 @@ void get_files_in_dir(const std::string& directory, std::vector* dirs, FILE_NAME_MODE mode) { - //if we have a path to find directories in, then convert relative //pathnames to be rooted on the wesnoth path -#ifdef WESNOTH_PATH - if(!directory.empty() && directory[0] != '/' && WESNOTH_PATH[0] == '/') { - const std::string& dir = WESNOTH_PATH + std::string("/") + directory; + if(!directory.empty() && directory[0] != '/' && !game_config::path.empty()){ + const std::string& dir = game_config::path + "/" + directory; if(is_directory(dir)) { get_files_in_dir(dir,files,dirs,mode); return; } } -#endif #ifdef _WIN32 _finddata_t fileinfo; @@ -220,16 +218,10 @@ std::string get_user_data_dir() #endif } -bool is_directory(const std::string& fname) +namespace { + +bool is_directory_internal(const std::string& fname) { - -#ifdef WESNOTH_PATH - if(!fname.empty() && fname[0] != '/' && WESNOTH_PATH[0] == '/') { - if(is_directory(WESNOTH_PATH + std::string("/") + fname)) - return true; - } -#endif - #ifdef _WIN32 _finddata_t info; const long handle = _findfirst((fname + "/*").c_str(),&info); @@ -250,3 +242,15 @@ bool is_directory(const std::string& fname) } #endif } + +} + +bool is_directory(const std::string& fname) +{ + if(!fname.empty() && fname[0] != '/' && !game_config::path.empty()) { + if(is_directory_internal(game_config::path + "/" + fname)) + return true; + } + + return is_directory_internal(fname); +} diff --git a/src/font.cpp b/src/font.cpp index 491e9cd456d..e3fc278ea32 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -15,6 +15,7 @@ #include "config.hpp" #include "font.hpp" +#include "game_config.hpp" #include "tooltips.hpp" #include @@ -33,27 +34,27 @@ TTF_Font* open_font(const std::string& fname, int size) { std::string name; -#ifdef WESNOTH_PATH - name = std::string(WESNOTH_PATH) + "/fonts/" + fname; - std::cerr << "Opening font file: " << name << " ...\n"; + if(game_config::path.empty() == false) { + name = game_config::path + "/fonts/" + fname; + std::cerr << "Opening font file: " << name << " ...\n"; - if(read_file(name).empty()) { + if(read_file(name).empty()) { + name = "fonts/" + fname; + std::cerr << "Failed, now trying: " << name << " ...\n"; + if(read_file(name).empty()) { + std::cerr << "Failed :(\n"; + return NULL; + } + } + } else { name = "fonts/" + fname; - std::cerr << "Failed, now trying: " << name << " ...\n"; + std::cerr << "Opening font file: " << name << " ...\n"; + if(read_file(name).empty()) { std::cerr << "Failed :(\n"; return NULL; } } -#else - name = "fonts/" + fname; - std::cerr << "Opening font file: " << name << " ...\n"; - - if(read_file(name).empty()) { - std::cerr << "Failed :(\n"; - return NULL; - } -#endif TTF_Font* font = TTF_OpenFont(name.c_str(),size); if(font == NULL) { diff --git a/src/game.cpp b/src/game.cpp index 422d15c8c36..e3a4018a03a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -18,6 +18,7 @@ #include "config.hpp" #include "dialogs.hpp" #include "display.hpp" +#include "filesystem.hpp" #include "font.hpp" #include "game_config.hpp" #include "game_events.hpp" @@ -148,6 +149,32 @@ int play_game(int argc, char** argv) const sound::manager sound_manager; const preferences::manager prefs_manager; + bool test_mode = false; + + for(int arg = 1; arg != argc; ++arg) { + const std::string val(argv[arg]); + if(val == "--windowed" || val == "-w") { + preferences::set_fullscreen(false); + } else if(val == "--test" || val == "-t") { + test_mode = true; + } else if(val == "--debug" || val == "-d") { + game_config::debug = true; + } else if(val == "--help" || val == "-h") { + std::cout << "usage: " << argv[0] + << " [options] [data-directory]\n"; + } else if(val == "--version" || val == "-v") { + std::cout << "Battle for Wesnoth " << game_config::version + << "\n"; + } else { + if(!is_directory(val)) { + std::cerr << "Could not find directory '" << val << "'\n"; + return 0; + } + + game_config::path = val; + } + } + std::map defines_map; defines_map["NORMAL"] = ""; std::vector line_src; @@ -180,19 +207,6 @@ int play_game(int argc, char** argv) } } - bool test_mode = false; - - for(int arg = 1; arg != argc; ++arg) { - const std::string val(argv[arg]); - if(val == "-windowed") { - preferences::set_fullscreen(false); - } else if(val == "-test") { - test_mode = true; - } else if(val == "-debug") { - game_config::debug = true; - } - } - int video_flags = preferences::fullscreen() ? FULL_SCREEN : 0; const std::pair& resolution = preferences::resolution(); diff --git a/src/game_config.cpp b/src/game_config.cpp index 3a370c6090a..f4ed1eb4d5f 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -24,4 +24,10 @@ namespace game_config const int recall_cost = 20; const std::string version = "0.4.9-CVS"; bool debug = false; + +#ifdef WESNOTH_PATH + std::string path = WESNOTH_PATH; +#else + std::string path = ""; +#endif } diff --git a/src/game_config.hpp b/src/game_config.hpp index 5cc101dbb19..bb71b1d13d1 100644 --- a/src/game_config.hpp +++ b/src/game_config.hpp @@ -28,6 +28,8 @@ namespace game_config extern const std::string version; extern bool debug; + + extern std::string path; } #endif diff --git a/src/menu.cpp b/src/menu.cpp index d4e00cc9279..fb9f946cc4c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -44,8 +44,6 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp) if(top == NULL || bot == NULL || left == NULL || right == NULL) return; - SDL_Surface* const scr = disp.video().getSurface(); - scoped_sdl_surface top_image(scale_surface(top,w,top->h)); if(top_image.get() != NULL) { diff --git a/src/sound.cpp b/src/sound.cpp index 55d68a72101..a2766fcb9c5 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -10,6 +10,8 @@ See the COPYING file for more details. */ + +#include "game_config.hpp" #include "sound.hpp" #include "SDL_mixer.h" @@ -84,10 +86,10 @@ void play_music(const std::string& file) std::string filename; Mix_Music* music = NULL; -#ifdef WESNOTH_PATH - filename = WESNOTH_PATH + std::string("/") + music_prefix + file; - music = Mix_LoadMUS(filename.c_str()); -#endif + if(game_config::path.empty() == false) { + filename = game_config::path + "/" + music_prefix + file; + music = Mix_LoadMUS(filename.c_str()); + } if(music == NULL) { filename = music_prefix + file; @@ -128,10 +130,10 @@ void play_sound(const std::string& file) std::string filename; Mix_Chunk* sfx = NULL; -#ifdef WESNOTH_PATH - filename = WESNOTH_PATH + std::string("/") + sound_prefix + file; - sfx = Mix_LoadWAV(filename.c_str()); -#endif + if(game_config::path.empty() == false) { + filename = game_config::path + "/" + sound_prefix + file; + sfx = Mix_LoadWAV(filename.c_str()); + } if(sfx == NULL) { filename = sound_prefix + file; diff --git a/src/terrain.cpp b/src/terrain.cpp index a835134847b..09ac727a15f 100644 --- a/src/terrain.cpp +++ b/src/terrain.cpp @@ -17,7 +17,8 @@ #include #include -terrain_type::terrain_type() : images_(1,"void"), type_(' '), letter_(' ') +terrain_type::terrain_type() : images_(1,"void"), type_(' '), letter_(' '), + equal_precedence_(false) {} terrain_type::terrain_type(config& cfg) @@ -35,6 +36,8 @@ terrain_type::terrain_type(config& cfg) type_ = alias[0]; colour_.read(cfg); + + equal_precedence_ = cfg.values["no_overlay"] == "true"; } const std::string& terrain_type::image(int x, int y) const @@ -75,6 +78,11 @@ bool terrain_type::is_alias() const return type_ != letter_; } +bool terrain_type::equal_precedence() const +{ + return equal_precedence_; +} + void create_terrain_maps(std::vector& cfgs, std::vector& terrain_precedence, std::map& letter_to_terrain, diff --git a/src/terrain.hpp b/src/terrain.hpp index ea3e90437d7..03a3f3583e7 100644 --- a/src/terrain.hpp +++ b/src/terrain.hpp @@ -33,6 +33,10 @@ public: pixel_data get_rgb() const; bool is_alias() const; + + //whether the terrain's overlay precedence is equal (rather than higher + //than) the preceeding terrain + bool equal_precedence() const; private: std::vector images_; std::string name_; @@ -44,6 +48,8 @@ private: char type_, letter_; pixel_data colour_; + + bool equal_precedence_; }; void create_terrain_maps(std::vector& cfgs, diff --git a/src/unit_types.cpp b/src/unit_types.cpp index 5ecbe60eb6b..845270cb9ab 100644 --- a/src/unit_types.cpp +++ b/src/unit_types.cpp @@ -357,12 +357,12 @@ unit_type::unit_type(config& cfg, const movement_type_map& mv_types, //check if the images necessary for units exist #ifdef linux struct stat stat_buf; -#ifdef WESNOTH_PATH - if(::stat((WESNOTH_PATH + std::string("/images/") + - cfg_.values["image"]).c_str(),&stat_buf) >= 0) { - return; + if(game_config::path.empty() == false) { + if(::stat((game_config::path + "/images/" + + cfg_.values["image"]).c_str(),&stat_buf) >= 0) { + return; + } } -#endif if(::stat(("images/" + cfg_.values["image"]).c_str(),&stat_buf) < 0) { std::cerr << "image '" << cfg_.values["image"] << "' does not exist!\n";