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

Function ChangeTownRating

src/town_cmd.cpp:4040–4068  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

4038 * @param flags Command flags, especially DoCommandFlag::NoModifyTownRating is tested
4039 */
4040void 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?

Callers 8

CmdBuildBridgeFunction · 0.85
DoClearTunnelFunction · 0.85
DoClearBridgeFunction · 0.85
CmdPlantTreeFunction · 0.85
ClearTile_TreesFunction · 0.85
ClearTile_TownFunction · 0.85
TownActionBribeFunction · 0.85
CheckAllowRemoveRoadFunction · 0.85

Calls 4

GetRatingFunction · 0.85
SetWindowDirtyFunction · 0.85
TestMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected