diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 8944e8bc4f..a0720e2ea5 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -28,6 +28,7 @@ #include "../widgets/dropdown_type.h" #include "../widgets/dropdown_func.h" #include "../hotkeys.h" +#include "../core/geometry_func.hpp" #include "ai.hpp" #include "ai_gui.hpp" @@ -766,6 +767,22 @@ struct AIConfigWindow : public Window { this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; size->height = 8 * this->line_height; break; + + case WID_AIC_CHANGE: { + SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT); + Dimension dim = GetStringBoundingBox(STR_AI_CONFIG_CHANGE); + + SetDParam(0, STR_AI_CONFIG_CHANGE_NONE); + dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE)); + + SetDParam(0, STR_AI_CONFIG_CHANGE_AI); + dim = maxdim(dim, GetStringBoundingBox(STR_AI_CONFIG_CHANGE)); + + dim.width += padding.width; + dim.height += padding.height; + *size = maxdim(*size, dim); + break; + } } } diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 193c5ac4a8..8c372e7eae 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -433,6 +433,7 @@ void AddArticulatedParts(Vehicle *first) v->x_pos = first->x_pos; v->y_pos = first->y_pos; v->z_pos = first->z_pos; + v->date_of_last_service = first->date_of_last_service; v->build_year = first->build_year; v->vehstatus = first->vehstatus & ~VS_STOPPED; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 4aff4700b3..24a14b8334 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -663,7 +663,8 @@ struct DepotWindow : Window { DepotSortList(&this->vehicle_list); uint new_unitnumber_digits = GetUnitNumberDigits(this->vehicle_list); - if (this->unitnumber_digits != new_unitnumber_digits) { + /* Only increase the size; do not decrease to prevent constant changes */ + if (this->unitnumber_digits < new_unitnumber_digits) { this->unitnumber_digits = new_unitnumber_digits; this->ReInit(); } diff --git a/src/economy.cpp b/src/economy.cpp index d78d2cccec..cdfa059e86 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1317,7 +1317,8 @@ static uint GetLoadAmount(Vehicle *v) /* Scale load amount the same as capacity */ if (HasBit(e->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER) && !air_mail) load_amount = CeilDiv(load_amount * CargoSpec::Get(v->cargo_type)->multiplier, 0x100); - return load_amount; + /* Zero load amount breaks a lot of things. */ + return max(1u, load_amount); } /** @@ -1651,6 +1652,7 @@ static void LoadUnloadVehicle(Vehicle *front) uint amount_unloaded = _settings_game.order.gradual_loading ? min(cargo_count, load_amount) : cargo_count; bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here? + assert(payment != NULL); payment->SetCargo(v->cargo_type); if (!HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE) && v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER) > 0) { diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 4c26d7b095..380b641da7 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -430,29 +430,34 @@ public: return true; } - static bool stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile) + static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance) { Tpf pf; - return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile); + return pf.FindNearestDepot(v, tile, td, max_distance); } - inline bool FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile) + /** + * Find the best depot for a road vehicle. + * @param v Vehicle + * @param tile Tile of the vehicle. + * @param td Trackdir of the vehicle. + * @param max_distance max length (penalty) for paths. + * @todo max_distance not used by YAPF for road vehicles. + * It can be removed or copy the SetMaxCost() strategy + * applied in YAPF for rail. The best depot can be at + * a distance greater than max_distance. + */ + inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance) { - /* set origin and destination nodes */ + /* Set origin. */ Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td)); - /* find the best path */ - bool bFound = Yapf().FindPath(v); - if (!bFound) return false; + /* Find the best path and return if no depot is found. */ + if (!Yapf().FindPath(v)) return FindDepotData(); - /* some path found - * get found depot tile */ + /* Return the cost of the best path and its depot. */ Node *n = Yapf().GetBestNode(); - - if (max_distance > 0 && n->m_cost > max_distance * YAPF_TILE_LENGTH) return false; - - *depot_tile = n->m_segment_last_tile; - return true; + return FindDepotData(n->m_segment_last_tile, n->m_cost); } }; @@ -504,7 +509,7 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist } /* default is YAPF type 2 */ - typedef bool (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int, TileIndex*); + typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int); PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; /* check if non-default YAPF type should be used */ @@ -512,8 +517,5 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg } - FindDepotData fdd; - bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, &fdd.tile); - fdd.best_length = ret ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND - return fdd; + return pfnFindNearestDepot(v, tile, trackdir, max_distance); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 6f2feeaab7..dca456d976 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -636,6 +636,7 @@ static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, const v->railtype = rvi->railtype; + v->date_of_last_service = _date; v->build_year = _cur_year; v->cur_image = SPR_IMG_QUERY; v->random_bits = VehicleRandomBits(); @@ -703,6 +704,7 @@ static void AddRearEngineToMultiheadedTrain(Train *v) u->refit_cap = v->refit_cap; u->railtype = v->railtype; u->engine_type = v->engine_type; + u->date_of_last_service = v->date_of_last_service; u->build_year = v->build_year; u->cur_image = SPR_IMG_QUERY; u->random_bits = VehicleRandomBits(); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index a482520f25..da2cfeb807 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -216,7 +216,7 @@ uint Vehicle::Crash(bool flooded) SetWindowDirty(WC_VEHICLE_DEPOT, this->tile); delete this->cargo_payment; - this->cargo_payment = NULL; + assert(this->cargo_payment == NULL); // cleared by ~CargoPayment return RandomRange(pass + 1); // Randomise deceased passengers. } @@ -746,6 +746,7 @@ void Vehicle::PreDestructor() HideFillingPercent(&this->fill_percent_te_id); this->CancelReservation(INVALID_STATION, st); delete this->cargo_payment; + assert(this->cargo_payment == NULL); // cleared by ~CargoPayment } if (this->IsEngineCountable()) { @@ -2085,6 +2086,7 @@ void Vehicle::LeaveStation() assert(this->current_order.IsType(OT_LOADING)); delete this->cargo_payment; + assert(this->cargo_payment == NULL); // cleared by ~CargoPayment /* Only update the timetable if the vehicle was supposed to stop here. */ if (this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false);