Merge branch 'template_train_replacement-sx' into jgrpp
# Conflicts: # src/build_vehicle_gui.cpp # src/saveload/afterload.cpp
This commit is contained in:
@@ -496,17 +496,15 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||
|
||||
/* Allow auto-refitting only during loading and normal refitting only in a depot. */
|
||||
if (!is_virtual_train) {
|
||||
if (!free_wagon && (!auto_refit || !front->current_order.IsType(OT_LOADING)) && !front->IsStoppedInDepot()) {
|
||||
if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
|
||||
!free_wagon && // used by autoreplace/renew
|
||||
(!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
|
||||
!front->IsStoppedInDepot()) { // refit inside depots
|
||||
return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
|
||||
}
|
||||
|
||||
if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
}
|
||||
if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
|
||||
!free_wagon && // used by autoreplace/renew
|
||||
(!auto_refit || !front->current_order.IsType(OT_LOADING)) && // refit inside stations
|
||||
!front->IsStoppedInDepot()) { // refit inside depots
|
||||
return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
|
||||
}
|
||||
|
||||
if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||
|
||||
@@ -853,8 +851,7 @@ inline void SetupTemplateVehicleFromVirtual(TemplateVehicle *tmp, TemplateVehicl
|
||||
|
||||
tmp->spritenum = virt->spritenum;
|
||||
tmp->cur_image = virt->GetImage(DIR_W, EIT_PURCHASE);
|
||||
Point *p = new Point();
|
||||
tmp->image_width = virt->GetDisplayImageWidth(p);
|
||||
tmp->image_width = virt->GetDisplayImageWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -966,34 +963,41 @@ CommandCost CmdVirtualTrainFromTemplateVehicle(TileIndex tile, DoCommandFlag fla
|
||||
bool should_execute = (flags & DC_EXEC) != 0;
|
||||
|
||||
if (should_execute) {
|
||||
Train* train = VirtualTrainFromTemplateVehicle(tv);
|
||||
StringID err = INVALID_STRING_ID;
|
||||
Train* train = VirtualTrainFromTemplateVehicle(tv, err);
|
||||
|
||||
if (train == NULL) {
|
||||
return CMD_ERROR;
|
||||
return_cmd_error(err);
|
||||
}
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
Train* VirtualTrainFromTemplateVehicle(TemplateVehicle* tv)
|
||||
CommandCost CmdDeleteVirtualTrain(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
|
||||
|
||||
Train* VirtualTrainFromTemplateVehicle(TemplateVehicle* tv, StringID &err)
|
||||
{
|
||||
CommandCost c;
|
||||
Train *tmp, *head, *tail;
|
||||
|
||||
head = CmdBuildVirtualRailVehicle(tv->engine_type);
|
||||
head = CmdBuildVirtualRailVehicle(tv->engine_type, true, err);
|
||||
if (!head) return NULL;
|
||||
|
||||
tail = head;
|
||||
tv = tv->GetNextUnit();
|
||||
while (tv) {
|
||||
tmp = CmdBuildVirtualRailVehicle(tv->engine_type);
|
||||
if (tmp) {
|
||||
tmp->cargo_type = tv->cargo_type;
|
||||
tmp->cargo_subtype = tv->cargo_subtype;
|
||||
CmdMoveRailVehicle(INVALID_TILE, DC_EXEC, (1 << 21) | tmp->index, tail->index, 0);
|
||||
tail = tmp;
|
||||
tmp = CmdBuildVirtualRailVehicle(tv->engine_type, true, err);
|
||||
if (!tmp) {
|
||||
CmdDeleteVirtualTrain(INVALID_TILE, DC_EXEC, head->index, 0, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmp->cargo_type = tv->cargo_type;
|
||||
tmp->cargo_subtype = tv->cargo_subtype;
|
||||
CmdMoveRailVehicle(INVALID_TILE, DC_EXEC, (1 << 21) | tmp->index, tail->index, 0);
|
||||
tail = tmp;
|
||||
|
||||
tv = tv->GetNextUnit();
|
||||
}
|
||||
|
||||
@@ -1027,20 +1031,25 @@ CommandCost CmdVirtualTrainFromTrain(TileIndex tile, DoCommandFlag flags, uint32
|
||||
if (should_execute) {
|
||||
CommandCost c;
|
||||
Train *tmp, *head, *tail;
|
||||
StringID err = INVALID_STRING_ID;
|
||||
|
||||
head = CmdBuildVirtualRailVehicle(train->engine_type);
|
||||
if (!head) return CMD_ERROR;
|
||||
head = CmdBuildVirtualRailVehicle(train->engine_type, false, err);
|
||||
if (!head) return_cmd_error(err);
|
||||
|
||||
tail = head;
|
||||
train = train->GetNextUnit();
|
||||
while (train) {
|
||||
tmp = CmdBuildVirtualRailVehicle(train->engine_type);
|
||||
if (tmp) {
|
||||
tmp->cargo_type = train->cargo_type;
|
||||
tmp->cargo_subtype = train->cargo_subtype;
|
||||
CmdMoveRailVehicle(0, DC_EXEC, (1 << 21) | tmp->index, tail->index, 0);
|
||||
tail = tmp;
|
||||
tmp = CmdBuildVirtualRailVehicle(train->engine_type, false, err);
|
||||
if (!tmp) {
|
||||
CmdDeleteVirtualTrain(tile, flags, head->index, 0, NULL);
|
||||
return_cmd_error(err);
|
||||
}
|
||||
|
||||
tmp->cargo_type = train->cargo_type;
|
||||
tmp->cargo_subtype = train->cargo_subtype;
|
||||
CmdMoveRailVehicle(0, DC_EXEC, (1 << 21) | tmp->index, tail->index, 0);
|
||||
tail = tmp;
|
||||
|
||||
train = train->GetNextUnit();
|
||||
}
|
||||
|
||||
@@ -1162,6 +1171,12 @@ CommandCost CmdTemplateVehicleFromTrain(TileIndex tile, DoCommandFlag flags, uin
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
||||
for (Train *v = clicked; v != NULL; v = v->GetNextUnit()) {
|
||||
if (!IsEngineBuildable(v->engine_type, VEH_TRAIN, _current_company)) {
|
||||
return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + VEH_TRAIN);
|
||||
}
|
||||
}
|
||||
|
||||
bool should_execute = (flags & DC_EXEC) != 0;
|
||||
|
||||
if (should_execute) {
|
||||
@@ -1211,6 +1226,7 @@ CommandCost CmdDeleteTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint32
|
||||
|
||||
delete del;
|
||||
|
||||
InvalidateWindowClassesData(WC_CREATE_TEMPLATE, 0);
|
||||
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN, 0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user