fix segfault in map generation
This commit is contained in:
parent
444dc086e4
commit
a8c00adae4
6 changed files with 46 additions and 13 deletions
|
@ -239,6 +239,10 @@ road_windiness=3
|
|||
min_distance=24
|
||||
[/castle]
|
||||
|
||||
[naming]
|
||||
{HUMAN_NAMES}
|
||||
[/naming]
|
||||
|
||||
[village_naming]
|
||||
{VILLAGE_NAMES}
|
||||
[/village_naming]
|
||||
|
|
|
@ -675,6 +675,13 @@ keep="Keep"
|
|||
cave="Cave"
|
||||
cavewall="Cave Wall"
|
||||
|
||||
#naming of terrain features
|
||||
bridge_name="$name's Bridge,$name's Crossing"
|
||||
road_name="$name's Highway,$name's Pass"
|
||||
river_name="$name River,River $name"
|
||||
forest_name="$name Forest,$name's Forest"
|
||||
lake_name="$name Lake"
|
||||
|
||||
#Li'sar is always meant to be 'Princess' no matter what level she is on
|
||||
BattlePrincess="Princess"
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "cavegen.hpp"
|
||||
#include "language.hpp"
|
||||
#include "mapgen.hpp"
|
||||
#include "mapgen_dialog.hpp"
|
||||
#include "pathfind.hpp"
|
||||
|
@ -618,6 +619,17 @@ gamemap::location place_village(const std::vector<std::vector<gamemap::TERRAIN>
|
|||
return best_loc;
|
||||
}
|
||||
|
||||
std::string generate_name(const unit_race& name_generator, const std::string& id)
|
||||
{
|
||||
const std::vector<std::string>& options = config::split(string_table[id]);
|
||||
if(options.empty() == false) {
|
||||
const size_t choice = rand()%options.size();
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//function to generate the map.
|
||||
|
@ -652,6 +664,15 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
|
|||
const height_map heights = generate_height_map(width,height,iterations,hill_size,island_size,island_off_center);
|
||||
std::cerr << "done generating height map...\n";
|
||||
|
||||
const config* const names_info = cfg.child("naming");
|
||||
config naming;
|
||||
if(names_info != NULL) {
|
||||
naming = *names_info;
|
||||
}
|
||||
|
||||
//make a dummy race for generating names
|
||||
unit_race name_generator(naming);
|
||||
|
||||
//the configuration file should contain a number of [height] tags:
|
||||
//[height]
|
||||
//height=n
|
||||
|
|
|
@ -17,9 +17,10 @@ namespace {
|
|||
|
||||
default_map_generator::default_map_generator(const config* cfg)
|
||||
: width_(40), height_(40), island_size_(0), iterations_(1000), hill_size_(10), max_lakes_(20),
|
||||
nvillages_(25), nplayers_(2), cfg_(cfg)
|
||||
nvillages_(25), nplayers_(2)
|
||||
{
|
||||
if(cfg_ != NULL) {
|
||||
if(cfg != NULL) {
|
||||
cfg_ = *cfg;
|
||||
|
||||
const int width = ::atoi((*cfg)["map_width"].c_str());
|
||||
if(width > 0)
|
||||
|
@ -283,25 +284,25 @@ std::string default_map_generator::generate_map(const std::vector<std::string>&
|
|||
std::cerr << "calculated coastal params...\n";
|
||||
}
|
||||
|
||||
std::cerr << "generating map with " << nplayers_ << " players\n";
|
||||
|
||||
if(cfg_ != NULL) {
|
||||
return default_generate_map(width_,height_,island_size,island_off_center,iterations,hill_size_,max_lakes,(nvillages_*width_*height_)/1000,nplayers_,labels,*cfg_);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
return default_generate_map(width_,height_,island_size,island_off_center,iterations,hill_size_,max_lakes,(nvillages_*width_*height_)/1000,nplayers_,labels,cfg_);
|
||||
}
|
||||
|
||||
config default_map_generator::create_scenario(const std::vector<std::string>& args)
|
||||
{
|
||||
std::cerr << "creating scenario...\n";
|
||||
config res;
|
||||
const config* const scenario = cfg_->child("scenario");
|
||||
|
||||
const config* const scenario = cfg_.child("scenario");
|
||||
if(scenario != NULL) {
|
||||
res = *scenario;
|
||||
}
|
||||
|
||||
std::cerr << "got scenario data...\n";
|
||||
|
||||
std::map<gamemap::location,std::string> labels;
|
||||
std::cerr << "generating map...\n";
|
||||
res["map_data"] = generate_map(args,&labels);
|
||||
std::cerr << "done generating map..\n";
|
||||
|
||||
for(std::map<gamemap::location,std::string>::const_iterator i = labels.begin(); i != labels.end(); ++i) {
|
||||
config& label = res.add_child("label");
|
||||
|
|
|
@ -21,7 +21,7 @@ private:
|
|||
std::string generate_map(const std::vector<std::string>& args, std::map<gamemap::location,std::string>* labels=NULL);
|
||||
|
||||
size_t width_, height_, island_size_, iterations_, hill_size_, max_lakes_, nvillages_, nplayers_;
|
||||
const config* cfg_;
|
||||
config cfg_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -410,12 +410,12 @@ lobby::RESULT multiplayer_game_setup_dialog::process()
|
|||
}
|
||||
}
|
||||
|
||||
if(generator_ != NULL && generator_->allow_user_config() && generator_settings_->process(mousex,mousey,left_button)) {
|
||||
if(generator_ != NULL && generator_->allow_user_config() && generator_settings_->pressed()) {
|
||||
generator_->user_config(disp_);
|
||||
map_changed = true;
|
||||
}
|
||||
|
||||
if(generator_ != NULL && level_ != NULL && (map_changed || regenerate_map_->process(mousex,mousey,left_button))) {
|
||||
if(generator_ != NULL && level_ != NULL && (map_changed || regenerate_map_->pressed())) {
|
||||
const cursor::setter cursor_setter(cursor::WAIT);
|
||||
|
||||
//generate the random map
|
||||
|
|
Loading…
Add table
Reference in a new issue