* Monthly callback to update town and station ratings. * @param t The town to update. */
| 3764 | * @param t The town to update. |
| 3765 | */ |
| 3766 | static void UpdateTownRating(Town *t) |
| 3767 | { |
| 3768 | /* Increase company ratings if they're low */ |
| 3769 | for (const Company *c : Company::Iterate()) { |
| 3770 | if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) { |
| 3771 | t->ratings[c->index] = std::min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP); |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | ForAllStationsNearTown(t, [&](const Station *st) { |
| 3776 | if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
| 3777 | if (Company::IsValidID(st->owner)) { |
| 3778 | int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP; |
| 3779 | t->ratings[st->owner] = std::min<int>(new_rating, INT16_MAX); // do not let it overflow |
| 3780 | } |
| 3781 | } else { |
| 3782 | if (Company::IsValidID(st->owner)) { |
| 3783 | int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP; |
| 3784 | t->ratings[st->owner] = std::max(new_rating, INT16_MIN); |
| 3785 | } |
| 3786 | } |
| 3787 | }); |
| 3788 | |
| 3789 | /* clamp all ratings to valid values */ |
| 3790 | for (uint i = 0; i < MAX_COMPANIES; i++) { |
| 3791 | t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM); |
| 3792 | } |
| 3793 | |
| 3794 | SetWindowDirty(WC_TOWN_AUTHORITY, t->index); |
| 3795 | } |
| 3796 | |
| 3797 | |
| 3798 | /** |
no test coverage detected