diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index a25b8e9035..5e417c785c 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -374,6 +374,7 @@ struct AISettingsWindow : public Window { /* One of the arrows is clicked (or green/red rect in case of bool value) */ if (IsInsideMM(x, 0, 21)) { int new_val = this->ai_config->GetSetting(config_item.name); + int old_val = new_val; if (bool_item) { new_val = !new_val; } else if (x >= 10) { @@ -388,18 +389,19 @@ struct AISettingsWindow : public Window { this->clicked_increase = false; } - this->ai_config->SetSetting(config_item.name, new_val); - this->clicked_button = num; - this->timeout = 5; + if (new_val != old_val) { + this->ai_config->SetSetting(config_item.name, new_val); + this->clicked_button = num; + this->timeout = 5; - this->CheckDifficultyLevel(); + this->CheckDifficultyLevel(); + } } else if (!bool_item) { /* Display a query box so users can enter a custom value. */ this->clicked_row = num; SetDParam(0, this->ai_config->GetSetting(config_item.name)); ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, 100, this, CS_NUMERAL, QSF_NONE); } - this->SetDirty(); break; } diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index f7d4348f90..08d703756c 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -216,7 +216,7 @@ void CargoList::Truncate(uint max_remaining) CargoPacket *cp = *it; if (max_remaining == 0) { /* Nothing should remain, just remove the packets. */ - this->packets.erase(it++); + it = this->packets.erase(it); static_cast(this)->RemoveFromCache(cp); delete cp; continue; @@ -276,7 +276,7 @@ bool CargoList::MoveTo(Tother_inst *dest, uint max_move, MoveToAction mta if (cp->count <= max_move) { /* Can move the complete packet */ max_move -= cp->count; - this->packets.erase(it++); + it = this->packets.erase(it); static_cast(this)->RemoveFromCache(cp); switch (mta) { case MTA_FINAL_DELIVERY: diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 9ff94b7e0d..e901721fa2 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -325,6 +325,7 @@ struct NewGRFParametersWindow : public Window { /* One of the arrows is clicked */ if (IsInsideMM(x, 0, 21)) { uint32 val = par_info->GetValue(this->grf_config); + uint32 old_val = val; if (par_info->type == PTYPE_BOOL) { val = !val; } else { @@ -338,16 +339,17 @@ struct NewGRFParametersWindow : public Window { this->clicked_increase = false; } } - par_info->SetValue(this->grf_config, val); + if (val != old_val) { + par_info->SetValue(this->grf_config, val); - this->clicked_button = num; - this->timeout = 5; + this->clicked_button = num; + this->timeout = 5; + } } else if (par_info->type == PTYPE_UINT_ENUM && click_count >= 2) { /* Display a query box so users can enter a custom value. */ SetDParam(0, this->grf_config->param[num]); ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, 100, this, CS_NUMERAL, QSF_NONE); } - this->SetDirty(); break; } diff --git a/src/newgrf_storage.cpp b/src/newgrf_storage.cpp index 27a806ab1f..58e4646e1f 100644 --- a/src/newgrf_storage.cpp +++ b/src/newgrf_storage.cpp @@ -14,7 +14,15 @@ #include /** The changed storage arrays */ -static std::set _changed_storage_arrays; +static std::set *_changed_storage_arrays = new std::set; + +/** + * Remove references to use. + */ +BaseStorageArray::~BaseStorageArray() +{ + _changed_storage_arrays->erase(this); +} /** * Add the changed storage array to the list of changed arrays. @@ -24,7 +32,7 @@ static std::set _changed_storage_arrays; */ void AddChangedStorage(BaseStorageArray *storage) { - _changed_storage_arrays.insert(storage); + _changed_storage_arrays->insert(storage); } /** @@ -40,10 +48,10 @@ void AddChangedStorage(BaseStorageArray *storage) void ClearStorageChanges(bool keep_changes) { /* Loop over all changes arrays */ - for (std::set::iterator it = _changed_storage_arrays.begin(); it != _changed_storage_arrays.end(); it++) { + for (std::set::iterator it = _changed_storage_arrays->begin(); it != _changed_storage_arrays->end(); it++) { (*it)->ClearChanges(keep_changes); } /* And then clear that array */ - _changed_storage_arrays.clear(); + _changed_storage_arrays->clear(); } diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index 0686a1ab1c..a7f5788c4a 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -20,8 +20,7 @@ */ struct BaseStorageArray { - /** The needed destructor */ - virtual ~BaseStorageArray() {} + virtual ~BaseStorageArray(); /** * Clear the changes made since the last ClearChanges. diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 35c764ac49..9737a57cea 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1807,8 +1807,9 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v) * @param order the order the vehicle currently has * @param v the vehicle to update * @param conditional_depth the depth (amount of steps) to go with conditional orders. This to prevent infinite loops. + * @param pbs_look_ahead Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified. */ -bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) +bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead) { if (conditional_depth > v->GetNumOrders()) return false; @@ -1819,6 +1820,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) case OT_GOTO_DEPOT: if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) { + assert(!pbs_look_ahead); UpdateVehicleTimetable(v, true); v->IncrementRealOrderIndex(); break; @@ -1831,6 +1833,9 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) bool reverse; if (v->FindClosestDepot(&location, &destination, &reverse)) { + /* PBS reservations cannot reverse */ + if (pbs_look_ahead && reverse) return false; + v->dest_tile = location; v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo(), v->current_order.GetRefitSubtype()); @@ -1848,6 +1853,9 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) return true; } + /* If there is no depot, we cannot help PBS either. */ + if (pbs_look_ahead) return false; + UpdateVehicleTimetable(v, true); v->IncrementRealOrderIndex(); } else { @@ -1863,6 +1871,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) return true; case OT_CONDITIONAL: { + assert(!pbs_look_ahead); VehicleOrderID next_order = ProcessConditionalOrder(order, v); if (next_order != INVALID_VEH_ORDER_ID) { /* Jump to next_order. cur_implicit_order_index becomes exactly that order, @@ -1907,7 +1916,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) } v->current_order = *order; - return UpdateOrderDest(v, order, conditional_depth + 1); + return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead); } /** diff --git a/src/order_func.h b/src/order_func.h index c6ed76d23a..ba3d7e6b57 100644 --- a/src/order_func.h +++ b/src/order_func.h @@ -22,7 +22,7 @@ void InvalidateVehicleOrder(const Vehicle *v, int data); void CheckOrders(const Vehicle*); void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist = false, bool reset_order_indices = true); bool ProcessOrders(Vehicle *v); -bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth = 0); +bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth = 0, bool pbs_look_ahead = false); VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v); void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 249bb6c9f5..86930c18e8 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2340,8 +2340,7 @@ public: case OT_GOTO_STATION: case OT_GOTO_WAYPOINT: this->v->current_order = *order; - UpdateOrderDest(this->v, order); - return true; + return UpdateOrderDest(this->v, order, 0, true); case OT_CONDITIONAL: { if (conditional_depth > this->v->GetNumOrders()) return false; VehicleOrderID next = ProcessConditionalOrder(order, this->v);