Add per-town override to disable town growth

This commit is contained in:
Jonathan G Rennison
2023-01-01 22:13:03 +00:00
parent 42891a6d9d
commit b8c7a0dd20
5 changed files with 42 additions and 6 deletions

View File

@@ -4522,11 +4522,12 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS :{YELLOW}Fund th
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT :{YELLOW}Buy 1 year's exclusive transport rights in town.{}Town authority will not allow passengers and cargo to use your competitors' stations.{}Cost: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT :{YELLOW}Buy 1 year's exclusive transport rights in town.{}Town authority will not allow passengers and cargo to use your competitors' stations.{}Cost: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{YELLOW}Bribe the local authority to increase your rating, at the risk of a severe penalty if caught.{}Cost: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{YELLOW}Bribe the local authority to increase your rating, at the risk of a severe penalty if caught.{}Cost: {CURRENCY_LONG}
###length 4 ###length 5
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS :Allowed to build roads STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS :Allowed to build roads
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_LEVEL_CROSSINGS :Allowed to build level crossings STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_LEVEL_CROSSINGS :Allowed to build level crossings
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TUNNELS :Allowed to build tunnels STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TUNNELS :Allowed to build tunnels
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_MAX_ROAD_SLOPE :Limit building continuous inclined roads STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_MAX_ROAD_SLOPE :Limit building continuous inclined roads
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TOWN_GROWTH :Town growth speed
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_DEFAULT :Default ({STRING1}) STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_DEFAULT :Default ({STRING1})
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_STR :{STRING}: {PUSH_COLOUR}{YELLOW}{STRING2}{POP_COLOUR} STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_STR :{STRING}: {PUSH_COLOUR}{YELLOW}{STRING2}{POP_COLOUR}

View File

@@ -4525,7 +4525,7 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS :{PUSH_COLOUR}{Y
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT :{PUSH_COLOUR}{YELLOW}1년 간 수송 권한 독점권을 구입합니다.{}도시 당국은 오직 당신 회사의 역에만 승객과 화물을 실을 것입니다.{}{POP_COLOUR}가격: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT :{PUSH_COLOUR}{YELLOW}1년 간 수송 권한 독점권을 구입합니다.{}도시 당국은 오직 당신 회사의 역에만 승객과 화물을 실을 것입니다.{}{POP_COLOUR}가격: {CURRENCY_LONG}
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{PUSH_COLOUR}{YELLOW}성취도를 올리기 위해 처벌을 감수하고 지역 당국에 뇌물을 줍니다.{}{POP_COLOUR}가격: {CURRENCY_LONG} STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{PUSH_COLOUR}{YELLOW}성취도를 올리기 위해 처벌을 감수하고 지역 당국에 뇌물을 줍니다.{}{POP_COLOUR}가격: {CURRENCY_LONG}
###length 4 ###length 5
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS :도로 건설 STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS :도로 건설
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_LEVEL_CROSSINGS :건널목 건설 STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_LEVEL_CROSSINGS :건널목 건설
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TUNNELS :터널 건설 STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TUNNELS :터널 건설

View File

@@ -65,6 +65,7 @@ enum TownSettingOverrideFlags {
TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS = 1, TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS = 1,
TSOF_OVERRIDE_BUILD_TUNNELS = 2, TSOF_OVERRIDE_BUILD_TUNNELS = 2,
TSOF_OVERRIDE_BUILD_INCLINED_ROADS = 3, TSOF_OVERRIDE_BUILD_INCLINED_ROADS = 3,
TSOF_OVERRIDE_GROWTH = 4,
}; };
/** Town data structure. */ /** Town data structure. */
@@ -187,6 +188,11 @@ struct Town : TownPool::PoolItem<&_town_pool> {
return this->cached_name.c_str(); return this->cached_name.c_str();
} }
inline bool IsTownGrowthDisabledByOverride() const
{
return HasBit(this->override_flags, TSOF_OVERRIDE_GROWTH);
}
inline bool GetAllowBuildRoads() const inline bool GetAllowBuildRoads() const
{ {
return HasBit(this->override_flags, TSOF_OVERRIDE_BUILD_ROADS) ? HasBit(this->override_values, TSOF_OVERRIDE_BUILD_ROADS) : _settings_game.economy.allow_town_roads; return HasBit(this->override_flags, TSOF_OVERRIDE_BUILD_ROADS) ? HasBit(this->override_values, TSOF_OVERRIDE_BUILD_ROADS) : _settings_game.economy.allow_town_roads;

View File

@@ -3823,6 +3823,9 @@ CommandCost CmdOverrideTownSetting(TileIndex tile, DoCommandFlag flags, uint32 p
const bool is_override = HasBit(p2, 16); const bool is_override = HasBit(p2, 16);
const uint8 value = GB(p2, 8, 8); const uint8 value = GB(p2, 8, 8);
switch (setting) { switch (setting) {
case TSOF_OVERRIDE_GROWTH:
if (is_override && value != 0) return CMD_ERROR;
break;
case TSOF_OVERRIDE_BUILD_ROADS: case TSOF_OVERRIDE_BUILD_ROADS:
case TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS: case TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS:
if (is_override && value != 0 && value != 1) return CMD_ERROR; if (is_override && value != 0 && value != 1) return CMD_ERROR;
@@ -3841,6 +3844,8 @@ CommandCost CmdOverrideTownSetting(TileIndex tile, DoCommandFlag flags, uint32 p
SB(t->override_flags, setting, 1, is_override ? 1 : 0); SB(t->override_flags, setting, 1, is_override ? 1 : 0);
if (is_override) { if (is_override) {
switch (setting) { switch (setting) {
case TSOF_OVERRIDE_GROWTH:
break;
case TSOF_OVERRIDE_BUILD_ROADS: case TSOF_OVERRIDE_BUILD_ROADS:
case TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS: case TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS:
SB(t->override_values, setting, 1, value & 1); SB(t->override_values, setting, 1, value & 1);
@@ -3856,6 +3861,7 @@ CommandCost CmdOverrideTownSetting(TileIndex tile, DoCommandFlag flags, uint32 p
} }
} }
SetWindowDirty(WC_TOWN_AUTHORITY, p1); SetWindowDirty(WC_TOWN_AUTHORITY, p1);
if (setting == TSOF_OVERRIDE_GROWTH) UpdateTownGrowth(t);
} }
return CommandCost(); return CommandCost();
@@ -3938,7 +3944,7 @@ static void UpdateTownRating(Town *t)
*/ */
static void UpdateTownGrowCounter(Town *t, uint16 prev_growth_rate) static void UpdateTownGrowCounter(Town *t, uint16 prev_growth_rate)
{ {
if (t->growth_rate == TOWN_GROWTH_RATE_NONE) return; if (t->growth_rate == TOWN_GROWTH_RATE_NONE || t->IsTownGrowthDisabledByOverride()) return;
if (prev_growth_rate == TOWN_GROWTH_RATE_NONE) { if (prev_growth_rate == TOWN_GROWTH_RATE_NONE) {
t->grow_counter = std::min<uint16>(t->growth_rate, t->grow_counter); t->grow_counter = std::min<uint16>(t->growth_rate, t->grow_counter);
return; return;
@@ -4025,6 +4031,7 @@ static uint GetNormalGrowthRate(Town *t)
static void UpdateTownGrowthRate(Town *t) static void UpdateTownGrowthRate(Town *t)
{ {
if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) return; if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) return;
if (t->IsTownGrowthDisabledByOverride()) return;
uint old_rate = t->growth_rate; uint old_rate = t->growth_rate;
t->growth_rate = GetNormalGrowthRate(t); t->growth_rate = GetNormalGrowthRate(t);
UpdateTownGrowCounter(t, old_rate); UpdateTownGrowCounter(t, old_rate);
@@ -4047,6 +4054,8 @@ static void UpdateTownGrowth(Town *t)
ClrBit(t->flags, TOWN_IS_GROWING); ClrBit(t->flags, TOWN_IS_GROWING);
if (t->IsTownGrowthDisabledByOverride()) return;
if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return; if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
if (t->fund_buildings_months == 0) { if (t->fund_buildings_months == 0) {
@@ -4068,7 +4077,6 @@ static void UpdateTownGrowth(Town *t)
if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) { if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) {
if (t->growth_rate != TOWN_GROWTH_RATE_NONE) SetBit(t->flags, TOWN_IS_GROWING); if (t->growth_rate != TOWN_GROWTH_RATE_NONE) SetBit(t->flags, TOWN_IS_GROWING);
SetWindowDirty(WC_TOWN_VIEW, t->index);
return; return;
} }

View File

@@ -113,7 +113,7 @@ private:
!(_local_company != COMPANY_SPECTATOR && _settings_game.difficulty.override_town_settings_in_multiplayer); !(_local_company != COMPANY_SPECTATOR && _settings_game.difficulty.override_town_settings_in_multiplayer);
} }
static const uint SETTING_OVERRIDE_COUNT = 4; static const uint SETTING_OVERRIDE_COUNT = 5;
public: public:
TownAuthorityWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), sel_index(-1), displayed_actions_on_previous_painting(0) TownAuthorityWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), sel_index(-1), displayed_actions_on_previous_painting(0)
@@ -228,6 +228,9 @@ public:
SetDParam(0, STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_VALUE + ((this->town->max_road_slope == 0) ? 1 : 0)); SetDParam(0, STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_VALUE + ((this->town->max_road_slope == 0) ? 1 : 0));
SetDParam(1, this->town->max_road_slope); SetDParam(1, this->town->max_road_slope);
break; break;
case TSOF_OVERRIDE_GROWTH:
SetDParam(0, STR_CONFIG_SETTING_TOWN_GROWTH_NONE);
break;
} }
} }
} }
@@ -255,6 +258,9 @@ public:
case TSOF_OVERRIDE_BUILD_INCLINED_ROADS: case TSOF_OVERRIDE_BUILD_INCLINED_ROADS:
SetDParam(1, STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_HELPTEXT); SetDParam(1, STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_HELPTEXT);
break; break;
case TSOF_OVERRIDE_GROWTH:
SetDParam(1, STR_CONFIG_SETTING_TOWN_GROWTH_HELPTEXT);
break;
} }
text = STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TEXT; text = STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TEXT;
SetDParam(0, STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS + this->sel_index - 0x100); SetDParam(0, STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS + this->sel_index - 0x100);
@@ -314,6 +320,10 @@ public:
SetDParam(3, max_slope); SetDParam(3, max_slope);
break; break;
} }
case TSOF_OVERRIDE_GROWTH:
SetDParam(1, overriden ? STR_CONFIG_SETTING_TOWN_GROWTH_NONE : STR_COLOUR_DEFAULT);
break;
} }
DrawString(ir.left, ir.right, y, DrawString(ir.left, ir.right, y,
STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_STR, tc); STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_STR, tc);
@@ -423,7 +433,7 @@ public:
ShowDropDownMenu(this, names, HasBit(this->town->override_flags, idx) ? this->town->build_tunnels + 1 : 0, WID_TA_SETTING, 0, 0); ShowDropDownMenu(this, names, HasBit(this->town->override_flags, idx) ? this->town->build_tunnels + 1 : 0, WID_TA_SETTING, 0, 0);
break; break;
} }
case TSOF_OVERRIDE_BUILD_INCLINED_ROADS: case TSOF_OVERRIDE_BUILD_INCLINED_ROADS: {
DropDownList dlist; DropDownList dlist;
dlist.emplace_back(new DropDownListStringItem(STR_COLOUR_DEFAULT, 0, false)); dlist.emplace_back(new DropDownListStringItem(STR_COLOUR_DEFAULT, 0, false));
dlist.emplace_back(new DropDownListStringItem(STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_ZERO, 1, false)); dlist.emplace_back(new DropDownListStringItem(STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_ZERO, 1, false));
@@ -434,6 +444,17 @@ public:
} }
ShowDropDownList(this, std::move(dlist), HasBit(this->town->override_flags, idx) ? this->town->max_road_slope + 1 : 0, WID_TA_SETTING); ShowDropDownList(this, std::move(dlist), HasBit(this->town->override_flags, idx) ? this->town->max_road_slope + 1 : 0, WID_TA_SETTING);
break; break;
}
case TSOF_OVERRIDE_GROWTH: {
int value = HasBit(this->town->override_flags, idx) ? 1 : 0;
const StringID names[] = {
STR_COLOUR_DEFAULT,
STR_CONFIG_SETTING_TOWN_GROWTH_NONE,
INVALID_STRING_ID
};
ShowDropDownMenu(this, names, value, WID_TA_SETTING, 0, 0);
break;
}
} }
break; break;
} }