equal
deleted
inserted
replaced
1885 } while (source->cargo_count > 0 && (dest = dest->next) != NULL); |
1885 } while (source->cargo_count > 0 && (dest = dest->next) != NULL); |
1886 dest = v; |
1886 dest = v; |
1887 } while ((source = source->next) != NULL); |
1887 } while ((source = source->next) != NULL); |
1888 } |
1888 } |
1889 |
1889 |
|
1890 static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, const EngineID engine_type) |
|
1891 { |
|
1892 const Order *o; |
|
1893 const Vehicle *u; |
|
1894 |
|
1895 if (v->type == VEH_Train) { |
|
1896 u = GetFirstVehicleInChain(v); |
|
1897 } else { |
|
1898 u = v; |
|
1899 } |
|
1900 |
|
1901 FOR_VEHICLE_ORDERS(u, o) { |
|
1902 if (o->refit_cargo == CT_NO_REFIT) continue; |
|
1903 if (!CanRefitTo(v->engine_type, o->refit_cargo)) continue; |
|
1904 if (!CanRefitTo(engine_type, o->refit_cargo)) return false; |
|
1905 } |
|
1906 |
|
1907 return true; |
|
1908 } |
|
1909 |
1890 /** |
1910 /** |
1891 * Function to find what type of cargo to refit to when autoreplacing |
1911 * Function to find what type of cargo to refit to when autoreplacing |
1892 * @param *v Original vehicle, that is being replaced |
1912 * @param *v Original vehicle, that is being replaced |
1893 * @param engine_type The EngineID of the vehicle that is being replaced to |
1913 * @param engine_type The EngineID of the vehicle that is being replaced to |
1894 * @return The cargo type to replace to |
1914 * @return The cargo type to replace to |
1924 default: NOT_REACHED(); break; |
1944 default: NOT_REACHED(); break; |
1925 } |
1945 } |
1926 |
1946 |
1927 if (!new_cargo_capacity) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity |
1947 if (!new_cargo_capacity) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity |
1928 |
1948 |
1929 if (v->cargo_type == new_cargo_type) return CT_NO_REFIT; |
1949 if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) { |
1930 if (CanRefitTo(engine_type, v->cargo_type)) return v->cargo_type; |
1950 if (VerifyAutoreplaceRefitForOrders(v, engine_type)) { |
|
1951 return v->cargo_type == new_cargo_type ? CT_NO_REFIT : v->cargo_type; |
|
1952 } else { |
|
1953 return CT_INVALID; |
|
1954 } |
|
1955 } |
1931 if (v->type != VEH_Train) return CT_INVALID; // We can't refit the vehicle to carry the cargo we want |
1956 if (v->type != VEH_Train) return CT_INVALID; // We can't refit the vehicle to carry the cargo we want |
1932 |
1957 |
1933 /* Below this line it's safe to assume that the vehicle in question is a train */ |
1958 /* Below this line it's safe to assume that the vehicle in question is a train */ |
1934 |
1959 |
1935 if (v->cargo_cap != 0) return CT_INVALID; // trying to replace a vehicle with cargo capacity into another one with incompatible cargo type |
1960 if (v->cargo_cap != 0) return CT_INVALID; // trying to replace a vehicle with cargo capacity into another one with incompatible cargo type |