Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2001:
[Freeciv-Dev] PATCH: mapgen warning removes
Home

[Freeciv-Dev] PATCH: mapgen warning removes

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: mapgen warning removes
From: Dirk Stoecker <stoecker@xxxxxxxxxxxxxx>
Date: Wed, 24 Jan 2001 19:51:34 +0100 (MET)

Hi,

this patch removes a series of compiler warnings for mapgen.c.

All should be self-explaining except, why I removed function is_cold and
moved it into the code: Well this function was used once only and also
used only one of its arguments. It is better understandable now and I added
a short comment which serves as a function-name replacement.

Also included 6 lines of comment text for amiga smakefile which don't
disturb :-)

For these interested in it, the warnings of my compiler are attached as
text.

Ciao
 ____  _ _  ____  _ _    _ _  ____
|    |  |  |    |  | \  / |  |    | the cool Gremlin from Bischofswerda
|  __   |   ____|  |  \/  |  |    | WWW: http://home.pages.de/~stoecker/
|    |  |  |       |      |  |    | PGP key available on www page.
|____| _|_ |____| _|_    _|_ |____| I hope AMIGA never ends to make fun!
diff -ur ../../freeciv-cvs/freeciv/common/map.h ./common/map.h
--- ../../freeciv-cvs/freeciv/common/map.h      Wed Jan 24 17:41:07 2001
+++ ./common/map.h      Wed Jan 24 18:21:03 2001
@@ -391,7 +391,7 @@
 #define cartesian_adjacent_iterate(x, y, IAC_x, IAC_y) \
 {                                                      \
   int IAC_i;                                           \
-  int IAC_x, IAC_y;                                    \
+  int IAC_x = 0, IAC_y = 0;                            \
   for (IAC_i = 0; IAC_i < 4; IAC_i++) {                \
     switch (IAC_i) {                                   \
     case 0:                                            \
diff -ur ../../freeciv-cvs/freeciv/server/mapgen.c ./server/mapgen.c
--- ../../freeciv-cvs/freeciv/server/mapgen.c   Wed Jan 24 17:41:35 2001
+++ ./server/mapgen.c   Wed Jan 24 18:32:42 2001
@@ -196,7 +196,8 @@
 static void make_forests(void)
 {
   int x,y;
-  int forestsize=25;
+  int forestsize;
+
   forestsize=(map.xsize*map.ysize*map.forestsize)/1000;
    do {
     x=myrand(map.xsize);
@@ -507,7 +508,7 @@
  If these rules haven't decided the direction, the random number
  generator gets the desicion.                              -Erik Sigra
 *********************************************************************/
-static int make_river(x, y)
+static int make_river(int x, int y)
 {
   /* The comparison values of the 4 tiles surrounding the current
      tile. It is the suitability to continue a river to that tile that
@@ -836,9 +837,10 @@
 {
   int x, y;
   int tres=(maxval*map.landpercent)/100;
-  int count=0;
+  int count;
   int total=(map.xsize*map.ysize*map.landpercent)/100;
   int forever=0;
+
   do {
     forever++;
     if (forever>50) break; /* loop elimination */
@@ -1023,8 +1025,8 @@
        {
          int goodval = is_good_tile(x, y);
          int x1, y1;
-         for (x1=-1; x1<=1; x1++) {
-           for (y1=-1; y1<=1; y1++) {
+         for (x1 = -1; x1 <= 1; x1++) {
+           for (y1 = -1; y1 <= 1; y1++) {
              int cont1 = map_get_continent(x+x1, y+y1);
              if (cont1>0) {  
                islands[cont1].goodies += goodval;
@@ -1165,7 +1167,7 @@
       freelog(LOG_VERBOSE, "starters on isle %i", k);
     }
   }
-  assert(game.nplayers<=nr+sum);
+  assert(game.nplayers<=sum);
 
   while (nr<game.nplayers) {
     x=myrand(map.xsize);
@@ -1453,10 +1455,6 @@
 static int isleindex, n, e, s, w;
 static long int totalmass; /* better a global than a duplicate formula */
 
-static int is_cold(int x, int y){
-  return ( y * 5 < map.ysize || y * 5 > map.ysize * 4 );
-}
-
 /**************************************************************************
   fill an island with up four types of terrains, rivers have extra code
 **************************************************************************/
@@ -1499,7 +1497,7 @@
             )
           &&( !is_at_coast(x, y) || myrand(100) < coast )) {
         if (cold1 != T_RIVER) {
-          if ( is_cold(x,y) )
+          if ( y * 5 < map.ysize || y * 5 > map.ysize * 4 ) /* check if cold 
area */
             map_set_terrain(x, y, 
(myrand(cold0_weight+cold1_weight)<cold0_weight) 
                            ? cold0 : cold1);
           else
@@ -1571,8 +1569,6 @@
   int x, y, xo, yo, i=0;
   yo = myrand(map.ysize)+n-s;
   xo = myrand(map.xsize)+w-e;
-  y = n + s / 2;
-  x = w + e / 2;
 
   /* this helps a lot for maps with high landmass */
   for (y = n, x = w ; y < s && x < e ; y++, x++)
@@ -1663,7 +1659,7 @@
   make an island, fill every tile type except plains
   note: you have to create big islands first.
 **************************************************************************/
-static void makeisland(int islemass, int starters)
+static void makeisland(long islemass, int starters)
 {
   static long int tilefactor, balance, lastplaced;/* int may be only 2 byte ! 
*/
   static long int riverbuck, mountbuck, desertbuck, forestbuck, swampbuck;
@@ -1685,11 +1681,11 @@
                + map.deserts + map.forestsize + map.swampsize;
     i = i <= 90 ? 100 : i * 11 / 10;
     tilefactor = totalmass / i;
-    riverbuck = -(long int)myrand(totalmass);
-    mountbuck = -(long int)myrand(totalmass);
-    desertbuck = -(long int)myrand(totalmass);
-    forestbuck = -(long int)myrand(totalmass);
-    swampbuck = -(long int)myrand(totalmass);
+    riverbuck = -(long int)myrand((RANDOM_TYPE)totalmass);
+    mountbuck = -(long int)myrand((RANDOM_TYPE)totalmass);
+    desertbuck = -(long int)myrand((RANDOM_TYPE)totalmass);
+    forestbuck = -(long int)myrand((RANDOM_TYPE)totalmass);
+    swampbuck = -(long int)myrand((RANDOM_TYPE)totalmass);
     lastplaced = totalmass;
   } else {
 
@@ -1902,9 +1898,9 @@
 
   while( isleindex<=MAP_NCONT-20 && checkmass>islandmass && ++j< 1500 ) {
       if(j<1000)
-       size = myrand((islandmass+1)/2+1)+islandmass/2;
+       size = myrand((RANDOM_TYPE)((islandmass+1)/2+1))+islandmass/2;
       else
-       size = myrand((islandmass+1)/2+1);
+       size = myrand((RANDOM_TYPE)((islandmass+1)/2+1));
       if(size<2) size=2;
 
       makeisland(size, (isleindex-2<=game.nplayers)?1:0 );
@@ -1926,8 +1922,8 @@
 **************************************************************************/
 static void mapgenerator4(void)
 {
-  int bigweight=70;
-  int spares= 1;
+  long bigweight;
+  int spares;
   int i;
 
   /* no islands with mass >> sqr(min(xsize,ysize)) */
diff -ur ../../freeciv-cvs/freeciv/amiga/smakefile ./amiga/smakefile
--- ../../freeciv-cvs/freeciv/amiga/smakefile   Wed Jan 24 17:41:28 2001
+++ ./amiga/smakefile   Wed Jan 24 18:36:48 2001
@@ -30,6 +30,14 @@
 
 # comment, if not debugging, disabled by default
 DEBFLAGS = #LIB LIB:debug.lib DEBUG=LINE NOSTRIPDEBUG WARN=ALL 
IGNORE=61,63,120,148,165,178,212
+# disabled warning types:
+# (in includes)   61 - undefined struct/union tag "tag-name"
+# (GCC)           63 - item "name" already declared
+#                120 - Integral type mismatch: possible portability problem
+# (in includes)  148 - use of incomplete struct/union/enum tag "name"
+#                165 - use of narrow type in prototype
+# (old style C)  178 - indirect call without indirection operator
+# (GCC)          212 - item "name" already declared
 
 # The optimize flags, set the comment mark, where you want. The options at the 
end
 # need much more time. Disabled by default.
/server/mapgen.c 511 Warning 161: no prototype declared at definition for 
function "make_river"

====================
          for (x1=-1; x1<=1; x1++) {
/server/mapgen.c 1026 Warning 220: old-fashioned assignment operator
                                   Taken as "= -"

====================
            for (y1=-1; y1<=1; y1++) {
/server/mapgen.c 1027 Warning 220: old-fashioned assignment operator
                                   Taken as "= -"

====================
    riverbuck = -(long int)myrand(totalmass);
/server/mapgen.c 1688 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
    mountbuck = -(long int)myrand(totalmass);
/server/mapgen.c 1689 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
    desertbuck = -(long int)myrand(totalmass);
/server/mapgen.c 1690 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
    forestbuck = -(long int)myrand(totalmass);
/server/mapgen.c 1691 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
    swampbuck = -(long int)myrand(totalmass);
/server/mapgen.c 1692 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
    makeisland(70*totalmass/totalweight, 1);
/server/mapgen.c 1830 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
    makeisland(20*totalmass/totalweight, 0);
/server/mapgen.c 1832 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
    makeisland(10*totalmass/totalweight, 0);
/server/mapgen.c 1834 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
    makeisland(islandmass,1);
/server/mapgen.c 1890 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
        size = myrand((islandmass+1)/2+1)+islandmass/2;
/server/mapgen.c 1905 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
        size = myrand((islandmass+1)/2+1);
/server/mapgen.c 1907 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "RANDOM_TYPE", found "long"

====================
      makeisland(size, (isleindex-2<=game.nplayers)?1:0 );
/server/mapgen.c 1910 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
    makeisland(bigweight*2*totalmass/totalweight, 2);
/server/mapgen.c 1974 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
    makeisland(20*totalmass/totalweight, 0);
/server/mapgen.c 1976 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"

====================
    makeisland(10*totalmass/totalweight, 0);
/server/mapgen.c 1978 Warning 120: integral type mismatch: possible portability 
problem
                                   Expecting "int", found "long"
/server/mapgen.c 158 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 159 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 159 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 161 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 161 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 275 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 275 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 276 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 276 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 293 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 293 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 310 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 310 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 395 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 395 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 1163 Warning 304: dead assignment eliminated "sum"
/server/mapgen.c 1929 Warning 304: dead assignment eliminated "bigweight"
/server/mapgen.c 1930 Warning 304: dead assignment eliminated "spares"
/server/mapgen.c 1502 Warning 308: inline function does not use formal 
parameter "x"
/server/mapgen.c 199 Warning 304: dead assignment eliminated "forestsize"
/server/mapgen.c 235 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 235 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 236 Warning 317: possibly uninitialized variable "x1"
/server/mapgen.c 236 Warning 317: possibly uninitialized variable "y1"
/server/mapgen.c 839 Warning 304: dead assignment eliminated "count"
/server/mapgen.c 1574 Warning 304: dead assignment eliminated "y"
/server/mapgen.c 1575 Warning 304: dead assignment eliminated "x"


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