301 CleanPool(&_Station_pool); |
301 CleanPool(&_Station_pool); |
302 CleanPool(&_Vehicle_pool); |
302 CleanPool(&_Vehicle_pool); |
303 CleanPool(&_Sign_pool); |
303 CleanPool(&_Sign_pool); |
304 CleanPool(&_Order_pool); |
304 CleanPool(&_Order_pool); |
305 CleanPool(&_Group_pool); |
305 CleanPool(&_Group_pool); |
|
306 CleanPool(&_CargoPacket_pool); |
306 |
307 |
307 free((void*)_town_sort); |
308 free((void*)_town_sort); |
308 free((void*)_industry_sort); |
309 free((void*)_industry_sort); |
309 |
310 |
310 free(_config_file); |
311 free(_config_file); |
928 if (_switch_mode_errorstr != INVALID_STRING_ID) { |
929 if (_switch_mode_errorstr != INVALID_STRING_ID) { |
929 ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0); |
930 ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0); |
930 } |
931 } |
931 } |
932 } |
932 |
933 |
|
934 #include "cargopacket.h" |
|
935 void CheckCargoPacketLeaks() |
|
936 { |
|
937 CargoPacket *cp; |
|
938 FOR_ALL_CARGOPACKETS(cp) cp->touched = false; |
|
939 |
|
940 Vehicle *v; |
|
941 FOR_ALL_VEHICLES(v) { |
|
942 const CargoList::List *packets = v->cargo.Packets(); |
|
943 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) (*it)->touched = true; |
|
944 } |
|
945 |
|
946 Station *st; |
|
947 FOR_ALL_STATIONS(st) { |
|
948 for (CargoID c = 0; c < NUM_CARGO; c++) { |
|
949 GoodsEntry *ge = &st->goods[c]; |
|
950 |
|
951 const CargoList::List *packets = ge->cargo.Packets(); |
|
952 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) (*it)->touched = true; |
|
953 } |
|
954 } |
|
955 |
|
956 FOR_ALL_CARGOPACKETS(cp) assert(cp->touched); |
|
957 } |
|
958 |
933 |
959 |
934 /* State controlling game loop. |
960 /* State controlling game loop. |
935 * The state must not be changed from anywhere |
961 * The state must not be changed from anywhere |
936 * but here. |
962 * but here. |
937 * That check is enforced in DoCommand. */ |
963 * That check is enforced in DoCommand. */ |
1894 } |
1921 } |
1895 |
1922 |
1896 if (CheckSavegameVersion(44)) { |
1923 if (CheckSavegameVersion(44)) { |
1897 Vehicle *v; |
1924 Vehicle *v; |
1898 /* If we remove a station while cargo from it is still enroute, payment calculation will assume |
1925 /* If we remove a station while cargo from it is still enroute, payment calculation will assume |
1899 * 0, 0 to be the origin of the cargo, resulting in very high payments usually. v->cargo_source_xy |
1926 * 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy |
1900 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded |
1927 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded |
1901 * where this situation exists, the cargo-source information is lost. in this case, we set the origin |
1928 * where this situation exists, the cargo-source information is lost. in this case, we set the source |
1902 * to the current tile of the vehicle to prevent excessive profits |
1929 * to the current tile of the vehicle to prevent excessive profits |
1903 */ |
1930 */ |
1904 FOR_ALL_VEHICLES(v) { |
1931 FOR_ALL_VEHICLES(v) { |
1905 v->cargo_source_xy = IsValidStationID(v->cargo_source) ? GetStation(v->cargo_source)->xy : v->tile; |
1932 const CargoList::List *packets = v->cargo.Packets(); |
|
1933 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { |
|
1934 CargoPacket *cp = *it; |
|
1935 cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : v->tile; |
|
1936 cp->loaded_at_xy = cp->source_xy; |
|
1937 } |
|
1938 v->cargo.InvalidateCache(); |
1906 } |
1939 } |
1907 |
1940 |
1908 /* Store position of the station where the goods come from, so there |
1941 /* Store position of the station where the goods come from, so there |
1909 * are no very high payments when stations get removed. However, if the |
1942 * are no very high payments when stations get removed. However, if the |
1910 * station where the goods came from is already removed, the source |
1943 * station where the goods came from is already removed, the source |
1913 Station *st; |
1946 Station *st; |
1914 FOR_ALL_STATIONS(st) { |
1947 FOR_ALL_STATIONS(st) { |
1915 for (CargoID c = 0; c < NUM_CARGO; c++) { |
1948 for (CargoID c = 0; c < NUM_CARGO; c++) { |
1916 GoodsEntry *ge = &st->goods[c]; |
1949 GoodsEntry *ge = &st->goods[c]; |
1917 |
1950 |
1918 /* In old versions, enroute_from used 0xFF as INVALID_STATION */ |
1951 const CargoList::List *packets = ge->cargo.Packets(); |
1919 if (CheckSavegameVersion(7) && ge->enroute_from == 0xFF) { |
1952 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { |
1920 ge->enroute_from = INVALID_STATION; |
1953 CargoPacket *cp = *it; |
|
1954 cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : st->xy; |
|
1955 cp->loaded_at_xy = cp->source_xy; |
1921 } |
1956 } |
1922 |
|
1923 ge->enroute_from_xy = IsValidStationID(ge->enroute_from) ? GetStation(ge->enroute_from)->xy : st->xy; |
|
1924 } |
1957 } |
1925 } |
1958 } |
1926 } |
1959 } |
1927 |
1960 |
1928 if (CheckSavegameVersion(45)) { |
1961 if (CheckSavegameVersion(45)) { |
1931 * stored to stop people cheating and cashing in several times. This |
1964 * stored to stop people cheating and cashing in several times. This |
1932 * wasn't enough though as it was cleared when the vehicle started |
1965 * wasn't enough though as it was cleared when the vehicle started |
1933 * loading again, even if it didn't actually load anything, so now the |
1966 * loading again, even if it didn't actually load anything, so now the |
1934 * amount of cargo that has been paid for is stored. */ |
1967 * amount of cargo that has been paid for is stored. */ |
1935 FOR_ALL_VEHICLES(v) { |
1968 FOR_ALL_VEHICLES(v) { |
1936 if (HASBIT(v->vehicle_flags, 2)) { |
1969 const CargoList::List *packets = v->cargo.Packets(); |
1937 v->cargo_paid_for = v->cargo_count; |
1970 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { |
1938 CLRBIT(v->vehicle_flags, 2); |
1971 CargoPacket *cp = *it; |
1939 } else { |
1972 cp->paid_for = HASBIT(v->vehicle_flags, 2); |
1940 v->cargo_paid_for = 0; |
1973 } |
1941 } |
1974 CLRBIT(v->vehicle_flags, 2); |
|
1975 v->cargo.InvalidateCache(); |
1942 } |
1976 } |
1943 } |
1977 } |
1944 |
1978 |
1945 /* Buoys do now store the owner of the previous water tile, which can never |
1979 /* Buoys do now store the owner of the previous water tile, which can never |
1946 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */ |
1980 * be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */ |