From 62a6e9509b9067443899afcf8791e97d48aa8983 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 18 Oct 2009 17:26:10 +0000 Subject: [PATCH] (svn r17804) -Codechange: move the CargoPacket 'invalidation' when stations get removed to CargoPacket. --- src/cargopacket.cpp | 12 ++++++++++++ src/cargopacket.h | 1 + src/station.cpp | 6 +----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 313e7db4f5..e9b3f50641 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -62,6 +62,18 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, Money feeder_share, } } +/** + * Invalidates (sets source to INVALID_STATION) all cargo packets from given station + * @param sid the station that gets removed + */ +/* static */ void CargoPacket::InvalidateAllFrom(StationID sid) +{ + CargoPacket *cp; + FOR_ALL_CARGOPACKETS(cp) { + if (cp->source == sid) cp->source_id = INVALID_SOURCE; + } +} + /* * * Cargo list implementation diff --git a/src/cargopacket.h b/src/cargopacket.h index a29a1ff22c..ee0e2163a6 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -116,6 +116,7 @@ public: static void InvalidateAllFrom(SourceType src_type, SourceID src); + static void InvalidateAllFrom(StationID sid); }; /** diff --git a/src/station.cpp b/src/station.cpp index 1ac0341c0a..ba0020c73f 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -97,11 +97,7 @@ Station::~Station() this->goods[c].cargo.Truncate(0); } - CargoPacket *cp; - FOR_ALL_CARGOPACKETS(cp) { - /* Don't allow cargo packets with invalid source station */ - if (cp->source == this->index) cp->source = INVALID_STATION; - } + CargoPacket::InvalidateAllFrom(this->index); }