TBTR: Fix various refit issues in refit as incoming vehicle mode
Allow refits to fail in refit as incoming vehicle mode Remove virtual train mode from CmdRefitVehicle Fix refit as incoming for non-head parts being free
This commit is contained in:
@@ -7221,6 +7221,11 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
|
|
||||||
CommandCost buy(EXPENSES_NEW_VEHICLES);
|
CommandCost buy(EXPENSES_NEW_VEHICLES);
|
||||||
|
|
||||||
|
auto refit_unit = [&](const Train *unit, CargoID cid, uint16 csubt) {
|
||||||
|
CommandCost refit_cost = DoCommand(unit->tile, unit->index, cid | csubt << 8 | (1 << 16), flags, GetCmdRefitVeh(unit));
|
||||||
|
if (refit_cost.Succeeded()) buy.AddCost(refit_cost);
|
||||||
|
};
|
||||||
|
|
||||||
if (need_replacement) {
|
if (need_replacement) {
|
||||||
// step 1: generate primary for newchain and generate remainder_chain
|
// step 1: generate primary for newchain and generate remainder_chain
|
||||||
// 1. primary of incoming might already fit the template
|
// 1. primary of incoming might already fit the template
|
||||||
@@ -7292,7 +7297,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
// additionally, if we don't want to use the template refit, refit as incoming
|
// additionally, if we don't want to use the template refit, refit as incoming
|
||||||
// the template refit will be set further down, if we use it at all
|
// the template refit will be set further down, if we use it at all
|
||||||
if (!refit_to_template) {
|
if (!refit_to_template) {
|
||||||
buy.AddCost(DoCommand(new_chain->tile, new_chain->index, store_refit_ct | store_refit_csubt << 8 | (1 << 16) | (1 << 31), flags, GetCmdRefitVeh(new_chain)));
|
refit_unit(new_chain, store_refit_ct, store_refit_csubt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7350,15 +7355,10 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
if (new_part != nullptr) {
|
if (new_part != nullptr) {
|
||||||
last_veh = new_part;
|
last_veh = new_part;
|
||||||
}
|
}
|
||||||
// TODO: is this enough ? might it be that we bought a new wagon here and it now has std refit ?
|
|
||||||
if (need_refit && new_part != nullptr) {
|
|
||||||
if (refit_to_template) {
|
|
||||||
DoCommand(tile, new_part->index, cur_tmpl->cargo_type | (cur_tmpl->cargo_subtype << 8) | (1 << 16) | (1 << 31), flags, GetCmdRefitVeh(new_part));
|
|
||||||
} else {
|
|
||||||
DoCommand(tile, new_part->index, store_refit_ct | (store_refit_csubt << 8) | (1 << 16) | (1 << 31), flags, GetCmdRefitVeh(new_part));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!refit_to_template && new_part != nullptr) {
|
||||||
|
refit_unit(new_part, store_refit_ct, store_refit_csubt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* no replacement done */
|
/* no replacement done */
|
||||||
|
@@ -512,7 +512,6 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
|
|||||||
* Only used if "refit only this vehicle" is false.
|
* Only used if "refit only this vehicle" is false.
|
||||||
* - p2 = (bit 24) - Automatic refitting.
|
* - p2 = (bit 24) - Automatic refitting.
|
||||||
* - p2 = (bit 25) - Refit only this vehicle. Used only for cloning vehicles.
|
* - p2 = (bit 25) - Refit only this vehicle. Used only for cloning vehicles.
|
||||||
* - p2 = (bit 31) - Is a virtual train (used by template replacement to allow refitting without stopped-in-depot checks)
|
|
||||||
* @param text unused
|
* @param text unused
|
||||||
* @return the cost of this operation or an error
|
* @return the cost of this operation or an error
|
||||||
*/
|
*/
|
||||||
@@ -529,10 +528,9 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||||||
|
|
||||||
bool auto_refit = HasBit(p2, 24);
|
bool auto_refit = HasBit(p2, 24);
|
||||||
bool is_virtual_train = v->type == VEH_TRAIN && Train::From(front)->IsVirtual();
|
bool is_virtual_train = v->type == VEH_TRAIN && Train::From(front)->IsVirtual();
|
||||||
bool virtual_train_mode = HasBit(p2, 31) || is_virtual_train;
|
|
||||||
bool free_wagon = v->type == VEH_TRAIN && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew
|
bool free_wagon = v->type == VEH_TRAIN && Train::From(front)->IsFreeWagon(); // used by autoreplace/renew
|
||||||
|
|
||||||
if (virtual_train_mode) {
|
if (is_virtual_train) {
|
||||||
CommandCost ret = CheckOwnership(front->owner);
|
CommandCost ret = CheckOwnership(front->owner);
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
} else {
|
} else {
|
||||||
@@ -544,7 +542,7 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||||||
if (v != front && (v->type == VEH_AIRCRAFT)) return CMD_ERROR;
|
if (v != front && (v->type == VEH_AIRCRAFT)) return CMD_ERROR;
|
||||||
|
|
||||||
/* Allow auto-refitting only during loading and normal refitting only in a depot. */
|
/* Allow auto-refitting only during loading and normal refitting only in a depot. */
|
||||||
if (!virtual_train_mode) {
|
if (!is_virtual_train) {
|
||||||
if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
|
if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
|
||||||
!free_wagon && // used by autoreplace/renew
|
!free_wagon && // used by autoreplace/renew
|
||||||
(!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
|
(!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
|
||||||
|
Reference in New Issue
Block a user