summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-05-21 21:58:31 +0000
committerrubidium <rubidium@openttd.org>2007-05-21 21:58:31 +0000
commit33c3420ef439a468be1922f54aa6e462de47b159 (patch)
treee4d59448a2b1e8612c8a90126fc7029d95b56d25
parentbba732921f20dceca8441836ad413be45ede1279 (diff)
downloadopenttd-33c3420ef439a468be1922f54aa6e462de47b159.tar.xz
(svn r9897) -Codechange: prepare the toolbar for more road types.
-rw-r--r--src/gui.h2
-rw-r--r--src/main_gui.cpp12
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/road_cmd.h2
-rw-r--r--src/road_gui.cpp32
-rw-r--r--src/window.h2
6 files changed, 32 insertions, 20 deletions
diff --git a/src/gui.h b/src/gui.h
index d2f3be76f..199410635 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -46,7 +46,7 @@ void ShowTrainViewWindow(const Vehicle *v);
void ShowOrdersWindow(const Vehicle *v);
/* road_gui.cpp */
-void ShowBuildRoadToolbar();
+void ShowBuildRoadToolbar(RoadType roadtype);
void ShowBuildRoadScenToolbar();
void ShowRoadVehViewWindow(const Vehicle *v);
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 613ea7dce..94b6829a3 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -51,6 +51,7 @@ static int _rename_what = -1;
static byte _terraform_size = 1;
RailType _last_built_railtype;
+RoadType _last_built_roadtype;
static int _scengen_town_size = 1; // depress medium-sized towns per default
extern void GenerateIndustries();
@@ -310,7 +311,8 @@ static void MenuClickBuildRail(int index)
static void MenuClickBuildRoad(int index)
{
- ShowBuildRoadToolbar();
+ _last_built_roadtype = (RoadType)index;
+ ShowBuildRoadToolbar(_last_built_roadtype);
}
static void MenuClickBuildWater(int index)
@@ -930,12 +932,13 @@ static void ToolbarBuildRailClick(Window *w)
const Player *p = GetPlayer(_local_player);
Window *w2;
w2 = PopupMainToolbMenu(w, 19, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes);
- WP(w2,menu_d).sel_index = _last_built_railtype;
+ WP(w2, menu_d).sel_index = _last_built_railtype;
}
static void ToolbarBuildRoadClick(Window *w)
{
- PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 1, 0);
+ Window *w2 = PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 1, 0);
+ WP(w2, menu_d).sel_index = _last_built_roadtype;
}
static void ToolbarBuildWaterClick(Window *w)
@@ -1873,7 +1876,7 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
case WKC_SHIFT | WKC_F5: ToolbarZoomInClick(w); break;
case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(w); break;
case WKC_SHIFT | WKC_F7: ShowBuildRailToolbar(_last_built_railtype, -1); break;
- case WKC_SHIFT | WKC_F8: ShowBuildRoadToolbar(); break;
+ case WKC_SHIFT | WKC_F8: ShowBuildRoadToolbar(_last_built_roadtype); break;
case WKC_SHIFT | WKC_F9: ShowBuildDocksToolbar(); break;
case WKC_SHIFT | WKC_F10:ShowBuildAirToolbar(); break;
case WKC_SHIFT | WKC_F11: ShowBuildTreesToolbar(); break;
@@ -2514,6 +2517,7 @@ void InitializeMainGui()
{
/* Clean old GUI values */
_last_built_railtype = RAILTYPE_RAIL;
+ _last_built_roadtype = ROADTYPE_ROAD;
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 71a21db7d..ff85e50a1 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -845,7 +845,7 @@ static void DrawTile_Road(TileInfo *ti)
DrawBridgeMiddle(ti);
}
-void DrawRoadDepotSprite(int x, int y, DiagDirection dir)
+void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
{
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
const DrawTileSprites* dts = &_road_depot[dir];
diff --git a/src/road_cmd.h b/src/road_cmd.h
index c6fb9f5af..66ea2f652 100644
--- a/src/road_cmd.h
+++ b/src/road_cmd.h
@@ -7,6 +7,6 @@
#include "direction.h"
-void DrawRoadDepotSprite(int x, int y, DiagDirection dir);
+void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt);
#endif /* ROAD_CMD_H */
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index 2ae045de9..9253de427 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -4,8 +4,6 @@
#include "stdafx.h"
#include "openttd.h"
-#include "road_cmd.h"
-#include "road_map.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
@@ -18,6 +16,9 @@
#include "sound.h"
#include "command.h"
#include "variables.h"
+#include "road.h"
+#include "road_cmd.h"
+#include "road_map.h"
#include "station_map.h"
//needed for catchments
#include "station.h"
@@ -31,6 +32,8 @@ static bool _remove_button_clicked;
static byte _place_road_flag;
+static RoadType _cur_roadtype;
+
static DiagDirection _road_depot_orientation;
static DiagDirection _road_station_picker_orientation;
@@ -69,7 +72,7 @@ void CcBuildRoadTunnel(bool success, TileIndex tile, uint32 p1, uint32 p2)
static void PlaceRoad_Tunnel(TileIndex tile)
{
- DoCommandP(tile, 0x200 | ROADTYPES_ROAD, 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
+ DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CcBuildRoadTunnel, CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
}
static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
@@ -77,7 +80,9 @@ static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction)
tile += TileOffsByDiagDir(direction);
// if there is a roadpiece just outside of the station entrance, build a connecting route
if (IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL) {
- DoCommandP(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
+ if (GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
+ DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, NULL, CMD_BUILD_ROAD);
+ }
}
}
@@ -95,7 +100,7 @@ void CcRoadDepot(bool success, TileIndex tile, uint32 p1, uint32 p2)
static void PlaceRoad_Depot(TileIndex tile)
{
- DoCommandP(tile, _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1807_CAN_T_BUILD_ROAD_VEHICLE));
+ DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0, CcRoadDepot, CMD_BUILD_ROAD_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1807_CAN_T_BUILD_ROAD_VEHICLE));
}
static void PlaceRoadStop(TileIndex tile, uint32 p2, uint32 cmd)
@@ -298,9 +303,9 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
if (e->we.place.userdata == 0) {
ResetObjectToPlace();
- ShowBuildBridgeWindow(start_tile, end_tile, 0x80 | ROADTYPES_ROAD);
+ ShowBuildBridgeWindow(start_tile, end_tile, 0x80 | RoadTypeToRoadTypes(_cur_roadtype));
} else if (e->we.place.userdata != 4) {
- DoCommandP(end_tile, start_tile, _place_road_flag, CcPlaySound1D,
+ DoCommandP(end_tile, start_tile, _place_road_flag | (_cur_roadtype << 3), CcPlaySound1D,
_remove_button_clicked ?
CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) :
CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE));
@@ -313,7 +318,7 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
case WE_PLACE_PRESIZE: {
TileIndex tile = e->we.place.tile;
- DoCommand(tile, 0x200 | ROADTYPES_ROAD, 0, DC_AUTO, CMD_BUILD_TUNNEL);
+ DoCommand(tile, 0x200 | _cur_roadtype, 0, DC_AUTO, CMD_BUILD_TUNNEL);
VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
break;
}
@@ -349,9 +354,10 @@ static const WindowDesc _build_road_desc = {
BuildRoadToolbWndProc
};
-void ShowBuildRoadToolbar()
+void ShowBuildRoadToolbar(RoadType roadtype)
{
if (!IsValidPlayer(_current_player)) return;
+ _cur_roadtype = roadtype;
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
Window *w = AllocateWindowDesc(&_build_road_desc);
@@ -396,10 +402,10 @@ static void BuildRoadDepotWndProc(Window *w, WindowEvent *e)
case WE_PAINT:
DrawWindowWidgets(w);
- DrawRoadDepotSprite(70, 17, DIAGDIR_NE);
- DrawRoadDepotSprite(70, 69, DIAGDIR_SE);
- DrawRoadDepotSprite( 2, 69, DIAGDIR_SW);
- DrawRoadDepotSprite( 2, 17, DIAGDIR_NW);
+ DrawRoadDepotSprite(70, 17, DIAGDIR_NE, _cur_roadtype);
+ DrawRoadDepotSprite(70, 69, DIAGDIR_SE, _cur_roadtype);
+ DrawRoadDepotSprite( 2, 69, DIAGDIR_SW, _cur_roadtype);
+ DrawRoadDepotSprite( 2, 17, DIAGDIR_NW, _cur_roadtype);
break;
case WE_CLICK: {
diff --git a/src/window.h b/src/window.h
index 6cc255178..0f59be1b6 100644
--- a/src/window.h
+++ b/src/window.h
@@ -9,6 +9,7 @@
#include "string.h"
#include "order.h"
#include "rail.h"
+#include "road.h"
#include "airport.h"
#include "vehicle.h"
@@ -328,6 +329,7 @@ struct buildvehicle_d {
union {
RailTypeByte railtype;
AirportFTAClass::Flags flags;
+ RoadTypes roadtypes;
} filter;
byte sel_index; ///< deprecated value, used for 'unified' ship and road
bool descending_sort_order;