author | truebrain |
Wed, 27 Feb 2008 21:07:31 +0000 | |
branch | noai |
changeset 9792 | e1222f4674c2 |
parent 9737 | ee408edf3851 |
child 9800 | ab08ca2a2018 |
permissions | -rw-r--r-- |
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" |
|
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" |
9599 | 9 |
#include "../../landscape.h" |
9511 | 10 |
#include "../../signs.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
11 |
#include "../../strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
12 |
#include "../../map_func.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 |
{ |
50 |
_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
|
51 |
return AIObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN); |
9511 | 52 |
} |
53 |
||
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
|
54 |
/* static */ SignID AISign::BuildSign(TileIndex location, const char *text) |
9511 | 55 |
{ |
56 |
if (!::IsValidTile(location)) return INVALID_SIGN; |
|
57 |
||
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
58 |
/* Reset the internal NewSignID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
59 |
AIObject::SetNewSignID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
60 |
|
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
|
61 |
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
|
62 |
if (!ret) return INVALID_SIGN; |
9511 | 63 |
|
64 |
SignID new_sign_id = AIObject::GetNewSignID(); |
|
65 |
_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
|
66 |
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
|
67 |
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
|
68 |
RemoveSign(new_sign_id); |
9511 | 69 |
return INVALID_SIGN; |
70 |
} |
|
71 |
return new_sign_id; |
|
72 |
} |