(svn r21500) -Feature [FS#730]: diagonal tile clearing and terraforming. Based on patch by fonsinchen

This commit is contained in:
rubidium 2010-12-13 15:15:02 +00:00
parent b20e77be92
commit 6892cc8a60
4 changed files with 24 additions and 12 deletions

View File

@ -642,7 +642,8 @@ CommandCost CmdLandscapeClear(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
* @param tile end tile of area dragging * @param tile end tile of area dragging
* @param flags of operation to conduct * @param flags of operation to conduct
* @param p1 start tile of area dragging * @param p1 start tile of area dragging
* @param p2 unused * @param p2 various bitstuffed data.
* bit 0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
* @param text unused * @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
*/ */
@ -656,7 +657,9 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
bool had_success = false; bool had_success = false;
TileArea ta(tile, p1); TileArea ta(tile, p1);
TILE_AREA_LOOP(t, ta) { TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(ta);
for (; *iter != INVALID_TILE; ++(*iter)) {
TileIndex t = *iter;
CommandCost ret = DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); CommandCost ret = DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) { if (ret.Failed()) {
last_error = ret; last_error = ret;
@ -668,6 +671,7 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
money -= ret.GetCost(); money -= ret.GetCost();
if (ret.GetCost() > 0 && money < 0) { if (ret.GetCost() > 0 && money < 0) {
_additional_cash_required = ret.GetCost(); _additional_cash_required = ret.GetCost();
delete iter;
return cost; return cost;
} }
DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR); DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@ -684,6 +688,7 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
cost.AddCost(ret); cost.AddCost(ret);
} }
delete iter;
return had_success ? cost : last_error; return had_success ? cost : last_error;
} }

View File

@ -236,7 +236,7 @@ STR_TOOLTIP_RESIZE :{BLACK}Click an
STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW :{BLACK}Toggle large/small window size STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW :{BLACK}Toggle large/small window size
STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST :{BLACK}Scroll bar - scrolls list up/down STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST :{BLACK}Scroll bar - scrolls list up/down
STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST :{BLACK}Scroll bar - scrolls list left/right STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST :{BLACK}Scroll bar - scrolls list left/right
STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC :{BLACK}Demolish buildings etc. on a square of land STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC :{BLACK}Demolish buildings etc. on a square of land. Ctrl selects the area diagonally
# Query window # Query window
STR_BUTTON_DEFAULT :{BLACK}Default STR_BUTTON_DEFAULT :{BLACK}Default
@ -2069,9 +2069,9 @@ STR_STATION_BUILD_NOISE :{BLACK}Noise ge
# Landscaping toolbar # Landscaping toolbar
STR_LANDSCAPING_TOOLBAR :{WHITE}Landscaping STR_LANDSCAPING_TOOLBAR :{WHITE}Landscaping
STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND :{BLACK}Lower a corner of land STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND :{BLACK}Lower a corner of land. Dragging lowers the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally
STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND :{BLACK}Raise a corner of land STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND :{BLACK}Raise a corner of land. Dragging raises the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally
STR_LANDSCAPING_LEVEL_LAND_TOOLTIP :{BLACK}Level land STR_LANDSCAPING_LEVEL_LAND_TOOLTIP :{BLACK}Level an area of land to the height of the first selected corner. Ctrl selects the area diagonally
STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND :{BLACK}Purchase land for future use STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND :{BLACK}Purchase land for future use
# Object construction window # Object construction window

View File

@ -379,6 +379,7 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
* @param flags for this command type * @param flags for this command type
* @param p1 start tile of area drag * @param p1 start tile of area drag
* @param p2 various bitstuffed data. * @param p2 various bitstuffed data.
* bit 0: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
* bits 1 - 2: Mode of leveling \c LevelMode. * bits 1 - 2: Mode of leveling \c LevelMode.
* @param text unused * @param text unused
* @return the cost of this operation or an error * @return the cost of this operation or an error
@ -411,7 +412,9 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
bool had_success = false; bool had_success = false;
TileArea ta(tile, p1); TileArea ta(tile, p1);
TILE_AREA_LOOP(t, ta) { TileIterator *iter = HasBit(p2, 0) ? (TileIterator *)new DiagonalTileIterator(tile, p1) : new OrthogonalTileIterator(ta);
for (; *iter != INVALID_TILE; ++(*iter)) {
TileIndex t = *iter;
uint curh = TileHeight(t); uint curh = TileHeight(t);
while (curh != h) { while (curh != h) {
CommandCost ret = DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND); CommandCost ret = DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
@ -424,6 +427,7 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
money -= ret.GetCost(); money -= ret.GetCost();
if (money < 0) { if (money < 0) {
_additional_cash_required = ret.GetCost(); _additional_cash_required = ret.GetCost();
delete iter;
return cost; return cost;
} }
DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); DoCommand(t, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
@ -435,5 +439,6 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
} }
} }
delete iter;
return had_success ? cost : last_error; return had_success ? cost : last_error;
} }

View File

@ -107,16 +107,16 @@ bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_t
switch (proc) { switch (proc) {
case DDSP_DEMOLISH_AREA: case DDSP_DEMOLISH_AREA:
DoCommandP(end_tile, start_tile, 0, CMD_CLEAR_AREA | CMD_MSG(STR_ERROR_CAN_T_CLEAR_THIS_AREA), CcPlaySound10); DoCommandP(end_tile, start_tile, _ctrl_pressed, CMD_CLEAR_AREA | CMD_MSG(STR_ERROR_CAN_T_CLEAR_THIS_AREA), CcPlaySound10);
break; break;
case DDSP_RAISE_AND_LEVEL_AREA: case DDSP_RAISE_AND_LEVEL_AREA:
DoCommandP(end_tile, start_tile, LM_RAISE << 1, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_RAISE_LAND_HERE), CcTerraform); DoCommandP(end_tile, start_tile, LM_RAISE << 1 | _ctrl_pressed, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_RAISE_LAND_HERE), CcTerraform);
break; break;
case DDSP_LOWER_AND_LEVEL_AREA: case DDSP_LOWER_AND_LEVEL_AREA:
DoCommandP(end_tile, start_tile, LM_LOWER << 1, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LOWER_LAND_HERE), CcTerraform); DoCommandP(end_tile, start_tile, LM_LOWER << 1 | _ctrl_pressed, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LOWER_LAND_HERE), CcTerraform);
break; break;
case DDSP_LEVEL_AREA: case DDSP_LEVEL_AREA:
DoCommandP(end_tile, start_tile, LM_LEVEL << 1, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LEVEL_LAND_HERE), CcTerraform); DoCommandP(end_tile, start_tile, LM_LEVEL << 1 | _ctrl_pressed, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LEVEL_LAND_HERE), CcTerraform);
break; break;
case DDSP_CREATE_ROCKS: case DDSP_CREATE_ROCKS:
GenerateRockyArea(end_tile, start_tile); GenerateRockyArea(end_tile, start_tile);
@ -622,7 +622,9 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
*/ */
bool IsDraggingDiagonal() bool IsDraggingDiagonal()
{ {
return false; return _ctrl_pressed && _left_button_down && (
_place_proc == PlaceProc_DemolishArea || _place_proc == PlaceProc_LevelLand ||
_place_proc == PlaceProc_RaiseLand || _place_proc == PlaceProc_LowerLand);
} }
struct ScenarioEditorLandscapeGenerationWindow : Window { struct ScenarioEditorLandscapeGenerationWindow : Window {