Changeset - r8816:b6e9b77d418c
[Not reviewed]
master
0 2 0
smatz - 16 years ago 2008-04-04 15:48:15
smatz@openttd.org
(svn r12562) -Cleanup: variable scope in terraform_cmd.cpp
2 files changed with 33 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/terraform_cmd.cpp
Show inline comments
 
@@ -35,8 +35,8 @@ struct TerraformerHeightMod {
 
};
 

	
 
struct TerraformerState {
 
	int modheight_count;                                         ///< amount of entries in "modheight".
 
	int tile_table_count;                                        ///< amount of entries in "tile_table".
 
	int modheight_count;  ///< amount of entries in "modheight".
 
	int tile_table_count; ///< amount of entries in "tile_table".
 

	
 
	/**
 
	 * Dirty tiles, i.e.\ at least one corner changed.
 
@@ -49,7 +49,7 @@ struct TerraformerState {
 
	TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE];  ///< Height modifications.
 
};
 

	
 
TileIndex _terraform_err_tile;
 
TileIndex _terraform_err_tile; ///< first tile we couldn't terraform
 

	
 
/**
 
 * Gets the TileHeight (height of north corner) of a tile as of current terraforming progress.
 
@@ -58,12 +58,11 @@ TileIndex _terraform_err_tile;
 
 * @param tile Tile.
 
 * @return TileHeight.
 
 */
 
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile)
 
static int TerraformGetHeightOfTile(const TerraformerState *ts, TileIndex tile)
 
{
 
	TerraformerHeightMod *mod = ts->modheight;
 
	int count;
 
	const TerraformerHeightMod *mod = ts->modheight;
 

	
 
	for (count = ts->modheight_count; count != 0; count--, mod++) {
 
	for (int count = ts->modheight_count; count != 0; count--, mod++) {
 
		if (mod->tile == tile) return mod->height;
 
	}
 

	
 
@@ -85,6 +84,7 @@ static void TerraformSetHeightOfTile(Ter
 
	 *       But during house- or industry-construction multiple corners can be terraformed at once. */
 
	TerraformerHeightMod *mod = ts->modheight;
 
	int count = ts->modheight_count;
 

	
 
	while ((count > 0) && (mod->tile != tile)) {
 
		mod++;
 
		count--;
 
@@ -110,12 +110,9 @@ static void TerraformSetHeightOfTile(Ter
 
 */
 
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
 
{
 
	int count;
 
	TileIndex *t;
 
	int count = ts->tile_table_count;
 

	
 
	count = ts->tile_table_count;
 

	
 
	for (t = ts->tile_table; count != 0; count--, t++) {
 
	for (TileIndex *t = ts->tile_table; count != 0; count--, t++) {
 
		if (*t == tile) return;
 
	}
 

	
 
@@ -149,8 +146,6 @@ static void TerraformAddDirtyTileAround(
 
 */
 
static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
 
{
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 

	
 
	assert(tile < MapSize());
 

	
 
	/* Check range of destination height */
 
@@ -184,6 +179,8 @@ static CommandCost TerraformTileHeight(T
 
	/* Store the height modification */
 
	TerraformSetHeightOfTile(ts, tile, height);
 

	
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 

	
 
	/* Increment cost */
 
	total_cost.AddCost(_price.terraform);
 

	
 
@@ -228,17 +225,17 @@ static CommandCost TerraformTileHeight(T
 
 */
 
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	TerraformerState ts;
 
	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
 
	if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
 

	
 
	_terraform_err_tile = INVALID_TILE;
 

	
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 
	int direction = (p2 != 0 ? 1 : -1);
 

	
 
	_terraform_err_tile = 0;
 
	TerraformerState ts;
 

	
 
	ts.modheight_count = ts.tile_table_count = 0;
 

	
 
	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
 
	if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
 

	
 
	/* Compute the costs and the terraforming result in a model of the landscape */
 
	if ((p1 & SLOPE_W) != 0) {
 
		TileIndex t = tile + TileDiffXY(1, 0);
 
@@ -270,10 +267,9 @@ CommandCost CmdTerraformLand(TileIndex t
 

	
 
	/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface */
 
	{
 
		int count;
 
		TileIndex *ti = ts.tile_table;
 

	
 
		for (count = ts.tile_table_count; count != 0; count--, ti++) {
 
		for (int count = ts.tile_table_count; count != 0; count--, ti++) {
 
			TileIndex tile = *ti;
 

	
 
			/* Find new heights of tile corners */
 
@@ -350,49 +346,41 @@ CommandCost CmdTerraformLand(TileIndex t
 
 */
 
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	int size_x, size_y;
 
	int ex;
 
	int ey;
 
	int sx, sy;
 
	uint h, oldh, curh;
 
	CommandCost money;
 
	CommandCost ret;
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	if (p1 >= MapSize()) return CMD_ERROR;
 

	
 
	/* remember level height */
 
	oldh = TileHeight(p1);
 
	uint oldh = TileHeight(p1);
 

	
 
	/* compute new height */
 
	h = oldh + p2;
 
	uint h = oldh + p2;
 

	
 
	/* Check range of destination height */
 
	if (h > MAX_TILE_HEIGHT) return_cmd_error((oldh == 0) ? STR_1003_ALREADY_AT_SEA_LEVEL : STR_1004_TOO_HIGH);
 

	
 
	/* make sure sx,sy are smaller than ex,ey */
 
	ex = TileX(tile);
 
	ey = TileY(tile);
 
	sx = TileX(p1);
 
	sy = TileY(p1);
 
	int ex = TileX(tile);
 
	int ey = TileY(tile);
 
	int sx = TileX(p1);
 
	int sy = TileY(p1);
 
	if (ex < sx) Swap(ex, sx);
 
	if (ey < sy) Swap(ey, sy);
 
	tile = TileXY(sx, sy);
 

	
 
	size_x = ex - sx + 1;
 
	size_y = ey - sy + 1;
 
	int size_x = ex - sx + 1;
 
	int size_y = ey - sy + 1;
 

	
 
	money.AddCost(GetAvailableMoneyForCommand());
 
	Money money = GetAvailableMoneyForCommand();
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
 
		curh = TileHeight(tile2);
 
		uint curh = TileHeight(tile2);
 
		while (curh != h) {
 
			ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
 
			CommandCost ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
 
			if (CmdFailed(ret)) break;
 

	
 
			if (flags & DC_EXEC) {
 
				money.AddCost(-ret.GetCost());
 
				if (money.GetCost() < 0) {
 
				money -= ret.GetCost();
 
				if (money < 0) {
 
					_additional_cash_required = ret.GetCost();
 
					return cost;
 
				}
src/town_cmd.cpp
Show inline comments
 
@@ -2255,7 +2255,7 @@ static void UpdateTownGrowRate(Town *t)
 

	
 
	int n = 0;
 

	
 
	Station *st;
 
	const Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) {
 
			if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
0 comments (0 inline, 0 general)