author | truebrain |
Wed, 23 Apr 2008 12:05:32 +0000 | |
branch | noai |
changeset 10308 | 0c81dfce3e9b |
parent 10090 | d6a6cac2fb25 |
child 10339 | ce6cd68d9eb8 |
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" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
7 |
#include "../../command_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
8 |
#include "../../core/alloc_func.hpp" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9833
diff
changeset
|
9 |
#include "../../signs_base.h" |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
10 |
#include "../../string_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
11 |
#include "../../strings_func.h" |
9800 | 12 |
#include "../../tile_map.h" |
9511 | 13 |
|
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
|
14 |
/* static */ SignID AISign::GetMaxSignID() |
9511 | 15 |
{ |
16 |
return ::GetMaxSignIndex(); |
|
17 |
} |
|
18 |
||
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
|
19 |
/* static */ int32 AISign::GetSignCount() |
9511 | 20 |
{ |
21 |
return ::GetNumSigns(); |
|
22 |
} |
|
23 |
||
24 |
/* static */ bool AISign::IsValidSign(SignID sign_id) |
|
25 |
{ |
|
26 |
return ::IsValidSignID(sign_id); |
|
27 |
} |
|
28 |
||
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
|
29 |
/* static */ char *AISign::GetText(SignID sign_id) |
9511 | 30 |
{ |
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
|
31 |
if (!IsValidSign(sign_id)) return NULL; |
9511 | 32 |
static const int len = 64; |
33 |
char *sign_name = MallocT<char>(len); |
|
34 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
35 |
::SetDParam(0, sign_id); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
36 |
::GetString(sign_name, STR_SIGN_NAME, &sign_name[len - 1]); |
9511 | 37 |
|
38 |
return sign_name; |
|
39 |
} |
|
40 |
||
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
|
41 |
/* static */ TileIndex AISign::GetLocation(SignID sign_id) |
9511 | 42 |
{ |
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
|
43 |
if (!IsValidSign(sign_id)) return INVALID_TILE; |
9511 | 44 |
const Sign *sign = ::GetSign(sign_id); |
45 |
return ::TileVirtXY(sign->x, sign->y); |
|
46 |
} |
|
47 |
||
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
|
48 |
/* static */ bool AISign::RemoveSign(SignID sign_id) |
9511 | 49 |
{ |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
50 |
EnforcePrecondition(false, IsValidSign(sign_id)); |
9511 | 51 |
_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
|
52 |
return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN); |
9511 | 53 |
} |
54 |
||
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
|
55 |
/* static */ SignID AISign::BuildSign(TileIndex location, const char *text) |
9511 | 56 |
{ |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
57 |
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); |
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
58 |
EnforcePrecondition(INVALID_SIGN, !StrEmpty(text)); |
9511 | 59 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
60 |
/* Reset the internal NewSignID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
61 |
AIObject::SetNewSignID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
62 |
|
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
|
63 |
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
|
64 |
if (!ret) return INVALID_SIGN; |
9511 | 65 |
|
66 |
SignID new_sign_id = AIObject::GetNewSignID(); |
|
67 |
_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
|
68 |
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
|
69 |
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
|
70 |
RemoveSign(new_sign_id); |
9511 | 71 |
return INVALID_SIGN; |
72 |
} |
|
73 |
return new_sign_id; |
|
74 |
} |