station_cmd.c
changeset 3515 86dccaaef457
parent 3503 44f50afb0a75
child 3527 a4e4b90a54f7
equal deleted inserted replaced
3514:04afddbf8228 3515:86dccaaef457
    26 #include "airport.h"
    26 #include "airport.h"
    27 #include "sprite.h"
    27 #include "sprite.h"
    28 #include "depot.h"
    28 #include "depot.h"
    29 #include "train.h"
    29 #include "train.h"
    30 #include "water_map.h"
    30 #include "water_map.h"
       
    31 #include "industry_map.h"
    31 
    32 
    32 enum {
    33 enum {
    33 	/* Max stations: 64000 (64 * 1000) */
    34 	/* Max stations: 64000 (64 * 1000) */
    34 	STATION_POOL_BLOCK_SIZE_BITS = 6,       /* In bits, so (1 << 6) == 64 */
    35 	STATION_POOL_BLOCK_SIZE_BITS = 6,       /* In bits, so (1 << 6) == 64 */
    35 	STATION_POOL_MAX_BLOCKS      = 1000,
    36 	STATION_POOL_MAX_BLOCKS      = 1000,
   271 	_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
   272 	_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
   272 	return NULL;
   273 	return NULL;
   273 }
   274 }
   274 
   275 
   275 
   276 
   276 static int CountMapSquareAround(TileIndex tile, byte type, byte min, byte max)
   277 /**
   277 {
   278  * Counts the numbers of tiles matching a specific type in the area around
   278 	static const TileIndexDiffC _count_square_table[] = {
   279  * @param tile the center tile of the 'count area'
   279 		{-3, -3}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
   280  * @param type the type of tile searched for
   280 		{-6,  1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
   281  * @param industry when type == MP_INDUSTRY, the type of the industry,
   281 		{-6,  1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
   282  *                 in all other cases this parameter is ignored
   282 		{-6,  1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
   283  * @result the noumber of matching tiles around
   283 		{-6,  1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
   284  */
   284 		{-6,  1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
   285 static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry)
   285 		{-6,  1}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}
   286 {
   286 	};
   287 	TileIndex cur_tile;
   287 	const TileIndexDiffC *p;
   288 	int dx, dy;
   288 	int num = 0;
   289 	int num = 0;
   289 
   290 
   290 	for (p = _count_square_table; p != endof(_count_square_table); ++p) {
   291 	for (dx = -3; dx <= 3; dx++) {
   291 		tile = TILE_MASK(tile + ToTileIndexDiff(*p));
   292 		for (dy = -3; dy <= 3; dy++) {
   292 
   293 			cur_tile = tile + TileDiffXY(dx, dy);
   293 		if (IsTileType(tile, type) && _m[tile].m5 >= min && _m[tile].m5 <= max)
   294 
   294 			num++;
   295 			if (IsTileType(cur_tile, type)) {
       
   296 				switch (type) {
       
   297 					case MP_INDUSTRY:
       
   298 						if (GetIndustryType(cur_tile) == industry)
       
   299 							num++;
       
   300 						break;
       
   301 
       
   302 					case MP_WATER:
       
   303 						if (!IsWater(cur_tile))
       
   304 							break;
       
   305 						/* FALL THROUGH WHEN WATER TILE */
       
   306 					case MP_TREES:
       
   307 						num++;
       
   308 						break;
       
   309 
       
   310 					default:
       
   311 						break;
       
   312 				}
       
   313 			}
       
   314 		}
   295 	}
   315 	}
   296 
   316 
   297 	return num;
   317 	return num;
   298 }
   318 }
   299 
   319 
   338 		goto done;
   358 		goto done;
   339 	}
   359 	}
   340 
   360 
   341 	/* check mine? */
   361 	/* check mine? */
   342 	if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
   362 	if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
   343 		if (CountMapSquareAround(tile, MP_INDUSTRY, 0, 6) >= 2 ||
   363 		if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 ||
   344 				CountMapSquareAround(tile, MP_INDUSTRY, 0x64, 0x73) >= 2 ||
   364 				CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 ||
   345 				CountMapSquareAround(tile, MP_INDUSTRY, 0x2F, 0x33) >= 2 ||
   365 				CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 ||
   346 				CountMapSquareAround(tile, MP_INDUSTRY, 0x48, 0x58) >= 2 ||
   366 				CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 ||
   347 				CountMapSquareAround(tile, MP_INDUSTRY, 0x5B, 0x63) >= 2) {
   367 				CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) {
   348 			found = M(STR_SV_STNAME_MINES);
   368 			found = M(STR_SV_STNAME_MINES);
   349 			goto done;
   369 			goto done;
   350 		}
   370 		}
   351 	}
   371 	}
   352 
   372 
   360 	}
   380 	}
   361 
   381 
   362 	/* Check lakeside */
   382 	/* Check lakeside */
   363 	if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
   383 	if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
   364 			DistanceFromEdge(tile) < 20 &&
   384 			DistanceFromEdge(tile) < 20 &&
   365 			CountMapSquareAround(tile, MP_WATER, 0, 0) >= 5) {
   385 			CountMapSquareAround(tile, MP_WATER, 0) >= 5) {
   366 		found = M(STR_SV_STNAME_LAKESIDE);
   386 		found = M(STR_SV_STNAME_LAKESIDE);
   367 		goto done;
   387 		goto done;
   368 	}
   388 	}
   369 
   389 
   370 	/* Check woods */
   390 	/* Check woods */
   371 	if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
   391 	if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
   372 				CountMapSquareAround(tile, MP_TREES, 0, 255) >= 8 ||
   392 				CountMapSquareAround(tile, MP_TREES, 0) >= 8 ||
   373 				CountMapSquareAround(tile, MP_INDUSTRY, 0x10, 0x11) >= 2)
   393 				CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2)
   374 			) {
   394 			) {
   375 		found = _opt.landscape == LT_DESERT ?
   395 		found = _opt.landscape == LT_DESERT ?
   376 			M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
   396 			M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
   377 		goto done;
   397 		goto done;
   378 	}
   398 	}