From d6e34c9ad0b0e8889562426f4f5dc1a0f399fddf Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 16 Aug 2010 23:06:22 +0000 Subject: [PATCH] (svn r20520) [1.0] -Backport from trunk: - Fix: Draw error messages in white by default, they may not have a colour set when coming from a NewGRF (r20514) - Fix: Entering half the 'generation seeds' in the console's 'newgame' command failed to set the correct seed [FS#4036] (r20512) - Fix: Desync when converting rail all as trains with a part on the converted rails need updating and not only the engines (r20500) - Fix: Ignore the non-stop state when comparing one order type to another order type, otherwise non-stop nearest depot orders fail [FS#4030] (r20498) - Fix: Non-dedicated servers failing to load a game caused the introgame to be the server's game causing desyncs when people tried to join [FS#3960] (r20497) --- src/console_cmds.cpp | 2 +- src/misc_gui.cpp | 5 +++-- src/network/network.cpp | 3 +++ src/openttd.cpp | 6 ++++++ src/order_cmd.cpp | 2 +- src/rail_cmd.cpp | 28 ++++++++++++++++++---------- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 45a4690fd9..6e4618b65e 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -955,7 +955,7 @@ DEF_CONSOLE_CMD(ConNewGame) return true; } - StartNewGameWithoutGUI((argc == 2) ? (uint)atoi(argv[1]) : GENERATE_NEW_SEED); + StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], NULL, 10) : (uint)GENERATE_NEW_SEED); return true; } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 6f61397753..78b1567bd5 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -650,13 +650,14 @@ public: } else { int extra = (r.bottom - r.top + 1 - this->height_summary - this->height_detailed - WD_PAR_VSEP_WIDE) / 2; + /* Note: NewGRF supplied error message often do not start with a colour code, so default to white. */ int top = r.top + WD_FRAMERECT_TOP; int bottom = top + this->height_summary + extra; - DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->summary_msg, TC_FROMSTRING, SA_CENTER); + DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->summary_msg, TC_WHITE, SA_CENTER); bottom = r.bottom - WD_FRAMERECT_BOTTOM; top = bottom - this->height_detailed - extra; - DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->detailed_msg, TC_FROMSTRING, SA_CENTER); + DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, top, bottom, this->detailed_msg, TC_WHITE, SA_CENTER); } SwitchToNormalRefStack(); // Switch back to the normal text ref. stack for NewGRF texts. diff --git a/src/network/network.cpp b/src/network/network.cpp index ba80da4642..082dd18a41 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -934,6 +934,9 @@ void NetworkDisconnect(bool blocking) DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); NetworkClose(); + + /* Reinitialize the UDP stack, i.e. close all existing connections. */ + NetworkUDPInitialize(); } /** diff --git a/src/openttd.cpp b/src/openttd.cpp index 928308d2db..37ea9f641c 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -878,6 +878,7 @@ bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory case SL_OK: return true; case SL_REINIT: +#ifdef ENABLE_NETWORK if (_network_dedicated) { /* * We need to reinit a network map... @@ -889,6 +890,11 @@ bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory MakeNewGame(false, true); return false; } + if (_network_server) { + /* We can't load the intro game as server, so disconnect first. */ + NetworkDisconnect(); + } +#endif /* ENABLE_NETWORK */ switch (ogm) { default: diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index fb282c7187..672013b166 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -115,7 +115,7 @@ bool Order::Equals(const Order &other) const * destination because those get clear/filled in during the order * evaluation. If we do not do this the order will continuously be seen as * a different order and it will try to find a "nearest depot" every tick. */ - if ((this->type == OT_GOTO_DEPOT && this->type == other.type) && + if ((this->IsType(OT_GOTO_DEPOT) && this->type == other.type) && ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0 || (other.GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0)) { return diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 2aeb3c5026..b882e30a54 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -41,6 +41,9 @@ #include "table/railtypes.h" #include "table/track_land.h" +/** Helper type for lists/vectors of trains */ +typedef SmallVector TrainList; + RailtypeInfo _railtypes[RAILTYPE_END]; assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes)); @@ -1344,12 +1347,8 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data) if (v->type != VEH_TRAIN) return NULL; /* Similar checks as in Train::PowerChanged() */ - - Train *t = Train::From(v); - if (t->IsArticulatedPart()) return NULL; - - const RailVehicleInfo *rvi = RailVehInfo(t->engine_type); - if (GetVehicleProperty(t, PROP_TRAIN_POWER, rvi->power) != 0) t->First()->PowerChanged(); + TrainList *affected_trains = static_cast(data); + affected_trains->Include(Train::From(v)->First()); return NULL; } @@ -1381,6 +1380,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (ey < sy) Swap(ey, sy); _error_message = STR_ERROR_NO_SUITABLE_RAILROAD_TRACK; // by default, there is no track to convert + TrainList affected_trains; for (uint x = sx; x <= ex; ++x) { for (uint y = sy; y <= ey; ++y) { @@ -1436,8 +1436,8 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 SetRailType(tile, totype); MarkTileDirtyByTile(tile); - /* update power of train engines on this tile */ - FindVehicleOnPos(tile, NULL, &UpdateTrainPowerProc); + /* update power of train on this tile */ + FindVehicleOnPos(tile, &affected_trains, &UpdateTrainPowerProc); } } @@ -1494,8 +1494,8 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 SetRailType(tile, totype); SetRailType(endtile, totype); - FindVehicleOnPos(tile, NULL, &UpdateTrainPowerProc); - FindVehicleOnPos(endtile, NULL, &UpdateTrainPowerProc); + FindVehicleOnPos(tile, &affected_trains, &UpdateTrainPowerProc); + FindVehicleOnPos(endtile, &affected_trains, &UpdateTrainPowerProc); YapfNotifyTrackLayoutChange(tile, track); YapfNotifyTrackLayoutChange(endtile, track); @@ -1529,6 +1529,14 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } } + if (flags & DC_EXEC) { + /* Railtype changed, update trains as when entering different track */ + for (Train **v = affected_trains.Begin(); v != affected_trains.End(); v++) { + (*v)->PowerChanged(); + (*v)->UpdateAcceleration(); + } + } + return (cost.GetCost() == 0) ? CMD_ERROR : cost; }