| 4399 | } |
| 4400 | |
| 4401 | static uint UpdateStationWaiting(Station *st, CargoType cargo, uint amount, Source source) |
| 4402 | { |
| 4403 | /* We can't allocate a CargoPacket? Then don't do anything |
| 4404 | * at all; i.e. just discard the incoming cargo. */ |
| 4405 | if (!CargoPacket::CanAllocateItem()) return 0; |
| 4406 | |
| 4407 | GoodsEntry &ge = st->goods[cargo]; |
| 4408 | amount += ge.amount_fract; |
| 4409 | ge.amount_fract = GB(amount, 0, 8); |
| 4410 | |
| 4411 | amount >>= 8; |
| 4412 | /* No new "real" cargo item yet. */ |
| 4413 | if (amount == 0) return 0; |
| 4414 | |
| 4415 | StationID next = ge.GetVia(st->index); |
| 4416 | ge.GetOrCreateData().cargo.Append(new CargoPacket(st->index, amount, source), next); |
| 4417 | LinkGraph *lg = nullptr; |
| 4418 | if (ge.link_graph == LinkGraphID::Invalid()) { |
| 4419 | if (LinkGraph::CanAllocateItem()) { |
| 4420 | lg = new LinkGraph(cargo); |
| 4421 | LinkGraphSchedule::instance.Queue(lg); |
| 4422 | ge.link_graph = lg->index; |
| 4423 | ge.node = lg->AddNode(st); |
| 4424 | } else { |
| 4425 | Debug(misc, 0, "Can't allocate link graph"); |
| 4426 | } |
| 4427 | } else { |
| 4428 | lg = LinkGraph::Get(ge.link_graph); |
| 4429 | } |
| 4430 | if (lg != nullptr) (*lg)[ge.node].UpdateSupply(amount); |
| 4431 | |
| 4432 | if (!ge.HasRating()) { |
| 4433 | InvalidateWindowData(WC_STATION_LIST, st->owner); |
| 4434 | ge.status.Set(GoodsEntry::State::Rating); |
| 4435 | } |
| 4436 | |
| 4437 | TriggerStationRandomisation(st, st->xy, StationRandomTrigger::NewCargo, cargo); |
| 4438 | TriggerStationAnimation(st, st->xy, StationAnimationTrigger::NewCargo, cargo); |
| 4439 | TriggerAirportAnimation(st, AirportAnimationTrigger::NewCargo, cargo); |
| 4440 | TriggerRoadStopRandomisation(st, st->xy, StationRandomTrigger::NewCargo, cargo); |
| 4441 | TriggerRoadStopAnimation(st, st->xy, StationAnimationTrigger::NewCargo, cargo); |
| 4442 | |
| 4443 | |
| 4444 | SetWindowDirty(WC_STATION_VIEW, st->index); |
| 4445 | st->MarkTilesDirty(true); |
| 4446 | return amount; |
| 4447 | } |
| 4448 | |
| 4449 | static bool IsUniqueStationName(const std::string &name) |
| 4450 | { |
no test coverage detected