ai_basestation.cpp

Go to the documentation of this file.
00001 /* $Id: ai_basestation.cpp 17693 2009-10-04 17:16:41Z 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 "../../command_func.h"
00015 #include "../../string_func.h"
00016 #include "../../strings_func.h"
00017 #include "../../company_func.h"
00018 #include "table/strings.h"
00019 
00020 /* static */ bool AIBaseStation::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 /* static */ char *AIBaseStation::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 /* static */ bool AIBaseStation::SetName(StationID station_id, const char *name)
00039 {
00040   EnforcePrecondition(false, IsValidBaseStation(station_id));
00041   EnforcePrecondition(false, !::StrEmpty(name));
00042   EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_STATION_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
00043 
00044   return AIObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, name);
00045 }
00046 
00047 /* static */ TileIndex AIBaseStation::GetLocation(StationID station_id)
00048 {
00049   if (!IsValidBaseStation(station_id)) return INVALID_TILE;
00050 
00051   return ::BaseStation::Get(station_id)->xy;
00052 }
00053 
00054 /* static */ int32 AIBaseStation::GetConstructionDate(StationID station_id)
00055 {
00056   if (!IsValidBaseStation(station_id)) return -1;
00057 
00058   return ::BaseStation::Get(station_id)->build_date;
00059 }

Generated on Sat Apr 17 23:24:45 2010 for OpenTTD by  doxygen 1.6.1