diff options
author | rubidium <rubidium@openttd.org> | 2007-05-25 08:13:01 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-05-25 08:13:01 +0000 |
commit | 0819f3a9a0229186fbd0624f590764553c7e7178 (patch) | |
tree | 20cb72fbcb2123cac75bfc9f3a06d9e590278b3a | |
parent | d5d94e230fe92fe461becdf9043034651141ab73 (diff) | |
download | openttd-0819f3a9a0229186fbd0624f590764553c7e7178.tar.xz |
(svn r9917) -Codechange: prepare some more areas for more road types.
-rw-r--r-- | src/build_vehicle_gui.cpp | 3 | ||||
-rw-r--r-- | src/engine.cpp | 4 | ||||
-rw-r--r-- | src/engine.h | 4 | ||||
-rw-r--r-- | src/main_gui.cpp | 7 | ||||
-rw-r--r-- | src/openttd.cpp | 5 | ||||
-rw-r--r-- | src/player.h | 2 | ||||
-rw-r--r-- | src/players.cpp | 19 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 8 | ||||
-rw-r--r-- | src/vehicle.cpp | 2 |
9 files changed, 42 insertions, 12 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 746d8bbc9..ad02f8557 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -28,6 +28,7 @@ #include "strings.h" #include "cargotype.h" #include "group.h" +#include "road_map.h" enum BuildVehicleWidgets { @@ -666,6 +667,7 @@ static void GenerateBuildRoadVehList(Window *w) for (eid = ROAD_ENGINES_INDEX; eid < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; eid++) { if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue; + if (!HASBIT(bv->filter.roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue; EngList_Add(&bv->eng_list, eid); if (eid == bv->sel_engine) sel_id = eid; @@ -1019,6 +1021,7 @@ void ShowBuildVehicleWindow(TileIndex tile, VehicleType type) ResizeWindow(w, 0, 16); break; case VEH_ROAD: + WP(w, buildvehicle_d).filter.roadtypes = (tile == 0) ? ROADTYPES_ALL : GetRoadTypes(tile); ResizeWindow(w, 0, 16); case VEH_SHIP: break; diff --git a/src/engine.cpp b/src/engine.cpp index b0336cc2d..37067bdd2 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -178,14 +178,16 @@ void StartupEngines() static void AcceptEnginePreview(EngineID eid, PlayerID player) { Engine *e = GetEngine(eid); + Player *p = GetPlayer(player); SETBIT(e->player_avail, player); if (e->type == VEH_TRAIN) { const RailVehicleInfo *rvi = RailVehInfo(eid); - Player *p = GetPlayer(player); assert(rvi->railtype < RAILTYPE_END); SETBIT(p->avail_railtypes, rvi->railtype); + } else if (e->type == VEH_ROAD) { + SETBIT(p->avail_roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); } e->preview_player = INVALID_PLAYER; diff --git a/src/engine.h b/src/engine.h index b34452c07..95d4fd338 100644 --- a/src/engine.h +++ b/src/engine.h @@ -127,8 +127,8 @@ struct Engine { * EngineInfo.misc_flags is a bitmask, with the following values */ enum { - EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves (unsupported) - EF_ROAD_TRAM = 0, ///< Road vehicle is a tram/light rail vehicle (unsup) + EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves + EF_ROAD_TRAM = 0, ///< Road vehicle is a tram/light rail vehicle EF_USES_2CC = 1, ///< Vehicle uses two company colours EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU) }; diff --git a/src/main_gui.cpp b/src/main_gui.cpp index cf111e96a..97d146cad 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -930,14 +930,15 @@ static void ToolbarZoomOutClick(Window *w) 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); + Window *w2 = PopupMainToolbMenu(w, 19, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes); WP(w2, menu_d).sel_index = _last_built_railtype; } static void ToolbarBuildRoadClick(Window *w) { - Window *w2 = PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 1, 0); + const Player *p = GetPlayer(_local_player); + /* The standard road button is *always* available */ + Window *w2 = PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 1, ~(p->avail_roadtypes | 1)); WP(w2, menu_d).sel_index = _last_built_roadtype; } diff --git a/src/openttd.cpp b/src/openttd.cpp index 69cb5c0de..6ba826ad9 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1716,7 +1716,10 @@ bool AfterLoadGame() if (CheckSavegameVersion(34)) FOR_ALL_PLAYERS(p) ResetPlayerLivery(p); - FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index); + FOR_ALL_PLAYERS(p) { + p->avail_railtypes = GetPlayerRailtypes(p->index); + p->avail_roadtypes = GetPlayerRoadtypes(p->index); + } if (!CheckSavegameVersion(27)) AfterLoadStations(); diff --git a/src/player.h b/src/player.h index 0732bf868..191fc30eb 100644 --- a/src/player.h +++ b/src/player.h @@ -168,6 +168,7 @@ struct Player { Livery livery[LS_END]; byte player_money_fraction; byte avail_railtypes; + byte avail_roadtypes; byte block_preview; PlayerByte index; @@ -248,6 +249,7 @@ static inline bool IsValidPlayer(PlayerID pi) } byte GetPlayerRailtypes(PlayerID p); +byte GetPlayerRoadtypes(PlayerID p); /** Finds out if a Player has a certain railtype available */ static inline bool HasRailtypeAvail(const Player *p, RailType Railtype) diff --git a/src/players.cpp b/src/players.cpp index b172f89b1..14a2ab117 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -472,6 +472,7 @@ Player *DoStartupNewPlayer(bool is_ai) p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR; p->avail_railtypes = GetPlayerRailtypes(p->index); + p->avail_roadtypes = GetPlayerRoadtypes(p->index); p->inaugurated_year = _cur_year; p->face = ConvertFromOldPlayerFace(Random()); @@ -609,6 +610,24 @@ byte GetPlayerRailtypes(PlayerID p) return rt; } +byte GetPlayerRoadtypes(PlayerID p) +{ + byte rt = 0; + EngineID i; + + for (i = 0; i != TOTAL_NUM_ENGINES; i++) { + const Engine* e = GetEngine(i); + const EngineInfo *ei = EngInfo(i); + + if (e->type == VEH_ROAD && HASBIT(ei->climates, _opt.landscape) && + (HASBIT(e->player_avail, p) || _date >= e->intro_date + 365)) { + SETBIT(rt, HASBIT(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); + } + } + + return rt; +} + static void DeletePlayerStuff(PlayerID pi) { Player *p; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 4a5c73b1f..a331c430f 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -173,9 +173,6 @@ int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->u.road.state = RVSB_IN_DEPOT; v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; - v->u.road.roadtype = ROADTYPE_ROAD; - v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); - v->spritenum = rvi->image_index; v->cargo_type = rvi->cargo_type; v->cargo_subtype = 0; @@ -194,6 +191,9 @@ int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->max_speed = rvi->max_speed; v->engine_type = (byte)p1; + v->u.road.roadtype = HASBIT(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; + v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); + e = GetEngine(p1); v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; @@ -1064,7 +1064,7 @@ static Trackdir RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection ent TrackdirBits trackdirs = (TrackdirBits)GB(r, 0, 16); if (IsTileType(tile, MP_STREET)) { - if (GetRoadTileType(tile) == ROAD_TILE_DEPOT && (!IsTileOwner(tile, v->owner) || GetRoadDepotDirection(tile) == enterdir)) { + if (GetRoadTileType(tile) == ROAD_TILE_DEPOT && (!IsTileOwner(tile, v->owner) || GetRoadDepotDirection(tile) == enterdir || (GetRoadTypes(tile) & v->u.road.compatible_roadtypes) == 0)) { /* Road depot owned by another player or with the wrong orientation */ trackdirs = TRACKDIR_BIT_NONE; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 97c14281a..e96145c01 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -241,7 +241,7 @@ void AfterLoadVehicles() switch (v->type) { case VEH_ROAD: v->cur_image = GetRoadVehImage(v, v->direction); - v->u.road.roadtype = ROADTYPE_ROAD; + v->u.road.roadtype = HASBIT(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); break; |