22 #include "table/strings.h" 
  119   uint x = 
TileX(tile);
 
  120   uint y = 
TileY(tile);
 
  140   total_cost.
AddCost(_price[PR_TERRAFORM]);
 
  154     for (ttm = _terraform_tilepos; ttm != 
endof(_terraform_tilepos); ttm++) {
 
  157       if (tile >= 
MapSize()) 
continue;
 
  164       int height_diff = height - r;
 
  167       if (
abs(height_diff) > 1) {
 
  169         height_diff += (height_diff < 0 ? 1 : -1);
 
  171         if (cost.
Failed()) 
return cost;
 
  194   int direction = (p2 != 0 ? 1 : -1);
 
  201     if (cost.
Failed()) 
return cost;
 
  208     if (cost.
Failed()) 
return cost;
 
  215     if (cost.
Failed()) 
return cost;
 
  222     if (cost.
Failed()) 
return cost;
 
  229   for (
int pass = 0; pass < 2; pass++) {
 
  245       int z_min = 
min(
min(z_N, z_W), 
min(z_S, z_E));
 
  246       int z_max = 
max(
max(z_N, z_W), 
max(z_S, z_E));
 
  250       if (z_W > z_min) tileh |= 
SLOPE_W;
 
  251       if (z_S > z_min) tileh |= 
SLOPE_S;
 
  252       if (z_E > z_min) tileh |= 
SLOPE_E;
 
  253       if (z_N > z_min) tileh |= 
SLOPE_N;
 
  261           if (direction == 1 && bridge_height <= z_max) {
 
  281       bool indirectly_cleared = coa != NULL && coa->
first_tile != tile;
 
  292       if (indirectly_cleared) {
 
  302       if (pass == 1) total_cost.
AddCost(cost);
 
  316       int height = it->second;
 
  345           for (
int cx = 0; cx >= -height - 1; cx--) {
 
  346             for (
int cy = 0; cy >= -height - 1; cy--) {
 
  350               if (cx + cy >= -height - 2) {
 
  356         } 
else if (y < (
int)
MapMaxY()) {
 
  357           for (
int cx = 0; cx >= -height - 1; cx--) {
 
  361           for (
int cx = 0; cx >= -height - 1; cx--) {
 
  362             for (
int cy = (
int)
MapMaxY(); cy <= (int)
MapMaxY() + height + 1; cy++) {
 
  363               if (cx + ((
int)
MapMaxY() - cy) >= -height - 2) {
 
  369       } 
else if (x < (
int)
MapMaxX()) {
 
  371           for (
int cy = 0; cy >= -height - 1; cy--) {
 
  374         } 
else if (y < (
int)
MapMaxY()) {
 
  377           for (
int cy = (
int)
MapMaxY(); cy <= (int)
MapMaxY() + height + 1; cy++) {
 
  383           for (
int cx = (
int)
MapMaxX(); cx <= (int)
MapMaxX() + height + 1; cx++) {
 
  384             for (
int cy = 0; cy >= -height - 1; cy--) {
 
  385               if (((
int)
MapMaxX() - cx) + cy >= -height - 2) {
 
  390         } 
else if (y < (
int)
MapMaxY()) {
 
  391           for (
int cx = (
int)
MapMaxX(); cx <= (int)
MapMaxX() + height + 1; cx++) {
 
  395           for (
int cx = (
int)
MapMaxX(); cx <= (int)
MapMaxX() + height + 1; cx++) {
 
  396             for (
int cy = (
int)
MapMaxY(); cy <= (int)
MapMaxY() + height + 1; cy++) {
 
  397               if (((
int)
MapMaxX() - cx) + ((
int)
MapMaxY() - cy) >= -height - 2) {
 
  448   bool had_success = 
false;
 
  464         if (ret.
GetErrorMessage() == STR_ERROR_TERRAFORM_LIMIT_REACHED) limit = 0;
 
  471           _additional_cash_required = ret.
GetCost();
 
  489       curh += (curh > h) ? -1 : 1;
 
  493     if (limit <= 0) 
break;
 
  497   return had_success ? cost : last_error;