OpenTTD
|
Handling of dates in our native format and transforming them to something human readable. More...
#include "stdafx.h"
#include "network/network.h"
#include "network/network_func.h"
#include "currency.h"
#include "window_func.h"
#include "settings_type.h"
#include "date_func.h"
#include "vehicle_base.h"
#include "rail_gui.h"
#include "linkgraph/linkgraph.h"
#include "saveload/saveload.h"
#include "safeguards.h"
Go to the source code of this file.
Macros | |
#define | M(a, b) ((a << 5) | b) |
Functions | |
void | SetDate (Date date, DateFract fract) |
Set the date. | |
void | ConvertDateToYMD (Date date, YearMonthDay *ymd) |
Converts a Date to a Year, Month & Day. | |
Date | ConvertYMDToDate (Year year, Month month, Day day) |
Converts a tuple of Year, Month and Day to a Date. | |
void | EnginesDailyLoop () |
Functions used by the IncreaseDate function. | |
void | DisasterDailyLoop () |
void | IndustryDailyLoop () |
Daily handler for the industry changes Taking the original map size of 256*256, the number of random changes was always of just one unit. | |
void | CompaniesMonthlyLoop () |
Monthly update of the economic data (of the companies as well as economic fluctuations). | |
void | EnginesMonthlyLoop () |
Monthly update of the availability, reliability, and preview offers of the engines. | |
void | TownsMonthlyLoop () |
void | IndustryMonthlyLoop () |
void | StationMonthlyLoop () |
Monthly loop for stations. | |
void | SubsidyMonthlyLoop () |
Perform the monthly update of open subsidies, and try to create a new one. | |
void | CompaniesYearlyLoop () |
A year has passed, update the economic data of all companies, and perhaps show the financial overview window of the local company. | |
void | VehiclesYearlyLoop () |
void | TownsYearlyLoop () |
void | ShowEndGameChart () |
Show the endgame victory screen in 2050. | |
static void | OnNewYear () |
Runs various procedures that have to be done yearly. | |
static void | OnNewMonth () |
Runs various procedures that have to be done monthly. | |
static void | OnNewDay () |
Runs various procedures that have to be done daily. | |
void | IncreaseDate () |
Increases the tick counter, increases date and possibly calls procedures that have to be called daily, monthly or yearly. |
Variables | |
Year | _cur_year |
Current year, starting at 0. | |
Month | _cur_month |
Current month (0..11) | |
Date | _date |
Current date in days (day counter) | |
DateFract | _date_fract |
Fractional part of the day. | |
uint16 | _tick_counter |
Ever incrementing (and sometimes wrapping) tick counter for setting off various events. | |
static const uint16 | _month_date_from_year_day [] |
static const uint16 | _accum_days_for_month [] |
Number of days to pass from the first day in the year before reaching the first of a month. | |
static const Month | _autosave_months [] |
Available settings for autosave intervals. |
Handling of dates in our native format and transforming them to something human readable.
Definition in file date.cpp.
void ConvertDateToYMD | ( | Date | date, |
YearMonthDay * | ymd | ||
) |
Converts a Date to a Year, Month & Day.
date | the date to convert from |
ymd | the year, month and day to write to |
Definition at line 94 of file date.cpp.
References YearMonthDay::day, DAYS_IN_LEAP_YEAR, DAYS_IN_YEAR, IsLeapYear(), YearMonthDay::month, and YearMonthDay::year.
Referenced by ClickChangeDateCheat(), NetworkGameWindow::DrawServerLine(), DrawVehiclePurchaseInfo(), SubsidyListWindow::DrawWidget(), CrashLog::FillCrashLog(), GetGlobalVariable(), GetSnowLine(), IncreaseDate(), SetDate(), SetDateWindow::SetDateWindow(), and SetYearEngineAgingStops().
Converts a tuple of Year, Month and Day to a Date.
year | is a number between 0..MAX_YEAR |
month | is a number between 0..11 |
day | is a number between 1..31 |
Definition at line 149 of file date.cpp.
References _accum_days_for_month, DAYS_TILL, and IsLeapYear().
Referenced by ClickChangeDateCheat(), SaveLoadWindow::DrawWidget(), ScenarioEditorToolbarWindow::DrawWidget(), FixTTOEngines(), GetGlobalVariable(), LoadNewGRF(), SetDateWindow::OnClick(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), NetworkUDPSocketHandler::ReceiveNetworkGameInfo(), ServerNetworkAdminSocketHandler::SendWelcome(), SetStartingYear(), GenerateLandscapeWindow::SetStringParameters(), CreateScenarioWindow::SetStringParameters(), StartupEngines(), StartupOneEngine(), CheatWindow::UpdateWidgetSize(), GenerateLandscapeWindow::UpdateWidgetSize(), CreateScenarioWindow::UpdateWidgetSize(), MessageHistoryWindow::UpdateWidgetSize(), and ScenarioEditorToolbarWindow::UpdateWidgetSize().
void EnginesMonthlyLoop | ( | ) |
Monthly update of the availability, reliability, and preview offers of the engines.
Definition at line 985 of file engine.cpp.
References _cur_year, _date, _year_engine_aging_stops, CalcEngineReliability(), DAYS_IN_YEAR, ENGINE_AVAILABLE, ENGINE_EXCLUSIVE_PREVIEW, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Engine::intro_date, INVALID_COMPANY, InvalidateWindowClassesData(), Engine::IsEnabled(), IsVehicleTypeDisabled(), IsWagon(), MAX_DAY, NewVehicleAvailable(), Engine::preview_asked, Engine::preview_company, Engine::type, and WC_BUILD_VEHICLE.
void IndustryDailyLoop | ( | ) |
Daily handler for the industry changes Taking the original map size of 256*256, the number of random changes was always of just one unit.
But it cannot be the same on smaller or bigger maps. That number has to be scaled up or down. For small maps, it implies that less than one change per month is required, while on bigger maps, it would be way more. The daily loop handles those changes.
Definition at line 2671 of file industry_cmd.cpp.
References _current_company, _industry_builder, Chance16(), ChangeIndustryProduction(), GetCurrentTotalNumberOfIndustries(), Industry::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Economy::industry_daily_change_counter, Economy::industry_daily_increment, InvalidateWindowData(), min(), OWNER_NONE, Backup< T >::Restore(), SetWindowDirty(), IndustryBuildData::TryBuildNewIndustry(), IndustryBuildData::wanted_inds, WC_INDUSTRY_DIRECTORY, and WC_INDUSTRY_VIEW.
Referenced by OnNewDay().
Set the date.
date | New date |
fract | The number of ticks that have passed on this date. |
Definition at line 37 of file date.cpp.
References _cur_month, _cur_year, _date, _date_fract, ConvertDateToYMD(), DAY_TICKS, YearMonthDay::month, and YearMonthDay::year.
Referenced by AfterLoadGame(), ClickChangeDateCheat(), and SetStartingYear().
void ShowEndGameChart | ( | ) |
Show the endgame victory screen in 2050.
Update the new highscore if it was high enough
Definition at line 241 of file highscore_gui.cpp.
References _local_company, _network_dedicated, _networking, DeleteWindowByClass(), HideVitalWindows(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and WC_ENDSCREEN.
Referenced by OnNewYear().
void StationMonthlyLoop | ( | ) |
Monthly loop for stations.
Definition at line 3626 of file station_cmd.cpp.
References ClrBit(), GB(), GoodsEntry::GES_CURRENT_MONTH, GoodsEntry::GES_LAST_MONTH, Station::goods, NUM_CARGO, SB(), and GoodsEntry::status.
Referenced by OnNewMonth().
void SubsidyMonthlyLoop | ( | ) |
Perform the monthly update of open subsidies, and try to create a new one.
Definition at line 469 of file subsidy.cpp.
References _local_company, _settings_game, AddNewsItem(), Subsidy::awarded, AI::BroadcastNewEvent(), LinkGraphSettings::distribution_armoured, LinkGraphSettings::distribution_default, LinkGraphSettings::distribution_mail, LinkGraphSettings::distribution_pax, Subsidy::dst, DT_MANUAL, FindSubsidyIndustryCargoRoute(), FindSubsidyPassengerRoute(), FindSubsidyTownCargoRoute(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), Subsidy::IsAwarded(), GameSettings::linkgraph, Game::NewEvent(), NF_NORMAL, NT_SUBSIDIES, RandomRange(), RebuildSubsidisedSourceAndDestinationCache(), Subsidy::remaining, SetupSubsidyDecodeParam(), Subsidy::src, and WC_SUBSIDIES_LIST.
Referenced by OnNewMonth().
|
static |
Number of days to pass from the first day in the year before reaching the first of a month.
Definition at line 83 of file date.cpp.
Referenced by ConvertYMDToDate().
|
static |
Available settings for autosave intervals.
Definition at line 181 of file date.cpp.
Referenced by OnNewMonth().
|
static |