diff options
author | tron <tron@openttd.org> | 2007-01-24 07:14:09 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2007-01-24 07:14:09 +0000 |
commit | 7fffe8b3d4cc8c75d6ae40c487d4b23fb22b2946 (patch) | |
tree | e2918d49dec3bdc87eab67e767fcb414e9cc04c2 /src | |
parent | 4dd0d007b1cf1f595fba5d690a096e69c7bbca20 (diff) | |
download | openttd-7fffe8b3d4cc8c75d6ae40c487d4b23fb22b2946.tar.xz |
(svn r8385) -Fix
-Regression (r8314): I only did half the necessary changes to move railtype from Engine to RailVehicleInfo. Now do the rest.
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/default/default.cpp | 4 | ||||
-rw-r--r-- | src/autoreplace_gui.cpp | 13 | ||||
-rw-r--r-- | src/build_vehicle_gui.cpp | 9 | ||||
-rw-r--r-- | src/elrail.cpp | 7 | ||||
-rw-r--r-- | src/engine.cpp | 32 | ||||
-rw-r--r-- | src/engine.h | 3 | ||||
-rw-r--r-- | src/engine_gui.cpp | 2 | ||||
-rw-r--r-- | src/oldloader.cpp | 3 | ||||
-rw-r--r-- | src/openttd.cpp | 11 | ||||
-rw-r--r-- | src/players.cpp | 11 | ||||
-rw-r--r-- | src/table/engines.h | 19 | ||||
-rw-r--r-- | src/train_cmd.cpp | 21 | ||||
-rw-r--r-- | src/vehicle.cpp | 1 |
13 files changed, 65 insertions, 71 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index 63a3ff556..9fc07abd5 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -142,7 +142,7 @@ static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, const RailVehicleInfo *rvi = RailVehInfo(i); const Engine* e = GetEngine(i); - if (!IsCompatibleRail(e->railtype, railtype) || + if (!IsCompatibleRail(rvi->railtype, railtype) || rvi->flags & RVI_WAGON || (rvi->flags & RVI_MULTIHEAD && flag & 1) || !HASBIT(e->player_avail, _current_player) || @@ -2365,7 +2365,7 @@ static EngineID AiFindBestWagon(CargoID cargo, RailType railtype) const RailVehicleInfo *rvi = RailVehInfo(i); const Engine* e = GetEngine(i); - if (!IsCompatibleRail(e->railtype, railtype) || + if (!IsCompatibleRail(rvi->railtype, railtype) || !(rvi->flags & RVI_WAGON) || !HASBIT(e->player_avail, _current_player)) { continue; diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 42901ed8f..64118e6e9 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -60,9 +60,9 @@ static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, Engine colour = *sel == 0 ? 0xC : 0x10; - if (!(ENGINE_AVAILABLE && show_outdated && RailVehInfo(i)->power && IsCompatibleRail(e->railtype, railtype))) { - if ((!IsCompatibleRail(e->railtype, railtype) && show_compatible) - || (e->railtype != railtype && !show_compatible) + if (!(ENGINE_AVAILABLE && show_outdated && RailVehInfo(i)->power && IsCompatibleRail(rvi->railtype, railtype))) { + if ((!IsCompatibleRail(rvi->railtype, railtype) && show_compatible) + || (rvi->railtype != railtype && !show_compatible) || !(rvi->flags & RVI_WAGON) != is_engine || !HASBIT(e->player_avail, _local_player)) continue; @@ -113,16 +113,17 @@ static void SetupScrollStuffForReplaceWindow(Window *w) for (i = 0; i < NUM_TRAIN_ENGINES; i++) { EngineID eid = GetRailVehAtPosition(i); const Engine* e = GetEngine(eid); + const RailVehicleInfo *rvi = RailVehInfo(eid); const EngineInfo* info = EngInfo(eid); // left window contains compatible engines while right window only contains engines of the selected type if (ENGINE_AVAILABLE && - (RailVehInfo(eid)->power != 0) == (WP(w, replaceveh_d).wagon_btnstate != 0)) { - if (IsCompatibleRail(e->railtype, railtype) && (p->num_engines[eid] > 0 || EngineHasReplacementForPlayer(p, eid))) { + (rvi->power != 0) == (WP(w, replaceveh_d).wagon_btnstate != 0)) { + if (IsCompatibleRail(rvi->railtype, railtype) && (p->num_engines[eid] > 0 || EngineHasReplacementForPlayer(p, eid))) { if (sel[0] == count) selected_id[0] = eid; count++; } - if (e->railtype == railtype && HASBIT(e->player_avail, _local_player)) { + if (rvi->railtype == railtype && HASBIT(e->player_avail, _local_player)) { if (sel[1] == count2) selected_id[1] = eid; count2++; } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 1129c2b54..3355199d9 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -386,7 +386,7 @@ static int DrawRailWagonPurchaseInfo(int x, int y, EngineID engine_number, const } /* Draw locomotive specific details */ -static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi, const Engine *e) +static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, const RailVehicleInfo *rvi) { int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); @@ -403,7 +403,7 @@ static int DrawRailEnginePurchaseInfo(int x, int y, EngineID engine_number, cons y += 10; /* Max tractive effort - not applicable if old acceleration or maglev */ - if (_patches.realistic_acceleration && e->railtype != RAILTYPE_MAGLEV) { + if (_patches.realistic_acceleration && rvi->railtype != RAILTYPE_MAGLEV) { SetDParam(0, ((rvi->weight << multihead) * 10 * rvi->tractive_effort) / 256); DrawString(x, y, STR_PURCHASE_INFO_MAX_TE, 0); y += 10; @@ -532,7 +532,7 @@ void DrawVehiclePurchaseInfo(int x, int y, uint w, EngineID engine_number) if (rvi->flags & RVI_WAGON) { y = DrawRailWagonPurchaseInfo(x, y, engine_number, rvi); } else { - y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi, e); + y = DrawRailEnginePurchaseInfo(x, y, engine_number, rvi); } /* Cargo type + capacity, or N/A */ @@ -601,10 +601,9 @@ static void GenerateBuildTrainList(Window *w) * and if not, reset selection to INVALID_ENGINE. This could be the case * when engines become obsolete and are removed */ for (sel_id = INVALID_ENGINE, eid = 0; eid < NUM_TRAIN_ENGINES; eid++) { - const Engine *e = GetEngine(eid); const RailVehicleInfo *rvi = RailVehInfo(eid); - if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue; + if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, bv->filter.railtype)) continue; if (!IsEngineBuildable(eid, VEH_Train, _local_player)) continue; EngList_Add(&bv->eng_list, eid); diff --git a/src/elrail.cpp b/src/elrail.cpp index f015f5d51..b208c9e07 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -406,12 +406,11 @@ int32 SettingsDisableElrail(int32 p1) /* walk through all train engines */ for (e_id = 0; e_id < NUM_TRAIN_ENGINES; e_id++) { - const RailVehicleInfo *rv_info = RailVehInfo(e_id); - Engine *e = GetEngine(e_id); + RailVehicleInfo *rv_info = &_rail_vehicle_info[e_id]; /* if it is an electric rail engine and its railtype is the wrong one */ - if (rv_info->engclass == 2 && e->railtype == old_railtype) { + if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { /* change it to the proper one */ - e->railtype = new_railtype; + rv_info->railtype = new_railtype; } } diff --git a/src/engine.cpp b/src/engine.cpp index 7cf2f3009..9c30e0cbf 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -180,13 +180,18 @@ void StartupEngines(void) AdjustAvailAircraft(); } -static void AcceptEnginePreview(Engine *e, PlayerID player) +static void AcceptEnginePreview(EngineID eid, PlayerID player) { - Player *p = GetPlayer(player); + Engine *e = GetEngine(eid); - assert(e->railtype < RAILTYPE_END); SETBIT(e->player_avail, player); - SETBIT(p->avail_railtypes, e->railtype); + 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); + } e->preview_player = INVALID_PLAYER; if (player == _local_player) { @@ -247,7 +252,7 @@ void EnginesDailyLoop(void) if (!IsHumanPlayer(best_player)) { /* XXX - TTDBUG: TTD has a bug here ???? */ - AcceptEnginePreview(e, best_player); + AcceptEnginePreview(i, best_player); } else { e->flags |= ENGINE_PREVIEWING; e->preview_wait = 20; @@ -272,7 +277,7 @@ int32 CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) e = GetEngine(p1); if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR; - if (flags & DC_EXEC) AcceptEnginePreview(e, _current_player); + if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_player); return 0; } @@ -323,15 +328,14 @@ static void NewVehicleAvailable(Engine *e) // Do not introduce new rail wagons if (IsWagon(index)) return; - // make maglev / monorail available - FOR_ALL_PLAYERS(p) { - if (p->is_active) { - assert(e->railtype < RAILTYPE_END); - SETBIT(p->avail_railtypes, e->railtype); + if (index < NUM_TRAIN_ENGINES) { + // maybe make another rail type available + RailType railtype = RailVehInfo(index)->railtype; + assert(railtype < RAILTYPE_END); + FOR_ALL_PLAYERS(p) { + if (p->is_active) SETBIT(p->avail_railtypes, railtype); } - } - if (index < NUM_TRAIN_ENGINES) { AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0); } else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) { AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0); @@ -603,7 +607,7 @@ static const SaveLoad _engine_desc[] = { SLE_VAR(Engine, flags, SLE_UINT8), SLE_VAR(Engine, preview_player, SLE_UINT8), SLE_VAR(Engine, preview_wait, SLE_UINT8), - SLE_VAR(Engine, railtype, SLE_UINT8), + SLE_CONDNULL(1, 0, 44), SLE_VAR(Engine, player_avail, SLE_UINT8), // reserve extra space in savegame here. (currently 16 bytes) diff --git a/src/engine.h b/src/engine.h index ef272f4d7..05ffb33a7 100644 --- a/src/engine.h +++ b/src/engine.h @@ -13,7 +13,7 @@ typedef struct RailVehicleInfo { byte image_index; byte flags; /* 1=multihead engine, 2=wagon */ byte base_cost; - byte railtype; + RailTypeByte railtype; uint16 max_speed; uint16 power; uint16 weight; @@ -100,7 +100,6 @@ typedef struct Engine { byte flags; PlayerByte preview_player; byte preview_wait; - RailTypeByte railtype; byte player_avail; byte type; // type, ie VEH_Road, VEH_Train, etc. Same as in vehicle.h } Engine; diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp index 08186b822..2f8307313 100644 --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -19,7 +19,7 @@ static StringID GetEngineCategoryName(EngineID engine) { if (engine < NUM_TRAIN_ENGINES) { - switch (GetEngine(engine)->railtype) { + switch (RailVehInfo(engine)->railtype) { case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE; case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE; case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE; diff --git a/src/oldloader.cpp b/src/oldloader.cpp index 5cf2973d6..841a76569 100644 --- a/src/oldloader.cpp +++ b/src/oldloader.cpp @@ -1249,9 +1249,8 @@ static const OldChunks engine_chunk[] = { OCL_SVAR( OC_UINT8, Engine, flags ), OCL_SVAR( OC_UINT8, Engine, preview_player ), OCL_SVAR( OC_UINT8, Engine, preview_wait ), - OCL_SVAR( OC_UINT8, Engine, railtype ), - OCL_NULL( 1 ), // Junk + OCL_NULL( 2 ), // Junk OCL_END() }; diff --git a/src/openttd.cpp b/src/openttd.cpp index 33595d885..1a85591d8 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1413,20 +1413,11 @@ bool AfterLoadGame(void) /* Elrails got added in rev 24 */ if (CheckSavegameVersion(24)) { Vehicle *v; - uint i; RailType min_rail = RAILTYPE_ELECTRIC; - for (i = 0; i < lengthof(_engines); i++) { - Engine *e = GetEngine(i); - if (e->type == VEH_Train && - (e->railtype != RAILTYPE_RAIL || RailVehInfo(i)->engclass == 2)) { - e->railtype++; - } - } - FOR_ALL_VEHICLES(v) { if (v->type == VEH_Train) { - RailType rt = GetEngine(v->engine_type)->railtype; + RailType rt = RailVehInfo(v->engine_type)->railtype; v->u.rail.railtype = rt; if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL; diff --git a/src/players.cpp b/src/players.cpp index 9cf74ae70..b306a0632 100644 --- a/src/players.cpp +++ b/src/players.cpp @@ -653,10 +653,13 @@ byte GetPlayerRailtypes(PlayerID p) const EngineInfo *ei = EngInfo(i); if (e->type == VEH_Train && HASBIT(ei->climates, _opt.landscape) && - (HASBIT(e->player_avail, p) || _date >= (e->intro_date + 365)) && - !(RailVehInfo(i)->flags & RVI_WAGON)) { - assert(e->railtype < RAILTYPE_END); - SETBIT(rt, e->railtype); + (HASBIT(e->player_avail, p) || _date >= e->intro_date + 365)) { + const RailVehicleInfo *rvi = RailVehInfo(i); + + if (!(rvi->flags & RVI_WAGON)) { + assert(rvi->railtype < RAILTYPE_END); + SETBIT(rt, rvi->railtype); + } } } diff --git a/src/table/engines.h b/src/table/engines.h index 4e481974e..9c56435fe 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -328,18 +328,17 @@ const EngineInfo orig_engine_info[] = { * @param l railtype * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76 */ -#define RVI(a, b, c, d, e, f, g, h, i, j, k, l) { a, b, c, l, d, e, f, g, h, h, i, j, k, 0, 0, 0, 0, 76, 0 } +#define RVI(a, b, c, d, e, f, g, h, i, j, k, l) { a, b, c, {l}, d, e, f, g, h, h, i, j, k, 0, 0, 0, 0, 76, 0 } #define M RVI_MULTIHEAD #define W RVI_WAGON #define S 0 #define D 1 #define E 2 -// Rail types -#define R 0 // Conventional railway -#define C 1 // Electrified railway -#define O 2 // Monorail -#define L 3 // MagLev +#define R RAILTYPE_RAIL +#define C RAILTYPE_ELECTRIC +#define O RAILTYPE_MONO +#define L RAILTYPE_MAGLEV const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES] = { // image_index max_speed (kph) running_cost_base @@ -370,10 +369,10 @@ const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES] = { RVI(16, M, 35, 160, 3500/2,95/2, 205/2, D, 0, 0 , 45, R), // 20 RVI(18, 0, 21, 104, 2200, 120, 145, D, 0, 0 , 32, R), // 21 RVI( 6, M, 20, 200, 4500/2,70/2, 190/2, D, 4, CT_MAIL , 50, R), // 22 - RVI(20, 0, 26, 160, 3600, 84, 180, E, 0, 0 , 40, E), // 23 - RVI(20, 0, 30, 176, 5000, 82, 205, E, 0, 0 , 41, E), // 24 - RVI(21, M, 40, 240, 7000/2,90/2, 240/2, E, 0, 0 , 51, E), // 25 - RVI(23, M, 43, 264, 8000/2,95/2, 250/2, E, 0, 0 , 52, E), // 26 + RVI(20, 0, 26, 160, 3600, 84, 180, E, 0, 0 , 40, C), // 23 + RVI(20, 0, 30, 176, 5000, 82, 205, E, 0, 0 , 41, C), // 24 + RVI(21, M, 40, 240, 7000/2,90/2, 240/2, E, 0, 0 , 51, C), // 25 + RVI(23, M, 43, 264, 8000/2,95/2, 250/2, E, 0, 0 , 52, C), // 26 RVI(33, W, 247, 0, 0, 25, 0, 0, 40, CT_PASSENGERS , 0, R), // 27 RVI(35, W, 228, 0, 0, 21, 0, 0, 30, CT_MAIL , 0, R), // 28 RVI(34, W, 176, 0, 0, 18, 0, 0, 30, CT_COAL , 0, R), // 29 diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 8e82f0b4f..d5ea4570d 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -164,7 +164,7 @@ void TrainConsistChanged(Vehicle* v) // update the 'first engine' u->u.rail.first_engine = (v == u) ? (EngineID)INVALID_ENGINE : first_engine; - u->u.rail.railtype = GetEngine(u->engine_type)->railtype; + u->u.rail.railtype = rvi_u->railtype; if (IsTrainEngine(u)) first_engine = u->engine_type; @@ -658,7 +658,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags) v->value = value; // v->day_counter = 0; - v->u.rail.railtype = GetEngine(engine)->railtype; + v->u.rail.railtype = rvi->railtype; v->build_year = _cur_year; v->type = VEH_Train; @@ -745,7 +745,6 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) int value; Vehicle *v; UnitID unit_num; - Engine *e; uint num_vehicles; /* Check if the engine-type is valid (for the player) */ @@ -761,11 +760,10 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); rvi = RailVehInfo(p1); - e = GetEngine(p1); /* Check if depot and new engine uses the same kind of tracks */ /* We need to see if the engine got power on the tile to avoid eletric engines in non-electric depots */ - if (!HasPowerOnRail(e->railtype, GetRailType(tile))) return CMD_ERROR; + if (!HasPowerOnRail(rvi->railtype, GetRailType(tile))) return CMD_ERROR; if (rvi->flags & RVI_WAGON) return CmdBuildRailWagon(p1, tile, flags); @@ -814,12 +812,13 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->engine_type = p1; + const Engine *e = GetEngine(p1); v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; v->max_age = e->lifelength * 366; v->string_id = STR_SV_TRAIN_NAME; - v->u.rail.railtype = e->railtype; + v->u.rail.railtype = rvi->railtype; _new_vehicle_id = v->index; v->service_interval = _patches.servint_trains; @@ -2084,16 +2083,16 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v) u = v; do { - EngineID engtype = v->engine_type; + const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); int effect_offset = GB(v->u.rail.cached_vis_effect, 0, 4) - 8; byte effect_type = GB(v->u.rail.cached_vis_effect, 4, 2); bool disable_effect = HASBIT(v->u.rail.cached_vis_effect, 6); int x, y; // no smoke? - if ((RailVehInfo(engtype)->flags & RVI_WAGON && effect_type == 0) || + if ((rvi->flags & RVI_WAGON && effect_type == 0) || disable_effect || - GetEngine(engtype)->railtype > RAILTYPE_ELECTRIC || + rvi->railtype > RAILTYPE_ELECTRIC || v->vehstatus & VS_HIDDEN) { continue; } @@ -2106,7 +2105,7 @@ static void HandleLocomotiveSmokeCloud(const Vehicle* v) if (effect_type == 0) { // Use default effect type for engine class. - effect_type = RailVehInfo(engtype)->engclass; + effect_type = rvi->engclass; } else { effect_type--; } @@ -2161,7 +2160,7 @@ static void TrainPlayLeaveStationSound(const Vehicle* v) if (PlayVehicleSound(v, VSE_START)) return; - switch (GetEngine(engtype)->railtype) { + switch (RailVehInfo(engtype)->railtype) { case RAILTYPE_RAIL: case RAILTYPE_ELECTRIC: SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], v); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index ba52ecee8..41be1ea75 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2837,6 +2837,7 @@ static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, Engine const RailVehicleInfo *rvi = RailVehInfo(engine_type); switch (rvi->railtype) { + default: NOT_REACHED(); case RAILTYPE_RAIL: case RAILTYPE_ELECTRIC: { |