src/train_cmd.cpp
changeset 6789 d32dd7c82158
parent 6788 9a1949f8fab4
child 6857 60130753e595
equal deleted inserted replaced
6788:9a1949f8fab4 6789:d32dd7c82158
  1203  * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines;
  1203  * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines;
  1204  *           all wagons of the same type will go on the same line. Used by the AI currently
  1204  *           all wagons of the same type will go on the same line. Used by the AI currently
  1205  */
  1205  */
  1206 int32 CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1206 int32 CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1207 {
  1207 {
       
  1208 	/* Check if we deleted a vehicle window */
       
  1209 	Window *w = NULL;
       
  1210 
  1208 	if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR;
  1211 	if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR;
  1209 
  1212 
  1210 	Vehicle *v = GetVehicle(p1);
  1213 	Vehicle *v = GetVehicle(p1);
  1211 
  1214 
  1212 	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
  1215 	if (v->type != VEH_TRAIN || !CheckOwnership(v->owner)) return CMD_ERROR;
  1223 
  1226 
  1224 	if (IsMultiheaded(v) && !IsTrainEngine(v)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
  1227 	if (IsMultiheaded(v) && !IsTrainEngine(v)) return_cmd_error(STR_REAR_ENGINE_FOLLOW_FRONT_ERROR);
  1225 
  1228 
  1226 	if (flags & DC_EXEC) {
  1229 	if (flags & DC_EXEC) {
  1227 		if (v == first && IsFrontEngine(first)) {
  1230 		if (v == first && IsFrontEngine(first)) {
  1228 			DeleteWindowById(WC_VEHICLE_VIEW, first->index);
  1231 			w = FindWindowById(WC_VEHICLE_VIEW, first->index);
       
  1232 			if (w != NULL) DeleteWindow(w);
  1229 		}
  1233 		}
  1230 		InvalidateWindow(WC_VEHICLE_DEPOT, first->tile);
  1234 		InvalidateWindow(WC_VEHICLE_DEPOT, first->tile);
  1231 		RebuildVehicleLists();
  1235 		RebuildVehicleLists();
  1232 	}
  1236 	}
  1233 
  1237 
  1290 					 */
  1294 					 */
  1291 					first->orders      = NULL;
  1295 					first->orders      = NULL;
  1292 					first->prev_shared = NULL;
  1296 					first->prev_shared = NULL;
  1293 					first->next_shared = NULL;
  1297 					first->next_shared = NULL;
  1294 
  1298 
  1295 					if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
  1299 					/* If we deleted a window then open a new one for the 'new' train */
       
  1300 					if (IsLocalPlayer() && w != NULL) ShowTrainViewWindow(new_f);
  1296 				}
  1301 				}
  1297 			}
  1302 			}
  1298 
  1303 
  1299 			/* 3. Delete the requested wagon */
  1304 			/* 3. Delete the requested wagon */
  1300 			cost -= v->value;
  1305 			cost -= v->value;