Mercurial > hg > openttd
changeset 13298:f590f261c90a draft
(svn r17807) -Codechange: move all 'updates' just after the 'load' constructor of CargoPackets to the constructor call itself
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 18 Oct 2009 17:52:44 +0000 |
parents | c2644b1a9d16 |
children | 366acecbae41 |
files | src/cargopacket.cpp src/cargopacket.h src/saveload/oldloader_sl.cpp src/saveload/station_sl.cpp src/saveload/vehicle_sl.cpp |
diffstat | 5 files changed, 19 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -40,11 +40,14 @@ } } -CargoPacket::CargoPacket(uint16 count, byte days_in_transit, Money feeder_share, SourceType source_type, SourceID source_id) : +CargoPacket::CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share, SourceType source_type, SourceID source_id) : feeder_share(feeder_share), count(count), days_in_transit(days_in_transit), - source_id(source_id) + source_id(source_id), + source(source), + source_xy(source_xy), + loaded_at_xy(loaded_at_xy) { this->source_type = source_type; } @@ -224,12 +227,7 @@ Money fs = cp->feeder_share * max_move / static_cast<uint>(cp->count); cp->feeder_share -= fs; - CargoPacket *cp_new = new CargoPacket(max_move, cp->days_in_transit, fs, cp->source_type, cp->source_id); - - cp_new->source = cp->source; - cp_new->source_xy = cp->source_xy; - cp_new->loaded_at_xy = (mta == MTA_CARGO_LOAD) ? data : cp->loaded_at_xy; - + CargoPacket *cp_new = new CargoPacket(max_move, cp->days_in_transit, cp->source, cp->source_xy, (mta == MTA_CARGO_LOAD) ? data : cp->loaded_at_xy, fs, cp->source_type, cp->source_id); this->RemoveFromCache(cp_new); // this reflects the changes in cp. if (mta == MTA_TRANSFER) {
--- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -74,11 +74,14 @@ * Used when loading or splitting packets. * @param count the number of cargo entities to put in this packet * @param days_in_transit number of days the cargo has been in transit + * @param source the station the cargo was initially loaded + * @param source_xy the station location the cargo was initially loaded + * @param loaded_at_xy the location the cargo was loaded last * @param feeder_share feeder share the packet has already accumulated * @param source_type the 'type' of source the packet comes from (for subsidies) * @param source_id the actual source of the packet (for subsidies) */ - CargoPacket(uint16 count, byte days_in_transit, Money feeder_share = 0, SourceType source_type = ST_INDUSTRY, SourceID source_id = INVALID_SOURCE); + CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = ST_INDUSTRY, SourceID source_id = INVALID_SOURCE); /** Destroy the packet */ ~CargoPacket() { }
--- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -698,9 +698,7 @@ SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15)); SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, _cargo_source != 0xFF); if (GB(_waiting_acceptance, 0, 12) != 0) { - CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_days); - cp->source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; - ge->cargo.Append(cp); + ge->cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_days, (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source, 0, 0)); } return true; @@ -1330,13 +1328,9 @@ v->next = (Vehicle *)(size_t)_old_next_ptr; if (_cargo_count != 0) { - CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_days); - cp->source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; - cp->source_xy = (cp->source != INVALID_STATION) ? Station::Get(cp->source)->xy : 0; - cp->loaded_at_xy = cp->source_xy; - cp->source_type = ST_INDUSTRY; - cp->source_id = INVALID_SOURCE; - v->cargo.Append(cp); + StationID source = (_cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; + TileIndex source_xy = (source != INVALID_STATION) ? Station::Get(source)->xy : 0; + v->cargo.Append(new CargoPacket(_cargo_count, _cargo_days, source, source_xy, source_xy)); } }
--- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -243,13 +243,12 @@ if (CheckSavegameVersion(68)) { SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15)); if (GB(_waiting_acceptance, 0, 12) != 0) { + /* In old versions, enroute_from used 0xFF as INVALID_STATION */ + StationID source = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; + /* Don't construct the packet with station here, because that'll fail with old savegames */ - CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_days, _cargo_feeder_share); - /* In old versions, enroute_from used 0xFF as INVALID_STATION */ - cp->source = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source; - cp->source_xy = _cargo_source_xy; + ge->cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share)); SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1); - ge->cargo.Append(cp); } } }
--- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -719,10 +719,7 @@ if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v)) { /* Don't construct the packet with station here, because that'll fail with old savegames */ - CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_days, _cargo_feeder_share); - cp->source = _cargo_source; - cp->source_xy = _cargo_source_xy; - cp->loaded_at_xy = _cargo_loaded_at_xy; + CargoPacket *cp = new CargoPacket(_cargo_count, _cargo_days, _cargo_source, _cargo_source_xy, _cargo_loaded_at_xy, _cargo_feeder_share); v->cargo.Append(cp); }