2009-07-31 22:30:54 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/** @file script_basestation.cpp Implementation of ScriptBaseStation. */
|
2009-07-31 22:30:54 +00:00
|
|
|
|
2011-01-22 10:33:16 +00:00
|
|
|
#include "../../stdafx.h"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "script_basestation.hpp"
|
2012-01-03 20:26:05 +00:00
|
|
|
#include "script_error.hpp"
|
2009-07-31 22:30:54 +00:00
|
|
|
#include "../../station_base.h"
|
|
|
|
#include "../../string_func.h"
|
|
|
|
#include "../../strings_func.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptBaseStation::IsValidBaseStation(StationID station_id)
|
2009-07-31 22:30:54 +00:00
|
|
|
{
|
|
|
|
const BaseStation *st = ::BaseStation::GetIfValid(station_id);
|
2011-12-19 21:05:25 +00:00
|
|
|
return st != NULL && (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || st->owner == OWNER_NONE);
|
2009-07-31 22:30:54 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ char *ScriptBaseStation::GetName(StationID station_id)
|
2009-07-31 22:30:54 +00:00
|
|
|
{
|
|
|
|
if (!IsValidBaseStation(station_id)) return NULL;
|
|
|
|
|
|
|
|
::SetDParam(0, station_id);
|
2012-01-08 21:48:05 +00:00
|
|
|
return GetString(::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME);
|
2009-07-31 22:30:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:06:06 +00:00
|
|
|
/* static */ bool ScriptBaseStation::SetName(StationID station_id, Text *name)
|
2009-07-31 22:30:54 +00:00
|
|
|
{
|
2011-12-19 21:06:06 +00:00
|
|
|
CCountedPtr<Text> counter(name);
|
|
|
|
|
2011-12-19 21:05:36 +00:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-07-31 22:30:54 +00:00
|
|
|
EnforcePrecondition(false, IsValidBaseStation(station_id));
|
2011-12-19 21:06:06 +00:00
|
|
|
EnforcePrecondition(false, name != NULL);
|
|
|
|
const char *text = name->GetEncodedText();
|
2013-02-08 20:34:27 +00:00
|
|
|
EnforcePreconditionEncodedText(false, text);
|
2011-12-19 21:06:06 +00:00
|
|
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
2009-07-31 22:30:54 +00:00
|
|
|
|
2011-12-19 21:06:06 +00:00
|
|
|
return ScriptObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, text);
|
2009-07-31 22:30:54 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ TileIndex ScriptBaseStation::GetLocation(StationID station_id)
|
2009-07-31 22:30:54 +00:00
|
|
|
{
|
|
|
|
if (!IsValidBaseStation(station_id)) return INVALID_TILE;
|
|
|
|
|
|
|
|
return ::BaseStation::Get(station_id)->xy;
|
|
|
|
}
|
2009-07-31 22:38:09 +00:00
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptBaseStation::GetConstructionDate(StationID station_id)
|
2009-07-31 22:38:09 +00:00
|
|
|
{
|
|
|
|
if (!IsValidBaseStation(station_id)) return -1;
|
|
|
|
|
|
|
|
return ::BaseStation::Get(station_id)->build_date;
|
|
|
|
}
|