From 98f77876e6d55ce1efeda1b614984b09366c9935 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 19 Mar 2007 18:47:10 +0000 Subject: [PATCH] (svn r9341) [0.5] -Backport from trunk (r8943, r8955, r8976, r8999, r9009): - Fix: NewGRF support for vehicle variable 48 (r8943) - Fix: crash on loading savegames with GRFs that do not have their GRF info/name set (r8955) - Fix: reinitialize all engines after grf files have been reloaded/changed (r8976) - Fix: do not select a disabled platform length/number of track count when going out of drag-drop mode (r8999) - Fix: play the correct engine sound based on the engine type instead of the sprite (r9009) --- newgrf_config.c | 4 ++-- newgrf_engine.c | 19 ++----------------- openttd.c | 1 + rail_gui.c | 38 ++++++++++++++++++++++++++++++++++++-- tunnelbridge_cmd.c | 2 +- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/newgrf_config.c b/newgrf_config.c index cf58551d5c..c294f4db4b 100644 --- a/newgrf_config.c +++ b/newgrf_config.c @@ -241,8 +241,8 @@ compatible_grf: free(c->filename); c->filename = strdup(f->filename); memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum)); - if (c->name == NULL) c->name = strdup(f->name); - if (c->info == NULL) c->info = strdup(f->info); + if (c->name == NULL && f->name != NULL) c->name = strdup(f->name); + if (c->info == NULL && f->info != NULL) c->info = strdup(f->info); } } } diff --git a/newgrf_engine.c b/newgrf_engine.c index 067f902054..fe50259135 100644 --- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -523,21 +523,6 @@ static void VehicleSetTriggers(const ResolverObject *object, int triggers) } -static uint32 GetVehicleTypeInfo(EngineID engine_type) -{ - /* Bit 0 Vehicle type is available on the market - * Bit 1 Vehicle type is in the testing phase - * Bit 2 Exclusive testing offer for a human player active */ - const Engine *e = GetEngine(engine_type); - uint32 var = 0; - - if (e->player_avail == 0xFF) SETBIT(var, 0); - if (e->age < e->duration_phase_1) SETBIT(var, 1); - if (e->player_avail > 0 && e->player_avail != 0xFF) SETBIT(var, 2); - return var; -} - - static uint32 GetGRFParameter(EngineID engine_type, byte parameter) { const GRFFile *file = GetEngineGRF(engine_type); @@ -556,7 +541,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by switch (variable) { case 0x43: return _current_player; /* Owner information */ case 0x46: return 0; /* Motion counter */ - case 0x48: return GetVehicleTypeInfo(object->u.vehicle.self_type); /* Vehicle Type Info */ + case 0x48: return GetEngine(object->u.vehicle.self_type)->flags; /* Vehicle Type Info */ case 0xC4: return clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; /* Build year */ case 0xDA: return INVALID_VEHICLE; /* Next vehicle */ case 0x7F: return GetGRFParameter(object->u.vehicle.self_type, parameter); /* Read GRF parameter */ @@ -669,7 +654,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by return (_cargo_classes[cid] << 16) | (_cargoc.weights[v->cargo_type] << 8) | cid; } - case 0x48: return GetVehicleTypeInfo(v->engine_type); /* Vehicle Type Info */ + case 0x48: return GetEngine(v->engine_type)->flags; /* Vehicle Type Info */ /* Variables which use the parameter */ case 0x60: /* Count consist's engine ID occurance */ diff --git a/openttd.c b/openttd.c index 8cff6ea632..c8ef91f688 100644 --- a/openttd.c +++ b/openttd.c @@ -1611,6 +1611,7 @@ void ReloadNewGRFData(void) /* reload vehicles */ ResetVehiclePosHash(); AfterLoadVehicles(); + StartupEngines(); /* update station and waypoint graphics */ AfterLoadWaypoints(); AfterLoadStations(); diff --git a/rail_gui.c b/rail_gui.c index 4b651db5e0..4fffcefd34 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -795,16 +795,33 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) case 8: case 9: case 10: - case 11: + case 11: { + const StationSpec *statspec; RaiseWindowWidget(w, _railstation.numtracks + 4); RaiseWindowWidget(w, 19); + _railstation.numtracks = (e->we.click.widget - 5) + 1; _railstation.dragdrop = false; + + statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL; + if (statspec != NULL && HASBIT(statspec->disallowed_lengths, _railstation.platlength - 1)) { + /* The previously selected number of platforms in invalid */ + uint i; + for (i = 0; i < 7; i++) { + if (!HASBIT(statspec->disallowed_lengths, i)) { + RaiseWindowWidget(w, _railstation.platlength + 11); + _railstation.platlength = i + 1; + break; + } + } + } + LowerWindowWidget(w, _railstation.platlength + 11); LowerWindowWidget(w, _railstation.numtracks + 4); SndPlayFx(SND_15_BEEP); SetWindowDirty(w); break; + } case 12: case 13: @@ -812,16 +829,33 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) case 15: case 16: case 17: - case 18: + case 18: { + const StationSpec *statspec; RaiseWindowWidget(w, _railstation.platlength + 11); RaiseWindowWidget(w, 19); + _railstation.platlength = (e->we.click.widget - 12) + 1; _railstation.dragdrop = false; + + statspec = _railstation.newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL; + if (statspec != NULL && HASBIT(statspec->disallowed_platforms, _railstation.numtracks - 1)) { + /* The previously selected number of tracks in invalid */ + uint i; + for (i = 0; i < 7; i++) { + if (!HASBIT(statspec->disallowed_platforms, i)) { + RaiseWindowWidget(w, _railstation.numtracks + 4); + _railstation.numtracks = i + 1; + break; + } + } + } + LowerWindowWidget(w, _railstation.platlength + 11); LowerWindowWidget(w, _railstation.numtracks + 4); SndPlayFx(SND_15_BEEP); SetWindowDirty(w); break; + } case 19: _railstation.dragdrop ^= true; diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 981ee16797..1ca2568284 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -1376,7 +1376,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y if (v->u.rail.track != 0x40 && dir == vdir) { if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { - if (!PlayVehicleSound(v, VSE_TUNNEL) && v->spritenum < 4) { + if (!PlayVehicleSound(v, VSE_TUNNEL) && RailVehInfo(v->engine_type)->engclass == 0) { SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v); } return 0;