unmovable_cmd.c
changeset 4300 c7e43c47a2b9
parent 4231 2823b3643862
child 4559 aa0c13e39840
equal deleted inserted replaced
4299:91f5d2bedcff 4300:c7e43c47a2b9
    16 #include "town.h"
    16 #include "town.h"
    17 #include "sprite.h"
    17 #include "sprite.h"
    18 #include "unmovable_map.h"
    18 #include "unmovable_map.h"
    19 #include "variables.h"
    19 #include "variables.h"
    20 #include "table/unmovable_land.h"
    20 #include "table/unmovable_land.h"
       
    21 #include "genworld.h"
    21 
    22 
    22 /** Destroy a HQ.
    23 /** Destroy a HQ.
    23  * During normal gameplay you can only implicitely destroy a HQ when you are
    24  * During normal gameplay you can only implicitely destroy a HQ when you are
    24  * rebuilding it. Otherwise, only water can destroy it.
    25  * rebuilding it. Otherwise, only water can destroy it.
    25  * @param tile tile coordinates where HQ is located to destroy
    26  * @param tile tile coordinates where HQ is located to destroy
   307 	TileIndex tile_s = tile - TileDiffXY(4, 4);
   308 	TileIndex tile_s = tile - TileDiffXY(4, 4);
   308 
   309 
   309 	BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
   310 	BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
   310 		if (IsTransmitterTile(tile)) return true;
   311 		if (IsTransmitterTile(tile)) return true;
   311 	END_TILE_LOOP(tile, 9, 9, tile_s)
   312 	END_TILE_LOOP(tile, 9, 9, tile_s)
       
   313 
   312 	return false;
   314 	return false;
   313 }
   315 }
   314 
   316 
   315 void GenerateUnmovables(void)
   317 void GenerateUnmovables(void)
   316 {
   318 {
   317 	int i,j;
   319 	int i, li, j, loop_count;
   318 	TileIndex tile;
   320 	TileIndex tile;
   319 	uint h;
   321 	uint h;
   320 	uint maxx;
   322 	uint maxx;
   321 	uint maxy;
   323 	uint maxy;
   322 
   324 
   323 	if (_opt.landscape == LT_CANDY) return;
   325 	if (_opt.landscape == LT_CANDY) return;
   324 
   326 
   325 	/* add radio tower */
   327 	/* add radio tower */
   326 	i = ScaleByMapSize(1000);
   328 	i = ScaleByMapSize(1000);
   327 	j = ScaleByMapSize(40); // maximum number of radio towers on the map
   329 	j = ScaleByMapSize(15); // maximum number of radio towers on the map
       
   330 	li = ScaleByMapSize1D((Random() & 3) + 7);
       
   331 	SetGeneratingWorldProgress(GWP_UNMOVABLE, j + li);
       
   332 
   328 	do {
   333 	do {
   329 		tile = RandomTile();
   334 		tile = RandomTile();
   330 		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h >= TILE_HEIGHT * 4) {
   335 		if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h >= TILE_HEIGHT * 4) {
   331 			if (IsRadioTowerNearby(tile)) continue;
   336 			if (IsRadioTowerNearby(tile)) continue;
   332 			MakeTransmitter(tile);
   337 			MakeTransmitter(tile);
       
   338 			IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
   333 			if (--j == 0) break;
   339 			if (--j == 0) break;
   334 		}
   340 		}
   335 	} while (--i);
   341 	} while (--i);
   336 
   342 
   337 	if (_opt.landscape == LT_DESERT) return;
   343 	if (_opt.landscape == LT_DESERT) return;
   338 
   344 
   339 	/* add lighthouses */
   345 	/* add lighthouses */
   340 	i = ScaleByMapSize1D((Random() & 3) + 7);
   346 	i = li;
   341 	maxx = MapMaxX();
   347 	maxx = MapMaxX();
   342 	maxy = MapMaxY();
   348 	maxy = MapMaxY();
       
   349 	loop_count = 0;
   343 	do {
   350 	do {
   344 		uint32 r;
   351 		uint32 r;
   345 		DiagDirection dir;
   352 		DiagDirection dir;
       
   353 		int perimeter;
   346 
   354 
   347 restart:
   355 restart:
       
   356 		/* Avoid infinite loops */
       
   357 		if (++loop_count > 1000) break;
       
   358 
   348 		r = Random();
   359 		r = Random();
   349 		dir = GB(r, 30, 2);
   360 
       
   361 		/* Scatter the lighthouses more evenly around the perimeter */
       
   362 		perimeter = (GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
       
   363 		for (dir = DIAGDIR_NE; perimeter > 0; dir++) {
       
   364 			perimeter -= (DiagDirToAxis(dir) == AXIS_X) ? maxx : maxy;
       
   365 		}
       
   366 
   350 		switch (dir) {
   367 		switch (dir) {
   351 			default:
   368 			default:
   352 			case DIAGDIR_NE: tile = TileXY(maxx,     r % maxy); break;
   369 			case DIAGDIR_NE: tile = TileXY(maxx,     r % maxy); break;
   353 			case DIAGDIR_SE: tile = TileXY(r % maxx, 0);        break;
   370 			case DIAGDIR_SE: tile = TileXY(r % maxx, 0);        break;
   354 			case DIAGDIR_SW: tile = TileXY(0,        r % maxy); break;
   371 			case DIAGDIR_SW: tile = TileXY(0,        r % maxy); break;
   361 		} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h <= TILE_HEIGHT * 2));
   378 		} while (!(IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h <= TILE_HEIGHT * 2));
   362 
   379 
   363 		assert(tile == TILE_MASK(tile));
   380 		assert(tile == TILE_MASK(tile));
   364 
   381 
   365 		MakeLighthouse(tile);
   382 		MakeLighthouse(tile);
       
   383 		IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
   366 	} while (--i);
   384 	} while (--i);
   367 }
   385 }
   368 
   386 
   369 static void ChangeTileOwner_Unmovable(TileIndex tile, PlayerID old_player, PlayerID new_player)
   387 static void ChangeTileOwner_Unmovable(TileIndex tile, PlayerID old_player, PlayerID new_player)
   370 {
   388 {