Files
@ r11976:ae6aa97461b7
Branch filter:
Location: cpp/openttd-patchpack/source/src/ai/api/ai_waypoint.cpp - annotation
r11976:ae6aa97461b7
1.6 KiB
text/x-c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11944:3b8f9f948e8d r11944:3b8f9f948e8d r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11169:8ceeaab16ab6 r11917:612c11f7ab47 r11169:8ceeaab16ab6 | /* $Id$ */
/** @file ai_waypoint.cpp Implementation of AIWaypoint. */
#include "ai_waypoint.hpp"
#include "ai_rail.hpp"
#include "../../command_func.h"
#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../company_func.h"
#include "../../waypoint.h"
#include "../../core/alloc_func.hpp"
#include "table/strings.h"
/* static */ bool AIWaypoint::IsValidWaypoint(WaypointID waypoint_id)
{
const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id);
return wp != NULL && wp->owner == _current_company;
}
/* static */ WaypointID AIWaypoint::GetWaypointID(TileIndex tile)
{
if (!AIRail::IsRailWaypointTile(tile)) return WAYPOINT_INVALID;
return ::GetWaypointIndex(tile);
}
/* static */ char *AIWaypoint::GetName(WaypointID waypoint_id)
{
if (!IsValidWaypoint(waypoint_id)) return NULL;
static const int len = 64;
char *waypoint_name = MallocT<char>(len);
::SetDParam(0, waypoint_id);
::GetString(waypoint_name, STR_WAYPOINT_RAW, &waypoint_name[len - 1]);
return waypoint_name;
}
/* static */ bool AIWaypoint::SetName(WaypointID waypoint_id, const char *name)
{
EnforcePrecondition(false, IsValidWaypoint(waypoint_id));
EnforcePrecondition(false, !::StrEmpty(name));
EnforcePreconditionCustomError(false, ::strlen(name) < MAX_LENGTH_WAYPOINT_NAME_BYTES, AIError::ERR_PRECONDITION_STRING_TOO_LONG);
return AIObject::DoCommand(0, waypoint_id, 0, CMD_RENAME_WAYPOINT, name);
}
/* static */ TileIndex AIWaypoint::GetLocation(WaypointID waypoint_id)
{
if (!IsValidWaypoint(waypoint_id)) return INVALID_TILE;
return ::Waypoint::Get(waypoint_id)->xy;
}
|