[Freeciv-Dev] (PR#9796) RfP: move assign_continent_numbers into maphand
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9796 >
Patch there
Marcelo
diff -ruN -Xfreeciv/diff_ignore freeciv/server/mapgen.c freeciv_/server/mapgen.c
--- freeciv/server/mapgen.c 2004-08-24 19:23:44.977333648 +0200
+++ freeciv_/server/mapgen.c 2004-08-24 19:41:21.986643808 +0200
@@ -25,6 +25,7 @@
#include "game.h"
#include "log.h"
#include "map.h"
+#include "maphand.h" /* assign_continent_numberd(), MAP_NCONT */
#include "mem.h"
#include "rand.h"
#include "shared.h"
@@ -84,9 +85,6 @@
};
static struct isledata *islands;
-/* this is used for generator>1 */
-#define MAP_NCONT 255
-
/* this is the maximal temperature at equators returned by map_temperature */
#define MAX_TEMP 1000
@@ -1204,64 +1202,6 @@
} whole_map_iterate_end;
}
-/**************************************************************************
- Number this tile and recursive adjacent tiles with specified
- continent number, by flood-fill algorithm.
- is_land tells us whether we are assigning continent numbers or ocean
- numbers.
-**************************************************************************/
-static void assign_continent_flood(int x, int y, bool is_land, int nr)
-{
- if (map_get_continent(x, y) != 0) {
- return;
- }
-
- if ((is_land && is_ocean(map_get_terrain(x, y)))
- || (!is_land && !is_ocean(map_get_terrain(x, y)))) {
- return;
- }
-
- map_set_continent(x, y, nr);
-
- adjc_iterate(x, y, x1, y1) {
- assign_continent_flood(x1, y1, is_land, nr);
- } adjc_iterate_end;
-}
-
-/**************************************************************************
- Assign continent and ocean numbers to all tiles, set map.num_continents
- and map.num_oceans.
- Continents have numbers 1 to map.num_continents _inclusive_.
- Oceans have (negative) numbers -1 to -map.num_oceans _inclusive_.
-**************************************************************************/
-void assign_continent_numbers(void)
-{
- /* Initialize */
- map.num_continents = 0;
- map.num_oceans = 0;
- whole_map_iterate(x, y) {
- map_set_continent(x, y, 0);
- } whole_map_iterate_end;
-
- /* Assign new numbers */
- whole_map_iterate(x, y) {
- if (map_get_continent(x, y) != 0) {
- /* Already assigned */
- continue;
- }
- if (!is_ocean(map_get_terrain(x, y))) {
- map.num_continents++;
- assign_continent_flood(x, y, TRUE, map.num_continents);
- } else {
- map.num_oceans++;
- assign_continent_flood(x, y, FALSE, -map.num_oceans);
- }
- } whole_map_iterate_end;
-
- freelog(LOG_VERBOSE, "Map has %d continents and %d oceans",
- map.num_continents, map.num_oceans);
-}
-
/****************************************************************************
Return an approximation of the goodness of a tile to a civilization.
****************************************************************************/
diff -ruN -Xfreeciv/diff_ignore freeciv/server/mapgen.h freeciv_/server/mapgen.h
--- freeciv/server/mapgen.h 2004-08-24 19:23:44.980333192 +0200
+++ freeciv_/server/mapgen.h 2004-08-24 19:31:23.415640432 +0200
@@ -13,7 +13,6 @@
#ifndef FC__MAPGEN_H
#define FC__MAPGEN_H
-void assign_continent_numbers(void);
void map_fractal_generate(void);
void create_start_positions(void);
diff -ruN -Xfreeciv/diff_ignore freeciv/server/maphand.c
freeciv_/server/maphand.c
--- freeciv/server/maphand.c 2004-08-24 19:23:44.996330760 +0200
+++ freeciv_/server/maphand.c 2004-08-24 19:44:14.687389304 +0200
@@ -32,7 +32,6 @@
#include "citytools.h"
#include "cityturn.h"
#include "gamelog.h"
-#include "mapgen.h" /* assign_continent_numbers */
#include "plrhand.h" /* notify_player */
#include "sernet.h"
#include "srv_main.h"
@@ -41,6 +40,66 @@
#include "maphand.h"
+/**************************************************************************
+ Number this tile and recursive adjacent tiles with specified
+ continent number, by flood-fill algorithm.
+ is_land tells us whether we are assigning continent numbers or ocean
+ numbers.
+**************************************************************************/
+static void assign_continent_flood(int x, int y, bool is_land, int nr)
+{
+ if (map_get_continent(x, y) != 0) {
+ return;
+ }
+
+ if (!XOR(is_land , is_ocean(map_get_terrain(x, y)))) {
+ return;
+ }
+
+ map_set_continent(x, y, nr);
+
+ adjc_iterate(x, y, x1, y1) {
+ assign_continent_flood(x1, y1, is_land, nr);
+ } adjc_iterate_end;
+}
+
+/**************************************************************************
+ Assign continent and ocean numbers to all tiles, set map.num_continents
+ and map.num_oceans.
+ Continents have numbers 1 to map.num_continents _inclusive_.
+ Oceans have (negative) numbers -1 to -map.num_oceans _inclusive_.
+**************************************************************************/
+void assign_continent_numbers(void)
+{
+ /* Initialize */
+ map.num_continents = 0;
+ map.num_oceans = 0;
+
+ whole_map_iterate(x, y) {
+ map_set_continent(x, y, 0);
+ } whole_map_iterate_end;
+
+ /* Assign new numbers */
+ whole_map_iterate(x, y) {
+ if (map_get_continent(x, y) != 0) {
+ /* Already assigned */
+ continue;
+ }
+ if (!is_ocean(map_get_terrain(x, y))) {
+ map.num_continents++;
+ assert ( map.num_continents < MAP_NCONT);
+ assign_continent_flood(x, y, TRUE, map.num_continents);
+ } else {
+ map.num_oceans++;
+ assert ( map.num_oceans < MAP_NCONT);
+ assign_continent_flood(x, y, FALSE, -map.num_oceans);
+ }
+ } whole_map_iterate_end;
+
+ freelog(LOG_VERBOSE, "Map has %d continents and %d oceans",
+ map.num_continents, map.num_oceans);
+}
+
static void player_tile_init(int x, int y, struct player *pplayer);
static void give_tile_info_from_player_to_player(struct player *pfrom,
struct player *pdest,
diff -ruN -Xfreeciv/diff_ignore freeciv/server/maphand.h
freeciv_/server/maphand.h
--- freeciv/server/maphand.h 2004-08-24 19:23:45.010328632 +0200
+++ freeciv_/server/maphand.h 2004-08-24 19:33:10.865305600 +0200
@@ -49,6 +49,12 @@
short last_updated;
};
+/* this is used for generator 2-4 and in assign_continent number */
+#define MAP_NCONT 300
+
+void assign_continent_numbers(void);
+
+
void global_warming(int effect);
void nuclear_winter(int effect);
void give_map_from_player_to_player(struct player *pfrom, struct player
*pdest);
diff -ruN -Xfreeciv/diff_ignore freeciv/utility/shared.h
freeciv_/utility/shared.h
--- freeciv/utility/shared.h 2004-08-24 19:23:45.181302640 +0200
+++ freeciv_/utility/shared.h 2004-08-24 19:36:22.977100168 +0200
@@ -101,8 +101,8 @@
? ((value) % (range) != 0 ? (value) % (range) + (range) : 0) \
: ((value) >= (range) ? (value) % (range) : (value)))
-#define BOOL_VAL(x) ((x)!=0)
-
+#define BOOL_VAL(x) ((x) != 0)
+#define XOR(p,q) (!(p) != !(q))
/*
* DIVIDE() divides and rounds down, rather than just divides and
* rounds toward 0. It is assumed that the divisor is positive.
|
|