clear_cmd.c
changeset 1796 614d996f6be7
parent 1782 48749e4c2dc6
child 1878 980fabc7d8a5
equal deleted inserted replaced
1795:06f7b463ee52 1796:614d996f6be7
   320 	}
   320 	}
   321 	return ts.cost;
   321 	return ts.cost;
   322 }
   322 }
   323 
   323 
   324 
   324 
   325 /*
   325 /** Levels a selected (rectangle) area of land
   326  * p1 - start
   326  * @param x,y end tile of area-drag
       
   327  * @param p1 start tile of area drag
       
   328  * @param p2 unused
   327  */
   329  */
   328 
       
   329 int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
   330 int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
   330 {
   331 {
   331 	int size_x, size_y;
   332 	int size_x, size_y;
   332 	int sx, sy;
   333 	int sx, sy;
   333 	uint h, curh;
   334 	uint h, curh;
   334 	uint tile;
   335 	TileIndex tile;
   335 	int32 ret, cost, money;
   336 	int32 ret, cost, money;
       
   337 
       
   338 	if (p1 > MapSize()) return CMD_ERROR;
   336 
   339 
   337 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   340 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   338 
   341 
   339 	// remember level height
   342 	// remember level height
   340 	h = TileHeight(p1);
   343 	h = TileHeight(p1);
   352 	size_y = ey-sy+1;
   355 	size_y = ey-sy+1;
   353 
   356 
   354 	money = GetAvailableMoneyForCommand();
   357 	money = GetAvailableMoneyForCommand();
   355 	cost = 0;
   358 	cost = 0;
   356 
   359 
   357 	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile)
   360 	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
   358 		curh = TileHeight(tile2);
   361 		curh = TileHeight(tile2);
   359 		while (curh != h) {
   362 		while (curh != h) {
   360 			ret = DoCommandByTile(tile2, 8, (curh > h)?0:1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
   363 			ret = DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
   361 			if (ret == CMD_ERROR) break;
   364 			if (CmdFailed(ret)) break;
   362 			cost += ret;
   365 			cost += ret;
   363 
   366 
   364 			if (flags & DC_EXEC) {
   367 			if (flags & DC_EXEC) {
   365 				if ((money -= ret) < 0) {
   368 				if ((money -= ret) < 0) {
   366 					_additional_cash_required = ret;
   369 					_additional_cash_required = ret;
   367 					return cost - ret;
   370 					return cost - ret;
   368 				}
   371 				}
   369 				DoCommandByTile(tile2, 8, (curh > h)?0:1, flags, CMD_TERRAFORM_LAND);
   372 				DoCommandByTile(tile2, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
   370 			}
   373 			}
   371 
   374 
   372 			curh += (curh > h) ? -1 : 1;
   375 			curh += (curh > h) ? -1 : 1;
   373 		}
   376 		}
   374 	END_TILE_LOOP(tile2, size_x, size_y, tile)
   377 	} END_TILE_LOOP(tile2, size_x, size_y, tile)
   375 
   378 
   376 	if (cost == 0) return CMD_ERROR;
   379 	return (cost == 0) ? CMD_ERROR : cost;
   377 	return cost;
       
   378 }
   380 }
   379 
   381 
   380 /** Purchase a land area. Actually you only purchase one tile, so
   382 /** Purchase a land area. Actually you only purchase one tile, so
   381  * the name is a bit confusing ;p
   383  * the name is a bit confusing ;p
   382  * @param x,y the tile the player is purchasing
   384  * @param x,y the tile the player is purchasing