(svn r12569) -Cleanup: variable scope and coding style in road*.cpp

This commit is contained in:
smatz 2008-04-04 18:41:16 +00:00
parent 15d5167a17
commit b78e8f82e1
3 changed files with 294 additions and 284 deletions

View File

@ -342,7 +342,7 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
* @param other The other existent RoadBits * @param other The other existent RoadBits
* @return The costs for these RoadBits on this slope * @return The costs for these RoadBits on this slope
*/ */
static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existing, RoadBits other) static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
{ {
/* Remove already build pieces */ /* Remove already build pieces */
CLRBITS(*pieces, existing); CLRBITS(*pieces, existing);
@ -418,7 +418,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits* pieces, RoadBits existi
CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{ {
CommandCost cost(EXPENSES_CONSTRUCTION); CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost ret;
RoadBits existing = ROAD_NONE; RoadBits existing = ROAD_NONE;
RoadBits other_bits = ROAD_NONE; RoadBits other_bits = ROAD_NONE;
@ -484,8 +484,6 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
break; break;
case MP_RAILWAY: { case MP_RAILWAY: {
Axis roaddir;
if (IsSteepSlope(tileh)) { if (IsSteepSlope(tileh)) {
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
} }
@ -496,6 +494,8 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
} }
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear; if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
Axis roaddir;
switch (GetTrackBits(tile)) { switch (GetTrackBits(tile)) {
case TRACK_BIT_X: case TRACK_BIT_X:
if (pieces & ROAD_X) goto do_clear; if (pieces & ROAD_X) goto do_clear;
@ -534,16 +534,17 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR; if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
break; break;
default: default: {
do_clear:; do_clear:;
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(ret)) return ret; if (CmdFailed(ret)) return ret;
cost.AddCost(ret); cost.AddCost(ret);
} break;
} }
if (other_bits != pieces) { if (other_bits != pieces) {
/* Check the foundation/slopes when adding road/tram bits */ /* Check the foundation/slopes when adding road/tram bits */
ret = CheckRoadSlope(tileh, &pieces, existing, other_bits); CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
/* Return an error if we need to build a foundation (ret != 0) but the /* Return an error if we need to build a foundation (ret != 0) but the
* current patch-setting is turned off (or stupid AI@work) */ * current patch-setting is turned off (or stupid AI@work) */
if (CmdFailed(ret) || (ret.GetCost() != 0 && !_patches.build_on_slopes)) { if (CmdFailed(ret) || (ret.GetCost() != 0 && !_patches.build_on_slopes)) {
@ -643,8 +644,7 @@ do_clear:;
*/ */
CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
{ {
TileIndex start_tile, tile; CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost ret, cost(EXPENSES_CONSTRUCTION);
bool had_bridge = false; bool had_bridge = false;
bool had_tunnel = false; bool had_tunnel = false;
bool had_success = false; bool had_success = false;
@ -654,7 +654,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32
if (p1 >= MapSize()) return CMD_ERROR; if (p1 >= MapSize()) return CMD_ERROR;
start_tile = p1; TileIndex start_tile = p1;
RoadType rt = (RoadType)GB(p2, 3, 2); RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
@ -678,7 +678,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32
/* No disallowed direction bits have to be toggled */ /* No disallowed direction bits have to be toggled */
if (!HasBit(p2, 5)) drd = DRD_NONE; if (!HasBit(p2, 5)) drd = DRD_NONE;
tile = start_tile; TileIndex tile = start_tile;
/* Start tile is the small number. */ /* Start tile is the small number. */
for (;;) { for (;;) {
RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X; RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
@ -686,7 +686,7 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32
if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE; if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW; if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD); CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
if (CmdFailed(ret)) { if (CmdFailed(ret)) {
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR; if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
} else { } else {
@ -729,13 +729,11 @@ CommandCost CmdBuildLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32
*/ */
CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2) CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p2)
{ {
TileIndex start_tile, tile; CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost ret, cost(EXPENSES_CONSTRUCTION);
Money money;
if (p1 >= MapSize()) return CMD_ERROR; if (p1 >= MapSize()) return CMD_ERROR;
start_tile = p1; TileIndex start_tile = p1;
RoadType rt = (RoadType)GB(p2, 3, 2); RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt)) return CMD_ERROR; if (!IsValidRoadType(rt)) return CMD_ERROR;
@ -751,8 +749,8 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint3
p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0; p2 ^= IsInsideMM(p2 & 3, 1, 3) ? 3 : 0;
} }
money = GetAvailableMoneyForCommand(); Money money = GetAvailableMoneyForCommand();
tile = start_tile; TileIndex tile = start_tile;
/* Start tile is the small number. */ /* Start tile is the small number. */
for (;;) { for (;;) {
RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X; RoadBits bits = HasBit(p2, 2) ? ROAD_Y : ROAD_X;
@ -762,7 +760,7 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint3
/* try to remove the halves. */ /* try to remove the halves. */
if (bits != 0) { if (bits != 0) {
ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true); CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
if (CmdSucceeded(ret)) { if (CmdSucceeded(ret)) {
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
money -= ret.GetCost(); money -= ret.GetCost();
@ -796,15 +794,12 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, uint32 flags, uint32 p1, uint3
*/ */
CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{ {
CommandCost cost;
Slope tileh;
DiagDirection dir = Extract<DiagDirection, 0>(p1); DiagDirection dir = Extract<DiagDirection, 0>(p1);
RoadType rt = (RoadType)GB(p1, 2, 2); RoadType rt = (RoadType)GB(p1, 2, 2);
if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
tileh = GetTileSlope(tile, NULL); Slope tileh = GetTileSlope(tile, NULL);
if (tileh != SLOPE_FLAT && ( if (tileh != SLOPE_FLAT && (
!_patches.build_on_slopes || !_patches.build_on_slopes ||
IsSteepSlope(tileh) || IsSteepSlope(tileh) ||
@ -813,7 +808,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED); return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
} }
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR; if (CmdFailed(cost)) return CMD_ERROR;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST); if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
@ -834,8 +829,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags) static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
{ {
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
@ -968,7 +962,7 @@ static bool AlwaysDrawUnpavedRoads(TileIndex tile, Roadside roadside)
* @param ti information about the tile (slopes, height etc) * @param ti information about the tile (slopes, height etc)
* @param tram the roadbits for the tram * @param tram the roadbits for the tram
*/ */
void DrawTramCatenary(TileInfo *ti, RoadBits tram) void DrawTramCatenary(const TileInfo *ti, RoadBits tram)
{ {
/* Do not draw catenary if it is invisible */ /* Do not draw catenary if it is invisible */
if (IsInvisibilitySet(TO_CATENARY)) return; if (IsInvisibilitySet(TO_CATENARY)) return;
@ -1003,7 +997,7 @@ void DrawTramCatenary(TileInfo *ti, RoadBits tram)
* @param dy the offset from the top of the BB of the tile * @param dy the offset from the top of the BB of the tile
* @param h the height of the sprite to draw * @param h the height of the sprite to draw
*/ */
static void DrawRoadDetail(SpriteID img, TileInfo *ti, int dx, int dy, int h) static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h)
{ {
int x = ti->x | dx; int x = ti->x | dx;
int y = ti->y | dy; int y = ti->y | dy;
@ -1016,15 +1010,13 @@ static void DrawRoadDetail(SpriteID img, TileInfo *ti, int dx, int dy, int h)
* Draw ground sprite and road pieces * Draw ground sprite and road pieces
* @param ti TileInfo * @param ti TileInfo
*/ */
static void DrawRoadBits(TileInfo* ti) static void DrawRoadBits(TileInfo *ti)
{ {
RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD); RoadBits road = GetRoadBits(ti->tile, ROADTYPE_ROAD);
RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM); RoadBits tram = GetRoadBits(ti->tile, ROADTYPE_TRAM);
const DrawRoadTileStruct *drts;
SpriteID image = 0; SpriteID image = 0;
SpriteID pal = PAL_NONE; SpriteID pal = PAL_NONE;
Roadside roadside;
if (ti->tileh != SLOPE_FLAT) { if (ti->tileh != SLOPE_FLAT) {
DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram)); DrawFoundation(ti, GetRoadFoundation(ti->tileh, road | tram));
@ -1036,7 +1028,7 @@ static void DrawRoadBits(TileInfo* ti)
if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram]; if (image == 0) image = _road_tile_sprites_1[road != ROAD_NONE ? road : tram];
roadside = GetRoadside(ti->tile); Roadside roadside = GetRoadside(ti->tile);
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) { if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
image += 19; image += 19;
@ -1096,7 +1088,7 @@ static void DrawRoadBits(TileInfo* ti)
if (CountBits(road) < 2) return; if (CountBits(road) < 2) return;
/* Draw extra details. */ /* Draw extra details. */
for (drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) { for (const DrawRoadTileStruct *drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) {
DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10); DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10);
} }
} }
@ -1109,17 +1101,16 @@ static void DrawTile_Road(TileInfo *ti)
break; break;
case ROAD_TILE_CROSSING: { case ROAD_TILE_CROSSING: {
SpriteID image;
SpriteID pal = PAL_NONE;
Roadside roadside = GetRoadside(ti->tile);
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing; SpriteID image = GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.crossing;
SpriteID pal = PAL_NONE;
if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++; if (GetCrossingRoadAxis(ti->tile) == AXIS_X) image++;
if (IsCrossingBarred(ti->tile)) image += 2; if (IsCrossingBarred(ti->tile)) image += 2;
Roadside roadside = GetRoadside(ti->tile);
if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) { if (AlwaysDrawUnpavedRoads(ti->tile, roadside)) {
image += 8; image += 8;
} else { } else {
@ -1141,14 +1132,11 @@ static void DrawTile_Road(TileInfo *ti)
default: default:
case ROAD_TILE_DEPOT: { case ROAD_TILE_DEPOT: {
const DrawTileSprites* dts;
const DrawTileSeqStruct* dtss;
SpriteID palette;
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)); SpriteID palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
const DrawTileSprites *dts;
if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) { if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
dts = &_tram_depot[GetRoadDepotDirection(ti->tile)]; dts = &_tram_depot[GetRoadDepotDirection(ti->tile)];
} else { } else {
@ -1160,7 +1148,7 @@ static void DrawTile_Road(TileInfo *ti)
/* End now if buildings are invisible */ /* End now if buildings are invisible */
if (IsInvisibilitySet(TO_BUILDINGS)) break; if (IsInvisibilitySet(TO_BUILDINGS)) break;
for (dtss = dts->seq; dtss->image.sprite != 0; dtss++) { for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
SpriteID image = dtss->image.sprite; SpriteID image = dtss->image.sprite;
SpriteID pal; SpriteID pal;
@ -1187,15 +1175,14 @@ static void DrawTile_Road(TileInfo *ti)
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt) void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
{ {
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player); SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
const DrawTileSprites* dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir]; const DrawTileSprites *dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
const DrawTileSeqStruct* dtss;
x += 33; x += 33;
y += 17; y += 17;
DrawSprite(dts->ground.sprite, PAL_NONE, x, y); DrawSprite(dts->ground.sprite, PAL_NONE, x, y);
for (dtss = dts->seq; dtss->image.sprite != 0; dtss++) { for (const DrawTileSeqStruct *dtss = dts->seq; dtss->image.sprite != 0; dtss++) {
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
SpriteID image = dtss->image.sprite; SpriteID image = dtss->image.sprite;
@ -1275,7 +1262,7 @@ static void TileLoop_Road(TileIndex tile)
if (IsRoadDepot(tile)) return; if (IsRoadDepot(tile)) return;
const Town* t = ClosestTownFromTile(tile, (uint)-1); const Town *t = ClosestTownFromTile(tile, (uint)-1);
if (!HasRoadWorks(tile)) { if (!HasRoadWorks(tile)) {
HouseZonesBits grp = HZB_TOWN_EDGE; HouseZonesBits grp = HZB_TOWN_EDGE;

View File

@ -175,7 +175,7 @@ static void PlaceRoad_Tunnel(TileIndex tile)
static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction) static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
{ {
tile += TileOffsByDiagDir(direction); tile += TileOffsByDiagDir(direction);
// if there is a roadpiece just outside of the station entrance, build a connecting route /* if there is a roadpiece just outside of the station entrance, build a connecting route */
if (IsNormalRoadTile(tile)) { if (IsNormalRoadTile(tile)) {
if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) { if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD); DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
@ -409,7 +409,7 @@ static const uint16 _road_keycodes[] = {
* @param w The toolbar window * @param w The toolbar window
* @param clicked_widget The widget which the player clicked just now * @param clicked_widget The widget which the player clicked just now
*/ */
static void UpdateOptionWidgetStatus(Window *w, int clicked_widget) static void UpdateOptionWidgetStatus(Window *w, RoadToolbarWidgets clicked_widget)
{ {
/* The remove and the one way button state is driven /* The remove and the one way button state is driven
* by the other buttons so they don't act on themselfs. * by the other buttons so they don't act on themselfs.
@ -419,15 +419,18 @@ static void UpdateOptionWidgetStatus(Window *w, int clicked_widget)
w->RaiseWidget(RTW_ONE_WAY); w->RaiseWidget(RTW_ONE_WAY);
w->InvalidateWidget(RTW_ONE_WAY); w->InvalidateWidget(RTW_ONE_WAY);
break; break;
case RTW_ONE_WAY: case RTW_ONE_WAY:
w->RaiseWidget(RTW_REMOVE); w->RaiseWidget(RTW_REMOVE);
w->InvalidateWidget(RTW_REMOVE); w->InvalidateWidget(RTW_REMOVE);
break; break;
case RTW_BUS_STATION: case RTW_BUS_STATION:
case RTW_TRUCK_STATION: case RTW_TRUCK_STATION:
w->DisableWidget(RTW_ONE_WAY); w->DisableWidget(RTW_ONE_WAY);
w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget)); w->SetWidgetDisabledState(RTW_REMOVE, !w->IsWidgetLowered(clicked_widget));
break; break;
case RTW_ROAD_X: case RTW_ROAD_X:
case RTW_ROAD_Y: case RTW_ROAD_Y:
case RTW_AUTOROAD: case RTW_AUTOROAD:
@ -436,6 +439,7 @@ static void UpdateOptionWidgetStatus(Window *w, int clicked_widget)
RTW_ONE_WAY, RTW_ONE_WAY,
WIDGET_LIST_END); WIDGET_LIST_END);
break; break;
default: default:
/* When any other buttons than road/station, raise and /* When any other buttons than road/station, raise and
* disable the removal button */ * disable the removal button */
@ -454,157 +458,162 @@ static void UpdateOptionWidgetStatus(Window *w, int clicked_widget)
static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
case WE_CREATE: case WE_CREATE:
w->SetWidgetsDisabledState(true, w->SetWidgetsDisabledState(true,
RTW_REMOVE, RTW_REMOVE,
RTW_ONE_WAY, RTW_ONE_WAY,
WIDGET_LIST_END); WIDGET_LIST_END);
break; break;
case WE_PAINT: case WE_PAINT:
w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD), w->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
RTW_DEPOT, RTW_DEPOT,
RTW_BUS_STATION, RTW_BUS_STATION,
RTW_TRUCK_STATION, RTW_TRUCK_STATION,
WIDGET_LIST_END); WIDGET_LIST_END);
DrawWindowWidgets(w); DrawWindowWidgets(w);
break; break;
case WE_CLICK: case WE_CLICK:
if (e->we.click.widget >= RTW_ROAD_X) { if (e->we.click.widget >= RTW_ROAD_X) {
_remove_button_clicked = false;
_one_way_button_clicked = false;
_build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w);
}
UpdateOptionWidgetStatus(w, e->we.click.widget);
if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
break;
case WE_KEYPRESS:
for (uint8 i = 0; i != lengthof(_road_keycodes); i++) {
if (e->we.keypress.keycode == _road_keycodes[i]) {
e->we.keypress.cont = false;
_remove_button_clicked = false; _remove_button_clicked = false;
_one_way_button_clicked = false; _one_way_button_clicked = false;
_build_road_button_proc[i](w); _build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w);
UpdateOptionWidgetStatus(w, i + RTW_ROAD_X);
if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
break;
} }
} UpdateOptionWidgetStatus(w, (RoadToolbarWidgets)e->we.click.widget);
MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
break; break;
case WE_PLACE_OBJ: case WE_KEYPRESS:
_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE); for (uint i = 0; i != lengthof(_road_keycodes); i++) {
_one_way_button_clicked = w->IsWidgetLowered(RTW_ONE_WAY); if (e->we.keypress.keycode == _road_keycodes[i]) {
_place_proc(e->we.place.tile); e->we.keypress.cont = false;
break; _remove_button_clicked = false;
_one_way_button_clicked = false;
case WE_ABORT_PLACE_OBJ: _build_road_button_proc[i](w);
w->RaiseButtons(); UpdateOptionWidgetStatus(w, (RoadToolbarWidgets)(i + RTW_ROAD_X));
w->SetWidgetsDisabledState(true, if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
RTW_REMOVE, break;
RTW_ONE_WAY,
WIDGET_LIST_END);
w->InvalidateWidget(RTW_REMOVE);
w->InvalidateWidget(RTW_ONE_WAY);
w = FindWindowById(WC_BUS_STATION, 0);
if (w != NULL) WP(w, def_d).close = true;
w = FindWindowById(WC_TRUCK_STATION, 0);
if (w != NULL) WP(w, def_d).close = true;
w = FindWindowById(WC_BUILD_DEPOT, 0);
if (w != NULL) WP(w, def_d).close = true;
break;
case WE_PLACE_DRAG:
/* Here we update the end tile flags
* of the road placement actions.
* At first we reset the end halfroad
* bits and if needed we set them again. */
switch (e->we.place.select_proc) {
case DDSP_PLACE_ROAD_X_DIR:
_place_road_flag &= ~RF_END_HALFROAD_X;
if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
break;
case DDSP_PLACE_ROAD_Y_DIR:
_place_road_flag &= ~RF_END_HALFROAD_Y;
if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
break;
case DDSP_PLACE_AUTOROAD:
_place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
/* For autoroad we need to update the
* direction of the road */
if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
(_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
/* Set dir = X */
_place_road_flag &= ~RF_DIR_Y;
} else {
/* Set dir = Y */
_place_road_flag |= RF_DIR_Y;
} }
}
MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection
break;
break; case WE_PLACE_OBJ:
} _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
_one_way_button_clicked = w->IsWidgetLowered(RTW_ONE_WAY);
_place_proc(e->we.place.tile);
break;
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); case WE_ABORT_PLACE_OBJ:
return; w->RaiseButtons();
w->SetWidgetsDisabledState(true,
RTW_REMOVE,
RTW_ONE_WAY,
WIDGET_LIST_END);
w->InvalidateWidget(RTW_REMOVE);
w->InvalidateWidget(RTW_ONE_WAY);
case WE_PLACE_MOUSEUP: w = FindWindowById(WC_BUS_STATION, 0);
if (e->we.place.pt.x != -1) { if (w != NULL) WP(w, def_d).close = true;
TileIndex start_tile = e->we.place.starttile; w = FindWindowById(WC_TRUCK_STATION, 0);
TileIndex end_tile = e->we.place.tile; if (w != NULL) WP(w, def_d).close = true;
w = FindWindowById(WC_BUILD_DEPOT, 0);
if (w != NULL) WP(w, def_d).close = true;
break;
case WE_PLACE_DRAG:
/* Here we update the end tile flags
* of the road placement actions.
* At first we reset the end halfroad
* bits and if needed we set them again. */
switch (e->we.place.select_proc) { switch (e->we.place.select_proc) {
case DDSP_BUILD_BRIDGE:
ResetObjectToPlace();
ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
break;
case DDSP_DEMOLISH_AREA:
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
break;
case DDSP_PLACE_ROAD_X_DIR: case DDSP_PLACE_ROAD_X_DIR:
case DDSP_PLACE_ROAD_Y_DIR: _place_road_flag &= ~RF_END_HALFROAD_X;
case DDSP_PLACE_AUTOROAD: if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
/* Flag description: break;
* Use the first three bits (0x07) if dir == Y
* else use the last 2 bits (X dir has
* not the 3rd bit set) */
_place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D, case DDSP_PLACE_ROAD_Y_DIR:
(_ctrl_pressed || _remove_button_clicked) ? _place_road_flag &= ~RF_END_HALFROAD_Y;
CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) : if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road)); break;
case DDSP_PLACE_AUTOROAD:
_place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
if (e->we.place.pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
if (e->we.place.pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
/* For autoroad we need to update the
* direction of the road */
if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
(_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
/* Set dir = X */
_place_road_flag &= ~RF_DIR_Y;
} else {
/* Set dir = Y */
_place_road_flag |= RF_DIR_Y;
}
break;
default:
break; break;
} }
}
break;
case WE_PLACE_PRESIZE: { VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
TileIndex tile = e->we.place.tile; return;
DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL); case WE_PLACE_MOUSEUP:
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); if (e->we.place.pt.x != -1) {
break; TileIndex start_tile = e->we.place.starttile;
} TileIndex end_tile = e->we.place.tile;
case WE_DESTROY: switch (e->we.place.select_proc) {
if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0); case DDSP_BUILD_BRIDGE:
break; ResetObjectToPlace();
ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
break;
case WE_CTRL_CHANGED: case DDSP_DEMOLISH_AREA:
if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false; DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
break; break;
case DDSP_PLACE_ROAD_X_DIR:
case DDSP_PLACE_ROAD_Y_DIR:
case DDSP_PLACE_AUTOROAD:
/* Flag description:
* Use the first three bits (0x07) if dir == Y
* else use the last 2 bits (X dir has
* not the 3rd bit set) */
_place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5), CcPlaySound1D,
(_ctrl_pressed || _remove_button_clicked) ?
CMD_REMOVE_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
CMD_BUILD_LONG_ROAD | CMD_NO_WATER | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road));
break;
}
}
break;
case WE_PLACE_PRESIZE: {
TileIndex tile = e->we.place.tile;
DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL);
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
} break;
case WE_DESTROY:
if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
break;
case WE_CTRL_CHANGED:
if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
break;
default:
break;
} }
} }
@ -724,39 +733,47 @@ enum BuildRoadDepotWidgets {
static void BuildRoadDepotWndProc(Window *w, WindowEvent *e) static void BuildRoadDepotWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
case WE_CREATE: w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE); break; case WE_CREATE:
w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
break;
case WE_PAINT: case WE_PAINT:
DrawWindowWidgets(w); DrawWindowWidgets(w);
DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype); DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype);
DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype); DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype);
DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype); DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype);
DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype); DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype);
break; break;
case WE_CLICK: case WE_CLICK:
switch (e->we.click.widget) { switch (e->we.click.widget) {
case BRDW_DEPOT_NW: case BRDW_DEPOT_NW:
case BRDW_DEPOT_NE: case BRDW_DEPOT_NE:
case BRDW_DEPOT_SW: case BRDW_DEPOT_SW:
case BRDW_DEPOT_SE: case BRDW_DEPOT_SE:
w->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE); w->RaiseWidget(_road_depot_orientation + BRDW_DEPOT_NE);
_road_depot_orientation = (DiagDirection)(e->we.click.widget - BRDW_DEPOT_NE); _road_depot_orientation = (DiagDirection)(e->we.click.widget - BRDW_DEPOT_NE);
w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE); w->LowerWidget(_road_depot_orientation + BRDW_DEPOT_NE);
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
SetWindowDirty(w); SetWindowDirty(w);
break; break;
}
break;
case WE_MOUSELOOP: default:
if (WP(w, def_d).close) DeleteWindow(w); break;
break; }
break;
case WE_DESTROY: case WE_MOUSELOOP:
if (!WP(w, def_d).close) ResetObjectToPlace(); if (WP(w, def_d).close) DeleteWindow(w);
break; break;
case WE_DESTROY:
if (!WP(w, def_d).close) ResetObjectToPlace();
break;
default:
break;
} }
} }
@ -824,93 +841,99 @@ enum BuildRoadStationWidgets {
static void RoadStationPickerWndProc(Window *w, WindowEvent *e) static void RoadStationPickerWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
case WE_CREATE: case WE_CREATE:
/* Trams don't have non-drivethrough stations */ /* Trams don't have non-drivethrough stations */
if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) { if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
_road_station_picker_orientation = DIAGDIR_END; _road_station_picker_orientation = DIAGDIR_END;
} }
w->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM, w->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
BRSW_STATION_NE, BRSW_STATION_NE,
BRSW_STATION_SE, BRSW_STATION_SE,
BRSW_STATION_SW, BRSW_STATION_SW,
BRSW_STATION_NW, BRSW_STATION_NW,
WIDGET_LIST_END); WIDGET_LIST_END);
w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE); w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
w->LowerWidget(_station_show_coverage + BRSW_LT_OFF); w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
break; break;
case WE_PAINT: { case WE_PAINT: {
if (WP(w, def_d).close) return; if (WP(w, def_d).close) return;
DrawWindowWidgets(w); DrawWindowWidgets(w);
if (_station_show_coverage) { if (_station_show_coverage) {
int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED; int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : CA_UNMODIFIED;
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
} else { } else {
SetTileSelectSize(1, 1); SetTileSelectSize(1, 1);
} }
StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK; StationType st = (w->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0); StationPickerDrawSprite(103, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 0);
StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1); StationPickerDrawSprite(103, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 1);
StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2); StationPickerDrawSprite( 35, 85, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 2);
StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3); StationPickerDrawSprite( 35, 35, st, INVALID_RAILTYPE, ROADTYPE_ROAD, 3);
StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4); StationPickerDrawSprite(171, 35, st, INVALID_RAILTYPE, _cur_roadtype, 4);
StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5); StationPickerDrawSprite(171, 85, st, INVALID_RAILTYPE, _cur_roadtype, 5);
int text_end = DrawStationCoverageAreaText(2, 146, int text_end = DrawStationCoverageAreaText(2, 146,
(w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY, (w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
3) + 4; 3) + 4;
if (text_end > w->widget[BRSW_BACKGROUND].bottom) { if (text_end > w->widget[BRSW_BACKGROUND].bottom) {
SetWindowDirty(w);
ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom);
SetWindowDirty(w);
}
} break;
case WE_CLICK: {
switch (e->we.click.widget) {
case BRSW_STATION_NE:
case BRSW_STATION_SE:
case BRSW_STATION_SW:
case BRSW_STATION_NW:
case BRSW_STATION_X:
case BRSW_STATION_Y:
w->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
_road_station_picker_orientation = (DiagDirection)(e->we.click.widget - BRSW_STATION_NE);
w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w); SetWindowDirty(w);
break; ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom);
case BRSW_LT_OFF:
case BRSW_LT_ON:
w->RaiseWidget(_station_show_coverage + BRSW_LT_OFF);
_station_show_coverage = (e->we.click.widget != BRSW_LT_OFF);
w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w); SetWindowDirty(w);
break; }
}
} break;
case WE_MOUSELOOP: { } break;
if (WP(w, def_d).close) {
DeleteWindow(w);
return;
}
CheckRedrawStationCoverage(w); case WE_CLICK: {
} break; switch (e->we.click.widget) {
case BRSW_STATION_NE:
case BRSW_STATION_SE:
case BRSW_STATION_SW:
case BRSW_STATION_NW:
case BRSW_STATION_X:
case BRSW_STATION_Y:
w->RaiseWidget(_road_station_picker_orientation + BRSW_STATION_NE);
_road_station_picker_orientation = (DiagDirection)(e->we.click.widget - BRSW_STATION_NE);
w->LowerWidget(_road_station_picker_orientation + BRSW_STATION_NE);
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
break;
case WE_DESTROY: case BRSW_LT_OFF:
if (!WP(w, def_d).close) ResetObjectToPlace(); case BRSW_LT_ON:
break; w->RaiseWidget(_station_show_coverage + BRSW_LT_OFF);
_station_show_coverage = (e->we.click.widget != BRSW_LT_OFF);
w->LowerWidget(_station_show_coverage + BRSW_LT_OFF);
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
break;
default:
break;
}
} break;
case WE_MOUSELOOP: {
if (WP(w, def_d).close) {
DeleteWindow(w);
return;
}
CheckRedrawStationCoverage(w);
} break;
case WE_DESTROY:
if (!WP(w, def_d).close) ResetObjectToPlace();
break;
default:
break;
} }
} }

View File

@ -31,6 +31,6 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *ed
* @param ti information about the tile (position, slope) * @param ti information about the tile (position, slope)
* @param tram the roadbits to draw the catenary for * @param tram the roadbits to draw the catenary for
*/ */
void DrawTramCatenary(TileInfo *ti, RoadBits tram); void DrawTramCatenary(const TileInfo *ti, RoadBits tram);
#endif /* ROAD_INTERNAL_H */ #endif /* ROAD_INTERNAL_H */