Files
@ r28572:dd3e6f760743
Branch filter:
Location: cpp/openttd-patchpack/source/src/script/api/script_basestation.cpp - annotation
r28572:dd3e6f760743
2.7 KiB
text/x-c
Update: nlohmann/json to 3.11.3
r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18876:3403b9c464f9 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26105:23588534dec9 r26105:23588534dec9 r28306:801b68f73a02 r18500:14a481bc4437 r18500:14a481bc4437 r21383:942c32fb8b0e r21383:942c32fb8b0e r18501:8e3d905ea4bc r18500:14a481bc4437 r27005:8631fe151182 r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r27364:db69a5f5c496 r18500:14a481bc4437 r27364:db69a5f5c496 r18500:14a481bc4437 r18500:14a481bc4437 r18917:144687613228 r18500:14a481bc4437 r18500:14a481bc4437 r18778:4848b0595531 r18500:14a481bc4437 r18778:4848b0595531 r18778:4848b0595531 r26996:7064173a70ca r18500:14a481bc4437 r23607:36c15679007d r26891:5a795b8188a7 r20025:983c2ed8d329 r18778:4848b0595531 r18500:14a481bc4437 r26105:23588534dec9 r26112:8e77e1979a31 r26105:23588534dec9 r26112:8e77e1979a31 r26105:23588534dec9 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r21219:7180bb39d4d9 r18500:14a481bc4437 r21219:7180bb39d4d9 r18500:14a481bc4437 r28112:bca7556a6bb6 r18500:14a481bc4437 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_basestation.cpp Implementation of ScriptBaseStation. */
#include "../../stdafx.h"
#include "script_basestation.hpp"
#include "script_error.hpp"
#include "../../station_base.h"
#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../station_cmd.h"
#include "../../waypoint_cmd.h"
#include "../../timer/timer_game_calendar.h"
#include "table/strings.h"
#include "../../safeguards.h"
/* static */ bool ScriptBaseStation::IsValidBaseStation(StationID station_id)
{
EnforceDeityOrCompanyModeValid(false);
const BaseStation *st = ::BaseStation::GetIfValid(station_id);
return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || st->owner == OWNER_NONE);
}
/* static */ std::optional<std::string> ScriptBaseStation::GetName(StationID station_id)
{
if (!IsValidBaseStation(station_id)) return std::nullopt;
::SetDParam(0, station_id);
return GetString(::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME);
}
/* static */ bool ScriptBaseStation::SetName(StationID station_id, Text *name)
{
CCountedPtr<Text> counter(name);
EnforceCompanyModeValid(false);
EnforcePrecondition(false, IsValidBaseStation(station_id));
EnforcePrecondition(false, name != nullptr);
const std::string &text = name->GetDecodedText();
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
if (::Station::IsValidID(station_id)) {
return ScriptObject::Command<CMD_RENAME_STATION>::Do(station_id, text);
} else {
return ScriptObject::Command<CMD_RENAME_WAYPOINT>::Do(station_id, text);
}
}
/* static */ TileIndex ScriptBaseStation::GetLocation(StationID station_id)
{
if (!IsValidBaseStation(station_id)) return INVALID_TILE;
return ::BaseStation::Get(station_id)->xy;
}
/* static */ ScriptDate::Date ScriptBaseStation::GetConstructionDate(StationID station_id)
{
if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date.base();
}
|