Author: mordante
Date: Fri Feb 29 19:17:30 2008
New Revision: 24154

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24154&view=rev
Log:
* random maps can no longer crash if two teams have the same starting
  position (that happened if 2 teams didn't get a starting position.)
  bug #11166.
* when the number of players for a random map can't be placed the engine
  tries maximal ten times before giving up.

Modified:
    trunk/changelog
    trunk/players_changelog
    trunk/src/mapgen.cpp
    trunk/src/mapgen_dialog.cpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=24154&r1=24153&r2=24154&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Fri Feb 29 19:17:30 2008
@@ -10,6 +10,11 @@
      or joining a new game
    * fixed an invalid vector access, which could happen since linger mode
      didn't reset the player_numer_ (bug #11094)
+   * random maps can no longer crash if two teams have the same starting
+     position (that happened if 2 teams didn't get a starting position.)
+     bug #11166.
+   * when the number of players for a random map can't be placed the engine
+     tries maximal ten times before giving up.
  * sound:
    * added new music track, "Knalgan Theme" by Ryan Reilly.
    * added new music track, "The King is Dead" by Mattias Westlund.

Modified: trunk/players_changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/players_changelog?rev=24154&r1=24153&r2=24154&view=diff
==============================================================================
--- trunk/players_changelog (original)
+++ trunk/players_changelog Fri Feb 29 19:17:30 2008
@@ -9,6 +9,10 @@
 
   * Multiplayer
     * Revised maps: Cynsaun Battlefield.
+       * The random map generator now tries harder to get the wanted number
+      of players and shows no map if it fails.
+       * When generating a random map two teams could get the same starting  
+      position, this has been fixed.
 
   * Sound and music:
     * New music track, "Nunc Dimittis" by Jeremy Nicoll.

Modified: trunk/src/mapgen.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mapgen.cpp?rev=24154&r1=24153&r2=24154&view=diff
==============================================================================
--- trunk/src/mapgen.cpp (original)
+++ trunk/src/mapgen.cpp Fri Feb 29 19:17:30 2008
@@ -29,6 +29,7 @@
 #include "wml_exception.hpp"
 
 #include <algorithm>
+#include <cassert>
 #include <cctype>
 #include <cmath>
 #include <cstdlib>
@@ -40,6 +41,7 @@
 #include <vector>
 
 #define ERR_CF LOG_STREAM(err, config)
+#define ERR_NG LOG_STREAM(err, engine)
 #define LOG_NG LOG_STREAM(info, engine)
 
 config map_generator::create_scenario(const std::vector<std::string>& args)
@@ -959,8 +961,14 @@
                                }
                        }
                }
-
+               if(best_ranking == 0) {
+                       ERR_NG << "No castle location found, aborting.\n";
+                       return "";
+               }
+               assert(std::find(castles.begin(), castles.end(), best_loc) == 
castles.end());
                castles.push_back(best_loc);
+               // Make sure the location can't get a second castle.
+               failed_locs.insert(best_loc);
        }
 
        LOG_NG << "placing roads...\n";

Modified: trunk/src/mapgen_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/mapgen_dialog.cpp?rev=24154&r1=24153&r2=24154&view=diff
==============================================================================
--- trunk/src/mapgen_dialog.cpp (original)
+++ trunk/src/mapgen_dialog.cpp Fri Feb 29 19:17:30 2008
@@ -355,7 +355,17 @@
                DBG_NG << "calculated coastal params...\n";
        }
 
-       return 
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_);
+       // A map generator can fail so try a few times to get a map before 
aborting.
+       std::string map;
+       int tries = 10;
+       do {
+               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_);
+               --tries; 
+       } while (tries && map.empty());
+
+       return map;
 }
 
 config default_map_generator::create_scenario(const std::vector<std::string>& 
args)


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to