Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Change speed of calendar progress (with optional real-time display) #10605

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a1f26e9
Change: Make tick length 27 milliseconds
nielsmh Dec 4, 2019
2e2bd4d
Add: Track economy date in additon to calendar date
2TallTyler Jan 1, 2023
40d11e0
Change: Split daily/monthly/yearly loops into economy and calendar loops
2TallTyler Jan 1, 2023
194164e
Feature: Setting to control calendar date progress speed
2TallTyler Jan 5, 2023
b7025bc
Add: String control codes for time units
2TallTyler Mar 5, 2023
c60b902
Add: Saveload conversions for economy dates
2TallTyler Jan 1, 2023
77edd6b
Add: Autosave interval setting uses optional real-time setting
2TallTyler Mar 8, 2023
12b92ae
Add: Town and industry windows use optional real-time setting
2TallTyler Mar 8, 2023
69bde4d
Change: Use seconds and economy dates for Linkgraph updates
2TallTyler Feb 2, 2023
b042cfb
Change: Use economy dates for desync savegame interval
2TallTyler Mar 8, 2023
def4a00
Add: Linkgraph hover tooltip uses optional real-time setting
2TallTyler Mar 8, 2023
698450e
Add: Station supply and rating string uses optional real-time setting
2TallTyler Mar 8, 2023
ddb2a0b
Codechange: Don't assert when using date cheat with slow calendar pro…
2TallTyler Jan 6, 2023
7ef7e8c
Add: Company finance window uses optional real-time setting
2TallTyler Feb 1, 2023
34409aa
Change: Use seconds for AI start delay
2TallTyler Feb 2, 2023
16f83a7
Change: Use economy dates for industry production changes and closures
2TallTyler Feb 3, 2023
338d3a9
Change: Use economy dates for economy statistics and interest payments
2TallTyler Feb 3, 2023
dac7047
Change: Use economy dates to clean up old news items
2TallTyler Feb 3, 2023
ac9d1ab
Add: NewGRF global variables for economy date and calendar speed prog…
2TallTyler Feb 8, 2023
f827422
Add: AI/GS API GetEconomyDate() method
2TallTyler Feb 8, 2023
429800f
Add: Vehicle service interval and last service date use optional real…
2TallTyler Jan 2, 2023
c71504a
Add: Vehicle and group profits use optional real-time setting
2TallTyler Mar 30, 2023
e4391c6
Add: Various financial settings use optional real-time setting
2TallTyler Mar 30, 2023
35bc8bd
Add: Performance details use optional real-time setting
2TallTyler Mar 30, 2023
1fd610b
Add: Various cost strings use optional real-time setting
2TallTyler Mar 30, 2023
0f89001
Add: Minimum company age to trade shares uses optional real-time setting
2TallTyler Feb 3, 2023
05cf4df
Add: Vehicle age uses optional real-time setting
2TallTyler Feb 3, 2023
f151591
Add: Tiles/day velocity unit uses optional real-time setting
2TallTyler Mar 31, 2023
623d32f
Add: Subsidies use optional real-time setting
2TallTyler Mar 31, 2023
90013c2
Add: Timetable use optional real-time setting
2TallTyler Jan 31, 2023
51854bd
Add: Cargo payment graph time axis uses optional real-time setting
2TallTyler Feb 2, 2023
41434c0
Add: Company graph time axis uses optional real-time setting
2TallTyler Feb 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ai/ai.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class AI {
* The default months AIs start after each other.
*/
enum StartNext {
START_NEXT_EASY = DAYS_IN_YEAR * 2,
START_NEXT_MEDIUM = DAYS_IN_YEAR,
START_NEXT_HARD = DAYS_IN_YEAR / 2,
START_NEXT_EASY = DAYS_IN_YEAR * SECONDS_PER_DAY * 2,
START_NEXT_MEDIUM = DAYS_IN_YEAR * SECONDS_PER_DAY,
START_NEXT_HARD = DAYS_IN_YEAR * SECONDS_PER_DAY / 2,
START_NEXT_MIN = 0,
START_NEXT_MAX = 3600,
START_NEXT_DEVIATION = 60,
START_NEXT_MAX = 7200,
START_NEXT_DEVIATION = 120,
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ai/ai_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/** Configuration for AI start date, every AI has this setting. */
ScriptConfigItem _start_date_config = {
"start_date",
"", // STR_AI_SETTINGS_START_DELAY
"", // STR_AI_SETTINGS_START_DELAY_SECONDS
AI::START_NEXT_MIN,
AI::START_NEXT_MAX,
AI::START_NEXT_MEDIUM,
Expand Down
2 changes: 2 additions & 0 deletions src/aircraft_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_aircraft);

v->date_of_last_service = _date;
v->economy_date_of_last_service = _economy_date;
v->build_year = u->build_year = _cur_year;

v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
Expand Down Expand Up @@ -1556,6 +1557,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
if (v->subtype == AIR_HELICOPTER && apc->num_helipads > 0) {
/* an excerpt of ServiceAircraft, without the invisibility stuff */
v->date_of_last_service = _date;
v->economy_date_of_last_service = _economy_date;
v->breakdowns_since_last_service = 0;
v->reliability = v->GetEngine()->reliability;
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
Expand Down
3 changes: 2 additions & 1 deletion src/build_vehicle_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,10 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number,

/* Draw details that apply to all types except rail wagons. */
if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
int days_in_year = (_settings_game.economy.use_realtime_units ? DAYS_IN_ECONOMY_YEAR : DAYS_IN_LEAP_YEAR);
/* Design date - Life length */
SetDParam(0, ymd.year);
SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR);
SetDParam(1, e->GetLifeLengthInDays() / days_in_year);
DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
y += FONT_HEIGHT_NORMAL;

Expand Down
16 changes: 9 additions & 7 deletions src/cheat_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static int32 ClickSetProdCheat(int32 p1, int32 p2)
return _cheats.setup_prod.value;
}

extern void EnginesMonthlyLoop();
extern void EnginesCalendarMonthlyLoop();

/**
* Handle changing of the current year.
Expand All @@ -102,17 +102,19 @@ extern void EnginesMonthlyLoop();
*/
static int32 ClickChangeDateCheat(int32 p1, int32 p2)
{
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);

p1 = Clamp(p1, MIN_YEAR, MAX_YEAR);
if (p1 == _cur_year) return _cur_year;

/* Change calendar date. */
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
Date new_date = ConvertYMDToDate(p1, ymd.month, ymd.day);
for (auto v : Vehicle::Iterate()) v->ShiftDates(new_date - _date);
LinkGraphSchedule::instance.ShiftDates(new_date - _date);
SetDate(new_date, _date_fract);
EnginesMonthlyLoop();

/* If not using real-time units, we keep economy date in sync with calendar date and must change it also. */
if (!_settings_game.economy.use_realtime_units) SetEconomyDate(new_date, _date_fract);

EnginesCalendarMonthlyLoop();
SetWindowDirty(WC_STATUS_BAR, 0);
InvalidateWindowClassesData(WC_BUILD_STATION, 0);
InvalidateWindowClassesData(WC_BUS_STATION, 0);
Expand Down
5 changes: 3 additions & 2 deletions src/company_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ struct CompanyProperties {

std::array<Owner, MAX_COMPANY_SHARE_OWNERS> share_owners; ///< Owners of the shares of the company. #INVALID_OWNER if nobody has bought them yet.

Year inaugurated_year; ///< Year of starting the company.
Year inaugurated_year; ///< Calendar year the company was started.
Year inaugurated_economy_year; ///< Economy year the company was started.

byte months_of_bankruptcy; ///< Number of months that the company is unable to pay its debts
CompanyMask bankrupt_asked; ///< which companies were asked about buying it?
Expand Down Expand Up @@ -109,7 +110,7 @@ struct CompanyProperties {
CompanyProperties()
: name_2(0), name_1(0), president_name_1(0), president_name_2(0),
face(0), money(0), money_fraction(0), current_loan(0), colour(0), block_preview(0),
location_of_HQ(0), last_build_coordinate(0), share_owners(), inaugurated_year(0),
location_of_HQ(0), last_build_coordinate(0), share_owners(), inaugurated_year(0), inaugurated_economy_year(0),
months_of_bankruptcy(0), bankrupt_asked(0), bankrupt_timeout(0), bankrupt_value(0),
terraform_limit(0), clear_limit(0), tree_limit(0), build_object_limit(0), is_ai(false), engine_renew_list(nullptr) {}
};
Expand Down
5 changes: 3 additions & 2 deletions src/company_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
c->avail_railtypes = GetCompanyRailtypes(c->index);
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
c->inaugurated_year = _cur_year;
c->inaugurated_economy_year = _cur_economy_year;

/* If starting a player company in singleplayer and a favorite company manager face is selected, choose it. Otherwise, use a random face.
* In a network game, we'll choose the favorite face later in CmdCompanyCtrl to sync it to all clients. */
Expand Down Expand Up @@ -722,7 +723,7 @@ void OnTick_Companies()

if (_next_competitor_start == 0) {
/* AI::GetStartNextTime() can return 0. */
_next_competitor_start = std::max(1, AI::GetStartNextTime() * DAY_TICKS);
_next_competitor_start = std::max(1, AI::GetStartNextTime() * DAY_TICKS / SECONDS_PER_DAY);
}

if (_game_mode != GM_MENU && AI::CanStartNew() && --_next_competitor_start == 0) {
Expand All @@ -743,7 +744,7 @@ void OnTick_Companies()
* A year has passed, update the economic data of all companies, and perhaps show the
* financial overview window of the local company.
*/
void CompaniesYearlyLoop()
void CompaniesEconomyYearlyLoop()
{
/* Copy statistics */
for (Company *c : Company::Iterate()) {
Expand Down
12 changes: 7 additions & 5 deletions src/company_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static uint GetTotalCategoriesHeight()
*/
static uint GetMaxCategoriesWidth()
{
uint max_width = 0;
uint max_width = GetStringBoundingBox(STR_FINANCES_YEAR_CAPTION).width;

/* Loop through categories to check max widths. */
for (uint i = 0; i < lengthof(_expenses_list_types); i++) {
Expand Down Expand Up @@ -174,8 +174,10 @@ static void DrawCategory(const Rect &r, int start_y, ExpensesList list)
*/
static void DrawCategories(const Rect &r)
{
/* Start with an empty space in the year row, plus the blockspace under the year. */
int y = r.top + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
int y = r.top;
/* Draw description of 12-minute economic period. */
DrawString(r.left, r.right, y, (STR_FINANCES_YEAR_CAPTION), TC_FROMSTRING, SA_LEFT, true);
y += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;

for (uint i = 0; i < lengthof(_expenses_list_types); i++) {
/* Draw category title and advance y */
Expand Down Expand Up @@ -432,10 +434,10 @@ struct CompanyFinancesWindow : Window {
case WID_CF_EXPS_PRICE2:
case WID_CF_EXPS_PRICE3: {
const Company *c = Company::Get((CompanyID)this->window_number);
int age = std::min(_cur_year - c->inaugurated_year, 2);
int age = std::min(_cur_economy_year - c->inaugurated_economy_year, 2);
int wid_offset = widget - WID_CF_EXPS_PRICE1;
if (wid_offset <= age) {
DrawYearColumn(r, _cur_year - (age - wid_offset), c->yearly_expenses[age - wid_offset]);
DrawYearColumn(r, _cur_economy_year - (age - wid_offset), c->yearly_expenses[age - wid_offset]);
}
break;
}
Expand Down