author | truelight |
Sun, 18 Mar 2007 19:52:09 +0000 | |
branch | noai |
changeset 9459 | 73300438e505 |
parent 9430 | 9e0a193b2bec |
child 9497 | f6678533ccba |
permissions | -rw-r--r-- |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
1 |
/* $Id$ */ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
2 |
|
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
3 |
/** @file ai_town.cpp handles the town-related functions of the AITown class */ |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
4 |
|
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
5 |
#include "ai_town.hpp" |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
6 |
#include "../../town.h" |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
7 |
#include "../../strings.h" |
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
8 |
#include "../../variables.h" /* For SetDParam */ |
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
9380
diff
changeset
|
9 |
#include "table/strings.h" |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
10 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
11 |
TownID AITown::GetMaxTownID() |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
12 |
{ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
13 |
return ::GetMaxTownIndex(); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
14 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
15 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
16 |
int32 AITown::GetTownCount() |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
17 |
{ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
18 |
return ::GetNumTowns(); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
19 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
20 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
21 |
bool AITown::IsValidTown(TownID town_id) |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
22 |
{ |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
23 |
return ::IsValidTownID(town_id); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
24 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
25 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
26 |
char *AITown::GetName(TownID town_id) |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
27 |
{ |
9459
73300438e505
(svn r9290) [NoAI] -Fix: AITown and AIIndustry segfaulted if you gave a negative value as param to most functions
truelight
parents:
9430
diff
changeset
|
28 |
if (!this->IsValidTown(town_id)) return NULL; |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
29 |
static const int len = 64; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
30 |
char *town_name = MallocT<char>(len); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
31 |
|
9405
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
9380
diff
changeset
|
32 |
SetDParam(0, town_id); |
df6f3b4b0038
(svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
9380
diff
changeset
|
33 |
GetString(town_name, STR_TOWN, &town_name[len - 1]); |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
34 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
35 |
return town_name; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
36 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
37 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
38 |
int32 AITown::GetPopulation(TownID town_id) |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
39 |
{ |
9459
73300438e505
(svn r9290) [NoAI] -Fix: AITown and AIIndustry segfaulted if you gave a negative value as param to most functions
truelight
parents:
9430
diff
changeset
|
40 |
if (!this->IsValidTown(town_id)) return 0; |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
41 |
const Town *t = ::GetTown(town_id); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
42 |
return t->population; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
43 |
} |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
44 |
|
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
45 |
TileIndex AITown::GetLocation(TownID town_id) |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
46 |
{ |
9459
73300438e505
(svn r9290) [NoAI] -Fix: AITown and AIIndustry segfaulted if you gave a negative value as param to most functions
truelight
parents:
9430
diff
changeset
|
47 |
if (!this->IsValidTown(town_id)) return INVALID_TILE; |
9380
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
48 |
const Town *t = ::GetTown(town_id); |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
49 |
return t->xy; |
f4c7eb98b43d
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff
changeset
|
50 |
} |