MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateStationAcceptance

Function UpdateStationAcceptance

src/station_cmd.cpp:611–657  ·  view source on GitHub ↗

* Update the acceptance for a station. * @param st Station to update * @param show_msg controls whether to display a message that acceptance was changed. */

Source from the content-addressed store, hash-verified

609 * @param show_msg controls whether to display a message that acceptance was changed.
610 */
611void UpdateStationAcceptance(Station *st, bool show_msg)
612{
613 /* old accepted goods types */
614 CargoTypes old_acc = GetAcceptanceMask(st);
615
616 /* And retrieve the acceptance. */
617 CargoArray acceptance{};
618 if (!st->rect.IsEmpty()) {
619 acceptance = GetAcceptanceAroundStation(st, &st->always_accepted);
620 }
621
622 /* Adjust in case our station only accepts fewer kinds of goods */
623 for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
624 uint amt = acceptance[cargo];
625
626 /* Make sure the station can accept the goods type. */
627 bool is_passengers = IsCargoInClass(cargo, CargoClass::Passengers);
628 if ((!is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::TruckStop, StationFacility::Airport, StationFacility::Dock})) ||
629 (is_passengers && !st->facilities.Any({StationFacility::Train, StationFacility::BusStop, StationFacility::Airport, StationFacility::Dock}))) {
630 amt = 0;
631 }
632
633 GoodsEntry &ge = st->goods[cargo];
634 ge.status.Set(GoodsEntry::State::Acceptance, amt >= 8);
635 if (LinkGraph::IsValidID(ge.link_graph)) {
636 (*LinkGraph::Get(ge.link_graph))[ge.node].SetDemand(amt / 8);
637 }
638 }
639
640 /* Only show a message in case the acceptance was actually changed. */
641 CargoTypes new_acc = GetAcceptanceMask(st);
642 if (old_acc == new_acc) return;
643
644 /* show a message to report that the acceptance was changed? */
645 if (show_msg && st->owner == _local_company && st->IsInUse()) {
646 /* Combine old and new masks to get changes */
647 CargoTypes accepts = new_acc & ~old_acc;
648 CargoTypes rejects = ~new_acc & old_acc;
649
650 /* Show news message if there are any changes */
651 if (accepts != 0) ShowRejectOrAcceptNews(st, accepts, false);
652 if (rejects != 0) ShowRejectOrAcceptNews(st, rejects, true);
653 }
654
655 /* redraw the station view since acceptance changed */
656 SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_ACCEPT_RATING_LIST);
657}
658
659static void UpdateStationSignCoord(BaseStation *st)
660{

Callers 4

StationHandleBigTickFunction · 0.85
BuildOilRigFunction · 0.85
AfterLoadGameFunction · 0.85

Calls 10

GetAcceptanceMaskFunction · 0.85
IsCargoInClassFunction · 0.85
ShowRejectOrAcceptNewsFunction · 0.85
SetWindowWidgetDirtyFunction · 0.85
AnyMethod · 0.80
SetDemandMethod · 0.80
IsInUseMethod · 0.80
IsEmptyMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected