Changeset - r21219:7180bb39d4d9
src/script/api/ai/ai_date.hpp.sq
Show inline comments
 
@@ -18,12 +18,15 @@ template <> const char *GetClassName<Scr
 
void SQAIDate_Register(Squirrel *engine)
 
{
 
	DefSQClass<ScriptDate, ST_AI> SQAIDate("AIDate");
 
	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");
 
	SQAIDate.DefSQStaticMethod(engine, &ScriptDate::GetDayOfMonth,  "GetDayOfMonth",  2, ".i");
 
	SQAIDate.DefSQStaticMethod(engine, &ScriptDate::GetDate,        "GetDate",        4, ".iii");
 

	
src/script/api/ai_changelog.hpp
Show inline comments
 
@@ -17,12 +17,14 @@
 
 *
 
 * \b 1.4.0
 
 *
 
 * 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
 
 * \li AITown::GetFundBuildingsDuration
 
 * \li AITown::TOWN_GROWTH_NONE
 
 *
src/script/api/game/game_date.hpp.sq
Show inline comments
 
@@ -18,12 +18,15 @@ template <> const char *GetClassName<Scr
 
void SQGSDate_Register(Squirrel *engine)
 
{
 
	DefSQClass<ScriptDate, ST_GS> SQGSDate("GSDate");
 
	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");
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::GetDayOfMonth,  "GetDayOfMonth",  2, ".i");
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::GetDate,        "GetDate",        4, ".iii");
 
	SQGSDate.DefSQStaticMethod(engine, &ScriptDate::GetSystemTime,  "GetSystemTime",  1, ".");
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -18,12 +18,14 @@
 
 * \b 1.4.0
 
 *
 
 * 1.4.0 is not yet released. The following changes are not set in stone yet.
 
 *
 
 * API additions:
 
 * \li GSCompany::ChangeBankBalance
 
 * \li GSDate::DATE_INVALID
 
 * \li GSDate::IsValidDate
 
 * \li GSGoal::GT_STORY_PAGE
 
 * \li GSGoal::IsCompleted
 
 * \li GSGoal::SetCompleted
 
 * \li GSGoal::SetProgress
 
 * \li GSGoal::SetText
 
 * \li GSStation::HasCargoRating
src/script/api/script_basestation.cpp
Show inline comments
 
@@ -49,12 +49,12 @@
 
{
 
	if (!IsValidBaseStation(station_id)) return INVALID_TILE;
 

	
 
	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
 
@@ -10,12 +10,13 @@
 
/** @file script_basestation.hpp Base for stations/waypoint handling. */
 

	
 
#ifndef SCRIPT_BASESTATION_HPP
 
#define SCRIPT_BASESTATION_HPP
 

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

	
 
/**
 
 * Base class for stations and waypoints.
 
 * @api ai game
 
 */
 
class ScriptBaseStation : public ScriptObject {
 
@@ -70,10 +71,10 @@ public:
 

	
 
	/**
 
	 * Get the last 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 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
 
@@ -11,51 +11,56 @@
 

	
 
#include <time.h>
 
#include "../../stdafx.h"
 
#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()
 
{
 
	time_t t;
 
	time(&t);
src/script/api/script_date.hpp
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file script_date.hpp Everything to query and manipulate date related information. */
 

	
 
#ifndef SCRIPT_DATE_HPP
 
#define SCRIPT_DATE_HPP
 

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

	
 
/**
 
 * Class that handles all date related (calculation) functions.
 
 * @api ai game
 
 *
 
 * @note Months and days of month are 1-based; the first month of the
 
@@ -25,49 +26,64 @@
 
 *       two different moments in time because they count the number
 
 *       of days since the year 0.
 
 */
 
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.
 
	 * @param year The year of the to-be determined date.
 
	 * @param month The month of the to-be determined date.
 
	 * @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.
 
	 * @return The amount of seconds passed since 1 Jan 1970.
 
	 * @api -ai
 
	 * @note This uses the clock of the host system, which can skew or be set back. Use with caution.
src/script/api/script_engine.cpp
Show inline comments
 
@@ -168,17 +168,17 @@
 
	if (GetVehicleType(engine_id) != ScriptVehicle::VT_RAIL && GetVehicleType(engine_id) != ScriptVehicle::VT_ROAD) return -1;
 
	if (IsWagon(engine_id)) return -1;
 

	
 
	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)
 
{
 
	if (!IsValidEngine(engine_id)) return ScriptVehicle::VT_INVALID;
 

	
src/script/api/script_engine.hpp
Show inline comments
 
@@ -12,12 +12,13 @@
 
#ifndef SCRIPT_ENGINE_HPP
 
#define SCRIPT_ENGINE_HPP
 

	
 
#include "script_vehicle.hpp"
 
#include "script_rail.hpp"
 
#include "script_airport.hpp"
 
#include "script_date.hpp"
 

	
 
/**
 
 * Class that handles all engine related functions.
 
 * @api ai game
 
 */
 
class ScriptEngine : public ScriptObject {
 
@@ -171,13 +172,13 @@ public:
 
	/**
 
	 * Get the date this engine was designed.
 
	 * @param engine_id The engine to get the design date of.
 
	 * @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.
 
	 * @param engine_id The engine to get the type of.
 
	 * @pre IsValidEngine(engine_id).
 
	 * @return The type the engine has.
src/script/api/script_story_page.cpp
Show inline comments
 
@@ -129,20 +129,21 @@
 
	CompanyID c = StoryPage::Get(story_page_id)->company;
 
	ScriptCompany::CompanyID company = c == INVALID_COMPANY ? ScriptCompany::COMPANY_INVALID : (ScriptCompany::CompanyID)c;
 

	
 
	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);
 

	
 
	return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, NULL);
 
}
src/script/api/script_story_page.hpp
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file script_story_page.hpp Everything to manipulate a story page. */
 

	
 
#ifndef SCRIPT_STORY_HPP
 
#define SCRIPT_STORY_HPP
 

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

	
 
/**
 
 * Class that handles story page related functions.
 
 *
 
@@ -151,23 +152,23 @@ public:
 
	/**
 
	 * Get the page 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 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.
 
	 * @param story_page_id The story page to update.
 
	 * @param title Page title (can be either a raw string, a ScriptText object, or null).
 
	 * @return True if the action succeeded.
src/script/api/script_subsidy.cpp
Show inline comments
 
@@ -45,15 +45,15 @@
 
{
 
	if (!IsAwarded(subsidy_id)) return ScriptCompany::COMPANY_INVALID;
 

	
 
	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());
 

	
 
	month += ::Subsidy::Get(subsidy_id)->remaining;
 

	
src/script/api/script_subsidy.hpp
Show inline comments
 
@@ -10,12 +10,13 @@
 
/** @file script_subsidy.hpp Everything to query subsidies. */
 

	
 
#ifndef SCRIPT_SUBSIDY_HPP
 
#define SCRIPT_SUBSIDY_HPP
 

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

	
 
/**
 
 * Class that handles all subsidy related functions.
 
 * @api ai game
 
 */
 
class ScriptSubsidy : public ScriptObject {
 
@@ -80,13 +81,13 @@ public:
 
	 * @param subsidy_id The SubsidyID to check.
 
	 * @pre IsValidSubsidy(subsidy_id).
 
	 * @return The last valid date of this subsidy.
 
	 * @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
 
	 *  subsidy.
 
	 * @param subsidy_id The SubsidyID to check.
 
	 * @pre IsValidSubsidy(subsidy_id).
src/script/api/template/template_date.hpp.sq
Show inline comments
 
@@ -9,12 +9,16 @@
 

	
 
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
 

	
 
#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; }
 
	template <> inline const ScriptDate *GetParam(ForceType<const ScriptDate *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (ScriptDate *)instance; }
 
	template <> inline const ScriptDate &GetParam(ForceType<const ScriptDate &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptDate *)instance; }
 
	template <> inline int Return<ScriptDate *>(HSQUIRRELVM vm, ScriptDate *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Date", res, NULL, DefSQDestructorCallback<ScriptDate>, true); return 1; }
src/story_gui.cpp
Show inline comments
 
@@ -516,14 +516,16 @@ public:
 

	
 
		/* Draw content (now coordinates given to Draw** are local to the new clipping region). */
 
		int line_height = FONT_HEIGHT_NORMAL;
 
		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 */
 
		SetDParamStr(0, page->title != NULL ? page->title : this->selected_generic_title);
 
		y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, STR_STORY_BOOK_TITLE, TC_BLACK, SA_TOP | SA_HOR_CENTER);
 

	
0 comments (0 inline, 0 general)