diff -urd -X freeciv.clean/diff_ignore part_app/server/mapgen.c work/server/mapgen.c --- part_app/server/mapgen.c Thu Feb 21 15:36:49 2002 +++ work/server/mapgen.c Sat Feb 23 14:08:58 2002 @@ -44,7 +44,7 @@ static void adjust_map(int minval); #define RIVERS_MAXTRIES 32767 -enum river_map_type {RS_BLOCKED = 1, RS_RIVER = 2}; +enum river_map_type {RS_BLOCKED = 0, RS_RIVER = 1}; /* Array needed to mark tiles as blocked to prevent a river from falling into itself, and for storing rivers temporarly. @@ -252,7 +252,7 @@ int x,y,i,j; i=map.deserts; j=0; - while (i && j<500) { + while (i > 0 && j<500) { j++; y=myrand(map.ysize*10/180)+map.ysize*110/180; @@ -309,16 +309,16 @@ *********************************************************************/ static int river_test_blocked(int x, int y) { - if (rmap(x, y) & RS_BLOCKED) - return TRUE; + if (TEST_BIT(rmap(x, y), RS_BLOCKED)) + return 1; /* any un-blocked? */ cartesian_adjacent_iterate(x, y, x1, y1) { - if (!(rmap(x1, y1) & RS_BLOCKED)) - return FALSE; + if (!TEST_BIT(rmap(x1, y1), RS_BLOCKED)) + return 0; } cartesian_adjacent_iterate_end; - return TRUE; /* none non-blocked |- all blocked */ + return 1; /* none non-blocked |- all blocked */ } /********************************************************************* @@ -326,16 +326,16 @@ *********************************************************************/ static int river_test_rivergrid(int x, int y) { - return adjacent_river_tiles4(x, y) > 1; + return (adjacent_river_tiles4(x, y) > 1) ? 1 : 0; } /********************************************************************* Help function used in make_river(). See the help there. *********************************************************************/ static int river_test_highlands(int x, int y) -{ - return (map_get_terrain(x, y) == T_HILLS) + - 2 * (map_get_terrain(x, y) == T_MOUNTAINS); +{ + return (((map_get_terrain(x, y) == T_HILLS) ? 1 : 0) + + ((map_get_terrain(x, y) == T_MOUNTAINS) ? 2 : 0)); } /********************************************************************* @@ -369,7 +369,7 @@ *********************************************************************/ static int river_test_swamp(int x, int y) { - return map_get_terrain(x, y) != T_SWAMP; + return (map_get_terrain(x, y) != T_SWAMP) ? 1 : 0; } /********************************************************************* @@ -396,10 +396,10 @@ freelog(LOG_DEBUG, "Blockmarking (%d, %d) and adjacent tiles.", x, y); - rmap(x, y) |= RS_BLOCKED; + rmap(x, y) |= (1u << RS_BLOCKED); cartesian_adjacent_iterate(x, y, x1, y1) { - rmap(x1, y1) |= RS_BLOCKED; + rmap(x1, y1) |= (1u << RS_BLOCKED); } cartesian_adjacent_iterate_end; } @@ -526,14 +526,14 @@ while (TRUE) { /* Mark the current tile as river. */ - rmap(x, y) |= RS_RIVER; + rmap(x, y) |= (1u << RS_RIVER); freelog(LOG_DEBUG, "The tile at (%d, %d) has been marked as river in river_map.\n", x, y); /* Test if the river is done. */ - if (adjacent_river_tiles4(x, y) || - adjacent_terrain_tiles4(x, y, T_OCEAN)) { + if (adjacent_river_tiles4(x, y) != 0|| + adjacent_terrain_tiles4(x, y, T_OCEAN) != 0) { freelog(LOG_DEBUG, "The river ended at (%d, %d).\n", x, y); return TRUE; @@ -730,7 +730,7 @@ /* Try to make a river. If it is OK, apply it to the map. */ if (make_river(x, y)) { whole_map_iterate(x1, y1) { - if (rmap(x1, y1) & RS_RIVER) { + if (TEST_BIT(rmap(x1, y1), RS_RIVER)) { if (terrain_control.river_style == R_AS_TERRAIN) { map_set_terrain(x1, y1, T_RIVER); /* Civ1 river style. */ } else if (terrain_control.river_style == R_AS_SPECIAL) { @@ -928,7 +928,7 @@ } whole_map_iterate(x, y) { - if (!map_get_continent(x, y) && map_get_terrain(x, y) != T_OCEAN) { + if (map_get_continent(x, y) == 0 && map_get_terrain(x, y) != T_OCEAN) { assign_continent_flood(x, y, isle++); } } whole_map_iterate_end; @@ -983,7 +983,7 @@ */ whole_map_iterate(x, y) { int cont = map_get_continent(x, y); - if (cont) { + if (cont != 0) { islands[cont].goodies += is_good_tile(x, y); if (map_has_special(x, y, S_HUT)) { islands[cont].goodies += 0; /* 3; *//* regression testing */ @@ -1067,7 +1067,7 @@ &&!(islands[x].goodies > (riches+oldisles-1)/oldisles)) { freelog(LOG_VERBOSE, "islands[x].goodies=%i",islands[x].goodies); islands[x].starters= (islands[x].goodies+guard1)/mingood; - if(!islands[x].starters) { + if(islands[x].starters == 0) { islands[x].starters+= 1;/* ?PS: may not be enough, guard1(tm) */ } starters+= islands[x].starters; @@ -1078,10 +1078,10 @@ /* starters are winners */ for (x=firstcont;x (riches+oldisles-1)/oldisles) { - assert(!islands[x].starters); + assert(islands[x].starters == 0); freelog(LOG_VERBOSE, "islands[x].goodies=%i", islands[x].goodies); islands[x].starters = (islands[x].goodies+guard1)/mingood; - if(!islands[x].starters) { + if(islands[x].starters == 0) { islands[x].starters+= 1;/* ?PS: may not be enough, guard1(tm) */ } starters+= islands[x].starters; @@ -1142,7 +1142,7 @@ while (nrspecial|=S_SPECIAL_1; } - else if (tile_types[ttype].special_2_name[0]) { + else if (tile_types[ttype].special_2_name[0] != '\0') { map_get_tile(x,y)->special|=S_SPECIAL_2; } } @@ -1427,7 +1427,7 @@ } } } - map.have_specials = 1; + map.have_specials = TRUE; } /************************************************************************** @@ -1438,7 +1438,7 @@ long int totalmass; }; -static int is_cold(int x, int y){ +static bool is_cold(int x, int y){ return ( y * 5 < map.ysize || y * 5 > map.ysize * 4 ); } @@ -1449,7 +1449,7 @@ const struct gen234_state *const pstate) { - int is_real; + bool is_real; *x = pstate->w; *y = pstate->n; @@ -1497,7 +1497,7 @@ if(warm0_weight+warm1_weight+cold0_weight+cold1_weight<=0) i= 0; - while (i && failsafe--) { + while (i > 0 && (failsafe--) > 0) { get_random_map_position_from_state(&x, &y, pstate); if (map_get_continent(x, y) == pstate->isleindex && @@ -1551,7 +1551,7 @@ failsafe = i * (pstate->s - pstate->n) * (pstate->e - pstate->w); if(failsafe<0){ failsafe= -failsafe; } - while (i && failsafe--) { + while (i > 0 && (failsafe--) > 0) { get_random_map_position_from_state(&x, &y, pstate); if (map_get_continent(x, y) == pstate->isleindex && map_get_terrain(x, y) == T_GRASSLAND) { @@ -1581,7 +1581,7 @@ /************************************************************************** finds a place and drop the island created when called with islemass != 0 **************************************************************************/ -static int place_island(struct gen234_state *pstate) +static bool place_island(struct gen234_state *pstate) { int x, y, xo, yo, i=0; rand_map_pos(&xo, &yo); @@ -1594,7 +1594,7 @@ if (!normalize_map_pos(&map_x, &map_y)) return FALSE; - if (hmap(x, y) && is_coastline(map_x, map_y)) + if (hmap(x, y) != 0 && is_coastline(map_x, map_y)) return FALSE; } @@ -1605,17 +1605,17 @@ if (!normalize_map_pos(&map_x, &map_y)) return FALSE; - if (hmap(x, y) && is_coastline(map_x, map_y)) + if (hmap(x, y) != 0 && is_coastline(map_x, map_y)) return FALSE; } } for (y = pstate->n; y < pstate->s; y++) { for (x = pstate->w; x < pstate->e; x++) { - if (hmap(x, y)) { + if (hmap(x, y) != 0) { int map_x = x + xo - pstate->w; int map_y = y + yo - pstate->n; - int is_real; + bool is_real; is_real = normalize_map_pos(&map_x, &map_y); assert(is_real); @@ -1623,7 +1623,7 @@ checkmass--; if(checkmass<=0) { freelog(LOG_ERROR, "mapgen.c: mass doesn't sum up."); - return i; + return i != 0; } map_set_terrain(map_x, map_y, T_GRASSLAND); @@ -1636,16 +1636,17 @@ pstate->e += xo - pstate->w; pstate->n = yo; pstate->w = xo; - return i; + return i != 0; } /************************************************************************** finds a place and drop the island created when called with islemass != 0 **************************************************************************/ -static int create_island(int islemass, struct gen234_state *pstate) +static bool create_island(int islemass, struct gen234_state *pstate) { int x, y, i; long int tries=islemass*(2+islemass/20)+99; + bool j; memset(height_map, '\0', sizeof(int) * map.xsize * map.ysize); y = map.ysize / 2; @@ -1656,11 +1657,10 @@ pstate->s = y + 2; pstate->e = x + 2; i = islemass - 1; - while (i && tries-->0) { + while (i > 0 && tries-->0) { get_random_map_position_from_state(&x, &y, pstate); - if ((!hmap(x, y)) && ( - hmap(x+1, y) || hmap(x-1, y) || - hmap(x, y+1) || hmap(x, y-1) )) { + if (hmap(x, y) == 0 && (hmap(x + 1, y) != 0 || hmap(x - 1, y) != 0 || + hmap(x, y + 1) != 0 || hmap(x, y - 1) != 0)) { hmap(x, y) = 1; i--; if (y >= pstate->s - 1 && pstate->s < map.ysize - 2) pstate->s++; @@ -1671,10 +1671,10 @@ if (i < islemass / 10) { for (y = pstate->n; y < pstate->s; y++) { for (x = pstate->w; x < pstate->e; x++) { - if ((!hmap(x, y)) && i && ( - hmap(x+1, y) && hmap(x-1, y) && - hmap(x, y+1) && hmap(x, y-1) )) { - hmap(x, y) = 1; + if (hmap(x, y) == 0 && i > 0 + && (hmap(x + 1, y) != 0 && hmap(x - 1, y) != 0 + && hmap(x, y + 1) != 0 && hmap(x, y - 1) != 0)) { + hmap(x, y) = 1; i--; } } @@ -1687,10 +1687,10 @@ } tries = map_num_tiles() / 4; /* on a 40x60 map, there are 2400 places */ - while (!(i = place_island(pstate)) && --tries) { + while (!(j = place_island(pstate)) && (--tries) > 0) { /* nothing */ } - return i; + return j; } /*************************************************************************/ @@ -1709,7 +1709,7 @@ int i; - if (!islemass) { + if (islemass == 0) { balance = 0; pstate->isleindex = 3; /* 0= none, 1= arctic, 2= antarctic */ @@ -1822,16 +1822,16 @@ map_set_continent(x, y, 0); } for (x = 0 ; x < map.xsize; x++) { - map_set_terrain(x, 0, myrand(9) ? T_ARCTIC : T_TUNDRA); + map_set_terrain(x, 0, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA); map_set_continent(x, 0, 1); - if (!myrand(9)) { - map_set_terrain(x, 1, myrand(9) ? T_TUNDRA : T_ARCTIC); + if (myrand(9) == 0) { + map_set_terrain(x, 1, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC); map_set_continent(x, 1, 1); } - map_set_terrain(x, map.ysize-1, myrand(9) ? T_ARCTIC : T_TUNDRA); + map_set_terrain(x, map.ysize-1, myrand(9) > 0 ? T_ARCTIC : T_TUNDRA); map_set_continent(x, map.ysize-1, 2); - if (!myrand(9)) { - map_set_terrain(x, map.ysize-2, myrand(9) ? T_TUNDRA : T_ARCTIC); + if (myrand(9) == 0) { + map_set_terrain(x, map.ysize-2, myrand(9) > 0 ? T_TUNDRA : T_ARCTIC); map_set_continent(x, map.ysize-2, 2); } } @@ -1866,22 +1866,22 @@ /*!PS: The weights NEED to sum up to totalweight (dammit) */ /* copying the flow of the make_island loops is the safest way */ totalweight= 0; - for (i = game.nplayers ; i ; i--) + for (i = game.nplayers; i > 0; i--) totalweight+= 70; - for (i = game.nplayers ; i ; i--) + for (i = game.nplayers; i > 0; i--) totalweight+= 20; - for (i = game.nplayers ; i ; i--) + for (i = game.nplayers; i > 0; i--) totalweight+= 10; initworld(pstate); - for (i = game.nplayers; i; i--) { + for (i = game.nplayers; i > 0; i--) { make_island(70 * pstate->totalmass / totalweight, 1, pstate); } - for (i = game.nplayers; i; i--) { + for (i = game.nplayers; i > 0; i--) { make_island(20 * pstate->totalmass / totalweight, 0, pstate); } - for (i = game.nplayers; i; i--) { + for (i = game.nplayers; i > 0; i--) { make_island(10 * pstate->totalmass / totalweight, 0, pstate); } make_plains(); @@ -2015,32 +2015,32 @@ /*!PS: The weights NEED to sum up to totalweight (dammit) */ totalweight= 0; - if (game.nplayers % 2) + if ((game.nplayers % 2) == 1) totalweight+= bigweight*3; else i++; - while (--i) + while ((--i) > 0) totalweight+= bigweight*2; - for (i = game.nplayers ; i ; i--) + for (i = game.nplayers; i > 0; i--) totalweight+= 20; - for (i = game.nplayers ; i ; i--) + for (i = game.nplayers; i > 0; i--) totalweight+= 10; initworld(pstate); i = game.nplayers / 2; - if (game.nplayers % 2) { + if ((game.nplayers % 2) == 1) { make_island(bigweight * 3, 3, pstate); } else { i++; } - while (--i) { + while ((--i) > 0) { make_island(bigweight * 2 * pstate->totalmass / totalweight, 2, pstate);} - for (i = game.nplayers; i; i--) { + for (i = game.nplayers; i > 0; i--) { make_island(20 * pstate->totalmass / totalweight, 0, pstate); } - for (i = game.nplayers; i; i--) { + for (i = game.nplayers; i > 0; i--) { make_island(10 * pstate->totalmass / totalweight, 0, pstate); } make_plains();