diff options
author | frosch <frosch@openttd.org> | 2010-07-09 19:50:06 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-07-09 19:50:06 +0000 |
commit | cddd6df25226ea5f13dbc5cadec73072e1b370ae (patch) | |
tree | 43d710bebf99543232ebbc9ffccdd564b68f32d9 | |
parent | 24fe1f41a5d778b55026b2ecd0fc7ca74f9e8bf8 (diff) | |
download | openttd-cddd6df25226ea5f13dbc5cadec73072e1b370ae.tar.xz |
(svn r20103) -Fix [FS#3934]: AITown::GetRating() returned wrong values. (Morloth)
-rw-r--r-- | bin/ai/regression/regression.txt | 6 | ||||
-rw-r--r-- | src/ai/api/ai_town.cpp | 22 |
2 files changed, 23 insertions, 5 deletions
diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 0c86ae6b6..ced0878c5 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -8049,7 +8049,7 @@ ERROR: IsEnd() is invalid as Begin() is never called GetPopulation(): 737 GetLocation(): 6446 GetHouseCount(): 26 - GetRating(): 5 + GetRating(): 6 Town 11 IsValidTown(): true GetName(): Fort Frindston @@ -8084,7 +8084,7 @@ ERROR: IsEnd() is invalid as Begin() is never called GetPopulation(): 807 GetLocation(): 42338 GetHouseCount(): 33 - GetRating(): 5 + GetRating(): 6 Town 16 IsValidTown(): true GetName(): Kennville @@ -8119,7 +8119,7 @@ ERROR: IsEnd() is invalid as Begin() is never called GetPopulation(): 437 GetLocation(): 22585 GetHouseCount(): 15 - GetRating(): 5 + GetRating(): 6 Town 21 IsValidTown(): true GetName(): Franinghead diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp index a11e374e8..37b9b84d6 100644 --- a/src/ai/api/ai_town.cpp +++ b/src/ai/api/ai_town.cpp @@ -14,6 +14,7 @@ #include "ai_cargo.hpp" #include "ai_error.hpp" #include "../../town.h" +#include "../../town_type.h" #include "../../strings_func.h" #include "../../company_func.h" #include "../../station_base.h" @@ -172,8 +173,25 @@ if (company == AICompany::COMPANY_INVALID) return TOWN_RATING_INVALID; const Town *t = ::Town::Get(town_id); - if (!HasBit(t->have_ratings, company)) return TOWN_RATING_NONE; - return max(TOWN_RATING_APPALLING, (TownRating)((t->ratings[company] / 200) + 3)); + if (!HasBit(t->have_ratings, company)) { + return TOWN_RATING_NONE; + } else if (t->ratings[company] <= RATING_APPALLING) { + return TOWN_RATING_APPALLING; + } else if (t->ratings[company] <= RATING_VERYPOOR) { + return TOWN_RATING_VERY_POOR; + } else if (t->ratings[company] <= RATING_POOR) { + return TOWN_RATING_POOR; + } else if (t->ratings[company] <= RATING_MEDIOCRE) { + return TOWN_RATING_MEDIOCRE; + } else if (t->ratings[company] <= RATING_GOOD) { + return TOWN_RATING_GOOD; + } else if (t->ratings[company] <= RATING_VERYGOOD) { + return TOWN_RATING_VERY_GOOD; + } else if (t->ratings[company] <= RATING_EXCELLENT) { + return TOWN_RATING_EXCELLENT; + } else { + return TOWN_RATING_OUTSTANDING; + } } /* static */ int AITown::GetAllowedNoise(TownID town_id) |