mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
(svn r25435) -Fix: reroute cargo in vehicles if station is deleted
This commit is contained in:
parent
3dd811e179
commit
930c19dae2
@ -92,20 +92,21 @@ Station::~Station()
|
|||||||
|
|
||||||
for (CargoID c = 0; c < NUM_CARGO; ++c) {
|
for (CargoID c = 0; c < NUM_CARGO; ++c) {
|
||||||
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
|
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
|
||||||
if (lg != NULL) {
|
if (lg == NULL) continue;
|
||||||
|
|
||||||
|
for (NodeID node = 0; node < lg->Size(); ++node) {
|
||||||
|
if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
|
||||||
|
Station *st = Station::Get((*lg)[node].Station());
|
||||||
|
st->goods[c].flows.DeleteFlows(this->index);
|
||||||
|
RerouteCargo(st, c, this->index, st->index);
|
||||||
|
}
|
||||||
|
}
|
||||||
lg->RemoveNode(this->goods[c].node);
|
lg->RemoveNode(this->goods[c].node);
|
||||||
if (lg->Size() == 0) {
|
if (lg->Size() == 0) {
|
||||||
LinkGraphSchedule::Instance()->Unqueue(lg);
|
LinkGraphSchedule::Instance()->Unqueue(lg);
|
||||||
delete lg;
|
delete lg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Station *st;
|
|
||||||
FOR_ALL_STATIONS(st) {
|
|
||||||
GoodsEntry *ge = &st->goods[c];
|
|
||||||
ge->flows.DeleteFlows(this->index);
|
|
||||||
ge->cargo.Reroute(UINT_MAX, &ge->cargo, this->index, st->index, ge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
|
@ -3377,6 +3377,30 @@ static void UpdateStationRating(Station *st)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reroute cargo of type c at station st or in any vehicles unloading there.
|
||||||
|
* Make sure the cargo's new next hop is neither "avoid" nor "avoid2".
|
||||||
|
* @param st Station to be rerouted at.
|
||||||
|
* @param c Type of cargo.
|
||||||
|
* @param avoid Original next hop of cargo, avoid this.
|
||||||
|
* @param avoid2 Another station to be avoided when rerouting.
|
||||||
|
*/
|
||||||
|
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
|
||||||
|
{
|
||||||
|
GoodsEntry &ge = st->goods[c];
|
||||||
|
|
||||||
|
/* Reroute cargo in station. */
|
||||||
|
ge.cargo.Reroute(UINT_MAX, &ge.cargo, avoid, avoid2, &ge);
|
||||||
|
|
||||||
|
/* Reroute cargo staged to be transfered. */
|
||||||
|
for (std::list<Vehicle *>::iterator it(st->loading_vehicles.begin()); it != st->loading_vehicles.end(); ++it) {
|
||||||
|
for (Vehicle *v = *it; v != NULL; v = v->Next()) {
|
||||||
|
if (v->cargo_type != c) continue;
|
||||||
|
v->cargo.Reroute(UINT_MAX, &v->cargo, avoid, avoid2, &ge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check all next hops of cargo packets in this station for existance of a
|
* Check all next hops of cargo packets in this station for existance of a
|
||||||
* a valid link they may use to travel on. Reroute any cargo not having a valid
|
* a valid link they may use to travel on. Reroute any cargo not having a valid
|
||||||
@ -3402,17 +3426,7 @@ void DeleteStaleLinks(Station *from)
|
|||||||
(DistanceManhattan(from->xy, to->xy) >> 2)) {
|
(DistanceManhattan(from->xy, to->xy) >> 2)) {
|
||||||
node.RemoveEdge(to->goods[c].node);
|
node.RemoveEdge(to->goods[c].node);
|
||||||
ge.flows.DeleteFlows(to->index);
|
ge.flows.DeleteFlows(to->index);
|
||||||
|
RerouteCargo(from, c, to->index, from->index);
|
||||||
/* Reroute cargo in station. */
|
|
||||||
ge.cargo.Reroute(UINT_MAX, &ge.cargo, to->index, from->index, &ge);
|
|
||||||
|
|
||||||
/* Reroute cargo staged to be transfered. */
|
|
||||||
for (std::list<Vehicle *>::iterator it(from->loading_vehicles.begin()); it != from->loading_vehicles.end(); ++it) {
|
|
||||||
for (Vehicle *v = *it; v != NULL; v = v->Next()) {
|
|
||||||
if (v->cargo_type != c) continue;
|
|
||||||
v->cargo.Reroute(UINT_MAX, &v->cargo, to->index, from->index, &ge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(_date >= lg->LastCompression());
|
assert(_date >= lg->LastCompression());
|
||||||
|
@ -50,6 +50,7 @@ bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrack
|
|||||||
|
|
||||||
void IncreaseStats(Station *st, const Vehicle *v, StationID next_station_id);
|
void IncreaseStats(Station *st, const Vehicle *v, StationID next_station_id);
|
||||||
void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage);
|
void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage);
|
||||||
|
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the maintenance cost of a number of station tiles.
|
* Calculates the maintenance cost of a number of station tiles.
|
||||||
|
Loading…
Reference in New Issue
Block a user