mirror of https://github.com/OpenTTD/OpenTTD
Change: [Script] Return different time values based on TimeMode
Changes ScriptEngine::GetMaxAge, ScriptVehicle::GetAge, ScriptVehicle::GetWagonAge, ScriptVehicle::GetMaxAge and ScriptVehicle::GetAgeLeft return value based on TimeMode.pull/12273/head
parent
a3cfd23cf9
commit
777f21417f
|
@ -10,6 +10,7 @@
|
||||||
#include "../../stdafx.h"
|
#include "../../stdafx.h"
|
||||||
#include "script_engine.hpp"
|
#include "script_engine.hpp"
|
||||||
#include "script_cargo.hpp"
|
#include "script_cargo.hpp"
|
||||||
|
#include "script_timemode.hpp"
|
||||||
#include "../../company_base.h"
|
#include "../../company_base.h"
|
||||||
#include "../../strings_func.h"
|
#include "../../strings_func.h"
|
||||||
#include "../../rail.h"
|
#include "../../rail.h"
|
||||||
|
@ -128,12 +129,14 @@
|
||||||
return ::Engine::Get(engine_id)->GetCost();
|
return ::Engine::Get(engine_id)->GetCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptEngine::GetMaxAge(EngineID engine_id)
|
/* static */ ScriptDate::Date ScriptEngine::GetMaxAge(EngineID engine_id)
|
||||||
{
|
{
|
||||||
if (!IsValidEngine(engine_id)) return -1;
|
if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
|
||||||
if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
|
if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return ScriptDate::DATE_INVALID;
|
||||||
|
|
||||||
return ::Engine::Get(engine_id)->GetLifeLengthInDays().base();
|
if (ScriptTimeMode::IsCalendarMode()) return (ScriptDate::Date)::Engine::Get(engine_id)->GetLifeLengthInDays().base();
|
||||||
|
|
||||||
|
return (ScriptDate::Date)(::Engine::Get(engine_id)->GetLifeLengthInDays().base() * std::max<uint>(_settings_game.economy.minutes_per_calendar_year, CalendarTime::DEF_MINUTES_PER_YEAR) / CalendarTime::DEF_MINUTES_PER_YEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id)
|
/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id)
|
||||||
|
|
|
@ -128,7 +128,7 @@ public:
|
||||||
* @returns The maximum age of a new engine in days.
|
* @returns The maximum age of a new engine in days.
|
||||||
* @note Age is in days; divide by 366 to get per year.
|
* @note Age is in days; divide by 366 to get per year.
|
||||||
*/
|
*/
|
||||||
static SQInteger GetMaxAge(EngineID engine_id);
|
static ScriptDate::Date GetMaxAge(EngineID engine_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the running cost of an engine.
|
* Get the running cost of an engine.
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "script_gamesettings.hpp"
|
#include "script_gamesettings.hpp"
|
||||||
#include "script_group.hpp"
|
#include "script_group.hpp"
|
||||||
#include "script_map.hpp"
|
#include "script_map.hpp"
|
||||||
|
#include "script_timemode.hpp"
|
||||||
#include "../script_instance.hpp"
|
#include "../script_instance.hpp"
|
||||||
#include "../../string_func.h"
|
#include "../../string_func.h"
|
||||||
#include "../../strings_func.h"
|
#include "../../strings_func.h"
|
||||||
|
@ -307,37 +308,43 @@
|
||||||
return GetString(STR_VEHICLE_NAME);
|
return GetString(STR_VEHICLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptVehicle::GetAge(VehicleID vehicle_id)
|
/* static */ ScriptDate::Date ScriptVehicle::GetAge(VehicleID vehicle_id)
|
||||||
{
|
{
|
||||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
if (!IsValidVehicle(vehicle_id)) return ScriptDate::DATE_INVALID;
|
||||||
|
|
||||||
return ::Vehicle::Get(vehicle_id)->age.base();
|
if (ScriptTimeMode::IsCalendarMode()) return (ScriptDate::Date)::Vehicle::Get(vehicle_id)->age.base();
|
||||||
|
|
||||||
|
return (ScriptDate::Date)::Vehicle::Get(vehicle_id)->economy_age.base();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptVehicle::GetWagonAge(VehicleID vehicle_id, SQInteger wagon)
|
/* static */ ScriptDate::Date ScriptVehicle::GetWagonAge(VehicleID vehicle_id, SQInteger wagon)
|
||||||
{
|
{
|
||||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
if (!IsValidVehicle(vehicle_id)) return ScriptDate::DATE_INVALID;
|
||||||
if (wagon >= GetNumWagons(vehicle_id)) return -1;
|
if (wagon >= GetNumWagons(vehicle_id)) return ScriptDate::DATE_INVALID;
|
||||||
|
|
||||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||||
if (v->type == VEH_TRAIN) {
|
if (v->type == VEH_TRAIN) {
|
||||||
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
|
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
|
||||||
}
|
}
|
||||||
return v->age.base();
|
if (ScriptTimeMode::IsCalendarMode()) return (ScriptDate::Date)v->age.base();
|
||||||
|
|
||||||
|
return (ScriptDate::Date)v->economy_age.base();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
|
/* static */ ScriptDate::Date ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
|
||||||
{
|
{
|
||||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
if (!IsPrimaryVehicle(vehicle_id)) return ScriptDate::DATE_INVALID;
|
||||||
|
|
||||||
return ::Vehicle::Get(vehicle_id)->max_age.base();
|
if (ScriptTimeMode::IsCalendarMode()) return (ScriptDate::Date)::Vehicle::Get(vehicle_id)->max_age.base();
|
||||||
|
|
||||||
|
return (ScriptDate::Date)(::Vehicle::Get(vehicle_id)->max_age.base() * std::max<uint>(_settings_game.economy.minutes_per_calendar_year, CalendarTime::DEF_MINUTES_PER_YEAR) / CalendarTime::DEF_MINUTES_PER_YEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptVehicle::GetAgeLeft(VehicleID vehicle_id)
|
/* static */ ScriptDate::Date ScriptVehicle::GetAgeLeft(VehicleID vehicle_id)
|
||||||
{
|
{
|
||||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
if (!IsPrimaryVehicle(vehicle_id)) return ScriptDate::DATE_INVALID;
|
||||||
|
|
||||||
return (::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age).base();
|
return (ScriptDate::Date)(GetMaxAge(vehicle_id) - GetAge(vehicle_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)
|
/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define SCRIPT_VEHICLE_HPP
|
#define SCRIPT_VEHICLE_HPP
|
||||||
|
|
||||||
#include "script_road.hpp"
|
#include "script_road.hpp"
|
||||||
|
#include "script_date.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that handles all vehicle related functions.
|
* Class that handles all vehicle related functions.
|
||||||
|
@ -189,7 +190,7 @@ public:
|
||||||
* @return The current age the vehicle has.
|
* @return The current age the vehicle has.
|
||||||
* @note The age is in days.
|
* @note The age is in days.
|
||||||
*/
|
*/
|
||||||
static SQInteger GetAge(VehicleID vehicle_id);
|
static ScriptDate::Date GetAge(VehicleID vehicle_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current age of a second (or third, etc.) engine in a train vehicle.
|
* Get the current age of a second (or third, etc.) engine in a train vehicle.
|
||||||
|
@ -200,7 +201,7 @@ public:
|
||||||
* @return The current age the vehicle has.
|
* @return The current age the vehicle has.
|
||||||
* @note The age is in days.
|
* @note The age is in days.
|
||||||
*/
|
*/
|
||||||
static SQInteger GetWagonAge(VehicleID vehicle_id, SQInteger wagon);
|
static ScriptDate::Date GetWagonAge(VehicleID vehicle_id, SQInteger wagon);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum age of a vehicle.
|
* Get the maximum age of a vehicle.
|
||||||
|
@ -209,7 +210,7 @@ public:
|
||||||
* @return The maximum age the vehicle has.
|
* @return The maximum age the vehicle has.
|
||||||
* @note The age is in days.
|
* @note The age is in days.
|
||||||
*/
|
*/
|
||||||
static SQInteger GetMaxAge(VehicleID vehicle_id);
|
static ScriptDate::Date GetMaxAge(VehicleID vehicle_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the age a vehicle has left (maximum - current).
|
* Get the age a vehicle has left (maximum - current).
|
||||||
|
@ -218,7 +219,7 @@ public:
|
||||||
* @return The age the vehicle has left.
|
* @return The age the vehicle has left.
|
||||||
* @note The age is in days.
|
* @note The age is in days.
|
||||||
*/
|
*/
|
||||||
static SQInteger GetAgeLeft(VehicleID vehicle_id);
|
static ScriptDate::Date GetAgeLeft(VehicleID vehicle_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current speed of a vehicle.
|
* Get the current speed of a vehicle.
|
||||||
|
|
Loading…
Reference in New Issue