author | truebrain |
Thu, 24 Apr 2008 23:39:18 +0000 | |
branch | noai |
changeset 10339 | ce6cd68d9eb8 |
parent 10090 | d6a6cac2fb25 |
child 10776 | 07203fc29812 |
permissions | -rw-r--r-- |
9511 | 1 |
/* $Id$ */ |
2 |
||
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9800
diff
changeset
|
3 |
/** @file ai_sign.cpp Implementation of AISign. */ |
9511 | 4 |
|
5 |
#include "ai_sign.hpp" |
|
6 |
#include "table/strings.h" |
|
10339
ce6cd68d9eb8
(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.
truebrain
parents:
10090
diff
changeset
|
7 |
#include "../../openttd.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
8 |
#include "../../command_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
9 |
#include "../../core/alloc_func.hpp" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9833
diff
changeset
|
10 |
#include "../../signs_base.h" |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
11 |
#include "../../string_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
12 |
#include "../../strings_func.h" |
9800 | 13 |
#include "../../tile_map.h" |
9511 | 14 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
15 |
/* static */ SignID AISign::GetMaxSignID() |
9511 | 16 |
{ |
17 |
return ::GetMaxSignIndex(); |
|
18 |
} |
|
19 |
||
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
20 |
/* static */ int32 AISign::GetSignCount() |
9511 | 21 |
{ |
22 |
return ::GetNumSigns(); |
|
23 |
} |
|
24 |
||
25 |
/* static */ bool AISign::IsValidSign(SignID sign_id) |
|
26 |
{ |
|
27 |
return ::IsValidSignID(sign_id); |
|
28 |
} |
|
29 |
||
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
30 |
/* static */ char *AISign::GetText(SignID sign_id) |
9511 | 31 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
32 |
if (!IsValidSign(sign_id)) return NULL; |
9511 | 33 |
static const int len = 64; |
34 |
char *sign_name = MallocT<char>(len); |
|
35 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
36 |
::SetDParam(0, sign_id); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
37 |
::GetString(sign_name, STR_SIGN_NAME, &sign_name[len - 1]); |
9511 | 38 |
|
39 |
return sign_name; |
|
40 |
} |
|
41 |
||
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
42 |
/* static */ TileIndex AISign::GetLocation(SignID sign_id) |
9511 | 43 |
{ |
9736
183b38e0a480
(svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents:
9724
diff
changeset
|
44 |
if (!IsValidSign(sign_id)) return INVALID_TILE; |
9511 | 45 |
const Sign *sign = ::GetSign(sign_id); |
46 |
return ::TileVirtXY(sign->x, sign->y); |
|
47 |
} |
|
48 |
||
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
49 |
/* static */ bool AISign::RemoveSign(SignID sign_id) |
9511 | 50 |
{ |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
51 |
EnforcePrecondition(false, IsValidSign(sign_id)); |
9511 | 52 |
_cmd_text = ""; |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
53 |
return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN); |
9511 | 54 |
} |
55 |
||
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
56 |
/* static */ SignID AISign::BuildSign(TileIndex location, const char *text) |
9511 | 57 |
{ |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
58 |
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); |
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
59 |
EnforcePrecondition(INVALID_SIGN, !StrEmpty(text)); |
9511 | 60 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
61 |
/* Reset the internal NewSignID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
62 |
AIObject::SetNewSignID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
63 |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
64 |
bool ret = AIObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN); |
9561
33b2f192bb34
(svn r9499) [NoAI] -Revert r9498: reverted part of ai_sign.cpp, as by policy this is the road we take
truelight
parents:
9560
diff
changeset
|
65 |
if (!ret) return INVALID_SIGN; |
9511 | 66 |
|
67 |
SignID new_sign_id = AIObject::GetNewSignID(); |
|
68 |
_cmd_text = text; |
|
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
69 |
ret = AIObject::DoCommand(0, new_sign_id, 0, CMD_RENAME_SIGN); |
9561
33b2f192bb34
(svn r9499) [NoAI] -Revert r9498: reverted part of ai_sign.cpp, as by policy this is the road we take
truelight
parents:
9560
diff
changeset
|
70 |
if (!ret) { |
9737
ee408edf3851
(svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents:
9736
diff
changeset
|
71 |
RemoveSign(new_sign_id); |
9511 | 72 |
return INVALID_SIGN; |
73 |
} |
|
74 |
return new_sign_id; |
|
75 |
} |