added in new villages

This commit is contained in:
Dave White 2003-10-10 13:27:44 +00:00
parent 7fab891141
commit edb9436fa7
26 changed files with 135 additions and 83 deletions

View File

@ -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]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -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_source>& 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());

View File

@ -1288,10 +1288,15 @@ std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
std::vector<gamemap::TERRAIN>::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());

View File

@ -39,6 +39,7 @@
#include <iostream>
#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<std::string>* 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);
}

View File

@ -15,6 +15,7 @@
#include "config.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "tooltips.hpp"
#include <cstdio>
@ -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) {

View File

@ -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<std::string,std::string> defines_map;
defines_map["NORMAL"] = "";
std::vector<line_source> 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<int,int>& resolution = preferences::resolution();

View File

@ -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
}

View File

@ -28,6 +28,8 @@ namespace game_config
extern const std::string version;
extern bool debug;
extern std::string path;
}
#endif

View File

@ -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) {

View File

@ -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;

View File

@ -17,7 +17,8 @@
#include <cstdlib>
#include <iostream>
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<config*>& cfgs,
std::vector<char>& terrain_precedence,
std::map<char,terrain_type>& letter_to_terrain,

View File

@ -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<std::string> images_;
std::string name_;
@ -44,6 +48,8 @@ private:
char type_, letter_;
pixel_data colour_;
bool equal_precedence_;
};
void create_terrain_maps(std::vector<config*>& cfgs,

View File

@ -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";