9511
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file ai_sign.cpp handles all functions of the AISign class */
|
|
4 |
|
|
5 |
#include "ai_sign.hpp"
|
|
6 |
#include "table/strings.h"
|
|
7 |
#include "../../command.h"
|
|
8 |
#include "../../signs.h"
|
|
9 |
#include "../../strings.h"
|
|
10 |
#include "../../variables.h" /* For SetDParam */
|
|
11 |
|
|
12 |
SignID AISign::GetMaxSignID()
|
|
13 |
{
|
|
14 |
return ::GetMaxSignIndex();
|
|
15 |
}
|
|
16 |
|
|
17 |
int32 AISign::GetSignCount()
|
|
18 |
{
|
|
19 |
return ::GetNumSigns();
|
|
20 |
}
|
|
21 |
|
|
22 |
/* static */ bool AISign::IsValidSign(SignID sign_id)
|
|
23 |
{
|
|
24 |
return ::IsValidSignID(sign_id);
|
|
25 |
}
|
|
26 |
|
|
27 |
char *AISign::GetText(SignID sign_id)
|
|
28 |
{
|
|
29 |
if (!AISign::IsValidSign(sign_id)) return NULL;
|
|
30 |
static const int len = 64;
|
|
31 |
char *sign_name = MallocT<char>(len);
|
|
32 |
|
|
33 |
::GetString(sign_name, ::GetSign(sign_id)->str, &sign_name[len - 1]);
|
|
34 |
|
|
35 |
return sign_name;
|
|
36 |
}
|
|
37 |
|
|
38 |
TileIndex AISign::GetLocation(SignID sign_id)
|
|
39 |
{
|
|
40 |
if (!AISign::IsValidSign(sign_id)) return INVALID_TILE;
|
|
41 |
const Sign *sign = ::GetSign(sign_id);
|
|
42 |
return ::TileVirtXY(sign->x, sign->y);
|
|
43 |
}
|
|
44 |
|
|
45 |
bool AISign::RemoveSign(SignID sign_id)
|
|
46 |
{
|
|
47 |
_cmd_text = "";
|
|
48 |
return this->DoCommand(0, sign_id, 0, CMD_RENAME_SIGN);
|
|
49 |
}
|
|
50 |
|
|
51 |
SignID AISign::BuildSign(TileIndex location, const char *text)
|
|
52 |
{
|
|
53 |
if (!::IsValidTile(location)) return INVALID_SIGN;
|
|
54 |
|
|
55 |
AIObject::SetNewSignID(INVALID_SIGN);
|
|
56 |
bool ret = this->DoCommand(location, 0, 0, CMD_PLACE_SIGN);
|
|
57 |
if (!ret) return INVALID_SIGN;
|
|
58 |
|
|
59 |
SignID new_sign_id = AIObject::GetNewSignID();
|
|
60 |
_cmd_text = text;
|
|
61 |
ret = this->DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN);
|
|
62 |
if (!ret) {
|
|
63 |
this->RemoveSign(new_sign_id);
|
|
64 |
return INVALID_SIGN;
|
|
65 |
}
|
|
66 |
return new_sign_id;
|
|
67 |
}
|