Fixes bug #13199...

(Map generation in mp fails when hills and size of hills sliders are at max).
This commit is contained in:
Jörg Hinrichs 2009-03-17 19:41:19 +00:00
parent 3edb0eb233
commit e06c03b77b
5 changed files with 43 additions and 6 deletions

View file

@ -11,6 +11,8 @@ Version 1.5.14+svn:
* Miscellaneous and bug fixes:
* Fixed bug #13204: NR: Death event doesn't re-spawn Malifor as expected
* Fixed bug #13198: Corrupt replay in MP
* Fixed bug #13199: Map generation in mp fails when hills and size of hills
sliders are at max
Version 1.5.14:
* Campaigns:

View file

@ -764,6 +764,8 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
}
}
std::map<int, t_translation::coordinate> starting_positions;
LOG_NG << output_map(terrain, starting_positions);
LOG_NG << "placed land forms\n";
LOG_NG << (SDL_GetTicks() - ticks) << "\n"; ticks = SDL_GetTicks();
@ -970,8 +972,10 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
}
}
if(best_ranking == 0) {
//FIXME: Make this error message translatable (not possible atm due to string freeze)
ERR_NG << "No castle location found, aborting.\n";
return "";
std::string error = "No valid castle location found. Too many or too few mountain hexes? (please check the 'max hill size' parameter)";
throw mapgen_exception(error);
}
assert(std::find(castles.begin(), castles.end(), best_loc) == castles.end());
castles.push_back(best_loc);
@ -1134,7 +1138,6 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
// Now that road drawing is done, we can plonk down the castles.
std::map<int, t_translation::coordinate> starting_positions;
for(std::vector<location>::const_iterator c = castles.begin(); c != castles.end(); ++c) {
if(c->valid() == false) {
continue;

View file

@ -26,6 +26,17 @@ class display;
#include <string>
#include <vector>
struct mapgen_exception : public std::exception
{
mapgen_exception(const std::string& msg)
: msg(msg)
{
}
~mapgen_exception() throw() {}
const char* what() const throw() { return msg.c_str(); }
const std::string msg;
};
class map_generator
{
public:

View file

@ -375,19 +375,30 @@ std::string default_map_generator::generate_map(const std::vector<std::string>&
std::string map;
// Keep a copy of labels as it can be written to by the map generator func
std::map<map_location,std::string> labels_copy;
std::string error_message;
int tries = 10;
do {
if (labels) {
labels_copy = *labels;
}
map = default_generate_map(width_, height_, island_size, island_off_center,
iterations, hill_size_, max_lakes, (nvillages_ * width_ * height_) / 1000,
castle_size_, nplayers_, link_castles_, labels, cfg_);
try{
map = default_generate_map(width_, height_, island_size, island_off_center,
iterations, hill_size_, max_lakes, (nvillages_ * width_ * height_) / 1000,
castle_size_, nplayers_, link_castles_, labels, cfg_);
error_message = "";
}
catch (mapgen_exception& exc){
error_message = exc.msg;
}
--tries;
} while (tries && map.empty());
if (labels) {
labels->swap(labels_copy);
}
if (error_message != "")
throw mapgen_exception(error_message);
return map;
}
@ -405,7 +416,13 @@ config default_map_generator::create_scenario(const std::vector<std::string>& ar
std::map<map_location,std::string> labels;
DBG_NG << "generating map...\n";
res["map_data"] = generate_map(args,&labels);
try{
res["map_data"] = generate_map(args,&labels);
}
catch (mapgen_exception exc){
res["map_data"] = "";
res["error_message"] = exc.msg;
}
DBG_NG << "done generating map..\n";
for(std::map<map_location,std::string>::const_iterator i =

View file

@ -25,6 +25,7 @@
#include "map.hpp"
#include "map_exception.hpp"
#include "map_create.hpp"
#include "Gui/Dialogs/message.hpp"
#include "minimap.hpp"
#include "multiplayer_create.hpp"
#include "filesystem.hpp"
@ -464,6 +465,9 @@ void create::process_event()
parameters_.scenario_data = generator_->create_scenario(std::vector<std::string>());
map_changed = true;
if (!parameters_.scenario_data["error_message"].empty())
gui2::show_message(disp().video(), "map generation error", parameters_.scenario_data["error_message"]);
// Set the scenario to have placing of sides
// based on the terrain they prefer
parameters_.scenario_data["modify_placing"] = "true";