diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 0357e337ea..6a92b411df 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -571,6 +571,8 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) AI::BroadcastNewEvent(new ScriptEventCompanyNew(c->index), c->index); Game::NewEvent(new ScriptEventCompanyNew(c->index)); + if (!is_ai) UpdateAllTownVirtCoords(); + return c; } diff --git a/src/lang/english.txt b/src/lang/english.txt index 7bb4f3b701..c9fc514b34 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1260,7 +1260,7 @@ STR_CONFIG_SETTING_HOVER_DELAY :Show tooltips: STR_CONFIG_SETTING_HOVER_DELAY_HELPTEXT :Delay before tooltips are displayed when hovering the mouse over some interface element. Alternatively tooltips can be bound to the right mouse button STR_CONFIG_SETTING_HOVER_DELAY_VALUE :Hover for {COMMA} second{P 0 "" s} STR_CONFIG_SETTING_HOVER_DELAY_DISABLED :Right click -STR_CONFIG_SETTING_POPULATION_IN_LABEL :Show town population in the town name label: {STRING2} +STR_CONFIG_SETTING_POPULATION_IN_LABEL :Show extra information in the town name label: {STRING2} STR_CONFIG_SETTING_POPULATION_IN_LABEL_HELPTEXT :Display the population of towns in their label on the map STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS :Thickness of lines in graphs: {STRING2} STR_CONFIG_SETTING_GRAPH_LINE_THICKNESS_HELPTEXT :Width of the line in the graphs. A thin line is more precisely readable, a thicker line is easier to see and colours are easier to distinguish @@ -4798,10 +4798,18 @@ STR_SAVEGAME_NAME_DEFAULT :{COMPANY}, {STR STR_SAVEGAME_NAME_SPECTATOR :Spectator, {1:STRING1} # Viewport strings +STR_VIEWPORT_TOWN_POP_VERY_POOR_RATING :{WHITE}{TOWN} {RED}({COMMA}) +STR_VIEWPORT_TOWN_POP_MEDIOCRE_RATING :{WHITE}{TOWN} {ORANGE}({COMMA}) +STR_VIEWPORT_TOWN_POP_GOOD_RATING :{WHITE}{TOWN} {YELLOW}({COMMA}) STR_VIEWPORT_TOWN_POP :{WHITE}{TOWN} ({COMMA}) +STR_VIEWPORT_TOWN_POP_EXCELLENT_RATING :{WHITE}{TOWN} {GREEN}({COMMA}) STR_VIEWPORT_TOWN :{WHITE}{TOWN} STR_VIEWPORT_TOWN_TINY_BLACK :{TINY_FONT}{BLACK}{TOWN} STR_VIEWPORT_TOWN_TINY_WHITE :{TINY_FONT}{WHITE}{TOWN} +STR_VIEWPORT_TOWN_TINY_VERY_POOR_RATING :{TINY_FONT}{RED}{TOWN} +STR_VIEWPORT_TOWN_TINY_MEDIOCRE_RATING :{TINY_FONT}{ORANGE}{TOWN} +STR_VIEWPORT_TOWN_TINY_GOOD_RATING :{TINY_FONT}{YELLOW}{TOWN} +STR_VIEWPORT_TOWN_TINY_EXCELLENT_RATING :{TINY_FONT}{GREEN}{TOWN} STR_VIEWPORT_SIGN_SMALL_BLACK :{TINY_FONT}{BLACK}{SIGN} STR_VIEWPORT_SIGN_SMALL_WHITE :{TINY_FONT}{WHITE}{SIGN} diff --git a/src/town.h b/src/town.h index 42495971ec..67e580d6b5 100644 --- a/src/town.h +++ b/src/town.h @@ -18,6 +18,9 @@ #include "newgrf_storage.h" #include "cargotype.h" #include "tilematrix_type.hpp" +#include "openttd.h" +#include "table/strings.h" +#include "company_func.h" #include template @@ -75,6 +78,7 @@ struct Town : TownPool::PoolItem<&_town_pool> { CompanyByte exclusivity; ///< which company has exclusivity uint8 exclusive_counter; ///< months till the exclusivity expires int16 ratings[MAX_COMPANIES]; ///< ratings of each company for this town + StringID town_label; ///< Label dependent on _local_company rating. TransportedCargoStat supplied[NUM_CARGO]; ///< Cargo statistics about supplied cargo. TransportedCargoStat received[NUM_TE]; ///< Cargo statistics about received cargotypes. @@ -113,6 +117,30 @@ struct Town : TownPool::PoolItem<&_town_pool> { void InitializeLayout(TownLayout layout); + void UpdateLabel(); + + /** + * Returns the correct town label, based on rating. + */ + inline StringID Label() const{ + if (!(_game_mode == GM_EDITOR) && (_local_company < MAX_COMPANIES)) { + return STR_VIEWPORT_TOWN_POP_VERY_POOR_RATING + this->town_label; + } else { + return _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN; + } + } + + /** + * Returns the correct town small label, based on rating. + */ + inline StringID SmallLabel() const{ + if (!(_game_mode == GM_EDITOR) && (_local_company < MAX_COMPANIES)) { + return STR_VIEWPORT_TOWN_TINY_VERY_POOR_RATING + this->town_label; + } else { + return STR_VIEWPORT_TOWN_TINY_WHITE; + } + } + /** * Calculate the max town noise. * The value is counted using the population divided by the content of the diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index d3c480af11..8b23a9afd3 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -160,6 +160,26 @@ void Town::InitializeLayout(TownLayout layout) return Town::Get(index); } +/** + * Updates the town label of the town after changes in rating. The colour scheme is: + * Red: Appalling and Very poor ratings. + * Orange: Poor and mediocre ratings. + * Yellow: Good rating. + * White: Very good rating (standard). + * Green: Excellent and outstanding ratings. + */ +void Town::UpdateLabel() +{ + if (!(_game_mode == GM_EDITOR) && (_local_company < MAX_COMPANIES)) { + int r = this->ratings[_local_company]; + (this->town_label = 0, r <= RATING_VERYPOOR) || // Appalling and Very Poor + (this->town_label++, r <= RATING_MEDIOCRE) || // Poor and Mediocre + (this->town_label++, r <= RATING_GOOD) || // Good + (this->town_label++, r <= RATING_VERYGOOD) || // Very Good + (this->town_label++, true); // Excellent and Outstanding + } +} + /** * Get the cost for removing this house * @return the cost (inflation corrected etc) @@ -371,11 +391,11 @@ static bool IsCloseToTown(TileIndex tile, uint dist) */ void Town::UpdateVirtCoord() { + this->UpdateLabel(); Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE); SetDParam(0, this->index); SetDParam(1, this->cache.population); - this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE, - _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN); + this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE, this->Label()); SetWindowDirty(WC_TOWN_VIEW, this->index); } @@ -2911,6 +2931,7 @@ static CommandCost TownActionBribe(Town *t, DoCommandFlag flags) */ if (t->ratings[_current_company] > RATING_BRIBE_DOWN_TO) { t->ratings[_current_company] = RATING_BRIBE_DOWN_TO; + t->UpdateVirtCoord(); SetWindowDirty(WC_TOWN_AUTHORITY, t->index); } } else { @@ -3043,6 +3064,7 @@ static void UpdateTownRating(Town *t) t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM); } + t->UpdateVirtCoord(); SetWindowDirty(WC_TOWN_AUTHORITY, t->index); } @@ -3296,6 +3318,7 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags) } else { SetBit(t->have_ratings, _current_company); t->ratings[_current_company] = rating; + t->UpdateVirtCoord(); SetWindowDirty(WC_TOWN_AUTHORITY, t->index); } } diff --git a/src/viewport.cpp b/src/viewport.cpp index c3ccea8735..9dacd7d43e 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1156,8 +1156,7 @@ static void ViewportAddTownNames(DrawPixelInfo *dpi) const Town *t; FOR_ALL_TOWNS(t) { ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &t->cache.sign, - _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN, - STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK, + t->Label(), t->SmallLabel(), STR_VIEWPORT_TOWN_TINY_BLACK, t->index, t->cache.population); } }