From 69b8e8e755959af5731e2caf05a421ef949a1bb6 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 20 Oct 2009 22:24:34 +0000 Subject: (svn r17836) -Codechange: split the CargoPacket constructor for creating 'real' new CargoPackets and saveload. For saveload we do not need to set anything except two variables (the rest is always overwritten by the load), for new 'real' cargo also pass the source_xy; dereferencing st before calling is easier than resolving st->index back to st and then dereferencing. Also don't set loaded_at_xy because that is of no importance when not loaded in a vehicle. --- src/cargopacket.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/cargopacket.cpp') diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index e2dbf900d..f2614c9b7 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -26,18 +26,20 @@ void InitializeCargoPackets() _cargopacket_pool.CleanPool(); } -CargoPacket::CargoPacket(StationID source, uint16 count, SourceType source_type, SourceID source_id) : +CargoPacket::CargoPacket() +{ + this->source_type = ST_INDUSTRY; + this->source_id = INVALID_SOURCE; +} + +CargoPacket::CargoPacket(StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id) : count(count), source_id(source_id), - source(source) + source(source), + source_xy(source_xy) { - this->source_type = source_type; - - if (source != INVALID_STATION) { - assert(count != 0); - this->source_xy = Station::Get(source)->xy; - this->loaded_at_xy = this->source_xy; - } + assert(count != 0); + this->source_type = source_type; } 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) : @@ -49,6 +51,7 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, StationID source, T source_xy(source_xy), loaded_at_xy(loaded_at_xy) { + assert(count != 0); this->source_type = source_type; } -- cgit v1.2.3-70-g09d2