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

Function UpdateTownRating

src/town_cmd.cpp:3766–3795  ·  view source on GitHub ↗

* Monthly callback to update town and station ratings. * @param t The town to update. */

Source from the content-addressed store, hash-verified

3764 * @param t The town to update.
3765 */
3766static 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/**

Callers 1

town_cmd.cppFile · 0.85

Calls 3

ForAllStationsNearTownFunction · 0.85
ClampFunction · 0.85
SetWindowDirtyFunction · 0.85

Tested by

no test coverage detected