[Freeciv-Dev] Implementation giving each player their own island with ma
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I like the maps that gen 1 generates. Alas, when playing a really small
map, there is a good chance that I will be sharing an island with another
player which can make for an extremely short game.
Hence, this patch. What it does is simple: After making a map, it checks
to make sure each player has their own island with enough resources to start
a nation. If not, then the seed is incremented and we check the next map
generated. We continue to generate maps until we find a map which gives each
player an island.
Perhaps we should make this a flag. Perhaps the patch should, instead
of using a new seed, set things up so that the map generator generates a
different map using the same seed number; maybe by running myrand() a
number of times based on the number of trials we have already done.
There may be some memory leaked when discarding the old map and making
a new one.
- Sam
--- freeciv-1.14.0/server/mapgen.c Fri Oct 11 16:35:50 2002
+++ freeciv-1.14.0-hacked/server/mapgen.c Mon Mar 10 02:43:35 2003
@@ -941,8 +941,9 @@
Allocate islands array and fill in values.
Note this is only use for map.generator<=1, since others
setups islands and starters explicitly.
+ Output: The number of good islands that this map has
**************************************************************************/
-static void setup_isledata(void)
+int setup_isledata(void)
{
int x;
int good, mingood, maxgood;
@@ -1104,6 +1105,7 @@
}
freelog(LOG_DEBUG, "The map has %i starting positions on %i isles.",
starters, goodisles);
+ return goodisles;
}
/**************************************************************************
@@ -1113,17 +1115,40 @@
FIXME: MAXTRIES used to be 1.000.000, but has been raised to 10.000.000
because a set of values hit the limit. At some point we want to
make a better solution.
+ Output: Whether this is a good map; 1 if yes, 0 if no
**************************************************************************/
#define MAXTRIES 10000000
-void create_start_positions(void)
+int create_start_positions(void)
{
int nr=0;
int dist=40;
int x, y, j=0, k, sum;
int counter = 0;
+ int isles, i;
+
+ isles = 10000; /* Big number so this passes the "own island" test */
if (!islands) /* already setup for generators 2,3, and 4 */
- setup_isledata();
+ isles = setup_isledata();
+
+ /*printf("Seed %d has %d good islands\n",map.seed,isles);*/
+
+ if(isles < game.nplayers) { /* Each player gets their own island */
+ printf("Seed %d does not create enough islands for %d players.\n",
+ map.seed,game.nplayers);
+ map.seed++;
+ printf("Trying seed %d\n",map.seed);
+ free(islands);
+ free(height_map);
+ free(river_map);
+ islands = 0;
+ maxval = 0;
+ forests = 0;
+ map.num_continents = 0;
+ free(map.tiles);
+ map.tiles = 0;
+ return 0;
+ }
if(dist>= map.xsize/2)
dist= map.xsize/2;
@@ -1169,6 +1194,7 @@
free(islands);
islands = NULL;
+ return 1; /* Good map */
}
/**************************************************************************
--- freeciv-1.14.0/server/srv_main.c Fri Oct 11 16:35:50 2002
+++ freeciv-1.14.0-hacked/server/srv_main.c Mon Mar 10 02:22:56 2003
@@ -1798,6 +1798,7 @@
void srv_main(void)
{
int i;
+ int is_good_map;
/* make sure it's initialized */
if (!has_been_srv_init) {
@@ -1943,7 +1944,11 @@
if(game.is_new_game)
generate_ai_players();
-
+
+ /* This is a loop which will recreate the map in case the map
+ generator decides the generated map is not good enough */
+ do {
+
/* if we have a tile map, and map.generator==0, call map_fractal_generate
anyway, to make the specials and huts */
if(map_is_empty() || (map.generator == 0 && game.is_new_game))
@@ -1972,13 +1977,16 @@
} players_iterate_end;
game.max_players=game.nplayers;
+ is_good_map = 1;
/* we don't want random start positions in a scenario which already
provides them. -- Gudy */
if(map.num_start_positions==0) {
- create_start_positions();
+ is_good_map = create_start_positions();
}
}
+ } while(is_good_map == 0);
+
initialize_move_costs(); /* this may be the wrong place to do this */
generate_minimap(); /* for city_desire; saves a lot of calculations */
--- freeciv-1.14.0/server/mapgen.h Tue Feb 5 11:05:51 2002
+++ freeciv-1.14.0-hacked/server/mapgen.h Mon Mar 10 02:23:20 2003
@@ -15,7 +15,7 @@
void assign_continent_numbers(void);
void map_fractal_generate(void);
-void create_start_positions(void);
+int create_start_positions(void);
void adjust_terrain_param(void);
#endif /* FC__MAPGEN_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Implementation giving each player their own island with map gen 1,
sam+civ <=
|
|