mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-17 11:39:11 +00:00
Codechange: Split calls to ScriptDate into correct Calendar and Economy class
This commit is contained in:
@@ -59,9 +59,9 @@
|
||||
return ::BaseStation::Get(station_id)->xy;
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptBaseStation::GetConstructionDate(StationID station_id)
|
||||
/* static */ ScriptDateCalendar::Date ScriptBaseStation::GetConstructionDate(StationID station_id)
|
||||
{
|
||||
if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
|
||||
if (!IsValidBaseStation(station_id)) return ScriptDateCalendar::DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date.base();
|
||||
return (ScriptDateCalendar::Date)::BaseStation::Get(station_id)->build_date.base();
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define SCRIPT_BASESTATION_HPP
|
||||
|
||||
#include "script_text.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_calendar.hpp"
|
||||
|
||||
/**
|
||||
* Base class for stations and waypoints.
|
||||
@@ -68,11 +68,11 @@ public:
|
||||
static TileIndex GetLocation(StationID station_id);
|
||||
|
||||
/**
|
||||
* Get the last date a station part was added to this station.
|
||||
* Get the last calendar date a station part was added to this station.
|
||||
* @param station_id The station to look at.
|
||||
* @return The last date some part of this station was build.
|
||||
*/
|
||||
static ScriptDate::Date GetConstructionDate(StationID station_id);
|
||||
static ScriptDateCalendar::Date GetConstructionDate(StationID station_id);
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_BASESTATION_HPP */
|
||||
|
@@ -46,9 +46,9 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client)
|
||||
return (ScriptCompany::CompanyID)ci->client_playas;
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client)
|
||||
/* static */ ScriptDateCalendar::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client)
|
||||
{
|
||||
NetworkClientInfo *ci = FindClientInfo(client);
|
||||
if (ci == nullptr) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)ci->join_date.base();
|
||||
if (ci == nullptr) return ScriptDateCalendar::DATE_INVALID;
|
||||
return (ScriptDateCalendar::Date)ci->join_date.base();
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define SCRIPT_CLIENT_HPP
|
||||
|
||||
#include "script_text.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_calendar.hpp"
|
||||
#include "script_company.hpp"
|
||||
#include "../../network/network_type.h"
|
||||
|
||||
@@ -56,12 +56,12 @@ public:
|
||||
static ScriptCompany::CompanyID GetCompany(ClientID client);
|
||||
|
||||
/**
|
||||
* Get the game date when the given client has joined.
|
||||
* Get the game calendar date when the given client has joined.
|
||||
* @param client The client to get joining date for.
|
||||
* @pre ResolveClientID(client) != CLIENT_INVALID.
|
||||
* @return The date when client has joined.
|
||||
*/
|
||||
static ScriptDate::Date GetJoinDate(ClientID client);
|
||||
static ScriptDateCalendar::Date GetJoinDate(ClientID client);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -168,11 +168,11 @@
|
||||
return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort() / 1000;
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptEngine::GetDesignDate(EngineID engine_id)
|
||||
/* static */ ScriptDateCalendar::Date ScriptEngine::GetDesignDate(EngineID engine_id)
|
||||
{
|
||||
if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
|
||||
if (!IsValidEngine(engine_id)) return ScriptDateCalendar::DATE_INVALID;
|
||||
|
||||
return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date.base();
|
||||
return (ScriptDateCalendar::Date)::Engine::Get(engine_id)->intro_date.base();
|
||||
}
|
||||
|
||||
/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)
|
||||
|
@@ -13,7 +13,7 @@
|
||||
#include "script_vehicle.hpp"
|
||||
#include "script_rail.hpp"
|
||||
#include "script_airport.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_calendar.hpp"
|
||||
|
||||
/**
|
||||
* Class that handles all engine related functions.
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
* @pre IsValidEngine(engine_id).
|
||||
* @return The date this engine was designed.
|
||||
*/
|
||||
static ScriptDate::Date GetDesignDate(EngineID engine_id);
|
||||
static ScriptDateCalendar::Date GetDesignDate(EngineID engine_id);
|
||||
|
||||
/**
|
||||
* Get the type of an engine.
|
||||
|
@@ -49,11 +49,11 @@
|
||||
return GetString(STR_INDUSTRY_NAME);
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptIndustry::GetConstructionDate(IndustryID industry_id)
|
||||
/* static */ ScriptDateCalendar::Date ScriptIndustry::GetConstructionDate(IndustryID industry_id)
|
||||
{
|
||||
Industry *i = Industry::GetIfValid(industry_id);
|
||||
if (i == nullptr) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)i->construction_date.base();
|
||||
if (i == nullptr) return ScriptDateCalendar::DATE_INVALID;
|
||||
return (ScriptDateCalendar::Date)i->construction_date.base();
|
||||
}
|
||||
|
||||
/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text)
|
||||
@@ -225,18 +225,18 @@
|
||||
return i->last_prod_year.base();
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type)
|
||||
/* static */ ScriptDateEconomy::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type)
|
||||
{
|
||||
Industry *i = Industry::GetIfValid(industry_id);
|
||||
if (i == nullptr) return ScriptDate::DATE_INVALID;
|
||||
if (i == nullptr) return ScriptDateEconomy::DATE_INVALID;
|
||||
|
||||
if (!::IsValidCargoID(cargo_type)) {
|
||||
auto it = std::max_element(std::begin(i->accepted), std::end(i->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
|
||||
return (ScriptDate::Date)it->last_accepted.base();
|
||||
return (ScriptDateEconomy::Date)it->last_accepted.base();
|
||||
} else {
|
||||
auto it = i->GetCargoAccepted(cargo_type);
|
||||
if (it == std::end(i->accepted)) return ScriptDate::DATE_INVALID;
|
||||
return (ScriptDate::Date)it->last_accepted.base();
|
||||
if (it == std::end(i->accepted)) return ScriptDateEconomy::DATE_INVALID;
|
||||
return (ScriptDateEconomy::Date)it->last_accepted.base();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,8 @@
|
||||
#define SCRIPT_INDUSTRY_HPP
|
||||
|
||||
#include "script_company.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_economy.hpp"
|
||||
#include "script_date_calendar.hpp"
|
||||
#include "script_object.hpp"
|
||||
#include "../../industry.h"
|
||||
|
||||
@@ -86,13 +87,13 @@ public:
|
||||
static std::optional<std::string> GetName(IndustryID industry_id);
|
||||
|
||||
/**
|
||||
* Get the construction date of an industry.
|
||||
* Get the construction calendar date of an industry.
|
||||
* @param industry_id The index of the industry.
|
||||
* @pre IsValidIndustry(industry_id).
|
||||
* @return Date the industry was constructed.
|
||||
* @api -ai
|
||||
*/
|
||||
static ScriptDate::Date GetConstructionDate(IndustryID industry_id);
|
||||
static ScriptDateCalendar::Date GetConstructionDate(IndustryID industry_id);
|
||||
|
||||
/**
|
||||
* Set the custom text of an industry, shown in the GUI.
|
||||
@@ -255,15 +256,15 @@ public:
|
||||
static SQInteger GetLastProductionYear(IndustryID industry_id);
|
||||
|
||||
/**
|
||||
* Get the last date this industry accepted any cargo delivery.
|
||||
* Get the last economy date this industry accepted any cargo delivery.
|
||||
* @param industry_id The index of the industry.
|
||||
* @param cargo_type The cargo to query, or CT_INVALID to query latest of all accepted cargoes.
|
||||
* @pre IsValidIndustry(industry_id).
|
||||
* @pre IsValidCargo(cargo_type) || cargo_type == CT_INVALID.
|
||||
* @return Date the industry last received cargo from a delivery, or ScriptDate::DATE_INVALID on error.
|
||||
* @return Date the industry last received cargo from a delivery, or ScriptDateEconomy::DATE_INVALID on error.
|
||||
* @api -ai
|
||||
*/
|
||||
static ScriptDate::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type);
|
||||
static ScriptDateEconomy::Date GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type);
|
||||
|
||||
/**
|
||||
* Get the current control flags for an industry.
|
||||
|
@@ -177,15 +177,15 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
return company;
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptStoryPage::GetDate(StoryPageID story_page_id)
|
||||
/* static */ ScriptDateCalendar::Date ScriptStoryPage::GetDate(StoryPageID story_page_id)
|
||||
{
|
||||
EnforcePrecondition(ScriptDate::DATE_INVALID, IsValidStoryPage(story_page_id));
|
||||
EnforceDeityMode(ScriptDate::DATE_INVALID);
|
||||
EnforcePrecondition(ScriptDateCalendar::DATE_INVALID, IsValidStoryPage(story_page_id));
|
||||
EnforceDeityMode(ScriptDateCalendar::DATE_INVALID);
|
||||
|
||||
return (ScriptDate::Date)StoryPage::Get(story_page_id)->date.base();
|
||||
return (ScriptDateCalendar::Date)StoryPage::Get(story_page_id)->date.base();
|
||||
}
|
||||
|
||||
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date)
|
||||
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDateCalendar::Date date)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
|
||||
EnforceDeityMode(false);
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define SCRIPT_STORY_HPP
|
||||
|
||||
#include "script_company.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_calendar.hpp"
|
||||
#include "script_vehicle.hpp"
|
||||
#include "../../story_type.h"
|
||||
#include "../../story_base.h"
|
||||
@@ -255,22 +255,22 @@ public:
|
||||
static ScriptCompany::CompanyID GetCompany(StoryPageID story_page_id);
|
||||
|
||||
/**
|
||||
* Get the page date which is displayed at the top of each page.
|
||||
* Get the page calendar date which is displayed at the top of each page.
|
||||
* @param story_page_id The story page to get the date of.
|
||||
* @return The date
|
||||
* @pre IsValidStoryPage(story_page_id).
|
||||
*/
|
||||
static ScriptDate::Date GetDate(StoryPageID story_page_id);
|
||||
static ScriptDateCalendar::Date GetDate(StoryPageID story_page_id);
|
||||
|
||||
/**
|
||||
* Update date of a story page. The date is shown in the top left of the page
|
||||
* Update calendar date of a story page. The date is shown in the top left of the page
|
||||
* @param story_page_id The story page to set the date for.
|
||||
* @param date Date to display at the top of story page or ScriptDate::DATE_INVALID to disable showing date on this page. (also, @see ScriptDate)
|
||||
* @param date Date to display at the top of story page or ScriptDateCalendar::DATE_INVALID to disable showing date on this page. (also, @see ScriptDateCalendar)
|
||||
* @return True if the action succeeded.
|
||||
* @pre ScriptCompanyMode::IsDeity().
|
||||
* @pre IsValidStoryPage(story_page_id).
|
||||
*/
|
||||
static bool SetDate(StoryPageID story_page_id, ScriptDate::Date date);
|
||||
static bool SetDate(StoryPageID story_page_id, ScriptDateCalendar::Date date);
|
||||
|
||||
/**
|
||||
* Update title of a story page. The title is shown in the page selector drop down.
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_subsidy.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_economy.hpp"
|
||||
#include "script_industry.hpp"
|
||||
#include "script_town.hpp"
|
||||
#include "script_error.hpp"
|
||||
@@ -50,19 +50,19 @@
|
||||
return (ScriptCompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded);
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id)
|
||||
/* static */ ScriptDateEconomy::Date ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id)
|
||||
{
|
||||
if (!IsValidSubsidy(subsidy_id)) return ScriptDate::DATE_INVALID;
|
||||
if (!IsValidSubsidy(subsidy_id)) return ScriptDateEconomy::DATE_INVALID;
|
||||
|
||||
int year = ScriptDate::GetYear(ScriptDate::GetCurrentDate());
|
||||
int month = ScriptDate::GetMonth(ScriptDate::GetCurrentDate());
|
||||
int year = ScriptDateEconomy::GetYear(ScriptDateEconomy::GetCurrentDate());
|
||||
int month = ScriptDateEconomy::GetMonth(ScriptDateEconomy::GetCurrentDate());
|
||||
|
||||
month += ::Subsidy::Get(subsidy_id)->remaining;
|
||||
|
||||
year += (month - 1) / 12;
|
||||
month = ((month - 1) % 12) + 1;
|
||||
|
||||
return ScriptDate::GetDate(year, month, 1);
|
||||
return ScriptDateEconomy::GetDate(year, month, 1);
|
||||
}
|
||||
|
||||
/* static */ CargoID ScriptSubsidy::GetCargoType(SubsidyID subsidy_id)
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define SCRIPT_SUBSIDY_HPP
|
||||
|
||||
#include "script_company.hpp"
|
||||
#include "script_date.hpp"
|
||||
#include "script_date_economy.hpp"
|
||||
|
||||
/**
|
||||
* Class that handles all subsidy related functions.
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
static ScriptCompany::CompanyID GetAwardedTo(SubsidyID subsidy_id);
|
||||
|
||||
/**
|
||||
* Get the date this subsidy expires. In case the subsidy is already
|
||||
* awarded, return the date the subsidy expires, else, return the date the
|
||||
* Get the economy date this subsidy expires. In case the subsidy is already
|
||||
* awarded, return the economy date the subsidy expires, else, return the economy date the
|
||||
* offer expires.
|
||||
* @param subsidy_id The SubsidyID to check.
|
||||
* @pre IsValidSubsidy(subsidy_id).
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
* @note The return value of this function will change if the subsidy is
|
||||
* awarded.
|
||||
*/
|
||||
static ScriptDate::Date GetExpireDate(SubsidyID subsidy_id);
|
||||
static ScriptDateEconomy::Date GetExpireDate(SubsidyID subsidy_id);
|
||||
|
||||
/**
|
||||
* Get the cargo type that has to be transported in order to be awarded this
|
||||
|
Reference in New Issue
Block a user