ai_waypoint.cpp

Go to the documentation of this file.
00001 /* $Id: ai_waypoint.cpp 15519 2009-02-19 07:40:08Z yexo $ */
00002 
00005 #include "ai_waypoint.hpp"
00006 #include "ai_rail.hpp"
00007 #include "../../command_func.h"
00008 #include "../../string_func.h"
00009 #include "../../strings_func.h"
00010 #include "../../company_func.h"
00011 #include "../../waypoint.h"
00012 #include "../../core/alloc_func.hpp"
00013 #include "table/strings.h"
00014 
00015 /* static */ bool AIWaypoint::IsValidWaypoint(WaypointID waypoint_id)
00016 {
00017   return ::IsValidWaypointID(waypoint_id) && ::GetWaypoint(waypoint_id)->owner == _current_company;
00018 }
00019 
00020 /* static */ WaypointID AIWaypoint::GetWaypointID(TileIndex tile)
00021 {
00022   if (!AIRail::IsRailWaypointTile(tile)) return WAYPOINT_INVALID;
00023 
00024   return ::GetWaypointIndex(tile);
00025 }
00026 
00027 /* static */ char *AIWaypoint::GetName(WaypointID waypoint_id)
00028 {
00029   if (!IsValidWaypoint(waypoint_id)) return NULL;
00030 
00031   static const int len = 64;
00032   char *waypoint_name = MallocT<char>(len);
00033 
00034   ::SetDParam(0, waypoint_id);
00035   ::GetString(waypoint_name, STR_WAYPOINT_RAW, &waypoint_name[len - 1]);
00036   return waypoint_name;
00037 }
00038 
00039 /* static */ bool AIWaypoint::SetName(WaypointID waypoint_id, const char *name)
00040 {
00041   EnforcePrecondition(false, IsValidWaypoint(waypoint_id));
00042   EnforcePrecondition(false, !::StrEmpty(name));
00043   EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_WAYPOINT_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
00044 
00045   return AIObject::DoCommand(0, waypoint_id, 0, CMD_RENAME_WAYPOINT, name);
00046 }
00047 
00048 /* static */ TileIndex AIWaypoint::GetLocation(WaypointID waypoint_id)
00049 {
00050   if (!IsValidWaypoint(waypoint_id)) return INVALID_TILE;
00051 
00052   return ::GetWaypoint(waypoint_id)->xy;
00053 }

Generated on Mon Dec 14 20:59:57 2009 for OpenTTD by  doxygen 1.5.6