ai/default/default.c
changeset 3644 7c9a6a91873b
parent 3609 eaf20d1e9aec
child 3792 67c865c9315c
equal deleted inserted replaced
3643:c04228043cb0 3644:7c9a6a91873b
  1601 				if (CmdFailed(ret)) return CMD_ERROR;
  1601 				if (CmdFailed(ret)) return CMD_ERROR;
  1602 				total_cost += ret;
  1602 				total_cost += ret;
  1603 			}
  1603 			}
  1604 		} else if (p->mode == 3) {
  1604 		} else if (p->mode == 3) {
  1605 			//Clear stuff and then build single rail.
  1605 			//Clear stuff and then build single rail.
  1606 			if (GetTileSlope(c,NULL) != 0)
  1606 			if (GetTileSlope(c, NULL) != SLOPE_FLAT)
  1607 				return CMD_ERROR;
  1607 				return CMD_ERROR;
  1608 			ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
  1608 			ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
  1609 			if (CmdFailed(ret)) return CMD_ERROR;
  1609 			if (CmdFailed(ret)) return CMD_ERROR;
  1610 			total_cost += ret + _price.build_rail;
  1610 			total_cost += ret + _price.build_rail;
  1611 
  1611 
  1673 
  1673 
  1674 static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
  1674 static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode)
  1675 {
  1675 {
  1676 	PlayerID old_player;
  1676 	PlayerID old_player;
  1677 	uint32 r;
  1677 	uint32 r;
  1678 	uint slope;
  1678 	Slope slope;
  1679 	uint h;
  1679 	uint h;
  1680 
  1680 
  1681 	old_player = _current_player;
  1681 	old_player = _current_player;
  1682 	_current_player = OWNER_NONE;
  1682 	_current_player = OWNER_NONE;
  1683 
  1683 
  1696 		dir &= 3;
  1696 		dir &= 3;
  1697 	} while (--unk >= 0);
  1697 	} while (--unk >= 0);
  1698 
  1698 
  1699 	slope = GetTileSlope(tile, &h);
  1699 	slope = GetTileSlope(tile, &h);
  1700 
  1700 
  1701 	if (slope != 0) {
  1701 	if (slope != SLOPE_FLAT) {
  1702 		if (mode > 0 || (mode == 0 && !(r & 0xC))) {
  1702 		if (mode > 0 || (mode == 0 && !(r & 0xC))) {
  1703 			// Terraform up
  1703 			// Terraform up
  1704 			DoCommand(tile, _terraform_up_flags[slope - 1], 1,
  1704 			DoCommand(tile, _terraform_up_flags[slope - 1], 1,
  1705 				DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
  1705 				DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
  1706 		} else if (h != 0) {
  1706 		} else if (h != 0) {
  1918 }
  1918 }
  1919 
  1919 
  1920 static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile, const byte *p)
  1920 static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile, const byte *p)
  1921 {
  1921 {
  1922 	TileIndex tile_new;
  1922 	TileIndex tile_new;
  1923 	uint tileh;
  1923 	Slope tileh;
  1924 	uint z;
  1924 	uint z;
  1925 	bool flag;
  1925 	bool flag;
  1926 
  1926 
  1927 	int dir2 = p[0] & 3;
  1927 	int dir2 = p[0] & 3;
  1928 
  1928 
  1929 	tileh = GetTileSlope(tile, &z);
  1929 	tileh = GetTileSlope(tile, &z);
  1930 	if (tileh == _dir_table_1[dir2] || (tileh == 0 && z != 0)) {
  1930 	if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) {
  1931 		tile_new = tile;
  1931 		tile_new = tile;
  1932 		// Allow bridges directly over bottom tiles
  1932 		// Allow bridges directly over bottom tiles
  1933 		flag = z == 0;
  1933 		flag = z == 0;
  1934 		for (;;) {
  1934 		for (;;) {
  1935 			TileType type;
  1935 			TileType type;
  1936 
  1936 
  1937 			if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
  1937 			if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
  1938 			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
  1938 			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
  1939 			type = GetTileType(tile_new);
  1939 			type = GetTileType(tile_new);
  1940 
  1940 
  1941 			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != 0) {
  1941 			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) {
  1942 				if (!flag) return;
  1942 				if (!flag) return;
  1943 				break;
  1943 				break;
  1944 			}
  1944 			}
  1945 			if (type != MP_WATER && type != MP_RAILWAY && type != MP_STREET) return;
  1945 			if (type != MP_WATER && type != MP_RAILWAY && type != MP_STREET) return;
  1946 			flag = true;
  1946 			flag = true;
  2584 				rating += _cleared_town_rating;
  2584 				rating += _cleared_town_rating;
  2585 			}
  2585 			}
  2586 		} else if (p->mode == 3) {
  2586 		} else if (p->mode == 3) {
  2587 			if (flag & DC_EXEC) continue;
  2587 			if (flag & DC_EXEC) continue;
  2588 
  2588 
  2589 			if (GetTileSlope(c, NULL) != 0) return CMD_ERROR;
  2589 			if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR;
  2590 
  2590 
  2591 			if (!IsTileType(c, MP_STREET) || GetRoadType(c) != ROAD_NORMAL) {
  2591 			if (!IsTileType(c, MP_STREET) || GetRoadType(c) != ROAD_NORMAL) {
  2592 				ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
  2592 				ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
  2593 				if (CmdFailed(ret)) return CMD_ERROR;
  2593 				if (CmdFailed(ret)) return CMD_ERROR;
  2594 			}
  2594 			}
  2826 }
  2826 }
  2827 
  2827 
  2828 static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
  2828 static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
  2829 {
  2829 {
  2830 	TileIndex tile_new;
  2830 	TileIndex tile_new;
  2831 	uint tileh;
  2831 	Slope tileh;
  2832 	uint z;
  2832 	uint z;
  2833 	bool flag;
  2833 	bool flag;
  2834 
  2834 
  2835 	int dir2 = p[0] & 3;
  2835 	int dir2 = p[0] & 3;
  2836 
  2836 
  2837 	tileh = GetTileSlope(tile, &z);
  2837 	tileh = GetTileSlope(tile, &z);
  2838 	if (tileh == _dir_table_1[dir2] || (tileh == 0 && z != 0)) {
  2838 	if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) {
  2839 		tile_new = tile;
  2839 		tile_new = tile;
  2840 		// Allow bridges directly over bottom tiles
  2840 		// Allow bridges directly over bottom tiles
  2841 		flag = z == 0;
  2841 		flag = z == 0;
  2842 		for (;;) {
  2842 		for (;;) {
  2843 			TileType type;
  2843 			TileType type;
  2844 
  2844 
  2845 			if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
  2845 			if ((TileIndexDiff)tile_new < -TileOffsByDir(dir2)) return; // Wraping around map, no bridge possible!
  2846 			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
  2846 			tile_new = TILE_MASK(tile_new + TileOffsByDir(dir2));
  2847 			type = GetTileType(tile_new);
  2847 			type = GetTileType(tile_new);
  2848 
  2848 
  2849 			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile, NULL) != 0) {
  2849 			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile, NULL) != SLOPE_FLAT) {
  2850 				// Allow a bridge if either we have a tile that's water, rail or street,
  2850 				// Allow a bridge if either we have a tile that's water, rail or street,
  2851 				// or if we found an up tile.
  2851 				// or if we found an up tile.
  2852 				if (!flag) return;
  2852 				if (!flag) return;
  2853 				break;
  2853 				break;
  2854 			}
  2854 			}