(svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
-Note: this is perfectly safe; when a type changes, any sane compiler starts complaining about redefining the typedef to an other type
/* $Id$ */
/** @file ai_sign.cpp Implementation of AISign. */
#include "ai_sign.hpp"
#include "table/strings.h"
#include "../../openttd.h"
#include "../../command_func.h"
#include "../../core/alloc_func.hpp"
#include "../../signs_base.h"
#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../tile_map.h"
/* static */ SignID AISign::GetMaxSignID()
{
return ::GetMaxSignIndex();
}
/* static */ int32 AISign::GetSignCount()
{
return ::GetNumSigns();
}
/* static */ bool AISign::IsValidSign(SignID sign_id)
{
return ::IsValidSignID(sign_id);
}
/* static */ char *AISign::GetText(SignID sign_id)
{
if (!IsValidSign(sign_id)) return NULL;
static const int len = 64;
char *sign_name = MallocT<char>(len);
::SetDParam(0, sign_id);
::GetString(sign_name, STR_SIGN_NAME, &sign_name[len - 1]);
return sign_name;
}
/* static */ TileIndex AISign::GetLocation(SignID sign_id)
{
if (!IsValidSign(sign_id)) return INVALID_TILE;
const Sign *sign = ::GetSign(sign_id);
return ::TileVirtXY(sign->x, sign->y);
}
/* static */ bool AISign::RemoveSign(SignID sign_id)
{
EnforcePrecondition(false, IsValidSign(sign_id));
_cmd_text = "";
return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN);
}
/* static */ SignID AISign::BuildSign(TileIndex location, const char *text)
{
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
EnforcePrecondition(INVALID_SIGN, !StrEmpty(text));
/* Reset the internal NewSignID in case we are in TestMode */
AIObject::SetNewSignID(0);
bool ret = AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN);
if (!ret) return INVALID_SIGN;
SignID new_sign_id = AIObject::GetNewSignID();
_cmd_text = text;
ret = AIObject::DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN);
if (!ret) {
RemoveSign(new_sign_id);
return INVALID_SIGN;
}
return new_sign_id;
}