ai_basestation.cpp

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

Generated on Fri Dec 31 17:15:28 2010 for OpenTTD by  doxygen 1.6.1