author | truebrain |
Fri, 13 Jun 2008 13:07:31 +0000 | |
branch | noai |
changeset 10952 | d16212cc2394 |
parent 10855 | 90904faa1890 |
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" |
10952
d16212cc2394
(svn r13506) [NoAI] -Change [API CHANGE]: like AIVehicle, AIStation, .. restrict AISign to only your own signs
truebrain
parents:
10855
diff
changeset
|
14 |
#include "../../player_func.h" |
9511 | 15 |
|
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
|
16 |
/* static */ SignID AISign::GetMaxSignID() |
9511 | 17 |
{ |
18 |
return ::GetMaxSignIndex(); |
|
19 |
} |
|
20 |
||
21 |
/* static */ bool AISign::IsValidSign(SignID sign_id) |
|
22 |
{ |
|
10952
d16212cc2394
(svn r13506) [NoAI] -Change [API CHANGE]: like AIVehicle, AIStation, .. restrict AISign to only your own signs
truebrain
parents:
10855
diff
changeset
|
23 |
return ::IsValidSignID(sign_id) && ::GetSign(sign_id)->owner == _current_player; |
9511 | 24 |
} |
25 |
||
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
|
26 |
/* static */ char *AISign::GetText(SignID sign_id) |
9511 | 27 |
{ |
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
|
28 |
if (!IsValidSign(sign_id)) return NULL; |
10952
d16212cc2394
(svn r13506) [NoAI] -Change [API CHANGE]: like AIVehicle, AIStation, .. restrict AISign to only your own signs
truebrain
parents:
10855
diff
changeset
|
29 |
|
9511 | 30 |
static const int len = 64; |
31 |
char *sign_name = MallocT<char>(len); |
|
32 |
||
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
33 |
::SetDParam(0, sign_id); |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
34 |
::GetString(sign_name, STR_SIGN_NAME, &sign_name[len - 1]); |
9511 | 35 |
|
36 |
return sign_name; |
|
37 |
} |
|
38 |
||
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
|
39 |
/* static */ TileIndex AISign::GetLocation(SignID sign_id) |
9511 | 40 |
{ |
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
|
41 |
if (!IsValidSign(sign_id)) return INVALID_TILE; |
10952
d16212cc2394
(svn r13506) [NoAI] -Change [API CHANGE]: like AIVehicle, AIStation, .. restrict AISign to only your own signs
truebrain
parents:
10855
diff
changeset
|
42 |
|
9511 | 43 |
const Sign *sign = ::GetSign(sign_id); |
44 |
return ::TileVirtXY(sign->x, sign->y); |
|
45 |
} |
|
46 |
||
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
|
47 |
/* static */ bool AISign::RemoveSign(SignID sign_id) |
9511 | 48 |
{ |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
49 |
EnforcePrecondition(false, IsValidSign(sign_id)); |
9511 | 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 |
{ |
10090
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
56 |
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); |
d6a6cac2fb25
(svn r12614) [NoAI] -Add: support for GetLastError in AISign. Patch by Morloth.
rubidium
parents:
9837
diff
changeset
|
57 |
EnforcePrecondition(INVALID_SIGN, !StrEmpty(text)); |
9511 | 58 |
|
9560
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
59 |
/* Reset the internal NewSignID in case we are in TestMode */ |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
60 |
AIObject::SetNewSignID(0); |
ff2dde050a4c
(svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents:
9511
diff
changeset
|
61 |
|
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
|
62 |
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
|
63 |
if (!ret) return INVALID_SIGN; |
9511 | 64 |
|
65 |
SignID new_sign_id = AIObject::GetNewSignID(); |
|
66 |
_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
|
67 |
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
|
68 |
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
|
69 |
RemoveSign(new_sign_id); |
9511 | 70 |
return INVALID_SIGN; |
71 |
} |
|
72 |
return new_sign_id; |
|
73 |
} |