Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../../stdafx.h"
00013 #include "script_basestation.hpp"
00014 #include "../../station_base.h"
00015 #include "../../string_func.h"
00016 #include "../../strings_func.h"
00017 #include "../../company_func.h"
00018 #include "table/strings.h"
00019
00020 bool ScriptBaseStation::IsValidBaseStation(StationID station_id)
00021 {
00022 const BaseStation *st = ::BaseStation::GetIfValid(station_id);
00023 return st != NULL && (st->owner == _current_company || st->owner == OWNER_NONE);
00024 }
00025
00026 char *ScriptBaseStation::GetName(StationID station_id)
00027 {
00028 if (!IsValidBaseStation(station_id)) return NULL;
00029
00030 static const int len = 64;
00031 char *name = MallocT<char>(len);
00032
00033 ::SetDParam(0, station_id);
00034 ::GetString(name, ::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME, &name[len - 1]);
00035 return name;
00036 }
00037
00038 bool ScriptBaseStation::SetName(StationID station_id, const char *name)
00039 {
00040 EnforcePrecondition(false, IsValidBaseStation(station_id));
00041 EnforcePrecondition(false, !::StrEmpty(name));
00042 EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
00043
00044 return ScriptObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, name);
00045 }
00046
00047 TileIndex ScriptBaseStation::GetLocation(StationID station_id)
00048 {
00049 if (!IsValidBaseStation(station_id)) return INVALID_TILE;
00050
00051 return ::BaseStation::Get(station_id)->xy;
00052 }
00053
00054 int32 ScriptBaseStation::GetConstructionDate(StationID station_id)
00055 {
00056 if (!IsValidBaseStation(station_id)) return -1;
00057
00058 return ::BaseStation::Get(station_id)->build_date;
00059 }