Add cheat: town local authority ratings fixed as Outstanding

This commit is contained in:
Jonathan G Rennison
2021-05-05 01:17:54 +01:00
parent a9515456cb
commit 95ca147445
7 changed files with 48 additions and 4 deletions

View File

@@ -192,6 +192,7 @@ static const CheatEntry _cheats_ui[] = {
{CNM_ALL, SLF_NOT_IN_SAVE, STR_CHEAT_INFLATION_COST, &_economy.inflation_prices, &_extra_cheats.inflation_cost.been_used, nullptr }, {CNM_ALL, SLF_NOT_IN_SAVE, STR_CHEAT_INFLATION_COST, &_economy.inflation_prices, &_extra_cheats.inflation_cost.been_used, nullptr },
{CNM_ALL, SLF_NOT_IN_SAVE, STR_CHEAT_INFLATION_INCOME, &_economy.inflation_payment, &_extra_cheats.inflation_income.been_used, nullptr }, {CNM_ALL, SLF_NOT_IN_SAVE, STR_CHEAT_INFLATION_INCOME, &_economy.inflation_payment, &_extra_cheats.inflation_income.been_used, nullptr },
{CNM_ALL, SLE_BOOL, STR_CHEAT_STATION_RATING, &_extra_cheats.station_rating.value, &_extra_cheats.station_rating.been_used, nullptr }, {CNM_ALL, SLE_BOOL, STR_CHEAT_STATION_RATING, &_extra_cheats.station_rating.value, &_extra_cheats.station_rating.been_used, nullptr },
{CNM_ALL, SLE_BOOL, STR_CHEAT_TOWN_RATING, &_extra_cheats.town_rating.value, &_extra_cheats.town_rating.been_used, nullptr },
}; };
static bool IsCheatAllowed(CheatNetworkMode mode) static bool IsCheatAllowed(CheatNetworkMode mode)
@@ -442,7 +443,7 @@ struct CheatWindow : Window {
} }
if (value != oldvalue) { if (value != oldvalue) {
if (_networking || btn == CHT_STATION_RATING) { if (_networking || btn == CHT_STATION_RATING || btn == CHT_TOWN_RATING) {
if (btn != CHT_MONEY) DoCommandP(0, (uint32)btn, (uint32)value, CMD_CHEAT_SETTING); if (btn != CHT_MONEY) DoCommandP(0, (uint32)btn, (uint32)value, CMD_CHEAT_SETTING);
} else { } else {
WriteValue(ce->variable, ce->type, (int64)value); WriteValue(ce->variable, ce->type, (int64)value);

View File

@@ -41,6 +41,7 @@ struct ExtraCheats {
Cheat inflation_cost; ///< inflation cost factor Cheat inflation_cost; ///< inflation cost factor
Cheat inflation_income; ///< inflation income factor Cheat inflation_income; ///< inflation income factor
Cheat station_rating; ///< 100% station rating Cheat station_rating; ///< 100% station rating
Cheat town_rating; ///< 100% town local authority rating
}; };
/** Available cheats. */ /** Available cheats. */
@@ -56,6 +57,7 @@ enum CheatNumbers {
CHT_INFLATION_COST, ///< Change inflation cost factor CHT_INFLATION_COST, ///< Change inflation cost factor
CHT_INFLATION_INCOME,///< Change inflation income factor CHT_INFLATION_INCOME,///< Change inflation income factor
CHT_STATION_RATING, ///< 100% station ratings CHT_STATION_RATING, ///< 100% station ratings
CHT_TOWN_RATING, ///< 100% town local authority ratings
CHT_NUM_CHEATS, ///< Number of cheats. CHT_NUM_CHEATS, ///< Number of cheats.
}; };

View File

@@ -2275,6 +2275,7 @@ STR_CHEAT_INFLATION_COST_QUERY_CAPT :{WHITE}Change i
STR_CHEAT_INFLATION_INCOME :{LTBLUE}Change inflation income factor: {ORANGE}{DECIMAL} STR_CHEAT_INFLATION_INCOME :{LTBLUE}Change inflation income factor: {ORANGE}{DECIMAL}
STR_CHEAT_INFLATION_INCOME_QUERY_CAPT :{WHITE}Change inflation income factor STR_CHEAT_INFLATION_INCOME_QUERY_CAPT :{WHITE}Change inflation income factor
STR_CHEAT_STATION_RATING :{LTBLUE}Stations ratings fixed at 100%: {ORANGE}{STRING1} STR_CHEAT_STATION_RATING :{LTBLUE}Stations ratings fixed at 100%: {ORANGE}{STRING1}
STR_CHEAT_TOWN_RATING :{LTBLUE}Town local authority ratings fixed at Outstanding: {ORANGE}{STRING1}
# Livery window # Livery window
STR_LIVERY_CAPTION :{WHITE}{COMPANY} - Colour Scheme STR_LIVERY_CAPTION :{WHITE}{COMPANY} - Colour Scheme

View File

@@ -286,6 +286,10 @@ CommandCost CmdCheatSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
cht = &_extra_cheats.station_rating; cht = &_extra_cheats.station_rating;
break; break;
case CHT_TOWN_RATING:
cht = &_extra_cheats.town_rating;
break;
default: default:
return CMD_ERROR; return CMD_ERROR;
} }
@@ -298,6 +302,10 @@ CommandCost CmdCheatSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
extern void UpdateAllStationRatings(); extern void UpdateAllStationRatings();
UpdateAllStationRatings(); UpdateAllStationRatings();
} }
if (p1 == CHT_TOWN_RATING) {
extern void UpdateAllTownRatings();
UpdateAllTownRatings();
}
} }
return CommandCost(); return CommandCost();
} }

View File

@@ -29,6 +29,7 @@ static ExtraCheatNameDesc _extra_cheat_descs[] = {
{ "inflation_cost", &_extra_cheats.inflation_cost }, { "inflation_cost", &_extra_cheats.inflation_cost },
{ "inflation_income", &_extra_cheats.inflation_income }, { "inflation_income", &_extra_cheats.inflation_income },
{ "station_rating", &_extra_cheats.station_rating }, { "station_rating", &_extra_cheats.station_rating },
{ "town_rating", &_extra_cheats.town_rating },
}; };
/** /**

View File

@@ -717,6 +717,9 @@ static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reus
ZoningTownAuthorityRatingChange(); ZoningTownAuthorityRatingChange();
} }
SetBit((*st)->town->have_ratings, _current_company); SetBit((*st)->town->have_ratings, _current_company);
if (_extra_cheats.town_rating.value) {
(*st)->town->ratings[_current_company] = RATING_MAXIMUM;
}
} }
} }
} }

View File

@@ -814,6 +814,7 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags)
if (rating > t->ratings[_current_company] if (rating > t->ratings[_current_company]
&& !(flags & DC_NO_TEST_TOWN_RATING) && !(flags & DC_NO_TEST_TOWN_RATING)
&& !_cheats.magic_bulldozer.value && !_cheats.magic_bulldozer.value
&& !_extra_cheats.town_rating.value
&& _settings_game.difficulty.town_council_tolerance != TOWN_COUNCIL_INDIFFERENT) { && _settings_game.difficulty.town_council_tolerance != TOWN_COUNCIL_INDIFFERENT) {
SetDParam(0, t->index); SetDParam(0, t->index);
return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS); return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
@@ -3228,6 +3229,9 @@ CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (!Company::IsValidID(company_id)) return CMD_ERROR; if (!Company::IsValidID(company_id)) return CMD_ERROR;
int16 new_rating = Clamp((int16)GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM); int16 new_rating = Clamp((int16)GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM);
if (_extra_cheats.town_rating.value) {
new_rating = RATING_MAXIMUM;
}
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
t->ratings[company_id] = new_rating; t->ratings[company_id] = new_rating;
InvalidateWindowData(WC_TOWN_AUTHORITY, town_id); InvalidateWindowData(WC_TOWN_AUTHORITY, town_id);
@@ -3711,6 +3715,8 @@ static void ForAllStationsNearTown(Town *t, Func func)
static void UpdateTownRating(Town *t) static void UpdateTownRating(Town *t)
{ {
if (_extra_cheats.town_rating.value) return;
/* Increase company ratings if they're low */ /* Increase company ratings if they're low */
for (const Company *c : Company::Iterate()) { for (const Company *c : Company::Iterate()) {
if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) { if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) {
@@ -4034,13 +4040,15 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
/* if magic_bulldozer cheat is active, town doesn't penalize for removing stuff */ /* if magic_bulldozer cheat is active, town doesn't penalize for removing stuff */
if (t == nullptr || (flags & DC_NO_MODIFY_TOWN_RATING) || if (t == nullptr || (flags & DC_NO_MODIFY_TOWN_RATING) ||
!Company::IsValidID(_current_company) || !Company::IsValidID(_current_company) ||
(_cheats.magic_bulldozer.value && add < 0)) { ((_cheats.magic_bulldozer.value || _extra_cheats.town_rating.value) && add < 0)) {
return; return;
} }
const int prev_rating = GetRating(t); const int prev_rating = GetRating(t);
int rating = prev_rating; int rating = prev_rating;
if (add < 0) { if (_extra_cheats.town_rating.value) {
rating = RATING_MAXIMUM;
} else if (add < 0) {
if (rating > max) { if (rating > max) {
rating += add; rating += add;
if (rating < max) rating = max; if (rating < max) rating = max;
@@ -4064,6 +4072,26 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
} }
} }
void UpdateAllTownRatings()
{
if (_extra_cheats.town_rating.value) {
for (Town *t : Town::Iterate()) {
if (Company::IsValidID(_local_company) && HasBit(t->have_ratings, _local_company) && t->ratings[_local_company] <= 0) {
ZoningTownAuthorityRatingChange();
}
uint8 c;
FOR_EACH_SET_BIT(c, t->have_ratings) {
t->ratings[c] = RATING_MAXIMUM;
}
if (t->have_ratings != 0) {
t->UpdateVirtCoord();
SetWindowDirty(WC_TOWN_AUTHORITY, t->index);
}
}
}
}
/** /**
* Does the town authority allow the (destructive) action of the current company? * Does the town authority allow the (destructive) action of the current company?
* @param flags Checking flags of the command. * @param flags Checking flags of the command.
@@ -4075,7 +4103,7 @@ CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType
{ {
/* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */ /* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */
if (t == nullptr || !Company::IsValidID(_current_company) || if (t == nullptr || !Company::IsValidID(_current_company) ||
_cheats.magic_bulldozer.value || (flags & DC_NO_TEST_TOWN_RATING)) { _cheats.magic_bulldozer.value || _extra_cheats.town_rating.value || (flags & DC_NO_TEST_TOWN_RATING)) {
return CommandCost(); return CommandCost();
} }