Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] [PATCH] get_map_area() (PR#1050)
Home

[Freeciv-Dev] [PATCH] get_map_area() (PR#1050)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] get_map_area() (PR#1050)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Thu, 1 Nov 2001 08:35:15 -0800 (PST)

The attached patch provides a new topology function, get_map_area(),
that returns the total area of the active map (equal to the size of the
normal set).

Later this can be optimized away; when the topology is initialized
map.area can be set up along with map.xsize and map.ysize.  For now,
this is a necessary step toward maps where normal!=regular.

This patch is tiny, and shouldn't be controversial.  The uses of the
function in mapgen() aren't strictly necessary, but for the most part
make the code more readable.  Some could be left out if necessary.

jason
? rc
? old
? topology
? corecleanup_08.ReadMe
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.98
diff -u -r1.98 map.c
--- common/map.c        2001/10/30 10:59:19     1.98
+++ common/map.c        2001/11/01 16:09:40
@@ -1340,6 +1340,14 @@
 }
 
 /**************************************************************************
+Returns the total number of positions (or tiles) on the map.
+**************************************************************************/
+int get_map_area(void)
+{
+  return map.xsize * map.ysize;
+}
+
+/**************************************************************************
 Random neighbouring square.
 **************************************************************************/
 void rand_neighbour(int x0, int y0, int *x, int *y)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.101
diff -u -r1.101 map.h
--- common/map.h        2001/10/30 10:59:20     1.101
+++ common/map.h        2001/11/01 16:09:40
@@ -284,6 +284,7 @@
 
 int normalize_map_pos(int *x, int *y);
 void nearest_real_pos(int *x, int *y);
+int get_map_area(void);
 
 void rand_neighbour(int x0, int y0, int *x, int *y);
 void rand_map_pos(int *x, int *y);
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.36
diff -u -r1.36 barbarian.c
--- server/barbarian.c  2001/10/30 10:59:20     1.36
+++ server/barbarian.c  2001/11/01 16:09:41
@@ -417,7 +417,7 @@
   if(game.year < game.onsetbarbarian)
     return;
 
-  n = map.xsize*map.ysize / MAP_FACTOR;    /* map size adjustment */
+  n = get_map_area() / MAP_FACTOR;
   if (n == 0) /* Allow barbarians on maps smaller than MAP_FACTOR */
     n = 1;
 
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.76
diff -u -r1.76 mapgen.c
--- server/mapgen.c     2001/10/30 10:59:20     1.76
+++ server/mapgen.c     2001/11/01 16:09:42
@@ -82,7 +82,7 @@
       if (hmap(x, y)>thill) 
        mount++;
     } whole_map_iterate_end;
-    if (mount<((map.xsize*map.ysize)*map.mountains)/1000) 
+    if (mount < get_map_area() * map.mountains / 1000)
       thill*=95;
     else 
       thill*=105;
@@ -197,7 +197,7 @@
 {
   int x,y;
   int forestsize=25;
-  forestsize=(map.xsize*map.ysize*map.forestsize)/1000;
+  forestsize=get_map_area()*map.forestsize/1000;
    do {
     rand_map_pos(&x, &y);
     if (map_get_terrain(x, y)==T_GRASSLAND) {
@@ -645,7 +645,7 @@
   int desirable_riverlength =
     map.riverlength *
     /* The size of the map (poles don't count). */
-    map.xsize * (map.ysize - 2) *
+    (get_map_area() - 2 * map.xsize) *
     /* Rivers need to be on land only. */
     map.landpercent /
     /* Adjustment value. Tested by me. Gives no rivers with 'set
@@ -823,7 +823,7 @@
 {
   int tres=(maxval*map.landpercent)/100;
   int count=0;
-  int total=(map.xsize*map.ysize*map.landpercent)/100;
+  int total=get_map_area()*map.landpercent/100;
   int forever=0;
   do {
     forever++;
@@ -1379,7 +1379,7 @@
 {
   int x,y,l;
   int count=0;
-  while ((number*map.xsize*map.ysize)/2000 && count++<map.xsize*map.ysize*2) {
+  while (get_map_area()*map.ysize/2000 && count++<get_map_area()*2) {
     rand_map_pos(&x, &y);
     l=myrand(6);
     if (map_get_terrain(x, y)!=T_OCEAN && 
@@ -1637,7 +1637,7 @@
            islemass-i, islemass);
   }
   
-  tries= map.xsize*(long int)map.ysize/4;/* on a 40x60 map, there are 2400 
places */
+  tries= get_map_area()/4;/* on a 40x60 map, there are 2400 places */
   while (!(i = place_island()) && --tries);
   return i;
 }
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.88
diff -u -r1.88 maphand.c
--- server/maphand.c    2001/10/30 10:59:21     1.88
+++ server/maphand.c    2001/11/01 16:09:42
@@ -73,7 +73,7 @@
 
   freelog(LOG_NORMAL, "Global warming: %d", game.heating);
 
-  k = map.xsize * map.ysize;
+  k = get_map_area();
   while(effect && k--) {
     rand_map_pos(&x, &y);
     if (map_get_terrain(x, y) != T_OCEAN) {
@@ -129,7 +129,7 @@
 
   freelog(LOG_NORMAL, "Nuclear winter: %d", game.cooling);
 
-  k =map.xsize * map.ysize;
+  k = get_map_area();
   while(effect && k--) {
     rand_map_pos(&x, &y);
     if (map_get_terrain(x, y) != T_OCEAN) {

[Prev in Thread] Current Thread [Next in Thread]