mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r23111) -Fix: Keep subtype when automatically choosing the cargo for auto-refitting.
This commit is contained in:
parent
9782b7bb0a
commit
ad2fdd8d6f
|
@ -1300,6 +1300,7 @@ static void LoadUnloadVehicle(Vehicle *front, int *cargo_left)
|
||||||
if (cargo_left[cid] > amount) {
|
if (cargo_left[cid] > amount) {
|
||||||
/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
|
/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
|
||||||
* the returned refit capacity will be greater than zero. */
|
* the returned refit capacity will be greater than zero. */
|
||||||
|
new_subtype = GetBestFittingSubType(v, v, cid);
|
||||||
DoCommand(v->tile, v->index, cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v)); // Auto-refit and only this vehicle including artic parts.
|
DoCommand(v->tile, v->index, cid | 1U << 6 | new_subtype << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v)); // Auto-refit and only this vehicle including artic parts.
|
||||||
if (_returned_refit_capacity > 0) {
|
if (_returned_refit_capacity > 0) {
|
||||||
amount = cargo_left[cid];
|
amount = cargo_left[cid];
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "newgrf_config.h"
|
#include "newgrf_config.h"
|
||||||
#include "track_type.h"
|
#include "track_type.h"
|
||||||
#include "livery.h"
|
#include "livery.h"
|
||||||
|
#include "cargotype.h"
|
||||||
|
|
||||||
#define is_custom_sprite(x) (x >= 0xFD)
|
#define is_custom_sprite(x) (x >= 0xFD)
|
||||||
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
|
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
|
||||||
|
@ -44,7 +45,7 @@ byte VehicleRandomBits();
|
||||||
void ResetVehiclePosHash();
|
void ResetVehiclePosHash();
|
||||||
void ResetVehicleColourMap();
|
void ResetVehicleColourMap();
|
||||||
|
|
||||||
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for);
|
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type = INVALID_CARGO);
|
||||||
|
|
||||||
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
||||||
|
|
||||||
|
|
|
@ -213,9 +213,10 @@ static const uint MAX_REFIT_CYCLE = 256;
|
||||||
* Assuming they are going to carry the same cargo ofcourse!
|
* Assuming they are going to carry the same cargo ofcourse!
|
||||||
* @param v_from the vehicle to match the subtype from
|
* @param v_from the vehicle to match the subtype from
|
||||||
* @param v_for the vehicle to get the subtype for
|
* @param v_for the vehicle to get the subtype for
|
||||||
|
* @param dest_cargo_type Destination cargo type, taken from #v_from if set to #INVALID_CARGO.
|
||||||
* @return the best sub type
|
* @return the best sub type
|
||||||
*/
|
*/
|
||||||
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for)
|
byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
|
||||||
{
|
{
|
||||||
const Engine *e_from = v_from->GetEngine();
|
const Engine *e_from = v_from->GetEngine();
|
||||||
const Engine *e_for = v_for->GetEngine();
|
const Engine *e_for = v_for->GetEngine();
|
||||||
|
@ -229,8 +230,10 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dest_cargo_type == INVALID_CARGO) dest_cargo_type = v_from->cargo_type;
|
||||||
|
|
||||||
/* It has to be possible for v_for to carry the cargo of v_from. */
|
/* It has to be possible for v_for to carry the cargo of v_from. */
|
||||||
if (!HasBit(e_for->info.refit_mask, v_from->cargo_type)) return 0;
|
if (!HasBit(e_for->info.refit_mask, dest_cargo_type)) return 0;
|
||||||
|
|
||||||
StringID expected_string = GetCargoSubtypeText(v_from);
|
StringID expected_string = GetCargoSubtypeText(v_from);
|
||||||
|
|
||||||
|
@ -239,7 +242,7 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for)
|
||||||
byte ret_refit_cyc = 0;
|
byte ret_refit_cyc = 0;
|
||||||
|
|
||||||
/* Set the 'destination' cargo */
|
/* Set the 'destination' cargo */
|
||||||
v_for->cargo_type = v_from->cargo_type;
|
v_for->cargo_type = dest_cargo_type;
|
||||||
|
|
||||||
/* Cycle through the refits */
|
/* Cycle through the refits */
|
||||||
for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
|
for (uint refit_cyc = 0; refit_cyc < MAX_REFIT_CYCLE; refit_cyc++) {
|
||||||
|
|
Loading…
Reference in New Issue