Skip to content

Commit

Permalink
Implement 'Complete scenario challenge' cheat (#1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronVanGeffen committed Jan 12, 2023
1 parent 650a67f commit 51e0ac5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
22.12+ (???)
------------------------------------------------------------------------
- Feature: [#1745] Add cheat to instantly win any scenario/challenge.

22.12 (2022-12-22)
------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions data/language/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2325,3 +2325,4 @@ strings:
2270: "Autosave preferences"
2271: "Disable town expansion"
2272: "{SMALLFONT}{COLOUR BLACK}When enabled, towns will not renew or expand over time"
2273: "Complete scenario challenge"
6 changes: 6 additions & 0 deletions src/OpenLoco/src/Company.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ namespace OpenLoco
return;
}

evaluateChallengeProgress();
}

// Split off from updateDailyPlayer
void Company::evaluateChallengeProgress()
{
if (challengeProgress == 100)
{
challengeFlags |= CompanyFlags::challengeCompleted;
Expand Down
1 change: 1 addition & 0 deletions src/OpenLoco/src/Company.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ namespace OpenLoco
void updateDaily();
void updateDailyLogic();
void updateDailyPlayer();
void evaluateChallengeProgress();
void updateDailyControllingPlayer();
void updateMonthlyHeadquarters();
void updateLoanAutorepay();
Expand Down
16 changes: 16 additions & 0 deletions src/OpenLoco/src/GameCommands/Cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ namespace OpenLoco::GameCommands
return 0;
}

static uint32_t completeChallenge(CompanyId targetCompanyId)
{
auto company = CompanyManager::get(targetCompanyId);
if ((company->challengeFlags & CompanyFlags::challengeCompleted) != CompanyFlags::none)
return 0;

company->challengeFlags &= ~(CompanyFlags::challengeBeatenByOpponent | CompanyFlags::challengeCompleted | CompanyFlags::challengeFailed);
company->challengeProgress = 100;
company->evaluateChallengeProgress();

return 0;
}

static uint32_t vehicleReliability(int32_t newReliablity)
{
auto ourCompanyId = CompanyManager::getUpdatingCompanyId();
Expand Down Expand Up @@ -214,6 +227,9 @@ namespace OpenLoco::GameCommands
case CheatCommand::modifyDate:
return Cheats::modifyDateCheat(param1, param2, param3);

case CheatCommand::completeChallenge:
return Cheats::completeChallenge(CompanyId(param1));

default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/OpenLoco/src/GameCommands/Cheat.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace OpenLoco::GameCommands
toggleBankruptcy,
toggleJail,
vehicleReliability,
modifyDate
modifyDate,
completeChallenge,
};
}
1 change: 1 addition & 0 deletions src/OpenLoco/src/Localisation/StringIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,7 @@ namespace OpenLoco::StringIds
constexpr string_id autosave_preferences = 2270;
constexpr string_id disableTownExpansion = 2271;
constexpr string_id disableTownExpansion_tip = 2272;
constexpr string_id completeChallenge = 2273;

constexpr string_id temporary_object_load_str_0 = 8192;
constexpr string_id temporary_object_load_str_1 = 8193;
Expand Down
24 changes: 21 additions & 3 deletions src/OpenLoco/src/Windows/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ namespace OpenLoco::Ui::Windows::Cheats

namespace Companies
{
static constexpr Ui::Size kWindowSize = { 250, 172 };
static constexpr Ui::Size kWindowSize = { 250, 188 };

static WindowEventList _events;

Expand All @@ -470,22 +470,24 @@ namespace OpenLoco::Ui::Windows::Cheats
acquire_company_assets_button,
toggle_bankruptcy_button,
toggle_jail_status_button,
complete_challenge_button,
};
}

static Widget _widgets[] = {
commonWidgets(kWindowSize.width, kWindowSize.height, StringIds::company_cheats),
makeWidget({ 4, 48 }, { kWindowSize.width - 8, 33 }, WidgetType::groupbox, WindowColour::secondary, StringIds::cheat_select_target_company),
makeDropdownWidgets({ 10, 62 }, { kWindowSize.width - 20, 12 }, WidgetType::textbox, WindowColour::secondary),
makeWidget({ 4, 86 }, { kWindowSize.width - 8, 80 }, WidgetType::groupbox, WindowColour::secondary, StringIds::cheat_select_cheat_to_apply),
makeWidget({ 4, 86 }, { kWindowSize.width - 8, 96 }, WidgetType::groupbox, WindowColour::secondary, StringIds::cheat_select_cheat_to_apply),
makeWidget({ 10, 100 }, { kWindowSize.width - 20, 12 }, WidgetType::button, WindowColour::secondary, StringIds::cheat_switch_to_company),
makeWidget({ 10, 116 }, { kWindowSize.width - 20, 12 }, WidgetType::button, WindowColour::secondary, StringIds::cheat_acquire_company_assets),
makeWidget({ 10, 132 }, { kWindowSize.width - 20, 12 }, WidgetType::button, WindowColour::secondary, StringIds::cheat_toggle_bankruptcy),
makeWidget({ 10, 148 }, { kWindowSize.width - 20, 12 }, WidgetType::button, WindowColour::secondary, StringIds::cheat_toggle_jail_status),
makeWidget({ 10, 164 }, { kWindowSize.width - 20, 12 }, WidgetType::button, WindowColour::secondary, StringIds::completeChallenge),
widgetEnd(),
};

static uint64_t enabledWidgets = Common::enabledWidgets | (1 << Widx::target_company_dropdown) | (1 << Widx::target_company_dropdown_btn) | (1 << Widx::switch_company_button) | (1 << Widx::acquire_company_assets_button) | (1 << Widx::toggle_bankruptcy_button) | (1 << Widx::toggle_jail_status_button);
static uint64_t enabledWidgets = Common::enabledWidgets | (1 << Widx::target_company_dropdown) | (1 << Widx::target_company_dropdown_btn) | (1 << Widx::switch_company_button) | (1 << Widx::acquire_company_assets_button) | (1 << Widx::toggle_bankruptcy_button) | (1 << Widx::toggle_jail_status_button) | (1 << Widx::complete_challenge_button);

static CompanyId _targetCompanyId{};

Expand All @@ -501,6 +503,15 @@ namespace OpenLoco::Ui::Windows::Cheats
{
self.disabledWidgets &= ~((1 << Widx::switch_company_button) | (1 << Widx::acquire_company_assets_button));
}

if (!CompanyManager::isPlayerCompany(_targetCompanyId))
{
self.disabledWidgets |= (1 << Widx::complete_challenge_button);
}
else
{
self.disabledWidgets &= ~(1 << Widx::complete_challenge_button);
}
}

static void draw(Ui::Window& self, Gfx::RenderTarget* const rt)
Expand Down Expand Up @@ -563,6 +574,13 @@ namespace OpenLoco::Ui::Windows::Cheats
WindowManager::invalidate(WindowType::playerInfoToolbar);
return;
}

case Widx::complete_challenge_button:
{
GameCommands::do_81(CheatCommand::completeChallenge, enumValue(_targetCompanyId));
WindowManager::invalidate(WindowType::playerInfoToolbar);
return;
}
}
}

Expand Down

0 comments on commit 51e0ac5

Please sign in to comment.