* Changes town rating of the current company * @param t Town to affect * @param add Value to add * @param max Minimum (add < 0) resp. maximum (add > 0) rating that should be achievable with this change. * @param flags Command flags, especially DoCommandFlag::NoModifyTownRating is tested */
| 4038 | * @param flags Command flags, especially DoCommandFlag::NoModifyTownRating is tested |
| 4039 | */ |
| 4040 | void ChangeTownRating(Town *t, int add, int max, DoCommandFlags flags) |
| 4041 | { |
| 4042 | /* if magic_bulldozer cheat is active, town doesn't penalize for removing stuff */ |
| 4043 | if (t == nullptr || flags.Test(DoCommandFlag::NoModifyTownRating) || |
| 4044 | !Company::IsValidID(_current_company) || |
| 4045 | (_cheats.magic_bulldozer.value && add < 0)) { |
| 4046 | return; |
| 4047 | } |
| 4048 | |
| 4049 | int rating = GetRating(t); |
| 4050 | if (add < 0) { |
| 4051 | if (rating > max) { |
| 4052 | rating += add; |
| 4053 | if (rating < max) rating = max; |
| 4054 | } |
| 4055 | } else { |
| 4056 | if (rating < max) { |
| 4057 | rating += add; |
| 4058 | if (rating > max) rating = max; |
| 4059 | } |
| 4060 | } |
| 4061 | if (_town_rating_test) { |
| 4062 | _town_test_ratings[t] = rating; |
| 4063 | } else { |
| 4064 | t->have_ratings.Set(_current_company); |
| 4065 | t->ratings[_current_company] = rating; |
| 4066 | SetWindowDirty(WC_TOWN_AUTHORITY, t->index); |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | /** |
| 4071 | * Does the town authority allow the (destructive) action of the current company? |
no test coverage detected