From 752d9bc89d51b7c3c138820f89f4491f73b2096d Mon Sep 17 00:00:00 2001 From: Harrison Gentry Date: Fri, 5 Jan 2018 23:10:50 -0500 Subject: [PATCH] Add cheat and console command to set game date. Run "date" command on cmdline to set date. Ex: $ date 0004 06 13 sets date to June 13th, year 4 --- data/language/en-GB.txt | 6 +++ src/openrct2-ui/windows/Cheats.cpp | 76 +++++++++++++++++++++++++-- src/openrct2/Cheats.cpp | 3 ++ src/openrct2/Cheats.h | 4 ++ src/openrct2/Date.cpp | 3 +- src/openrct2/interface/Console.cpp | 1 + src/openrct2/localisation/Date.cpp | 63 ++++++++++++++++++++++ src/openrct2/localisation/Date.h | 2 + src/openrct2/localisation/StringIds.h | 8 +++ 9 files changed, 159 insertions(+), 7 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 1f387c7e47..da89d1af38 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -4502,6 +4502,12 @@ STR_6192 :Wall STR_6193 :{COMMA16} guest STR_6194 :{INLINE_SPRITE}{11}{20}{00}{00}{COMMA16} guest STR_6195 :{INLINE_SPRITE}{10}{20}{00}{00}{COMMA16} guest +STR_6196 :{BLACK}Year: +STR_6197 :{BLACK}Month: +STR_6198 :{BLACK}Day: +STR_6199 :Set date +STR_6200 :Reset date +STR_6201 :{MONTH} ############# # Scenarios # diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index ce37c44834..d2766f196c 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -20,8 +20,8 @@ #include #include #include - #include +#include #include #include #include @@ -68,6 +68,18 @@ enum WINDOW_CHEATS_WIDGET_IDX { WIDX_ADD_MONEY, WIDX_SET_MONEY, WIDX_CLEAR_LOAN, + WIDX_DATE_GROUP, + WIDX_YEAR_BOX, + WIDX_YEAR_UP, + WIDX_YEAR_DOWN, + WIDX_MONTH_BOX, + WIDX_MONTH_UP, + WIDX_MONTH_DOWN, + WIDX_DAY_BOX, + WIDX_DAY_UP, + WIDX_DAY_DOWN, + WIDX_DATE_SET, + WIDX_DATE_RESET, WIDX_GUEST_PARAMETERS_GROUP = WIDX_TAB_CONTENT, WIDX_GUEST_HAPPINESS_MAX, @@ -194,6 +206,18 @@ static rct_widget window_cheats_money_widgets[] = { { WWT_CLOSEBOX, 1, XPL(0), WPL(0), YPL(3), HPL(3), STR_ADD_MONEY, STR_NONE }, // add money { WWT_CLOSEBOX, 1, XPL(1), WPL(1), YPL(3), HPL(3), STR_SET_MONEY, STR_NONE }, // set money { WWT_CLOSEBOX, 1, XPL(0), WPL(0), YPL(5), HPL(5), STR_CHEAT_CLEAR_LOAN, STR_NONE }, // Clear loan + { WWT_GROUPBOX, 1, XPL(0) - GROUP_SPACE, WPL(1) + GROUP_SPACE, YPL(6.5), HPL(10.5), STR_DATE_SET, STR_NONE }, // Date group + { WWT_SPINNER, 1, WPL(0), WPL(1) - 10, YPL(7) + 2, HPL(7) - 3, STR_NONE, STR_NONE }, // Year box + { WWT_DROPDOWN_BUTTON, 1, WPL(1) - 10, WPL(1), YPL(7) + 3, YPL(7) + 7, STR_NUMERIC_UP, STR_NONE }, // increase year + { WWT_DROPDOWN_BUTTON, 1, WPL(1) - 10, WPL(1), YPL(7) + 8, YPL(7) + 12, STR_NUMERIC_DOWN, STR_NONE }, // decrease year + { WWT_SPINNER, 1, WPL(0), WPL(1) - 10, YPL(8) + 2, HPL(8) - 3, STR_NONE, STR_NONE }, // Month box + { WWT_DROPDOWN_BUTTON, 1, WPL(1) - 10, WPL(1), YPL(8) + 3, YPL(8) + 7, STR_NUMERIC_UP, STR_NONE }, // increase month + { WWT_DROPDOWN_BUTTON, 1, WPL(1) - 10, WPL(1), YPL(8) + 8, YPL(8) + 12, STR_NUMERIC_DOWN, STR_NONE }, // decrease month + { WWT_SPINNER, 1, WPL(0), WPL(1) - 10, YPL(9) + 2, HPL(9) - 3, STR_NONE, STR_NONE }, // Day box + { WWT_DROPDOWN_BUTTON, 1, WPL(1) - 10, WPL(1), YPL(9) + 3, YPL(9) + 7, STR_NUMERIC_UP, STR_NONE }, // increase day + { WWT_DROPDOWN_BUTTON, 1, WPL(1) - 10, WPL(1), YPL(9) + 8, YPL(9) + 12, STR_NUMERIC_DOWN, STR_NONE }, // decrease day + { WWT_CLOSEBOX, 1, XPL(0), WPL(0), YPL(10), HPL(10), STR_DATE_SET, STR_NONE }, // Set Date + { WWT_CLOSEBOX, 1, XPL(1), WPL(1), YPL(10), HPL(10), STR_DATE_RESET, STR_NONE }, // Reset Date { WIDGETS_END }, }; @@ -439,7 +463,9 @@ static rct_window_event_list *window_cheats_page_events[] = { static uint64 window_cheats_page_enabled_widgets[] = { MAIN_CHEAT_ENABLED_WIDGETS | (1ULL << WIDX_NO_MONEY) | (1ULL << WIDX_ADD_SET_MONEY_GROUP) | (1ULL << WIDX_MONEY_SPINNER) | (1ULL << WIDX_MONEY_SPINNER_INCREMENT) | - (1ULL << WIDX_MONEY_SPINNER_DECREMENT) | (1ULL << WIDX_ADD_MONEY) | (1ULL << WIDX_SET_MONEY) | (1ULL << WIDX_CLEAR_LOAN), + (1ULL << WIDX_MONEY_SPINNER_DECREMENT) | (1ULL << WIDX_ADD_MONEY) | (1ULL << WIDX_SET_MONEY) | (1ULL << WIDX_CLEAR_LOAN) | (1ULL << WIDX_DATE_SET) | + (1ULL << WIDX_MONTH_BOX) | (1ULL << WIDX_MONTH_UP) | (1ULL << WIDX_MONTH_DOWN) | (1ULL << WIDX_YEAR_BOX) | (1ULL << WIDX_YEAR_UP) | (1ULL << WIDX_YEAR_DOWN) | (1ULL << WIDX_DAY_BOX) | + (1ULL << WIDX_DAY_UP) | (1ULL << WIDX_DAY_DOWN) | (1ULL << WIDX_MONTH_BOX) | (1ULL << WIDX_DATE_GROUP) | (1ULL << WIDX_DATE_RESET), MAIN_CHEAT_ENABLED_WIDGETS | (1ULL << WIDX_GUEST_PARAMETERS_GROUP) | (1ULL << WIDX_GUEST_HAPPINESS_MAX) | (1ULL << WIDX_GUEST_HAPPINESS_MIN) | (1ULL << WIDX_GUEST_ENERGY_MAX) | (1ULL << WIDX_GUEST_ENERGY_MIN) | (1ULL << WIDX_GUEST_HUNGER_MAX) | (1ULL << WIDX_GUEST_HUNGER_MIN) | (1ULL << WIDX_GUEST_THIRST_MAX) | (1ULL << WIDX_GUEST_THIRST_MIN) | @@ -461,7 +487,8 @@ static uint64 window_cheats_page_enabled_widgets[] = { }; static uint64 window_cheats_page_hold_down_widgets[] = { - (1ULL << WIDX_MONEY_SPINNER_INCREMENT) | (1ULL << WIDX_MONEY_SPINNER_DECREMENT) | (1ULL << WIDX_ADD_MONEY), + (1ULL << WIDX_MONEY_SPINNER_INCREMENT) | (1ULL << WIDX_MONEY_SPINNER_DECREMENT) | (1ULL << WIDX_ADD_MONEY) | (1ULL << WIDX_YEAR_UP) | + (1ULL << WIDX_YEAR_DOWN) | (1ULL << WIDX_MONTH_UP) | (1ULL << WIDX_MONTH_DOWN) | (1ULL << WIDX_DAY_UP) | (1ULL << WIDX_DAY_DOWN), 0, (1ULL << WIDX_INCREASE_PARK_RATING) | (1ULL << WIDX_DECREASE_PARK_RATING), 0 @@ -510,6 +537,38 @@ static void window_cheats_money_mousedown(rct_window *w, rct_widgetindex widgetI case WIDX_ADD_MONEY: game_do_command(0, GAME_COMMAND_FLAG_APPLY, CHEAT_ADDMONEY, _moneySpinnerValue, GAME_COMMAND_CHEAT, 0, 0); break; + case WIDX_YEAR_UP: + year_spinner_value++; + year_spinner_value = Math::Clamp(1, year_spinner_value, 8192); + break; + case WIDX_YEAR_DOWN: + year_spinner_value--; + year_spinner_value = Math::Clamp(1, year_spinner_value, 8192); + break; + case WIDX_MONTH_UP: + month_spinner_value++; + month_spinner_value = Math::Clamp(1, month_spinner_value, (int)MONTH_COUNT); + day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + break; + case WIDX_MONTH_DOWN: + month_spinner_value--; + month_spinner_value = Math::Clamp(1, month_spinner_value, (int)MONTH_COUNT); + day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + break; + case WIDX_DAY_UP: + day_spinner_value++; + day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + break; + case WIDX_DAY_DOWN: + day_spinner_value--; + day_spinner_value = Math::Clamp(1, day_spinner_value, (int)days_in_month[month_spinner_value - 1]); + break; + case WIDX_DATE_SET: + date_set(year_spinner_value, month_spinner_value, day_spinner_value); + break; + case WIDX_DATE_RESET: + date_set(1, 1, 1); + break; } } @@ -937,12 +996,19 @@ static void window_cheats_paint(rct_window *w, rct_drawpixelinfo *dpi) if (widget_is_disabled(w, WIDX_MONEY_SPINNER)) { colour |= COLOUR_FLAG_INSET; } - gfx_draw_string_left(dpi, STR_BOTTOM_TOOLBAR_CASH, gCommonFormatArgs, colour, w->x + XPL(0) + TXTO, w->y + YPL(2) + TXTO); + sint32 actual_month = month_spinner_value - 1; + gfx_draw_string_left(dpi, STR_BOTTOM_TOOLBAR_CASH, gCommonFormatArgs, colour, w->x + XPL(0) + TXTO, w->y + YPL(2) + TXTO); + gfx_draw_string_left(dpi, STR_YEAR, nullptr, COLOUR_BLACK, w->x + XPL(0) + TXTO, w->y + YPL(7) + TXTO); + gfx_draw_string_left(dpi, STR_MONTH, nullptr, COLOUR_BLACK, w->x + XPL(0) + TXTO, w->y + YPL(8) + TXTO); + gfx_draw_string_left(dpi, STR_DAY, nullptr, COLOUR_BLACK, w->x + XPL(0) + TXTO, w->y + YPL(9) + TXTO); + gfx_draw_string_right(dpi, STR_FORMAT_INTEGER, &year_spinner_value, w->colours[1], w->x + WPL(1) - 10 - TXTO, w->y + YPL(7) + TXTO); + gfx_draw_string_right(dpi, STR_FORMAT_MONTH, &actual_month, w->colours[1], w->x + WPL(1) - 10 - TXTO, w->y + YPL(8) + TXTO); + gfx_draw_string_right(dpi, STR_FORMAT_INTEGER, &day_spinner_value, w->colours[1], w->x + WPL(1) - 10 - TXTO, w->y + YPL(9) + TXTO); } else if(w->page == WINDOW_CHEATS_PAGE_MISC){ gfx_draw_string_left(dpi, STR_CHEAT_STAFF_SPEED, nullptr, COLOUR_BLACK, w->x + XPL(0) + TXTO, w->y + YPL(17) + TXTO); gfx_draw_string_left(dpi, STR_FORCE_WEATHER, nullptr, COLOUR_BLACK, w->x + XPL(0) + TXTO, w->y + YPL(10) + TXTO); - gfx_draw_string_right(dpi, STR_FORMAT_INTEGER, &park_rating_spinner_value, w->colours[1], w->x + WPL(1) - 10 - TXTO, w->y + YPL(5) + TXTO); + gfx_draw_string_right(dpi, STR_FORMAT_INTEGER, &park_rating_spinner_value, w->colours[1], w->x + WPL(1) - 10 - TXTO, w->y + YPL(5) + TXTO); } else if (w->page == WINDOW_CHEATS_PAGE_GUESTS){ gfx_draw_string_left(dpi, STR_CHEAT_GUEST_HAPPINESS, nullptr, COLOUR_BLACK, w->x + XPL(0) + TXTO, w->y + YPL(1) + TXTO); diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index 39d080924c..8e6ab3d2e0 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -54,6 +54,9 @@ bool gCheatsIgnoreResearchStatus = false; bool gCheatsEnableAllDrawableTrackPieces = false; sint32 park_rating_spinner_value; +sint32 year_spinner_value = 1; +sint32 month_spinner_value = 1; +sint32 day_spinner_value = 1; #pragma region Cheat functions diff --git a/src/openrct2/Cheats.h b/src/openrct2/Cheats.h index 0a61a4b777..f2e31caa46 100644 --- a/src/openrct2/Cheats.h +++ b/src/openrct2/Cheats.h @@ -95,6 +95,7 @@ enum { CHEAT_DISABLERIDEVALUEAGING, CHEAT_IGNORERESEARCHSTATUS, CHEAT_ENABLEALLDRAWABLETRACKPIECES, + CHEAT_DATE_SET, }; enum { @@ -121,6 +122,9 @@ enum { #define CHEATS_STAFF_NORMAL_SPEED 0x60 extern sint32 park_rating_spinner_value; +extern sint32 year_spinner_value; +extern sint32 month_spinner_value; +extern sint32 day_spinner_value; void game_command_cheat(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); diff --git a/src/openrct2/Date.cpp b/src/openrct2/Date.cpp index 47f20a4652..0af2478ff8 100644 --- a/src/openrct2/Date.cpp +++ b/src/openrct2/Date.cpp @@ -122,6 +122,5 @@ sint32 Date::GetDaysInMonth(sint32 month) { Guard::ArgumentInRange(month, 0, MONTH_COUNT - 1); - static const sint16 DaysInMonth[MONTH_COUNT] = { 31, 30, 31, 30, 31, 31, 30, 31 }; - return DaysInMonth[month]; + return days_in_month[month]; } diff --git a/src/openrct2/interface/Console.cpp b/src/openrct2/interface/Console.cpp index 6b8f2ad6e9..b6c3f3891e 100644 --- a/src/openrct2/interface/Console.cpp +++ b/src/openrct2/interface/Console.cpp @@ -1407,6 +1407,7 @@ static const console_command console_command_table[] = { { "remove_unused_objects", cc_remove_unused_objects, "Removes all the unused objects from the object selection.", "remove_unused_objects" }, { "remove_park_fences", cc_remove_park_fences, "Removes all park fences from the surface", "remove_park_fences"}, { "show_limits", cc_show_limits, "Shows the map data counts and limits.", "show_limits" }, + { "date", cmdline_for_date, "Sets the date to a given date. Format YYYY MM DD, YYYY MM, or YYYY."} }; static sint32 cc_windows(const utf8 **argv, sint32 argc) { diff --git a/src/openrct2/localisation/Date.cpp b/src/openrct2/localisation/Date.cpp index 0c36b347f0..b428cc6f44 100644 --- a/src/openrct2/localisation/Date.cpp +++ b/src/openrct2/localisation/Date.cpp @@ -16,6 +16,8 @@ #include #include "../Game.h" +#include "../core/Math.hpp" +#include "../interface/window.h" #include "Date.h" #include "StringIds.h" @@ -65,6 +67,67 @@ void date_reset() gDateMonthsElapsed = 0; gDateMonthTicks = 0; gCurrentTicks = 0; + window_invalidate_by_class(WC_BOTTOM_TOOLBAR); +} + +void date_set(sint32 year, sint32 month, sint32 day) +{ + year = Math::Clamp(1, year, 8192); + month = Math::Clamp(1, month, (int)MONTH_COUNT); + day = Math::Clamp(1, day, (int)days_in_month[month - 1]); + gDateMonthsElapsed = (year - 1) * MONTH_COUNT + month - 1; + gDateMonthTicks = 0x10000 / days_in_month[month - 1] * (day - 1) + 4; + window_invalidate_by_class(WC_BOTTOM_TOOLBAR); +} + +sint32 cmdline_for_date(const utf8 **argv, sint32 argc) +{ + sint32 year = 0; + sint32 month = 0; + sint32 day = 0; + if (argc < 1 || argc > 3) + { + return -1; + } + + //All cases involve providing a year, so grab that first + year = atoi(argv[0]); + if (year < 1 || year > 8192) { + return -1; + } + + //YYYY (no month provided, preserve existing month) + if (argc == 1) + { + month = gDateMonthsElapsed % MONTH_COUNT + 1; + } + + ////YYYY MM or YYYY MM DD (month provided) + if (argc >= 2) + { + month = atoi(argv[1]); + month -= 2; + if (month < 1 || month > MONTH_COUNT) { + return -1; + } + } + + //YYYY OR YYYY MM (no day provided, preserve existing day) + if (argc <= 2) + { + day = Math::Clamp(1, gDateMonthTicks / (0x10000 / days_in_month[month - 1]) + 1, (int)days_in_month[month - 1]); + } + + //YYYY MM DD (year, month, and day provided) + if (argc == 3) + { + day = atoi(argv[2]); + if (day < 1 || day > days_in_month[month-1]) { + return -1; + } + } + date_set(year, month, day); + return 1; } void date_update() diff --git a/src/openrct2/localisation/Date.h b/src/openrct2/localisation/Date.h index 8065a7b9bc..4d3a9459bf 100644 --- a/src/openrct2/localisation/Date.h +++ b/src/openrct2/localisation/Date.h @@ -61,8 +61,10 @@ extern openrct_timeofday gRealTimeOfDay; sint32 date_get_month(sint32 months); sint32 date_get_year(sint32 months); sint32 date_get_total_months(sint32 month, sint32 year); +sint32 cmdline_for_date(const utf8 **argv, sint32 argc); void date_reset(); void date_update(); +void date_set(sint32 year, sint32 month, sint32 day); void date_update_real_time_of_day(); bool date_is_day_start(sint32 monthTicks); bool date_is_week_start(sint32 monthTicks); diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index b4bd757732..845c1a4795 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -3847,6 +3847,14 @@ enum { STR_BOTTOM_TOOLBAR_NUM_GUESTS_STABLE_SINGULAR = 6193, STR_BOTTOM_TOOLBAR_NUM_GUESTS_DECREASE_SINGULAR = 6194, STR_BOTTOM_TOOLBAR_NUM_GUESTS_INCREASE_SINGULAR = 6195, + + STR_YEAR = 6196, + STR_MONTH = 6197, + STR_DAY = 6198, + STR_DATE_SET = 6199, + STR_DATE_RESET = 6200, + STR_FORMAT_MONTH = 6201, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 };