(svn r27592) [1.6] -Backport from trunk:

- Fix: Automatic servicing of road vehicles compared path finder costs with tile distances, thus vehicles went to depots which were factor 100 too far away [FS#6410] (r27586)
- Fix: Enforce a non-zero load amount for all vehicles, so that vehicles can process their cargo reservations [FS#6437] (r27585, r27584)
- Fix: Do not decrease the column width of depot windows when vehicles with high unitnumbers leave [FS#6415] (r27583)
- Fix: Button size computation in script configuration window [FS#6461] (r27581)
- Fix: [NewGRF] Set date of last service on construction also for wagons and articulated parts [FS#6395] (r27580)
This commit is contained in:
frosch 2016-05-29 19:08:01 +00:00
parent 4b4e8f0a1e
commit a68d0d430c
7 changed files with 49 additions and 22 deletions

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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) {

View File

@ -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);
}

View File

@ -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();

View File

@ -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);