TBTR: Handle setting unit direction separately from refits
This commit is contained in:
@@ -344,6 +344,20 @@ CommandCost CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFl
|
|||||||
|
|
||||||
cost.AddCost(DoCommand(t->tile, t->index, tv->cargo_type | tv->cargo_subtype << 8 | (1 << 16) | (1 << 31), flags, cb));
|
cost.AddCost(DoCommand(t->tile, t->index, tv->cargo_type | tv->cargo_subtype << 8 | (1 << 16) | (1 << 31), flags, cb));
|
||||||
|
|
||||||
|
// next
|
||||||
|
t = t->GetNextUnit();
|
||||||
|
tv = tv->GetNextUnit();
|
||||||
|
}
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set unit direction of each vehicle in t as is in tv, assume t and tv contain the same types of vehicles
|
||||||
|
CommandCost CmdSetTrainUnitDirectionFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag flags)
|
||||||
|
{
|
||||||
|
CommandCost cost(t->GetExpenseType(false));
|
||||||
|
|
||||||
|
while (t && tv) {
|
||||||
|
// refit t as tv
|
||||||
if (HasBit(t->flags, VRF_REVERSE_DIRECTION) != HasBit(tv->ctrl_flags, TVCF_REVERSED)) {
|
if (HasBit(t->flags, VRF_REVERSE_DIRECTION) != HasBit(tv->ctrl_flags, TVCF_REVERSED)) {
|
||||||
cost.AddCost(DoCommand(t->tile, t->index, true, flags, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE)));
|
cost.AddCost(DoCommand(t->tile, t->index, true, flags, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE)));
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,7 @@ uint CountsTrainsNeedingTemplateReplacement(GroupID g_id, const TemplateVehicle
|
|||||||
CommandCost TestBuyAllTemplateVehiclesInChain(TemplateVehicle *tv, TileIndex tile);
|
CommandCost TestBuyAllTemplateVehiclesInChain(TemplateVehicle *tv, TileIndex tile);
|
||||||
|
|
||||||
CommandCost CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag flags);
|
CommandCost CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag flags);
|
||||||
|
CommandCost CmdSetTrainUnitDirectionFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag flags);
|
||||||
void BreakUpRemainders(Train *t);
|
void BreakUpRemainders(Train *t);
|
||||||
|
|
||||||
bool TemplateVehicleContainsEngineOfRailtype(const TemplateVehicle *tv, RailType type);
|
bool TemplateVehicleContainsEngineOfRailtype(const TemplateVehicle *tv, RailType type);
|
||||||
|
@@ -7357,9 +7357,6 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
} else {
|
} else {
|
||||||
DoCommand(tile, new_part->index, store_refit_ct | (store_refit_csubt << 8) | (1 << 16) | (1 << 31), flags, GetCmdRefitVeh(new_part));
|
DoCommand(tile, new_part->index, store_refit_ct | (store_refit_csubt << 8) | (1 << 16) | (1 << 31), flags, GetCmdRefitVeh(new_part));
|
||||||
}
|
}
|
||||||
if (HasBit(new_part->flags, VRF_REVERSE_DIRECTION) != HasBit(cur_tmpl->ctrl_flags, TVCF_REVERSED)) {
|
|
||||||
DoCommand(tile, new_part->index, true, flags, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7378,6 +7375,8 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
buy.AddCost(CmdRefitTrainFromTemplate(new_chain, tv, flags));
|
buy.AddCost(CmdRefitTrainFromTemplate(new_chain, tv, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buy.AddCost(CmdSetTrainUnitDirectionFromTemplate(new_chain, tv, flags));
|
||||||
|
|
||||||
if (new_chain && remainder_chain) {
|
if (new_chain && remainder_chain) {
|
||||||
for (Train *ct = remainder_chain; ct != nullptr; ct = ct->Next()) {
|
for (Train *ct = remainder_chain; ct != nullptr; ct = ct->Next()) {
|
||||||
TransferCargoForTrain(ct, new_chain);
|
TransferCargoForTrain(ct, new_chain);
|
||||||
|
Reference in New Issue
Block a user