ai_basestation.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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 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 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 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 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 int32 AIBaseStation::GetConstructionDate(StationID station_id)
00054 {
00055 if (!IsValidBaseStation(station_id)) return -1;
00056
00057 return ::BaseStation::Get(station_id)->build_date;
00058 }