From 7cf8dd70c3e2c1687a86fcfd2a4e017400fe734b Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 20 Aug 2010 18:28:46 +0000 Subject: [PATCH] (svn r20585) [1.0] -Backport from trunk: - Fix: Autoreplace failed while attaching non-replaced wagons to the new chain, if to-be-sold-engines would become front-engines and the unitnumber limit would be exceeded (r20583) - Fix: Autoreplace can trigger an assertion when at the vehicle limit [FS#4044] (r20582) - Fix: Go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again [FS#4039] (r20580) - Fix: Draw bounding boxes using white instead of pure white, so they are recoloured to grey in coloured newspaper instead of blue [FS#4051] (r20578) - Fix: Scroll button flickering when pressed [FS#4043] (r20577) --- src/autoreplace_cmd.cpp | 8 ++++++++ src/gfx.cpp | 2 +- src/order_cmd.cpp | 8 ++++++-- src/train_cmd.cpp | 9 +++++---- src/vehicle.cpp | 4 +++- src/widget.cpp | 8 ++++---- src/window.cpp | 10 +++------- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 26a92e5197..be66b21801 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -454,6 +454,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon /* Append engines to the new chain * We do this from back to front, so that the head of the temporary vehicle chain does not change all the time. + * That way we also have less trouble when exceeding the unitnumber limit. * OTOH the vehicle attach callback is more expensive this way :s */ Train *last_engine = NULL; ///< Shall store the last engine unit after this step if (cost.Succeeded()) { @@ -462,6 +463,13 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue; + if (new_vehs[i] != NULL) { + /* Move the old engine to a separate row with DC_AUTOREPLACE. Else + * moving the wagon in front may fail later due to unitnumber limit. + * (We have to attach wagons without DC_AUTOREPLACE.) */ + MoveVehicle(old_vehs[i], NULL, DC_EXEC | DC_AUTOREPLACE, false); + } + if (last_engine == NULL) last_engine = append; cost.AddCost(MoveVehicle(append, new_head, DC_EXEC, false)); if (cost.Failed()) break; diff --git a/src/gfx.cpp b/src/gfx.cpp index d84ab8b3c5..fb8f3f88ee 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -229,7 +229,7 @@ void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) * ....V. */ - static const byte colour = 255; + static const byte colour = 15; GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, colour); GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, colour); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 672013b166..025bc40430 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1775,11 +1775,15 @@ bool ProcessOrders(Vehicle *v) */ bool may_reverse = v->current_order.IsType(OT_NOTHING); - /* Check if we've reached a non-stop station.. */ + /* Check if we've reached a 'via' destination. */ if (((v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) || v->current_order.IsType(OT_GOTO_WAYPOINT)) && IsTileType(v->tile, MP_STATION) && v->current_order.GetDestination() == GetStationIndex(v->tile)) { - if (v->current_order.IsType(OT_GOTO_STATION)) v->last_station_visited = v->current_order.GetDestination(); + /* We set the last visited station here because we do not want + * the train to stop at this 'via' station if the next order + * is a no-non-stop order; in that case not setting the last + * visited station will cause the vehicle to still stop. */ + v->last_station_visited = v->current_order.GetDestination(); UpdateVehicleTimetable(v, true); v->IncrementOrderIndex(); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 88937591e8..947ac7e232 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1228,9 +1228,10 @@ static CommandCost CheckTrainAttachment(Train *t) * @param dst The destination chain after constructing the train. * @param original_dst The original source chain. * @param dst The source chain after constructing the train. + * @param check_limit Whether to check the vehicle limit. * @return possible error of this command. */ -static CommandCost ValidateTrains(Train *original_dst, Train *dst, Train *original_src, Train *src) +static CommandCost ValidateTrains(Train *original_dst, Train *dst, Train *original_src, Train *src, bool check_limit) { /* Check whether we may actually construct the trains. */ CommandCost ret = CheckTrainAttachment(src); @@ -1239,7 +1240,7 @@ static CommandCost ValidateTrains(Train *original_dst, Train *dst, Train *origin if (ret.Failed()) return ret; /* Check whether we need to build a new train. */ - return CheckNewTrain(original_dst, dst, original_src, src); + return check_limit ? CheckNewTrain(original_dst, dst, original_src, src) : CommandCost(); } /** @@ -1403,7 +1404,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u /* If the autoreplace flag is set we do not need to test for the validity * because we are going to revert the train to its original state. As we * assume the original state was correct autoreplace can skip this. */ - CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head); + CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true); if (ret.Failed()) { /* Restore the train we had. */ RestoreTrainBackup(original_src); @@ -1533,7 +1534,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin ArrangeTrains(&sell_head, NULL, &new_head, v, sell_chain); /* We don't need to validate the second train; it's going to be sold. */ - CommandCost ret = ValidateTrains(NULL, NULL, first, new_head); + CommandCost ret = ValidateTrains(NULL, NULL, first, new_head, (flags & DC_AUTOREPLACE) == 0); if (ret.Failed()) { /* Restore the train we had. */ RestoreTrainBackup(original); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 81a5fe22ed..26058c44e6 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -971,7 +971,9 @@ uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour) bool loading = false; const Vehicle *u = v; - const Station *st = v->last_station_visited != INVALID_STATION ? Station::Get(v->last_station_visited) : NULL; + /* The station may be NULL when the (colour) string does not need to be set. */ + const Station *st = Station::GetIfValid(v->last_station_visited); + assert(colour == NULL || st != NULL); /* Count up max and used */ for (; v != NULL; v = v->Next()) { diff --git a/src/widget.cpp b/src/widget.cpp index 0aa988d622..6e9274bc54 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -107,8 +107,8 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i if (pos <= mi + 9) { /* Pressing the upper button? */ w->flags4 |= WF_SCROLL_UP; - if (_scroller_click_timeout == 0) { - _scroller_click_timeout = 6; + if (_scroller_click_timeout <= 1) { + _scroller_click_timeout = 3; sb->UpdatePosition(rtl ? 1 : -1); } _left_button_clicked = false; @@ -116,8 +116,8 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i /* Pressing the lower button? */ w->flags4 |= WF_SCROLL_DOWN; - if (_scroller_click_timeout == 0) { - _scroller_click_timeout = 6; + if (_scroller_click_timeout <= 1) { + _scroller_click_timeout = 3; sb->UpdatePosition(rtl ? -1 : 1); } _left_button_clicked = false; diff --git a/src/window.cpp b/src/window.cpp index 0a8079ef24..285fbd2aaa 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -53,7 +53,7 @@ Point _cursorpos_drag_start; int _scrollbar_start_pos; int _scrollbar_size; -byte _scroller_click_timeout; +byte _scroller_click_timeout = 0; bool _scrolling_scrollbar; bool _scrolling_viewport; @@ -1321,7 +1321,7 @@ static void DecreaseWindowCounters() Window *w; FOR_ALL_WINDOWS_FROM_FRONT(w) { /* Unclick scrollbar buttons if they are pressed. */ - if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { + if (_scroller_click_timeout == 0 && w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); w->SetDirty(); } @@ -2388,11 +2388,7 @@ void InvalidateWindowClassesData(WindowClass cls, int data) */ void CallWindowTickEvent() { - if (_scroller_click_timeout > 3) { - _scroller_click_timeout -= 3; - } else { - _scroller_click_timeout = 0; - } + if (_scroller_click_timeout != 0) _scroller_click_timeout--; Window *w; FOR_ALL_WINDOWS_FROM_FRONT(w) {