author | truebrain |
Sun, 08 Jun 2008 21:20:48 +0000 | |
branch | noai |
changeset 10871 | 326ee226e9d7 |
parent 10864 | 9a6616a1dce6 |
child 11010 | 69532778abab |
permissions | -rw-r--r-- |
9599 | 1 |
/* $Id$ */ |
2 |
||
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9801
diff
changeset
|
3 |
/** @file ai_tilelist.cpp Implementation of AITileList and friends. */ |
9599 | 4 |
|
9592
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
5 |
#include "ai_tilelist.hpp" |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
6 |
#include "ai_industry.hpp" |
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:
9837
diff
changeset
|
7 |
#include "../../openttd.h" |
9599 | 8 |
#include "../../landscape.h" |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
9 |
#include "../../settings_type.h" |
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9833
diff
changeset
|
10 |
#include "../../station_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9599
diff
changeset
|
11 |
#include "../../map_func.h" |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
12 |
#include "../../tile_map.h" |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
13 |
#include "../../industry_map.h" |
10864
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
14 |
#include "../../station_base.h" |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
15 |
#include "../../station_map.h" |
9599 | 16 |
|
9592
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
17 |
void AITileList::FixRectangleSpan(TileIndex &t1, TileIndex &t2) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
18 |
{ |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
19 |
uint x1 = ::TileX(t1); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
20 |
uint x2 = ::TileX(t2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
21 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
22 |
uint y1 = ::TileY(t1); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
23 |
uint y2 = ::TileY(t2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
24 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
25 |
if (x1 >= x2) ::Swap(x1, x2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
26 |
if (y1 >= y2) ::Swap(y1, y2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
27 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
28 |
t1 = ::TileXY(x1, y1); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
29 |
t2 = ::TileXY(x2, y2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
30 |
} |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
31 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
32 |
void AITileList::AddRectangle(TileIndex t1, TileIndex t2) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
33 |
{ |
9801
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9767
diff
changeset
|
34 |
if (!::IsValidTile(t1)) return; |
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9767
diff
changeset
|
35 |
if (!::IsValidTile(t2)) return; |
9592
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
36 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
37 |
this->FixRectangleSpan(t1, t2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
38 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
39 |
uint w = TileX(t2) - TileX(t1) + 1; |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
40 |
uint h = TileY(t2) - TileY(t1) + 1; |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
41 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
42 |
BEGIN_TILE_LOOP(t, w, h, t1) { |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
43 |
this->AddItem(t); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
44 |
} END_TILE_LOOP(t, w, h, t1) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
45 |
} |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
46 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
47 |
void AITileList::AddTile(TileIndex tile) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
48 |
{ |
9801
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9767
diff
changeset
|
49 |
if (!::IsValidTile(tile)) return; |
9592
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
50 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
51 |
this->AddItem(tile); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
52 |
} |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
53 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
54 |
void AITileList::RemoveRectangle(TileIndex t1, TileIndex t2) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
55 |
{ |
9801
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9767
diff
changeset
|
56 |
if (!::IsValidTile(t1)) return; |
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9767
diff
changeset
|
57 |
if (!::IsValidTile(t2)) return; |
9592
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
58 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
59 |
this->FixRectangleSpan(t1, t2); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
60 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
61 |
uint w = TileX(t2) - TileX(t1) + 1; |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
62 |
uint h = TileY(t2) - TileY(t1) + 1; |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
63 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
64 |
BEGIN_TILE_LOOP(t, w, h, t1) { |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
65 |
this->RemoveItem(t); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
66 |
} END_TILE_LOOP(t, w, h, t1) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
67 |
} |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
68 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
69 |
void AITileList::RemoveTile(TileIndex tile) |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
70 |
{ |
9801
03a3eebd7fb7
(svn r12307) [NoAI] -Codechange: as followup on r12303 (trunk), use ::IsValidTile to check if a tile is inside the map, instead of all our custom ways
truebrain
parents:
9767
diff
changeset
|
71 |
if (!::IsValidTile(tile)) return; |
9592
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
72 |
|
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
73 |
this->RemoveItem(tile); |
c5c09cfde63a
(svn r9625) [NoAI] -Add: added AITileList() and one valuator for now: AITileListBuildable()
truelight
parents:
diff
changeset
|
74 |
} |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
75 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
76 |
AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_id, uint radius) |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
77 |
{ |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
78 |
if (!AIIndustry::IsValidIndustry(industry_id)) return; |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
79 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
80 |
const Industry *i = ::GetIndustry(industry_id); |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
81 |
const IndustrySpec *indsp = ::GetIndustrySpec(i->type); |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
82 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
83 |
/* Check if this industry accepts anything */ |
9765
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
84 |
{ |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
85 |
bool cargo_accepts = false; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
86 |
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) { |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
87 |
if (indsp->accepts_cargo[j] != CT_INVALID) cargo_accepts = true; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
88 |
} |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
89 |
if (!cargo_accepts) return; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
90 |
} |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
91 |
|
10776 | 92 |
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED; |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
93 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
94 |
BEGIN_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) { |
9766
bf67ecd8fd1f
(svn r12255) [NoAI] -Fix: ensure AITileList_Industry* only operates on valid tiles (Morloth)
truebrain
parents:
9765
diff
changeset
|
95 |
if (!::IsValidTile(cur_tile)) continue; |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
96 |
/* Exclude all tiles that belong to this industry */ |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
97 |
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue; |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
98 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
99 |
/* Only add the tile if it accepts the cargo (sometimes just 1 tile of an |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
100 |
* industry triggers the acceptance). */ |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
101 |
AcceptedCargo accepts; |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
102 |
::GetAcceptanceAroundTiles(accepts, cur_tile, 1, 1, radius); |
9765
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
103 |
{ |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
104 |
bool cargo_accepts = false; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
105 |
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) { |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
106 |
if (indsp->accepts_cargo[j] != CT_INVALID && accepts[indsp->accepts_cargo[j]] != 0) cargo_accepts = true; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
107 |
} |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
108 |
if (!cargo_accepts) continue; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
109 |
} |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
110 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
111 |
this->AddTile(cur_tile); |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
112 |
} END_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
113 |
} |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
114 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
115 |
AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_id, uint radius) |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
116 |
{ |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
117 |
if (!AIIndustry::IsValidIndustry(industry_id)) return; |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
118 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
119 |
const Industry *i = ::GetIndustry(industry_id); |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
120 |
const IndustrySpec *indsp = ::GetIndustrySpec(i->type); |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
121 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
122 |
/* Check if this industry produces anything */ |
9765
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
123 |
{ |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
124 |
bool cargo_produces = false; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
125 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
126 |
if (indsp->produced_cargo[j] != CT_INVALID) cargo_produces = true; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
127 |
} |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
128 |
if (!cargo_produces) return; |
4253d585cdbb
(svn r12254) [NoAI] -Fix: make AITileList_Industry* newgrf compatible (tnx glx)
truebrain
parents:
9757
diff
changeset
|
129 |
} |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
130 |
|
10776 | 131 |
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED; |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
132 |
|
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
133 |
BEGIN_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) { |
9766
bf67ecd8fd1f
(svn r12255) [NoAI] -Fix: ensure AITileList_Industry* only operates on valid tiles (Morloth)
truebrain
parents:
9765
diff
changeset
|
134 |
if (!::IsValidTile(cur_tile)) continue; |
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
135 |
/* Exclude all tiles that belong to this industry */ |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
136 |
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue; |
9767
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
137 |
|
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
138 |
/* Only add the tile if it produces the cargo (a bug in OpenTTD makes this |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
139 |
* inconsitance). */ |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
140 |
AcceptedCargo produces; |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
141 |
::GetProductionAroundTiles(produces, cur_tile, 1, 1, radius); |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
142 |
{ |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
143 |
bool cargo_produces = false; |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
144 |
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) { |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
145 |
if (indsp->produced_cargo[j] != CT_INVALID && produces[indsp->produced_cargo[j]] != 0) cargo_produces = true; |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
146 |
} |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
147 |
if (!cargo_produces) continue; |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
148 |
} |
a937441fecf1
(svn r12256) [NoAI] -Fix: because of a 'bug' in OpenTTD, FindStationsAroundIndustryTile gave inconsitant results with GetProductionAroundTiles (first ignores station layout). Fixed with HACK, waiting for real solution in OpenTTD.
truebrain
parents:
9766
diff
changeset
|
149 |
|
9757
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
150 |
this->AddTile(cur_tile); |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
151 |
} END_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) |
5cdc14959fb6
(svn r12242) [NoAI] -Add: added AITileList_Industry(Accepting|Producing), giving tiles on which you want to build a station for an industry
truebrain
parents:
9723
diff
changeset
|
152 |
} |
10864
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
153 |
|
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
154 |
AITileList_StationType::AITileList_StationType(StationID station_id, AIStation::StationType station_type) |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
155 |
{ |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
156 |
if (!AIStation::IsValidStation(station_id)) return; |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
157 |
|
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
158 |
const StationRect *rect = &::GetStation(station_id)->rect; |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
159 |
int station_type_value = ::FindFirstBit(station_type); |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
160 |
|
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
161 |
BEGIN_TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top)) { |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
162 |
if (!::IsTileType(cur_tile, MP_STATION)) continue; |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
163 |
if (::GetStationIndex(cur_tile) != station_id) continue; |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
164 |
if (::GetStationType(cur_tile) != station_type_value) continue; |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
165 |
this->AddTile(cur_tile); |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
166 |
} END_TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top)) |
9a6616a1dce6
(svn r13415) [NoAI] -Add: added AITileList_StationType, giving all the tiles on which a station of your requested type is, for a given station
truebrain
parents:
10776
diff
changeset
|
167 |
} |