Changeset - r21219:7180bb39d4d9
src/script/api/ai/ai_date.hpp.sq
Show inline comments
 
@@ -21,6 +21,9 @@ void SQAIDate_Register(Squirrel *engine)
 
	SQAIDate.PreRegister(engine);
 
	SQAIDate.AddConstructor<void (ScriptDate::*)(), 1>(engine, "x");
 

	
 
	SQAIDate.DefSQConst(engine, ScriptDate::DATE_INVALID, "DATE_INVALID");
 

	
 
	SQAIDate.DefSQStaticMethod(engine, &ScriptDate::IsValidDate,    "IsValidDate",    2, ".i");
 
	SQAIDate.DefSQStaticMethod(engine, &ScriptDate::GetCurrentDate, "GetCurrentDate", 1, ".");
 
	SQAIDate.DefSQStaticMethod(engine, &ScriptDate::GetYear,        "GetYear",        2, ".i");
 
	SQAIDate.DefSQStaticMethod(engine, &ScriptDate::GetMonth,       "GetMonth",       2, ".i");
src/script/api/ai_changelog.hpp
Show inline comments
 
@@ -20,6 +20,8 @@
 
 * 1.4.0 is not yet released. The following changes are not set in stone yet.
 
 *
 
 * API additions:
 
 * \li AIDate::DATE_INVALID
 
 * \li AIDate::IsValidDate
 
 * \li AIStation::HasCargoRating
 
 * \li AITile::GetTerrainType
 
 * \li AITown::FoundTown
src/script/api/game/game_date.hpp.sq
Show inline comments
 
@@ -21,6 +21,9 @@ void SQGSDate_Register(Squirrel *engine)
 
	SQGSDate.PreRegister(engine);
 
	SQGSDate.AddConstructor<void (ScriptDate::*)(), 1>(engine, "x");
 

	
 
	SQGSDate.DefSQConst(engine, ScriptDate::DATE_INVALID, "DATE_INVALID");
 

	
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::IsValidDate,    "IsValidDate",    2, ".i");
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::GetCurrentDate, "GetCurrentDate", 1, ".");
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::GetYear,        "GetYear",        2, ".i");
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::GetMonth,       "GetMonth",       2, ".i");
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -21,6 +21,8 @@
 
 *
 
 * API additions:
 
 * \li GSCompany::ChangeBankBalance
 
 * \li GSDate::DATE_INVALID
 
 * \li GSDate::IsValidDate
 
 * \li GSGoal::GT_STORY_PAGE
 
 * \li GSGoal::IsCompleted
 
 * \li GSGoal::SetCompleted
src/script/api/script_basestation.cpp
Show inline comments
 
@@ -52,9 +52,9 @@
 
	return ::BaseStation::Get(station_id)->xy;
 
}
 

	
 
/* static */ int32 ScriptBaseStation::GetConstructionDate(StationID station_id)
 
/* static */ ScriptDate::Date ScriptBaseStation::GetConstructionDate(StationID station_id)
 
{
 
	if (!IsValidBaseStation(station_id)) return -1;
 
	if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
 

	
 
	return ::BaseStation::Get(station_id)->build_date;
 
	return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date;
 
}
src/script/api/script_basestation.hpp
Show inline comments
 
@@ -13,6 +13,7 @@
 
#define SCRIPT_BASESTATION_HPP
 

	
 
#include "script_text.hpp"
 
#include "script_date.hpp"
 

	
 
/**
 
 * Base class for stations and waypoints.
 
@@ -73,7 +74,7 @@ public:
 
	 * @param station_id The station to look at.
 
	 * @return The last date some part of this station was build.
 
	 */
 
	static int32 GetConstructionDate(StationID station_id);
 
	static ScriptDate::Date GetConstructionDate(StationID station_id);
 
};
 

	
 
#endif /* SCRIPT_BASESTATION_HPP */
src/script/api/script_date.cpp
Show inline comments
 
@@ -14,45 +14,50 @@
 
#include "script_date.hpp"
 
#include "../../date_func.h"
 

	
 
/* static */ int32 ScriptDate::GetCurrentDate()
 
/* static */ bool ScriptDate::IsValidDate(Date date)
 
{
 
	return ::_date;
 
	return date >= 0;
 
}
 

	
 
/* static */ int32 ScriptDate::GetYear(int32 date)
 
/* static */ ScriptDate::Date ScriptDate::GetCurrentDate()
 
{
 
	if (date < 0) return -1;
 
	return (ScriptDate::Date)_date;
 
}
 

	
 
/* static */ int32 ScriptDate::GetYear(ScriptDate::Date date)
 
{
 
	if (date < 0) return DATE_INVALID;
 

	
 
	::YearMonthDay ymd;
 
	::ConvertDateToYMD(date, &ymd);
 
	return ymd.year;
 
}
 

	
 
/* static */ int32 ScriptDate::GetMonth(int32 date)
 
/* static */ int32 ScriptDate::GetMonth(ScriptDate::Date date)
 
{
 
	if (date < 0) return -1;
 
	if (date < 0) return DATE_INVALID;
 

	
 
	::YearMonthDay ymd;
 
	::ConvertDateToYMD(date, &ymd);
 
	return ymd.month + 1;
 
}
 

	
 
/* static */ int32 ScriptDate::GetDayOfMonth(int32 date)
 
/* static */ int32 ScriptDate::GetDayOfMonth(ScriptDate::Date date)
 
{
 
	if (date < 0) return -1;
 
	if (date < 0) return DATE_INVALID;
 

	
 
	::YearMonthDay ymd;
 
	::ConvertDateToYMD(date, &ymd);
 
	return ymd.day;
 
}
 

	
 
/* static */ int32 ScriptDate::GetDate(int32 year, int32 month, int32 day_of_month)
 
/* static */ ScriptDate::Date ScriptDate::GetDate(int32 year, int32 month, int32 day_of_month)
 
{
 
	if (month < 1 || month > 12) return -1;
 
	if (day_of_month < 1 || day_of_month > 31) return -1;
 
	if (year < 0 || year > MAX_YEAR) return -1;
 
	if (month < 1 || month > 12) return DATE_INVALID;
 
	if (day_of_month < 1 || day_of_month > 31) return DATE_INVALID;
 
	if (year < 0 || year > MAX_YEAR) return DATE_INVALID;
 

	
 
	return ::ConvertYMDToDate(year, month - 1, day_of_month);
 
	return (ScriptDate::Date)::ConvertYMDToDate(year, month - 1, day_of_month);
 
}
 

	
 
/* static */ int32 ScriptDate::GetSystemTime()
src/script/api/script_date.hpp
Show inline comments
 
@@ -13,6 +13,7 @@
 
#define SCRIPT_DATE_HPP
 

	
 
#include "script_object.hpp"
 
#include "../../date_type.h"
 

	
 
/**
 
 * Class that handles all date related (calculation) functions.
 
@@ -28,34 +29,49 @@
 
class ScriptDate : public ScriptObject {
 
public:
 
	/**
 
	 * Date data type is an integer value. Use ScriptDate::GetDate to
 
	 * compose valid date values for a known year, month and day.
 
	 */
 
	enum Date {
 
		DATE_INVALID = ::INVALID_DATE, ///< A value representing an invalid date.
 
	};
 

	
 
	/**
 
	 * Validates if a date value represent a valid date.
 
	 * @param date The date to validate.
 
	 * @return True if the date is valid, otherwise false
 
	 */
 
	static bool IsValidDate(Date date);
 

	
 
	/**
 
	 * Get the current date.
 
	 * This is the number of days since epoch under the assumption that
 
	 *  there is a leap year every 4 years, except when dividable by
 
	 *  100 but not by 400.
 
	 * @return The current date.
 
	 */
 
	static int32 GetCurrentDate();
 
	static Date GetCurrentDate();
 

	
 
	/**
 
	 * Get the year of the given date.
 
	 * @param date The date to get the year of.
 
	 * @return The year.
 
	 */
 
	static int32 GetYear(int32 date);
 
	static int32 GetYear(Date date);
 

	
 
	/**
 
	 * Get the month of the given date.
 
	 * @param date The date to get the month of.
 
	 * @return The month.
 
	 */
 
	static int32 GetMonth(int32 date);
 
	static int32 GetMonth(Date date);
 

	
 
	/**
 
	 * Get the day (of the month) of the given date.
 
	 * @param date The date to get the day of.
 
	 * @return The day.
 
	 */
 
	static int32 GetDayOfMonth(int32 date);
 
	static int32 GetDayOfMonth(Date date);
 

	
 
	/**
 
	 * Get the date given a year, month and day of month.
 
@@ -64,7 +80,7 @@ public:
 
	 * @param day_of_month The day of month of the to-be determined date.
 
	 * @return The date.
 
	 */
 
	static int32 GetDate(int32 year, int32 month, int32 day_of_month);
 
	static Date GetDate(int32 year, int32 month, int32 day_of_month);
 

	
 
	/**
 
	 * Get the time of the host system.
src/script/api/script_engine.cpp
Show inline comments
 
@@ -171,11 +171,11 @@
 
	return ::Engine::Get(engine_id)->GetDisplayMaxTractiveEffort();
 
}
 

	
 
/* static */ int32 ScriptEngine::GetDesignDate(EngineID engine_id)
 
/* static */ ScriptDate::Date ScriptEngine::GetDesignDate(EngineID engine_id)
 
{
 
	if (!IsValidEngine(engine_id)) return -1;
 
	if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
 

	
 
	return ::Engine::Get(engine_id)->intro_date;
 
	return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date;
 
}
 

	
 
/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)
src/script/api/script_engine.hpp
Show inline comments
 
@@ -15,6 +15,7 @@
 
#include "script_vehicle.hpp"
 
#include "script_rail.hpp"
 
#include "script_airport.hpp"
 
#include "script_date.hpp"
 

	
 
/**
 
 * Class that handles all engine related functions.
 
@@ -174,7 +175,7 @@ public:
 
	 * @pre IsValidEngine(engine_id).
 
	 * @return The date this engine was designed.
 
	 */
 
	static int32 GetDesignDate(EngineID engine_id);
 
	static ScriptDate::Date GetDesignDate(EngineID engine_id);
 

	
 
	/**
 
	 * Get the type of an engine.
src/script/api/script_story_page.cpp
Show inline comments
 
@@ -132,14 +132,15 @@
 
	return company;
 
}
 

	
 
/* static */ int32 ScriptStoryPage::GetDate(StoryPageID story_page_id)
 
/* static */ ScriptDate::Date ScriptStoryPage::GetDate(StoryPageID story_page_id)
 
{
 
	EnforcePrecondition(-1, IsValidStoryPage(story_page_id));
 
	EnforcePrecondition(ScriptDate::DATE_INVALID, IsValidStoryPage(story_page_id));
 
	EnforcePrecondition(ScriptDate::DATE_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
 

	
 
	return StoryPage::Get(story_page_id)->date;
 
	return (ScriptDate::Date)StoryPage::Get(story_page_id)->date;
 
}
 

	
 
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, int32 date)
 
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date)
 
{
 
	EnforcePrecondition(false, IsValidStoryPage(story_page_id));
 
	EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
src/script/api/script_story_page.hpp
Show inline comments
 
@@ -13,6 +13,7 @@
 
#define SCRIPT_STORY_HPP
 

	
 
#include "script_company.hpp"
 
#include "script_date.hpp"
 
#include "../../story_type.h"
 
#include "../../story_base.h"
 

	
 
@@ -154,17 +155,17 @@ public:
 
	 * @return The date
 
	 * @pre IsValidStoryPage(story_page_id).
 
	 */
 
	static int32 GetDate(StoryPageID story_page_id);
 
	static ScriptDate::Date GetDate(StoryPageID story_page_id);
 

	
 
	/**
 
	 * Update 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 Page date (@see ScriptDate)
 
	 * @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)
 
	 * @return True if the action succeeded.
 
	 * @pre No ScriptCompanyMode may be in scope.
 
	 * @pre IsValidStoryPage(story_page_id).
 
	 */
 
	static bool SetDate(StoryPageID story_page_id, int32 date);
 
	static bool SetDate(StoryPageID story_page_id, ScriptDate::Date date);
 

	
 
	/**
 
	 * Update title of a story page. The title is shown in the page selector drop down.
src/script/api/script_subsidy.cpp
Show inline comments
 
@@ -48,9 +48,9 @@
 
	return (ScriptCompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded);
 
}
 

	
 
/* static */ int32 ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id)
 
/* static */ ScriptDate::Date ScriptSubsidy::GetExpireDate(SubsidyID subsidy_id)
 
{
 
	if (!IsValidSubsidy(subsidy_id)) return -1;
 
	if (!IsValidSubsidy(subsidy_id)) return ScriptDate::DATE_INVALID;
 

	
 
	int year = ScriptDate::GetYear(ScriptDate::GetCurrentDate());
 
	int month = ScriptDate::GetMonth(ScriptDate::GetCurrentDate());
src/script/api/script_subsidy.hpp
Show inline comments
 
@@ -13,6 +13,7 @@
 
#define SCRIPT_SUBSIDY_HPP
 

	
 
#include "script_company.hpp"
 
#include "script_date.hpp"
 

	
 
/**
 
 * Class that handles all subsidy related functions.
 
@@ -83,7 +84,7 @@ public:
 
	 * @note The return value of this function will change if the subsidy is
 
	 *  awarded.
 
	 */
 
	static int32 GetExpireDate(SubsidyID subsidy_id);
 
	static ScriptDate::Date GetExpireDate(SubsidyID subsidy_id);
 

	
 
	/**
 
	 * Get the cargo type that has to be transported in order to be awarded this
src/script/api/template/template_date.hpp.sq
Show inline comments
 
@@ -12,6 +12,10 @@
 
#include "../script_date.hpp"
 

	
 
namespace SQConvert {
 
	/* Allow enums to be used as Squirrel parameters */
 
	template <> inline ScriptDate::Date GetParam(ForceType<ScriptDate::Date>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptDate::Date)tmp; }
 
	template <> inline int Return<ScriptDate::Date>(HSQUIRRELVM vm, ScriptDate::Date res) { sq_pushinteger(vm, (int32)res); return 1; }
 

	
 
	/* Allow ScriptDate to be used as Squirrel parameter */
 
	template <> inline ScriptDate *GetParam(ForceType<ScriptDate *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (ScriptDate *)instance; }
 
	template <> inline ScriptDate &GetParam(ForceType<ScriptDate &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptDate *)instance; }
src/story_gui.cpp
Show inline comments
 
@@ -519,8 +519,10 @@ public:
 
		int y_offset = - this->vscroll->GetPosition();
 

	
 
		/* Date */
 
		SetDParam(0, page->date);
 
		DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
 
		if (page->date != INVALID_DATE) {
 
			SetDParam(0, page->date);
 
			DrawString(0, right - x, y_offset, STR_JUST_DATE_LONG, TC_BLACK);
 
		}
 
		y_offset += line_height;
 

	
 
		/* Title */
0 comments (0 inline, 0 general)