author | smatz |
Fri, 18 Jan 2008 14:48:57 +0000 | |
changeset 8847 | 98ccd8072daf |
parent 8818 | d8d3812f8f35 |
child 8885 | b18a67c2eaeb |
permissions | -rw-r--r-- |
2423
84222db5a01a
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2381
diff
changeset
|
1 |
/* $Id$ */ |
2381
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
2 |
|
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
3 |
#include "../../stdafx.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
4 |
#include "../../openttd.h" |
3964
7c1b20ebdb07
(svn r5127) Use IsRoadVehInDepotStopped() and IsAircraftInHangarStopped()
tron
parents:
3948
diff
changeset
|
5 |
#include "../../aircraft.h" |
3196 | 6 |
#include "../../bridge_map.h" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8612
diff
changeset
|
7 |
#include "../../tile_cmd.h" |
6949
72d11a1e1e60
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6900
diff
changeset
|
8 |
#include "../../landscape.h" |
3185 | 9 |
#include "../../rail_map.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3088
diff
changeset
|
10 |
#include "../../road_map.h" |
3964
7c1b20ebdb07
(svn r5127) Use IsRoadVehInDepotStopped() and IsAircraftInHangarStopped()
tron
parents:
3948
diff
changeset
|
11 |
#include "../../roadveh.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
12 |
#include "../../station_map.h" |
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3179
diff
changeset
|
13 |
#include "../../tunnel_map.h" |
2381
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
14 |
#include "../../engine.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8604
diff
changeset
|
15 |
#include "../../command_func.h" |
2381
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
16 |
#include "../../town.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
17 |
#include "../../industry.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
18 |
#include "../../station.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
19 |
#include "../../pathfind.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
20 |
#include "../../airport.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
21 |
#include "../../depot.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2186
diff
changeset
|
22 |
#include "../../variables.h" |
3359
d4316b1af327
(svn r4154) -Moved MAX_BRIDGES in bridge.h and made it an enum. This makes two drops ...
celestar
parents:
3355
diff
changeset
|
23 |
#include "../../bridge.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
24 |
#include "../../date_func.h" |
8579
3efbb430092e
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
8502
diff
changeset
|
25 |
#include "../../tunnelbridge_map.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8626
diff
changeset
|
26 |
#include "../../window_func.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
27 |
#include "../../vehicle_func.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8626
diff
changeset
|
28 |
#include "../../functions.h" |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
29 |
#include "../../saveload.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8732
diff
changeset
|
30 |
#include "../../player_func.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8732
diff
changeset
|
31 |
#include "../../player_base.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
32 |
#include "../../settings_type.h" |
2447
47f2b670fb22
(svn r2973) Move a function declaration somewhere where it belongs
tron
parents:
2425
diff
changeset
|
33 |
#include "default.h" |
0 | 34 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
35 |
#include "../../table/ai_rail.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
36 |
|
0 | 37 |
// remove some day perhaps? |
192
614bba52258d
(svn r193) -Fix: [OldAI] If service-interval is in %, it works correct now.
truelight
parents:
159
diff
changeset
|
38 |
static uint _ai_service_interval; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
39 |
PlayerAI _players_ai[MAX_PLAYERS]; |
0 | 40 |
|
41 |
typedef void AiStateAction(Player *p); |
|
42 |
||
43 |
enum { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
44 |
AIS_0 = 0, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
45 |
AIS_1 = 1, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
46 |
AIS_VEH_LOOP = 2, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
47 |
AIS_VEH_CHECK_REPLACE_VEHICLE = 3, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
48 |
AIS_VEH_DO_REPLACE_VEHICLE = 4, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
49 |
AIS_WANT_NEW_ROUTE = 5, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
50 |
AIS_BUILD_DEFAULT_RAIL_BLOCKS = 6, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
51 |
AIS_BUILD_RAIL = 7, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
52 |
AIS_BUILD_RAIL_VEH = 8, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
53 |
AIS_DELETE_RAIL_BLOCKS = 9, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
54 |
AIS_BUILD_DEFAULT_ROAD_BLOCKS = 10, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
55 |
AIS_BUILD_ROAD = 11, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
56 |
AIS_BUILD_ROAD_VEHICLES = 12, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
57 |
AIS_DELETE_ROAD_BLOCKS = 13, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
58 |
AIS_AIRPORT_STUFF = 14, |
0 | 59 |
AIS_BUILD_DEFAULT_AIRPORT_BLOCKS = 15, |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
60 |
AIS_BUILD_AIRCRAFT_VEHICLES = 16, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
61 |
AIS_CHECK_SHIP_STUFF = 17, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
62 |
AIS_BUILD_DEFAULT_SHIP_BLOCKS = 18, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
63 |
AIS_DO_SHIP_STUFF = 19, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
64 |
AIS_SELL_VEHICLE = 20, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
65 |
AIS_REMOVE_STATION = 21, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
66 |
AIS_REMOVE_TRACK = 22, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
67 |
AIS_REMOVE_SINGLE_RAIL_TILE = 23 |
0 | 68 |
}; |
69 |
||
70 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
71 |
static TrackBits GetRailTrackStatus(TileIndex tile) |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
72 |
{ |
7179
3e123c2b7c93
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
7177
diff
changeset
|
73 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_RAIL, 0); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
74 |
return (TrackBits)(byte) (r | r >> 8); |
0 | 75 |
} |
76 |
||
77 |
||
78 |
static void AiCase0(Player *p) |
|
79 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
80 |
_players_ai[p->index].state = AIS_REMOVE_TRACK; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
81 |
_players_ai[p->index].state_counter = 0; |
0 | 82 |
} |
83 |
||
84 |
static void AiCase1(Player *p) |
|
85 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
86 |
_players_ai[p->index].cur_veh = NULL; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
87 |
_players_ai[p->index].state = AIS_VEH_LOOP; |
0 | 88 |
} |
89 |
||
90 |
static void AiStateVehLoop(Player *p) |
|
91 |
{ |
|
92 |
Vehicle *v; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
93 |
uint index; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
94 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
95 |
index = (_players_ai[p->index].cur_veh == NULL) ? 0 : _players_ai[p->index].cur_veh->index + 1; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
96 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
97 |
FOR_ALL_VEHICLES_FROM(v, index) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
98 |
if (v->owner != _current_player) continue; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
99 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
100 |
if ((v->type == VEH_TRAIN && v->subtype == 0) || |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
101 |
v->type == VEH_ROAD || |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
102 |
(v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) || |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
103 |
v->type == VEH_SHIP) { |
0 | 104 |
/* replace engine? */ |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
105 |
if (v->type == VEH_TRAIN && v->engine_type < 3 && |
0 | 106 |
(_price.build_railvehicle >> 3) < p->player_money) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
107 |
_players_ai[p->index].state = AIS_VEH_CHECK_REPLACE_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
108 |
_players_ai[p->index].cur_veh = v; |
0 | 109 |
return; |
110 |
} |
|
111 |
||
112 |
/* not profitable? */ |
|
113 |
if (v->age >= 730 && |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
114 |
v->profit_last_year < _price.station_value * 5 && |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
115 |
v->profit_this_year < _price.station_value * 5) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
116 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
117 |
_players_ai[p->index].state = AIS_SELL_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
118 |
_players_ai[p->index].cur_veh = v; |
0 | 119 |
return; |
120 |
} |
|
121 |
||
122 |
/* not reliable? */ |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
123 |
if (v->age >= v->max_age || ( |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
124 |
v->age != 0 && |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
125 |
GetEngine(v->engine_type)->reliability < 35389 |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
126 |
)) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
127 |
_players_ai[p->index].state = AIS_VEH_CHECK_REPLACE_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
128 |
_players_ai[p->index].cur_veh = v; |
0 | 129 |
return; |
130 |
} |
|
131 |
} |
|
132 |
} |
|
133 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
134 |
_players_ai[p->index].state = AIS_WANT_NEW_ROUTE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
135 |
_players_ai[p->index].state_counter = 0; |
0 | 136 |
} |
137 |
||
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
138 |
static EngineID AiChooseTrainToBuild(RailType railtype, Money money, byte flag, TileIndex tile) |
0 | 139 |
{ |
2544 | 140 |
EngineID best_veh_index = INVALID_ENGINE; |
0 | 141 |
byte best_veh_score = 0; |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
142 |
CommandCost ret; |
2544 | 143 |
EngineID i; |
460
f11659d28617
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
410
diff
changeset
|
144 |
|
f11659d28617
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
410
diff
changeset
|
145 |
for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
539 | 146 |
const RailVehicleInfo *rvi = RailVehInfo(i); |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
147 |
const Engine* e = GetEngine(i); |
460
f11659d28617
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
410
diff
changeset
|
148 |
|
6074 | 149 |
if (!IsCompatibleRail(rvi->railtype, railtype) || |
6119
b47985557d1e
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents:
6105
diff
changeset
|
150 |
rvi->railveh_type == RAILVEH_WAGON || |
b47985557d1e
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents:
6105
diff
changeset
|
151 |
(rvi->railveh_type == RAILVEH_MULTIHEAD && flag & 1) || |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8149
diff
changeset
|
152 |
!HasBit(e->player_avail, _current_player) || |
2529
97c0b71ee7dd
(svn r3058) The default AI may not build dual headed trains under certain circumstances.
tron
parents:
2523
diff
changeset
|
153 |
e->reliability < 0x8A3D) { |
0 | 154 |
continue; |
2529
97c0b71ee7dd
(svn r3058) The default AI may not build dual headed trains under certain circumstances.
tron
parents:
2523
diff
changeset
|
155 |
} |
0 | 156 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
157 |
ret = DoCommand(tile, i, 0, 0, CMD_BUILD_RAIL_VEHICLE); |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
158 |
if (CmdSucceeded(ret) && ret.GetCost() <= money && rvi->ai_rank >= best_veh_score) { |
3022
236a3e5b3c69
(svn r3602) - Move _railveh_score data to _rail_vehicle_info->ai_rank and remove global variable to return data as we can now access this directly.
peter1138
parents:
2989
diff
changeset
|
159 |
best_veh_score = rvi->ai_rank; |
0 | 160 |
best_veh_index = i; |
161 |
} |
|
460
f11659d28617
(svn r677) -newgrf: Fix some custom electric trains appearing in maglev depots (pasky).
darkvater
parents:
410
diff
changeset
|
162 |
} |
0 | 163 |
|
164 |
return best_veh_index; |
|
165 |
} |
|
166 |
||
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
167 |
static EngineID AiChooseRoadVehToBuild(CargoID cargo, Money money, TileIndex tile) |
0 | 168 |
{ |
2544 | 169 |
EngineID best_veh_index = INVALID_ENGINE; |
5029
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
170 |
int32 best_veh_rating = 0; |
5016
63281a3e8548
(svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.
peter1138
parents:
5004
diff
changeset
|
171 |
EngineID i = ROAD_ENGINES_INDEX; |
63281a3e8548
(svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.
peter1138
parents:
5004
diff
changeset
|
172 |
EngineID end = i + NUM_ROAD_ENGINES; |
3034
230ec6a1af82
(svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents:
3033
diff
changeset
|
173 |
|
230ec6a1af82
(svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents:
3033
diff
changeset
|
174 |
for (; i != end; i++) { |
5029
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
175 |
const RoadVehicleInfo *rvi = RoadVehInfo(i); |
3034
230ec6a1af82
(svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents:
3033
diff
changeset
|
176 |
const Engine* e = GetEngine(i); |
5029
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
177 |
int32 rating; |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
178 |
CommandCost ret; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
179 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8149
diff
changeset
|
180 |
if (!HasBit(e->player_avail, _current_player) || e->reliability < 0x8A3D) { |
0 | 181 |
continue; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
182 |
} |
0 | 183 |
|
5016
63281a3e8548
(svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.
peter1138
parents:
5004
diff
changeset
|
184 |
/* Skip vehicles which can't take our cargo type */ |
5031
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
185 |
if (rvi->cargo_type != cargo && !CanRefitTo(i, cargo)) continue; |
5029
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
186 |
|
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
187 |
/* Rate and compare the engine by speed & capacity */ |
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
188 |
rating = rvi->max_speed * rvi->capacity; |
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
189 |
if (rating <= best_veh_rating) continue; |
5016
63281a3e8548
(svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.
peter1138
parents:
5004
diff
changeset
|
190 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
191 |
ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH); |
5031
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
192 |
if (CmdFailed(ret)) continue; |
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
193 |
|
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
194 |
/* Add the cost of refitting */ |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
195 |
if (rvi->cargo_type != cargo) ret.AddCost(GetRefitCost(i)); |
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
196 |
if (ret.GetCost() > money) continue; |
5029
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
197 |
|
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
198 |
best_veh_rating = rating; |
66c90d197b7b
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents:
5028
diff
changeset
|
199 |
best_veh_index = i; |
3034
230ec6a1af82
(svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents:
3033
diff
changeset
|
200 |
} |
0 | 201 |
|
202 |
return best_veh_index; |
|
203 |
} |
|
204 |
||
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
205 |
static EngineID AiChooseAircraftToBuild(Money money, byte flag) |
0 | 206 |
{ |
2544 | 207 |
EngineID best_veh_index = INVALID_ENGINE; |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
208 |
Money best_veh_cost = 0; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
209 |
EngineID i; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
210 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
211 |
for (i = AIRCRAFT_ENGINES_INDEX; i != AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) { |
3034
230ec6a1af82
(svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents:
3033
diff
changeset
|
212 |
const Engine* e = GetEngine(i); |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
213 |
CommandCost ret; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
214 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8149
diff
changeset
|
215 |
if (!HasBit(e->player_avail, _current_player) || e->reliability < 0x8A3D) { |
0 | 216 |
continue; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
217 |
} |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
218 |
|
4024
636df31c7aff
(svn r5263) Use the flag which denotes if it's a plane or helicopter instead of magical engine numbers
tron
parents:
4015
diff
changeset
|
219 |
if ((AircraftVehInfo(i)->subtype & AIR_CTOL) != flag) continue; |
0 | 220 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
221 |
ret = DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT); |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
222 |
if (CmdSucceeded(ret) && ret.GetCost() <= money && ret.GetCost() >= best_veh_cost) { |
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
223 |
best_veh_cost = ret.GetCost(); |
0 | 224 |
best_veh_index = i; |
225 |
} |
|
3034
230ec6a1af82
(svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents:
3033
diff
changeset
|
226 |
} |
0 | 227 |
|
228 |
return best_veh_index; |
|
229 |
} |
|
230 |
||
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
231 |
static Money AiGetBasePrice(const Player* p) |
0 | 232 |
{ |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
233 |
Money base = _price.station_value; |
0 | 234 |
|
235 |
// adjust base price when more expensive vehicles are available |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
236 |
switch (_players_ai[p->index].railtype_to_use) { |
3966
e6bfc5a2e8aa
(svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents:
3965
diff
changeset
|
237 |
default: NOT_REACHED(); |
e6bfc5a2e8aa
(svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents:
3965
diff
changeset
|
238 |
case RAILTYPE_RAIL: break; |
e6bfc5a2e8aa
(svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents:
3965
diff
changeset
|
239 |
case RAILTYPE_ELECTRIC: break; |
e6bfc5a2e8aa
(svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents:
3965
diff
changeset
|
240 |
case RAILTYPE_MONO: base = (base * 3) >> 1; break; |
e6bfc5a2e8aa
(svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents:
3965
diff
changeset
|
241 |
case RAILTYPE_MAGLEV: base *= 2; break; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
242 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
243 |
|
0 | 244 |
return base; |
245 |
} |
|
246 |
||
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
247 |
static EngineID AiChooseRoadVehToReplaceWith(const Player* p, const Vehicle* v) |
0 | 248 |
{ |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
249 |
Money avail_money = p->player_money + v->value; |
1224
09b0f5a1db97
(svn r1728) - Fix: now a player can only build a road vehicle in depots he owns (hacked client protection)
bjarni
parents:
1223
diff
changeset
|
250 |
return AiChooseRoadVehToBuild(v->cargo_type, avail_money, v->tile); |
0 | 251 |
} |
252 |
||
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
253 |
static EngineID AiChooseAircraftToReplaceWith(const Player* p, const Vehicle* v) |
0 | 254 |
{ |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
255 |
Money avail_money = p->player_money + v->value; |
4024
636df31c7aff
(svn r5263) Use the flag which denotes if it's a plane or helicopter instead of magical engine numbers
tron
parents:
4015
diff
changeset
|
256 |
return AiChooseAircraftToBuild( |
636df31c7aff
(svn r5263) Use the flag which denotes if it's a plane or helicopter instead of magical engine numbers
tron
parents:
4015
diff
changeset
|
257 |
avail_money, AircraftVehInfo(v->engine_type)->subtype & AIR_CTOL |
636df31c7aff
(svn r5263) Use the flag which denotes if it's a plane or helicopter instead of magical engine numbers
tron
parents:
4015
diff
changeset
|
258 |
); |
0 | 259 |
} |
260 |
||
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
261 |
static EngineID AiChooseTrainToReplaceWith(const Player* p, const Vehicle* v) |
0 | 262 |
{ |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
263 |
Money avail_money = p->player_money + v->value; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
264 |
const Vehicle* u = v; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
265 |
int num = 0; |
0 | 266 |
|
7988
6075538f6111
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7986
diff
changeset
|
267 |
while (++num, u->Next() != NULL) { |
6075538f6111
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7986
diff
changeset
|
268 |
u = u->Next(); |
0 | 269 |
} |
270 |
||
271 |
// XXX: check if a wagon |
|
1223
e32459dd8000
(svn r1727) - Fix: now CmdBuildRailVehicle() behaves correctly if DC_EXEC is set
bjarni
parents:
1217
diff
changeset
|
272 |
return AiChooseTrainToBuild(v->u.rail.railtype, avail_money, 0, v->tile); |
0 | 273 |
} |
274 |
||
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
275 |
static EngineID AiChooseShipToReplaceWith(const Player* p, const Vehicle* v) |
0 | 276 |
{ |
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
277 |
/* Ships are not implemented in this (broken) AI */ |
2544 | 278 |
return INVALID_ENGINE; |
0 | 279 |
} |
280 |
||
281 |
static void AiHandleGotoDepot(Player *p, int cmd) |
|
282 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
283 |
if (_players_ai[p->index].cur_veh->current_order.type != OT_GOTO_DEPOT) |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
284 |
DoCommand(0, _players_ai[p->index].cur_veh->index, 0, DC_EXEC, cmd); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
285 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
286 |
if (++_players_ai[p->index].state_counter <= 1387) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
287 |
_players_ai[p->index].state = AIS_VEH_DO_REPLACE_VEHICLE; |
0 | 288 |
return; |
289 |
} |
|
290 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
291 |
if (_players_ai[p->index].cur_veh->current_order.type == OT_GOTO_DEPOT) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
292 |
_players_ai[p->index].cur_veh->current_order.type = OT_DUMMY; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
293 |
_players_ai[p->index].cur_veh->current_order.flags = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
294 |
InvalidateWindow(WC_VEHICLE_VIEW, _players_ai[p->index].cur_veh->index); |
0 | 295 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
296 |
} |
0 | 297 |
|
298 |
static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak) |
|
299 |
{ |
|
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
300 |
if (bak->order == NULL) return; |
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
301 |
|
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
302 |
for (uint i = 0; bak->order[i].type != OT_NOTHING; i++) { |
4560
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4559
diff
changeset
|
303 |
if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) |
0 | 304 |
break; |
2639 | 305 |
} |
0 | 306 |
} |
307 |
||
308 |
static void AiHandleReplaceTrain(Player *p) |
|
309 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
310 |
const Vehicle* v = _players_ai[p->index].cur_veh; |
8149
eb78fb69096f
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
8141
diff
changeset
|
311 |
BackuppedOrders orderbak; |
2544 | 312 |
EngineID veh; |
0 | 313 |
|
314 |
// wait until the vehicle reaches the depot. |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
315 |
if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { |
4495
b44566fc9025
(svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents:
4434
diff
changeset
|
316 |
AiHandleGotoDepot(p, CMD_SEND_TRAIN_TO_DEPOT); |
0 | 317 |
return; |
318 |
} |
|
319 |
||
320 |
veh = AiChooseTrainToReplaceWith(p, v); |
|
2544 | 321 |
if (veh != INVALID_ENGINE) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
322 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
323 |
|
8149
eb78fb69096f
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
8141
diff
changeset
|
324 |
BackupVehicleOrders(v, &orderbak); |
0 | 325 |
tile = v->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
326 |
|
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
327 |
if (CmdSucceeded(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) && |
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
328 |
CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) { |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3933
diff
changeset
|
329 |
VehicleID veh = _new_vehicle_id; |
8149
eb78fb69096f
(svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents:
8141
diff
changeset
|
330 |
AiRestoreVehicleOrders(GetVehicle(veh), &orderbak); |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
331 |
DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_TRAIN); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
332 |
|
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
333 |
DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); |
0 | 334 |
} |
335 |
} |
|
336 |
} |
|
337 |
||
338 |
static void AiHandleReplaceRoadVeh(Player *p) |
|
339 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
340 |
const Vehicle* v = _players_ai[p->index].cur_veh; |
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
341 |
BackuppedOrders orderbak; |
2544 | 342 |
EngineID veh; |
0 | 343 |
|
7986
881998b115c2
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7951
diff
changeset
|
344 |
if (!v->IsStoppedInDepot()) { |
0 | 345 |
AiHandleGotoDepot(p, CMD_SEND_ROADVEH_TO_DEPOT); |
346 |
return; |
|
347 |
} |
|
348 |
||
349 |
veh = AiChooseRoadVehToReplaceWith(p, v); |
|
2544 | 350 |
if (veh != INVALID_ENGINE) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
351 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
352 |
|
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
353 |
BackupVehicleOrders(v, &orderbak); |
0 | 354 |
tile = v->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
355 |
|
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
356 |
if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) && |
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
357 |
CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) { |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3933
diff
changeset
|
358 |
VehicleID veh = _new_vehicle_id; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
359 |
|
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
360 |
AiRestoreVehicleOrders(GetVehicle(veh), &orderbak); |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
361 |
DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_ROADVEH); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
362 |
DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); |
0 | 363 |
} |
364 |
} |
|
365 |
} |
|
366 |
||
367 |
static void AiHandleReplaceAircraft(Player *p) |
|
368 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
369 |
const Vehicle* v = _players_ai[p->index].cur_veh; |
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
370 |
BackuppedOrders orderbak; |
2544 | 371 |
EngineID veh; |
0 | 372 |
|
7986
881998b115c2
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7951
diff
changeset
|
373 |
if (!v->IsStoppedInDepot()) { |
0 | 374 |
AiHandleGotoDepot(p, CMD_SEND_AIRCRAFT_TO_HANGAR); |
375 |
return; |
|
376 |
} |
|
377 |
||
378 |
veh = AiChooseAircraftToReplaceWith(p, v); |
|
2544 | 379 |
if (veh != INVALID_ENGINE) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
380 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
381 |
|
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
382 |
BackupVehicleOrders(v, &orderbak); |
0 | 383 |
tile = v->tile; |
384 |
||
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
385 |
if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) && |
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
386 |
CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) { |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3933
diff
changeset
|
387 |
VehicleID veh = _new_vehicle_id; |
8818
d8d3812f8f35
(svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents:
8798
diff
changeset
|
388 |
AiRestoreVehicleOrders(GetVehicle(veh), &orderbak); |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
389 |
DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
390 |
|
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
391 |
DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); |
0 | 392 |
} |
393 |
} |
|
394 |
} |
|
395 |
||
396 |
static void AiHandleReplaceShip(Player *p) |
|
397 |
{ |
|
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
398 |
/* Ships are not implemented in this (broken) AI */ |
0 | 399 |
} |
400 |
||
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
401 |
typedef EngineID CheckReplaceProc(const Player* p, const Vehicle* v); |
0 | 402 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
403 |
static CheckReplaceProc* const _veh_check_replace_proc[] = { |
0 | 404 |
AiChooseTrainToReplaceWith, |
405 |
AiChooseRoadVehToReplaceWith, |
|
406 |
AiChooseShipToReplaceWith, |
|
407 |
AiChooseAircraftToReplaceWith, |
|
408 |
}; |
|
409 |
||
410 |
typedef void DoReplaceProc(Player *p); |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
411 |
static DoReplaceProc* const _veh_do_replace_proc[] = { |
0 | 412 |
AiHandleReplaceTrain, |
413 |
AiHandleReplaceRoadVeh, |
|
414 |
AiHandleReplaceShip, |
|
415 |
AiHandleReplaceAircraft |
|
416 |
}; |
|
417 |
||
418 |
static void AiStateCheckReplaceVehicle(Player *p) |
|
419 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
420 |
const Vehicle* v = _players_ai[p->index].cur_veh; |
0 | 421 |
|
7883
7777bca58ae0
(svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
rubidium
parents:
7866
diff
changeset
|
422 |
if (!v->IsValid() || |
2544 | 423 |
v->owner != _current_player || |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
424 |
v->type > VEH_SHIP || |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
425 |
_veh_check_replace_proc[v->type - VEH_TRAIN](p, v) == INVALID_ENGINE) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
426 |
_players_ai[p->index].state = AIS_VEH_LOOP; |
0 | 427 |
} else { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
428 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
429 |
_players_ai[p->index].state = AIS_VEH_DO_REPLACE_VEHICLE; |
0 | 430 |
} |
431 |
} |
|
432 |
||
433 |
static void AiStateDoReplaceVehicle(Player *p) |
|
434 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
435 |
const Vehicle* v = _players_ai[p->index].cur_veh; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
436 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
437 |
_players_ai[p->index].state = AIS_VEH_LOOP; |
0 | 438 |
// vehicle is not owned by the player anymore, something went very wrong. |
7883
7777bca58ae0
(svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
rubidium
parents:
7866
diff
changeset
|
439 |
if (!v->IsValid() || v->owner != _current_player) return; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
440 |
_veh_do_replace_proc[v->type - VEH_TRAIN](p); |
0 | 441 |
} |
442 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
443 |
struct FoundRoute { |
0 | 444 |
int distance; |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3338
diff
changeset
|
445 |
CargoID cargo; |
0 | 446 |
void *from; |
447 |
void *to; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
448 |
}; |
0 | 449 |
|
6573 | 450 |
static Town *AiFindRandomTown() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1043
diff
changeset
|
451 |
{ |
4356
bc52a48e2590
(svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents:
4354
diff
changeset
|
452 |
return GetRandomTown(); |
0 | 453 |
} |
454 |
||
6573 | 455 |
static Industry *AiFindRandomIndustry() |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1043
diff
changeset
|
456 |
{ |
6640
642fb706f4fa
(svn r9251) -Fix(r6057, FS#644): Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game. The AI now sucks a even a bit more than before (if that's even possible).
celestar
parents:
6585
diff
changeset
|
457 |
int num = RandomRange(GetMaxIndustryIndex()); |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7883
diff
changeset
|
458 |
if (IsValidIndustryID(num)) return GetIndustry(num); |
6640
642fb706f4fa
(svn r9251) -Fix(r6057, FS#644): Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game. The AI now sucks a even a bit more than before (if that's even possible).
celestar
parents:
6585
diff
changeset
|
459 |
|
642fb706f4fa
(svn r9251) -Fix(r6057, FS#644): Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game. The AI now sucks a even a bit more than before (if that's even possible).
celestar
parents:
6585
diff
changeset
|
460 |
return NULL; |
0 | 461 |
} |
462 |
||
463 |
static void AiFindSubsidyIndustryRoute(FoundRoute *fr) |
|
464 |
{ |
|
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
465 |
uint i; |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3338
diff
changeset
|
466 |
CargoID cargo; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
467 |
const Subsidy* s; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
468 |
Industry* from; |
0 | 469 |
TileIndex to_xy; |
470 |
||
471 |
// initially error |
|
472 |
fr->distance = -1; |
|
473 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
474 |
// Randomize subsidy index.. |
0 | 475 |
i = RandomRange(lengthof(_subsidies) * 3); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
476 |
if (i >= lengthof(_subsidies)) return; |
0 | 477 |
|
478 |
s = &_subsidies[i]; |
|
479 |
||
480 |
// Don't want passengers or mail |
|
481 |
cargo = s->cargo_type; |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
482 |
if (cargo == CT_INVALID || |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
483 |
cargo == CT_PASSENGERS || |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
484 |
cargo == CT_MAIL || |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
485 |
s->age > 7) { |
0 | 486 |
return; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
487 |
} |
0 | 488 |
fr->cargo = cargo; |
489 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
490 |
fr->from = from = GetIndustry(s->from); |
0 | 491 |
|
492 |
if (cargo == CT_GOODS || cargo == CT_FOOD) { |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
493 |
Town* to_tow = GetTown(s->to); |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
494 |
|
4015
17f39cad5157
(svn r5228) Suppress MSVC warnings about signed/unsigned comparison
KUDr
parents:
4011
diff
changeset
|
495 |
if (to_tow->population < (cargo == CT_FOOD ? 200U : 900U)) return; // error |
0 | 496 |
fr->to = to_tow; |
497 |
to_xy = to_tow->xy; |
|
498 |
} else { |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
499 |
Industry* to_ind = GetIndustry(s->to); |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
500 |
|
0 | 501 |
fr->to = to_ind; |
502 |
to_xy = to_ind->xy; |
|
503 |
} |
|
504 |
||
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
505 |
fr->distance = DistanceManhattan(from->xy, to_xy); |
0 | 506 |
} |
507 |
||
508 |
static void AiFindSubsidyPassengerRoute(FoundRoute *fr) |
|
509 |
{ |
|
510 |
uint i; |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
511 |
const Subsidy* s; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
512 |
Town *from, *to; |
0 | 513 |
|
514 |
// initially error |
|
515 |
fr->distance = -1; |
|
516 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
517 |
// Randomize subsidy index.. |
0 | 518 |
i = RandomRange(lengthof(_subsidies) * 3); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
519 |
if (i >= lengthof(_subsidies)) return; |
0 | 520 |
|
521 |
s = &_subsidies[i]; |
|
522 |
||
523 |
// Only want passengers |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
524 |
if (s->cargo_type != CT_PASSENGERS || s->age > 7) return; |
0 | 525 |
fr->cargo = s->cargo_type; |
526 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
527 |
fr->from = from = GetTown(s->from); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
528 |
fr->to = to = GetTown(s->to); |
0 | 529 |
|
530 |
// They must be big enough |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
531 |
if (from->population < 400 || to->population < 400) return; |
0 | 532 |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
533 |
fr->distance = DistanceManhattan(from->xy, to->xy); |
0 | 534 |
} |
535 |
||
536 |
static void AiFindRandomIndustryRoute(FoundRoute *fr) |
|
537 |
{ |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
538 |
Industry* i; |
0 | 539 |
uint32 r; |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3338
diff
changeset
|
540 |
CargoID cargo; |
0 | 541 |
|
542 |
// initially error |
|
543 |
fr->distance = -1; |
|
544 |
||
545 |
r = Random(); |
|
546 |
||
547 |
// pick a source |
|
548 |
fr->from = i = AiFindRandomIndustry(); |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
549 |
if (i == NULL) return; |
0 | 550 |
|
551 |
// pick a random produced cargo |
|
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
552 |
cargo = i->produced_cargo[0]; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
553 |
if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1]; |
0 | 554 |
|
555 |
fr->cargo = cargo; |
|
556 |
||
557 |
// don't allow passengers |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
558 |
if (cargo == CT_INVALID || cargo == CT_PASSENGERS) return; |
0 | 559 |
|
560 |
if (cargo != CT_GOODS && cargo != CT_FOOD) { |
|
561 |
// pick a dest, and see if it can receive |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
562 |
Industry* i2 = AiFindRandomIndustry(); |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
563 |
if (i2 == NULL || i == i2 || |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
564 |
(i2->accepts_cargo[0] != cargo && |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
565 |
i2->accepts_cargo[1] != cargo && |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
566 |
i2->accepts_cargo[2] != cargo)) { |
0 | 567 |
return; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
568 |
} |
0 | 569 |
|
570 |
fr->to = i2; |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
571 |
fr->distance = DistanceManhattan(i->xy, i2->xy); |
0 | 572 |
} else { |
573 |
// pick a dest town, and see if it's big enough |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
574 |
Town* t = AiFindRandomTown(); |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
575 |
|
4015
17f39cad5157
(svn r5228) Suppress MSVC warnings about signed/unsigned comparison
KUDr
parents:
4011
diff
changeset
|
576 |
if (t == NULL || t->population < (cargo == CT_FOOD ? 200U : 900U)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
577 |
|
0 | 578 |
fr->to = t; |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
579 |
fr->distance = DistanceManhattan(i->xy, t->xy); |
0 | 580 |
} |
581 |
} |
|
582 |
||
583 |
static void AiFindRandomPassengerRoute(FoundRoute *fr) |
|
584 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
585 |
Town* source; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
586 |
Town* dest; |
0 | 587 |
|
588 |
// initially error |
|
589 |
fr->distance = -1; |
|
590 |
||
591 |
fr->from = source = AiFindRandomTown(); |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
592 |
if (source == NULL || source->population < 400) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
593 |
|
0 | 594 |
fr->to = dest = AiFindRandomTown(); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
595 |
if (dest == NULL || source == dest || dest->population < 400) return; |
0 | 596 |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
597 |
fr->distance = DistanceManhattan(source->xy, dest->xy); |
0 | 598 |
} |
599 |
||
600 |
// Warn: depends on 'xy' being the first element in both Town and Industry |
|
601 |
#define GET_TOWN_OR_INDUSTRY_TILE(p) (((Town*)(p))->xy) |
|
602 |
||
603 |
static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask) |
|
604 |
{ |
|
605 |
TileIndex from_tile, to_tile; |
|
606 |
Station *st; |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
607 |
int dist; |
0 | 608 |
uint same_station = 0; |
609 |
||
610 |
from_tile = GET_TOWN_OR_INDUSTRY_TILE(fr->from); |
|
611 |
to_tile = GET_TOWN_OR_INDUSTRY_TILE(fr->to); |
|
612 |
||
613 |
dist = 0xFFFF; |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
614 |
FOR_ALL_STATIONS(st) { |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
615 |
int cur; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
616 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
617 |
if (st->owner != _current_player) continue; |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
618 |
cur = DistanceMax(from_tile, st->xy); |
0 | 619 |
if (cur < dist) dist = cur; |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
620 |
cur = DistanceMax(to_tile, st->xy); |
0 | 621 |
if (cur < dist) dist = cur; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
622 |
if (to_tile == from_tile && st->xy == to_tile) same_station++; |
0 | 623 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
624 |
|
0 | 625 |
// To prevent the AI from building ten busstations in the same town, do some calculations |
626 |
// For each road or airport station, we want 350 of population! |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
627 |
if ((bitmask == 2 || bitmask == 4) && |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
628 |
same_station > 2 && |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
629 |
((Town*)fr->from)->population < same_station * 350) { |
0 | 630 |
return false; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
631 |
} |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
632 |
|
7354
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
633 |
/* Requiring distance to nearest station to be always under 37 tiles may be suboptimal, |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
634 |
* Especially for longer aircraft routes that start and end pretty at any arbitrary place on map |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
635 |
* While it may be nice for AI to cluster their creations together, hardcoded limit is not ideal. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
636 |
* If AI will randomly start on some isolated spot, it will never get out of there. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
637 |
* AI will have chance of randomly rejecting routes further than 37 tiles from their network, |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
638 |
* so there will be some attempt to cluster the network together */ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
639 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
640 |
/* Random value between 37 and 292. Low values are exponentially more likely |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
641 |
* With 50% chance the value will be under 52 tiles */ |
7362
4e2ac4d15263
(svn r10106) -Fix (r10098): there's always a compiler complaining about something...
rubidium
parents:
7354
diff
changeset
|
642 |
int min_distance = 36 + (1 << (Random() % 9)); // 0..8 |
7354
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
643 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
644 |
/* Make sure distance to closest station is < min_distance tiles. */ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
645 |
if (dist != 0xFFFF && dist > min_distance) return false; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
646 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
647 |
if (_players_ai[p->index].route_type_mask != 0 && |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
648 |
!(_players_ai[p->index].route_type_mask & bitmask) && |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8450
diff
changeset
|
649 |
!Chance16(1, 5)) { |
0 | 650 |
return false; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
651 |
} |
0 | 652 |
|
653 |
if (fr->cargo == CT_PASSENGERS || fr->cargo == CT_MAIL) { |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
654 |
const Town* from = (const Town*)fr->from; |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
655 |
const Town* to = (const Town*)fr->to; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
656 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
657 |
if (from->pct_pass_transported > 0x99 || |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
658 |
to->pct_pass_transported > 0x99) { |
0 | 659 |
return false; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
660 |
} |
0 | 661 |
|
662 |
// Make sure it has a reasonably good rating |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
663 |
if (from->ratings[_current_player] < -100 || |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
664 |
to->ratings[_current_player] < -100) { |
0 | 665 |
return false; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
666 |
} |
0 | 667 |
} else { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
668 |
const Industry* i = (const Industry*)fr->from; |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
669 |
|
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
670 |
if (i->last_month_pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 || |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7988
diff
changeset
|
671 |
i->last_month_production[fr->cargo != i->produced_cargo[0]] == 0) { |
0 | 672 |
return false; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
673 |
} |
0 | 674 |
} |
675 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
676 |
_players_ai[p->index].route_type_mask |= bitmask; |
0 | 677 |
return true; |
678 |
} |
|
679 |
||
680 |
static byte AiGetDirectionBetweenTiles(TileIndex a, TileIndex b) |
|
681 |
{ |
|
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
682 |
byte i = (TileX(a) < TileX(b)) ? 1 : 0; |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
683 |
if (TileY(a) >= TileY(b)) i ^= 3; |
0 | 684 |
return i; |
685 |
} |
|
686 |
||
687 |
static TileIndex AiGetPctTileBetween(TileIndex a, TileIndex b, byte pct) |
|
688 |
{ |
|
1981 | 689 |
return TileXY( |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
690 |
TileX(a) + ((TileX(b) - TileX(a)) * pct >> 8), |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
691 |
TileY(a) + ((TileY(b) - TileY(a)) * pct >> 8) |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
692 |
); |
0 | 693 |
} |
694 |
||
695 |
static void AiWantLongIndustryRoute(Player *p) |
|
696 |
{ |
|
697 |
int i; |
|
698 |
FoundRoute fr; |
|
699 |
||
700 |
i = 60; |
|
2952 | 701 |
for (;;) { |
0 | 702 |
// look for one from the subsidy list |
703 |
AiFindSubsidyIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
704 |
if (IsInsideMM(fr.distance, 60, 90 + 1)) break; |
0 | 705 |
|
706 |
// try a random one |
|
707 |
AiFindRandomIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
708 |
if (IsInsideMM(fr.distance, 60, 90 + 1)) break; |
0 | 709 |
|
710 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
711 |
if (--i == 0) return; |
0 | 712 |
} |
713 |
||
2639 | 714 |
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; |
0 | 715 |
|
716 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
717 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
718 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
719 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
720 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
721 |
_players_ai[p->index].src.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
722 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
723 |
_players_ai[p->index].src.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
724 |
_players_ai[p->index].src.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
725 |
_players_ai[p->index].src.buildcmd_a = 0x24; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
726 |
_players_ai[p->index].src.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
727 |
_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles( |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
728 |
_players_ai[p->index].src.spec_tile, |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
729 |
_players_ai[p->index].dst.spec_tile |
2639 | 730 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
731 |
_players_ai[p->index].src.cargo = fr.cargo | 0x80; |
0 | 732 |
|
733 |
// Fill the dest field |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
734 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
735 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
736 |
_players_ai[p->index].dst.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
737 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
738 |
_players_ai[p->index].dst.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
739 |
_players_ai[p->index].dst.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
740 |
_players_ai[p->index].dst.buildcmd_a = 0x34; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
741 |
_players_ai[p->index].dst.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
742 |
_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles( |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
743 |
_players_ai[p->index].dst.spec_tile, |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
744 |
_players_ai[p->index].src.spec_tile |
2639 | 745 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
746 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 747 |
|
748 |
// Fill middle field 1 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
749 |
_players_ai[p->index].mid1.spec_tile = AiGetPctTileBetween( |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
750 |
_players_ai[p->index].src.spec_tile, |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
751 |
_players_ai[p->index].dst.spec_tile, |
2639 | 752 |
0x55 |
753 |
); |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
754 |
_players_ai[p->index].mid1.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
755 |
_players_ai[p->index].mid1.rand_rng = 6; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
756 |
_players_ai[p->index].mid1.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
757 |
_players_ai[p->index].mid1.unk6 = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
758 |
_players_ai[p->index].mid1.unk7 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
759 |
_players_ai[p->index].mid1.buildcmd_a = 0x30; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
760 |
_players_ai[p->index].mid1.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
761 |
_players_ai[p->index].mid1.direction = _players_ai[p->index].src.direction; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
762 |
_players_ai[p->index].mid1.cargo = fr.cargo; |
0 | 763 |
|
764 |
// Fill middle field 2 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
765 |
_players_ai[p->index].mid2.spec_tile = AiGetPctTileBetween( |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
766 |
_players_ai[p->index].src.spec_tile, |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
767 |
_players_ai[p->index].dst.spec_tile, |
2639 | 768 |
0xAA |
769 |
); |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
770 |
_players_ai[p->index].mid2.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
771 |
_players_ai[p->index].mid2.rand_rng = 6; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
772 |
_players_ai[p->index].mid2.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
773 |
_players_ai[p->index].mid2.unk6 = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
774 |
_players_ai[p->index].mid2.unk7 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
775 |
_players_ai[p->index].mid2.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
776 |
_players_ai[p->index].mid2.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
777 |
_players_ai[p->index].mid2.direction = _players_ai[p->index].dst.direction; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
778 |
_players_ai[p->index].mid2.cargo = fr.cargo; |
0 | 779 |
|
780 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
781 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
782 |
_players_ai[p->index].num_wagons = 3; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
783 |
_players_ai[p->index].build_kind = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
784 |
_players_ai[p->index].num_build_rec = 4; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
785 |
_players_ai[p->index].num_loco_to_build = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
786 |
_players_ai[p->index].num_want_fullload = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
787 |
_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
788 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
789 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
790 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
791 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
792 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
793 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
794 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
795 |
_players_ai[p->index].timeout_counter = 0; |
0 | 796 |
} |
797 |
||
798 |
static void AiWantMediumIndustryRoute(Player *p) |
|
799 |
{ |
|
800 |
int i; |
|
801 |
FoundRoute fr; |
|
802 |
||
803 |
i = 60; |
|
2952 | 804 |
for (;;) { |
0 | 805 |
// look for one from the subsidy list |
806 |
AiFindSubsidyIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
807 |
if (IsInsideMM(fr.distance, 40, 60 + 1)) break; |
0 | 808 |
|
809 |
// try a random one |
|
810 |
AiFindRandomIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
811 |
if (IsInsideMM(fr.distance, 40, 60 + 1)) break; |
0 | 812 |
|
813 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
814 |
if (--i == 0) return; |
0 | 815 |
} |
816 |
||
2639 | 817 |
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; |
0 | 818 |
|
819 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
820 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
821 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
822 |
_players_ai[p->index].src.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
823 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
824 |
_players_ai[p->index].src.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
825 |
_players_ai[p->index].src.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
826 |
_players_ai[p->index].src.buildcmd_a = 0x10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
827 |
_players_ai[p->index].src.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
828 |
_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
829 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
830 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
831 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
832 |
_players_ai[p->index].src.cargo = fr.cargo | 0x80; |
0 | 833 |
|
834 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
835 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
836 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
837 |
_players_ai[p->index].dst.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
838 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
839 |
_players_ai[p->index].dst.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
840 |
_players_ai[p->index].dst.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
841 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
842 |
_players_ai[p->index].dst.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
843 |
_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
844 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
845 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
846 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
847 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 848 |
|
849 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
850 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
851 |
_players_ai[p->index].num_wagons = 3; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
852 |
_players_ai[p->index].build_kind = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
853 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
854 |
_players_ai[p->index].num_loco_to_build = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
855 |
_players_ai[p->index].num_want_fullload = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
856 |
_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
857 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
858 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
859 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
860 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
861 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
862 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
863 |
_players_ai[p->index].timeout_counter = 0; |
0 | 864 |
} |
865 |
||
866 |
static void AiWantShortIndustryRoute(Player *p) |
|
867 |
{ |
|
868 |
int i; |
|
869 |
FoundRoute fr; |
|
870 |
||
871 |
i = 60; |
|
2952 | 872 |
for (;;) { |
0 | 873 |
// look for one from the subsidy list |
874 |
AiFindSubsidyIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
875 |
if (IsInsideMM(fr.distance, 15, 40 + 1)) break; |
0 | 876 |
|
877 |
// try a random one |
|
878 |
AiFindRandomIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
879 |
if (IsInsideMM(fr.distance, 15, 40 + 1)) break; |
0 | 880 |
|
881 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
882 |
if (--i == 0) return; |
0 | 883 |
} |
884 |
||
2639 | 885 |
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; |
0 | 886 |
|
887 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
888 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
889 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
890 |
_players_ai[p->index].src.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
891 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
892 |
_players_ai[p->index].src.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
893 |
_players_ai[p->index].src.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
894 |
_players_ai[p->index].src.buildcmd_a = 0x10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
895 |
_players_ai[p->index].src.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
896 |
_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
897 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
898 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
899 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
900 |
_players_ai[p->index].src.cargo = fr.cargo | 0x80; |
0 | 901 |
|
902 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
903 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
904 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
905 |
_players_ai[p->index].dst.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
906 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
907 |
_players_ai[p->index].dst.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
908 |
_players_ai[p->index].dst.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
909 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
910 |
_players_ai[p->index].dst.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
911 |
_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
912 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
913 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
914 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
915 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 916 |
|
917 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
918 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
919 |
_players_ai[p->index].num_wagons = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
920 |
_players_ai[p->index].build_kind = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
921 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
922 |
_players_ai[p->index].num_loco_to_build = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
923 |
_players_ai[p->index].num_want_fullload = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
924 |
_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
925 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
926 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
927 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
928 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
929 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
930 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
931 |
_players_ai[p->index].timeout_counter = 0; |
0 | 932 |
} |
933 |
||
934 |
static void AiWantMailRoute(Player *p) |
|
935 |
{ |
|
936 |
int i; |
|
937 |
FoundRoute fr; |
|
938 |
||
939 |
i = 60; |
|
2952 | 940 |
for (;;) { |
0 | 941 |
// look for one from the subsidy list |
942 |
AiFindSubsidyPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
943 |
if (IsInsideMM(fr.distance, 60, 110 + 1)) break; |
0 | 944 |
|
945 |
// try a random one |
|
946 |
AiFindRandomPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
947 |
if (IsInsideMM(fr.distance, 60, 110 + 1)) break; |
0 | 948 |
|
949 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
950 |
if (--i == 0) return; |
0 | 951 |
} |
952 |
||
953 |
fr.cargo = CT_MAIL; |
|
2639 | 954 |
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; |
0 | 955 |
|
956 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
957 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
958 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
959 |
_players_ai[p->index].src.rand_rng = 7; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
960 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
961 |
_players_ai[p->index].src.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
962 |
_players_ai[p->index].src.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
963 |
_players_ai[p->index].src.buildcmd_a = 0x24; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
964 |
_players_ai[p->index].src.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
965 |
_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
966 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
967 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
968 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
969 |
_players_ai[p->index].src.cargo = fr.cargo; |
0 | 970 |
|
971 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
972 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
973 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
974 |
_players_ai[p->index].dst.rand_rng = 7; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
975 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
976 |
_players_ai[p->index].dst.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
977 |
_players_ai[p->index].dst.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
978 |
_players_ai[p->index].dst.buildcmd_a = 0x34; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
979 |
_players_ai[p->index].dst.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
980 |
_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
981 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
982 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from) |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
983 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
984 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 985 |
|
986 |
// Fill middle field 1 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
987 |
_players_ai[p->index].mid1.spec_tile = AiGetPctTileBetween( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
988 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
989 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
990 |
0x55 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
991 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
992 |
_players_ai[p->index].mid1.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
993 |
_players_ai[p->index].mid1.rand_rng = 6; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
994 |
_players_ai[p->index].mid1.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
995 |
_players_ai[p->index].mid1.unk6 = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
996 |
_players_ai[p->index].mid1.unk7 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
997 |
_players_ai[p->index].mid1.buildcmd_a = 0x30; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
998 |
_players_ai[p->index].mid1.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
999 |
_players_ai[p->index].mid1.direction = _players_ai[p->index].src.direction; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1000 |
_players_ai[p->index].mid1.cargo = fr.cargo; |
0 | 1001 |
|
1002 |
// Fill middle field 2 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1003 |
_players_ai[p->index].mid2.spec_tile = AiGetPctTileBetween( |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1004 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1005 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to), |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1006 |
0xAA |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1007 |
); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1008 |
_players_ai[p->index].mid2.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1009 |
_players_ai[p->index].mid2.rand_rng = 6; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1010 |
_players_ai[p->index].mid2.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1011 |
_players_ai[p->index].mid2.unk6 = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1012 |
_players_ai[p->index].mid2.unk7 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1013 |
_players_ai[p->index].mid2.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1014 |
_players_ai[p->index].mid2.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1015 |
_players_ai[p->index].mid2.direction = _players_ai[p->index].dst.direction; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1016 |
_players_ai[p->index].mid2.cargo = fr.cargo; |
0 | 1017 |
|
1018 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1019 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1020 |
_players_ai[p->index].num_wagons = 3; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1021 |
_players_ai[p->index].build_kind = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1022 |
_players_ai[p->index].num_build_rec = 4; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1023 |
_players_ai[p->index].num_loco_to_build = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1024 |
_players_ai[p->index].num_want_fullload = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1025 |
_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1026 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1027 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1028 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1029 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1030 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1031 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1032 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1033 |
} |
1034 |
||
1035 |
static void AiWantPassengerRoute(Player *p) |
|
1036 |
{ |
|
1037 |
int i; |
|
1038 |
FoundRoute fr; |
|
1039 |
||
1040 |
i = 60; |
|
2952 | 1041 |
for (;;) { |
0 | 1042 |
// look for one from the subsidy list |
1043 |
AiFindSubsidyPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1044 |
if (IsInsideMM(fr.distance, 0, 55 + 1)) break; |
0 | 1045 |
|
1046 |
// try a random one |
|
1047 |
AiFindRandomPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1048 |
if (IsInsideMM(fr.distance, 0, 55 + 1)) break; |
0 | 1049 |
|
1050 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1051 |
if (--i == 0) return; |
0 | 1052 |
} |
1053 |
||
1054 |
fr.cargo = CT_PASSENGERS; |
|
2639 | 1055 |
if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; |
0 | 1056 |
|
1057 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1058 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1059 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1060 |
_players_ai[p->index].src.rand_rng = 7; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1061 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1062 |
_players_ai[p->index].src.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1063 |
_players_ai[p->index].src.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1064 |
_players_ai[p->index].src.buildcmd_a = 0x10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1065 |
_players_ai[p->index].src.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1066 |
_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles( |
2639 | 1067 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from), |
1068 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to) |
|
1069 |
); |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1070 |
_players_ai[p->index].src.cargo = fr.cargo; |
0 | 1071 |
|
1072 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1073 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1074 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1075 |
_players_ai[p->index].dst.rand_rng = 7; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1076 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1077 |
_players_ai[p->index].dst.unk6 = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1078 |
_players_ai[p->index].dst.unk7 = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1079 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1080 |
_players_ai[p->index].dst.buildcmd_b = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1081 |
_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles( |
2639 | 1082 |
GET_TOWN_OR_INDUSTRY_TILE(fr.to), |
1083 |
GET_TOWN_OR_INDUSTRY_TILE(fr.from) |
|
1084 |
); |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1085 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 1086 |
|
1087 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1088 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1089 |
_players_ai[p->index].num_wagons = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1090 |
_players_ai[p->index].build_kind = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1091 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1092 |
_players_ai[p->index].num_loco_to_build = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1093 |
_players_ai[p->index].num_want_fullload = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1094 |
_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1095 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1096 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1097 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1098 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1099 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1100 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1101 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1102 |
} |
1103 |
||
1104 |
static void AiWantTrainRoute(Player *p) |
|
1105 |
{ |
|
2635 | 1106 |
uint16 r = GB(Random(), 0, 16); |
1107 |
||
8732
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8726
diff
changeset
|
1108 |
_players_ai[p->index].railtype_to_use = GetBestRailtype(p->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1109 |
|
0 | 1110 |
if (r > 0xD000) { |
1111 |
AiWantLongIndustryRoute(p); |
|
1112 |
} else if (r > 0x6000) { |
|
1113 |
AiWantMediumIndustryRoute(p); |
|
1114 |
} else if (r > 0x1000) { |
|
1115 |
AiWantShortIndustryRoute(p); |
|
1116 |
} else if (r > 0x800) { |
|
1117 |
AiWantPassengerRoute(p); |
|
1118 |
} else { |
|
1119 |
AiWantMailRoute(p); |
|
1120 |
} |
|
1121 |
} |
|
1122 |
||
1123 |
static void AiWantLongRoadIndustryRoute(Player *p) |
|
1124 |
{ |
|
1125 |
int i; |
|
1126 |
FoundRoute fr; |
|
1127 |
||
1128 |
i = 60; |
|
2952 | 1129 |
for (;;) { |
0 | 1130 |
// look for one from the subsidy list |
1131 |
AiFindSubsidyIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1132 |
if (IsInsideMM(fr.distance, 35, 55 + 1)) break; |
0 | 1133 |
|
1134 |
// try a random one |
|
1135 |
AiFindRandomIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1136 |
if (IsInsideMM(fr.distance, 35, 55 + 1)) break; |
0 | 1137 |
|
1138 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1139 |
if (--i == 0) return; |
0 | 1140 |
} |
1141 |
||
2639 | 1142 |
if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; |
0 | 1143 |
|
1144 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1145 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1146 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1147 |
_players_ai[p->index].src.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1148 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1149 |
_players_ai[p->index].src.buildcmd_a = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1150 |
_players_ai[p->index].src.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1151 |
_players_ai[p->index].src.cargo = fr.cargo | 0x80; |
0 | 1152 |
|
1153 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1154 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1155 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1156 |
_players_ai[p->index].dst.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1157 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1158 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1159 |
_players_ai[p->index].dst.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1160 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 1161 |
|
1162 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1163 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1164 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1165 |
_players_ai[p->index].num_loco_to_build = 5; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1166 |
_players_ai[p->index].num_want_fullload = 5; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1167 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1168 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1169 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1170 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1171 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1172 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1173 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1174 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1175 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1176 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1177 |
} |
1178 |
||
1179 |
static void AiWantMediumRoadIndustryRoute(Player *p) |
|
1180 |
{ |
|
1181 |
int i; |
|
1182 |
FoundRoute fr; |
|
1183 |
||
1184 |
i = 60; |
|
2952 | 1185 |
for (;;) { |
0 | 1186 |
// look for one from the subsidy list |
1187 |
AiFindSubsidyIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1188 |
if (IsInsideMM(fr.distance, 15, 40 + 1)) break; |
0 | 1189 |
|
1190 |
// try a random one |
|
1191 |
AiFindRandomIndustryRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1192 |
if (IsInsideMM(fr.distance, 15, 40 + 1)) break; |
0 | 1193 |
|
1194 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1195 |
if (--i == 0) return; |
0 | 1196 |
} |
1197 |
||
2639 | 1198 |
if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; |
0 | 1199 |
|
1200 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1201 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1202 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1203 |
_players_ai[p->index].src.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1204 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1205 |
_players_ai[p->index].src.buildcmd_a = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1206 |
_players_ai[p->index].src.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1207 |
_players_ai[p->index].src.cargo = fr.cargo | 0x80; |
0 | 1208 |
|
1209 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1210 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1211 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1212 |
_players_ai[p->index].dst.rand_rng = 9; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1213 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1214 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1215 |
_players_ai[p->index].dst.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1216 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 1217 |
|
1218 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1219 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1220 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1221 |
_players_ai[p->index].num_loco_to_build = 3; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1222 |
_players_ai[p->index].num_want_fullload = 3; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1223 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1224 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1225 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1226 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1227 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1228 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1229 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1230 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1231 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1232 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1233 |
} |
1234 |
||
1235 |
static void AiWantLongRoadPassengerRoute(Player *p) |
|
1236 |
{ |
|
1237 |
int i; |
|
1238 |
FoundRoute fr; |
|
1239 |
||
1240 |
i = 60; |
|
2952 | 1241 |
for (;;) { |
0 | 1242 |
// look for one from the subsidy list |
1243 |
AiFindSubsidyPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1244 |
if (IsInsideMM(fr.distance, 55, 180 + 1)) break; |
0 | 1245 |
|
1246 |
// try a random one |
|
1247 |
AiFindRandomPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1248 |
if (IsInsideMM(fr.distance, 55, 180 + 1)) break; |
0 | 1249 |
|
1250 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1251 |
if (--i == 0) return; |
0 | 1252 |
} |
1253 |
||
1254 |
fr.cargo = CT_PASSENGERS; |
|
1255 |
||
2639 | 1256 |
if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; |
0 | 1257 |
|
1258 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1259 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1260 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1261 |
_players_ai[p->index].src.rand_rng = 10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1262 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1263 |
_players_ai[p->index].src.buildcmd_a = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1264 |
_players_ai[p->index].src.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1265 |
_players_ai[p->index].src.cargo = CT_PASSENGERS; |
0 | 1266 |
|
1267 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1268 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1269 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1270 |
_players_ai[p->index].dst.rand_rng = 10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1271 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1272 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1273 |
_players_ai[p->index].dst.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1274 |
_players_ai[p->index].dst.cargo = CT_PASSENGERS; |
0 | 1275 |
|
1276 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1277 |
_players_ai[p->index].cargo_type = CT_PASSENGERS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1278 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1279 |
_players_ai[p->index].num_loco_to_build = 4; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1280 |
_players_ai[p->index].num_want_fullload = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1281 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1282 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1283 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1284 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1285 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1286 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1287 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1288 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1289 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1290 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1291 |
} |
1292 |
||
1293 |
static void AiWantPassengerRouteInsideTown(Player *p) |
|
1294 |
{ |
|
1295 |
int i; |
|
1296 |
FoundRoute fr; |
|
1297 |
Town *t; |
|
1298 |
||
1299 |
i = 60; |
|
2952 | 1300 |
for (;;) { |
0 | 1301 |
// Find a town big enough |
1302 |
t = AiFindRandomTown(); |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1303 |
if (t != NULL && t->population >= 700) break; |
0 | 1304 |
|
1305 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1306 |
if (--i == 0) return; |
0 | 1307 |
} |
1308 |
||
1309 |
fr.cargo = CT_PASSENGERS; |
|
1310 |
fr.from = fr.to = t; |
|
1311 |
||
2639 | 1312 |
if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; |
0 | 1313 |
|
1314 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1315 |
_players_ai[p->index].src.spec_tile = t->xy; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1316 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1317 |
_players_ai[p->index].src.rand_rng = 10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1318 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1319 |
_players_ai[p->index].src.buildcmd_a = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1320 |
_players_ai[p->index].src.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1321 |
_players_ai[p->index].src.cargo = CT_PASSENGERS; |
0 | 1322 |
|
1323 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1324 |
_players_ai[p->index].dst.spec_tile = t->xy; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1325 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1326 |
_players_ai[p->index].dst.rand_rng = 10; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1327 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1328 |
_players_ai[p->index].dst.buildcmd_a = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1329 |
_players_ai[p->index].dst.direction = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1330 |
_players_ai[p->index].dst.cargo = CT_PASSENGERS; |
0 | 1331 |
|
1332 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1333 |
_players_ai[p->index].cargo_type = CT_PASSENGERS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1334 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1335 |
_players_ai[p->index].num_loco_to_build = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1336 |
_players_ai[p->index].num_want_fullload = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1337 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1338 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1339 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1340 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1341 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1342 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1343 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1344 |
_players_ai[p->index].state_mode = UCHAR_MAX; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1345 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1346 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1347 |
} |
1348 |
||
1349 |
static void AiWantRoadRoute(Player *p) |
|
1350 |
{ |
|
2635 | 1351 |
uint16 r = GB(Random(), 0, 16); |
0 | 1352 |
|
1353 |
if (r > 0x4000) { |
|
1354 |
AiWantLongRoadIndustryRoute(p); |
|
1355 |
} else if (r > 0x2000) { |
|
1356 |
AiWantMediumRoadIndustryRoute(p); |
|
1357 |
} else if (r > 0x1000) { |
|
1358 |
AiWantLongRoadPassengerRoute(p); |
|
1359 |
} else { |
|
1360 |
AiWantPassengerRouteInsideTown(p); |
|
1361 |
} |
|
1362 |
} |
|
1363 |
||
1364 |
static void AiWantPassengerAircraftRoute(Player *p) |
|
1365 |
{ |
|
1366 |
FoundRoute fr; |
|
1367 |
int i; |
|
1368 |
||
7354
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1369 |
/* Get aircraft that would be bought for this route |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1370 |
* (probably, as conditions may change before the route is fully built, |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1371 |
* like running out of money and having to select different aircraft, etc ...) */ |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1372 |
EngineID veh = AiChooseAircraftToBuild(p->player_money, _players_ai[p->index].build_kind != 0 ? 0 : AIR_CTOL); |
7354
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1373 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1374 |
/* No aircraft buildable mean no aircraft route */ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1375 |
if (veh == INVALID_ENGINE) return; |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1376 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1377 |
const AircraftVehicleInfo *avi = AircraftVehInfo(veh); |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1378 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1379 |
/* For passengers, "optimal" number of days in transit is about 80 to 100 |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1380 |
* Calculate "maximum optimal number of squares" from speed for 80 days |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1381 |
* 20 days should be enough for takeoff, land, taxi, etc ... |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1382 |
* |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1383 |
* "A vehicle traveling at 100kph will cross 5.6 tiles per day" -> |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1384 |
* Since in table aircraft speeds are in "real km/h", this should be accurate |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1385 |
* We get max_squares = avi->max_speed * 5.6 / 100.0 * 80 */ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1386 |
int max_squares = avi->max_speed * 448 / 100; |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1387 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1388 |
/* For example this will be 10456 tiles for 2334 km/h aircrafts with realistic aircraft speeds |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1389 |
* and 836 with "unrealistic" speeds, much more than the original 95 squares limit |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1390 |
* |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1391 |
* Size of the map, if not rectangular, it is the larger dimension of it |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1392 |
*/ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1393 |
int map_size = max(MapSizeX(), MapSizeY()); |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1394 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1395 |
/* Minimum distance between airports is half of map size, clamped between 1% and 20% of optimum. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1396 |
* May prevent building plane routes at all on small maps, but they will be ineffective there, so |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1397 |
* it is feature, not a bug. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1398 |
* On smaller distances, buses or trains are usually more effective approach anyway. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1399 |
* Additional safeguard is needing at least 20 squares, |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1400 |
* which may trigger in highly unusual configurations */ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1401 |
int min_squares = max(20, max(max_squares / 100, min(max_squares / 5, map_size / 2))); |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1402 |
|
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1403 |
/* Should not happen, unless aircraft with real speed under approx. 5 km/h is selected. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1404 |
* No such exist, unless using some NewGRF with ballons, zeppelins or similar |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1405 |
* slow-moving stuff. In that case, bail out, it is faster to walk by foot anyway :). */ |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1406 |
if (max_squares < min_squares) return; |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1407 |
|
0 | 1408 |
i = 60; |
2952 | 1409 |
for (;;) { |
7354
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1410 |
|
0 | 1411 |
// look for one from the subsidy list |
1412 |
AiFindSubsidyPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1413 |
if (IsInsideMM(fr.distance, min_squares, max_squares + 1)) break; |
0 | 1414 |
|
1415 |
// try a random one |
|
1416 |
AiFindRandomPassengerRoute(&fr); |
|
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8427
diff
changeset
|
1417 |
if (IsInsideMM(fr.distance, min_squares, max_squares + 1)) break; |
0 | 1418 |
|
1419 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1420 |
if (--i == 0) return; |
0 | 1421 |
} |
1422 |
||
1423 |
fr.cargo = CT_PASSENGERS; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1424 |
if (!AiCheckIfRouteIsGood(p, &fr, 4)) return; |
0 | 1425 |
|
1426 |
||
1427 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1428 |
_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1429 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1430 |
_players_ai[p->index].src.rand_rng = 12; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1431 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1432 |
_players_ai[p->index].src.cargo = fr.cargo; |
0 | 1433 |
|
1434 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1435 |
_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1436 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1437 |
_players_ai[p->index].dst.rand_rng = 12; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1438 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1439 |
_players_ai[p->index].dst.cargo = fr.cargo; |
0 | 1440 |
|
1441 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1442 |
_players_ai[p->index].cargo_type = fr.cargo; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1443 |
_players_ai[p->index].build_kind = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1444 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1445 |
_players_ai[p->index].num_loco_to_build = 1; |
7354
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1446 |
/* Using full load always may not be the best. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1447 |
* Pick random value and rely on selling the vehicle & route |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1448 |
* afterwards if the choice was utterly wrong (or maybe altering the value if AI is improved) |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1449 |
* When traffic is very low or very assymetric, is is better not to full load |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1450 |
* When traffic is high, full/non-full make no difference |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1451 |
* It should be better to run with aircraft only one way full 6 times per year, |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1452 |
* rather than two way full 1 times. |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1453 |
* Practical experiments with AI show that the non-full-load aircrafts are usually |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1454 |
* those that survive |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1455 |
* Also, non-full load is more resistant against starving (by building better stations |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1456 |
* or using exclusive rights) |
4108080dce70
(svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents:
7338
diff
changeset
|
1457 |
*/ |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1458 |
_players_ai[p->index].num_want_fullload = Chance16(1, 5); // 20% chance |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1459 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1460 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1461 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1462 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1463 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1464 |
_players_ai[p->index].state = AIS_AIRPORT_STUFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1465 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1466 |
} |
1467 |
||
1468 |
static void AiWantOilRigAircraftRoute(Player *p) |
|
1469 |
{ |
|
1470 |
int i; |
|
1471 |
FoundRoute fr; |
|
1472 |
Town *t; |
|
1473 |
Industry *in; |
|
1474 |
||
1475 |
i = 60; |
|
2952 | 1476 |
for (;;) { |
0 | 1477 |
// Find a town |
1478 |
t = AiFindRandomTown(); |
|
1479 |
if (t != NULL) { |
|
1480 |
// Find a random oil rig industry |
|
4342
e2c427ed862e
(svn r6043) -Codechange: use wrapper if they are available
truelight
parents:
4322
diff
changeset
|
1481 |
in = AiFindRandomIndustry(); |
6896
b6051812d11f
(svn r9530) -Codechange: Replace a direct industry type access by a behaviour
belugas
parents:
6683
diff
changeset
|
1482 |
if (in != NULL && GetIndustrySpec(in->type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) { |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
1483 |
if (DistanceManhattan(t->xy, in->xy) < 60) |
0 | 1484 |
break; |
1485 |
} |
|
1486 |
} |
|
1487 |
||
1488 |
// only test 60 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1489 |
if (--i == 0) return; |
0 | 1490 |
} |
1491 |
||
1492 |
fr.cargo = CT_PASSENGERS; |
|
1493 |
fr.from = fr.to = t; |
|
1494 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1495 |
if (!AiCheckIfRouteIsGood(p, &fr, 4)) return; |
0 | 1496 |
|
1497 |
// Fill the source field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1498 |
_players_ai[p->index].src.spec_tile = t->xy; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1499 |
_players_ai[p->index].src.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1500 |
_players_ai[p->index].src.rand_rng = 12; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1501 |
_players_ai[p->index].src.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1502 |
_players_ai[p->index].src.cargo = CT_PASSENGERS; |
0 | 1503 |
|
1504 |
// Fill the dest field |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1505 |
_players_ai[p->index].dst.spec_tile = in->xy; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1506 |
_players_ai[p->index].dst.use_tile = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1507 |
_players_ai[p->index].dst.rand_rng = 5; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1508 |
_players_ai[p->index].dst.cur_building_rule = 0xFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1509 |
_players_ai[p->index].dst.cargo = CT_PASSENGERS; |
0 | 1510 |
|
1511 |
// Fill common fields |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1512 |
_players_ai[p->index].cargo_type = CT_PASSENGERS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1513 |
_players_ai[p->index].build_kind = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1514 |
_players_ai[p->index].num_build_rec = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1515 |
_players_ai[p->index].num_loco_to_build = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1516 |
_players_ai[p->index].num_want_fullload = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1517 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1518 |
_players_ai[p->index].order_list_blocks[0] = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1519 |
_players_ai[p->index].order_list_blocks[1] = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1520 |
_players_ai[p->index].order_list_blocks[2] = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1521 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1522 |
_players_ai[p->index].state = AIS_AIRPORT_STUFF; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1523 |
_players_ai[p->index].timeout_counter = 0; |
0 | 1524 |
} |
1525 |
||
1526 |
static void AiWantAircraftRoute(Player *p) |
|
1527 |
{ |
|
1528 |
uint16 r = (uint16)Random(); |
|
1529 |
||
4322
0bee6d9bc452
(svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents:
4261
diff
changeset
|
1530 |
if (r >= 0x2AAA || _date < 0x3912 + DAYS_TILL_ORIGINAL_BASE_YEAR) { |
0 | 1531 |
AiWantPassengerAircraftRoute(p); |
1532 |
} else { |
|
1533 |
AiWantOilRigAircraftRoute(p); |
|
1534 |
} |
|
1535 |
} |
|
1536 |
||
1537 |
||
1538 |
||
1539 |
static void AiStateWantNewRoute(Player *p) |
|
1540 |
{ |
|
1541 |
uint16 r; |
|
1542 |
int i; |
|
1543 |
||
1544 |
if (p->player_money < AiGetBasePrice(p) * 500) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1545 |
_players_ai[p->index].state = AIS_0; |
0 | 1546 |
return; |
1547 |
} |
|
1548 |
||
1549 |
i = 200; |
|
2952 | 1550 |
for (;;) { |
0 | 1551 |
r = (uint16)Random(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1552 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1553 |
if (_patches.ai_disable_veh_train && |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1554 |
_patches.ai_disable_veh_roadveh && |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1555 |
_patches.ai_disable_veh_aircraft && |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1556 |
_patches.ai_disable_veh_ship) { |
76
30511cbc5188
(svn r77) -Fix: [1010788] AI service interval bug (tnx truesatan)
truelight
parents:
21
diff
changeset
|
1557 |
return; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1558 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1559 |
|
0 | 1560 |
if (r < 0x7626) { |
20
13a47054d81e
(svn r21) Remove: PE_BYTE (bit-bools) in favour of PE_BOOL
truelight
parents:
0
diff
changeset
|
1561 |
if (_patches.ai_disable_veh_train) continue; |
0 | 1562 |
AiWantTrainRoute(p); |
1563 |
} else if (r < 0xC4EA) { |
|
20
13a47054d81e
(svn r21) Remove: PE_BYTE (bit-bools) in favour of PE_BOOL
truelight
parents:
0
diff
changeset
|
1564 |
if (_patches.ai_disable_veh_roadveh) continue; |
0 | 1565 |
AiWantRoadRoute(p); |
1566 |
} else if (r < 0xD89B) { |
|
20
13a47054d81e
(svn r21) Remove: PE_BYTE (bit-bools) in favour of PE_BOOL
truelight
parents:
0
diff
changeset
|
1567 |
if (_patches.ai_disable_veh_aircraft) continue; |
0 | 1568 |
AiWantAircraftRoute(p); |
1569 |
} else { |
|
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
1570 |
/* Ships are not implemented in this (broken) AI */ |
0 | 1571 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1572 |
|
0 | 1573 |
// got a route? |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1574 |
if (_players_ai[p->index].state != AIS_WANT_NEW_ROUTE) break; |
0 | 1575 |
|
1576 |
// time out? |
|
1577 |
if (--i == 0) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1578 |
if (++_players_ai[p->index].state_counter == 556) _players_ai[p->index].state = AIS_0; |
0 | 1579 |
break; |
1580 |
} |
|
1581 |
} |
|
1582 |
} |
|
1583 |
||
1584 |
static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo) |
|
1585 |
{ |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1586 |
uint rad = (_patches.modified_catchment) ? CA_TRAIN : 4; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1587 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1588 |
for (; p->mode != 4; p++) { |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1589 |
AcceptedCargo values; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1590 |
TileIndex tile2; |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2096
diff
changeset
|
1591 |
uint w; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2096
diff
changeset
|
1592 |
uint h; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2096
diff
changeset
|
1593 |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1594 |
if (p->mode != 1) continue; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1595 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1596 |
tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)); |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2096
diff
changeset
|
1597 |
w = GB(p->attr, 1, 3); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2096
diff
changeset
|
1598 |
h = GB(p->attr, 4, 3); |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1599 |
|
6432 | 1600 |
if (p->attr & 1) Swap(w, h); |
0 | 1601 |
|
1602 |
if (cargo & 0x80) { |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
1603 |
GetProductionAroundTiles(values, tile2, w, h, rad); |
0 | 1604 |
return values[cargo & 0x7F] != 0; |
1605 |
} else { |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
1606 |
GetAcceptanceAroundTiles(values, tile2, w, h, rad); |
0 | 1607 |
if (!(values[cargo] & ~7)) |
1608 |
return false; |
|
1609 |
if (cargo != CT_MAIL) |
|
1610 |
return true; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
1611 |
return !!((values[cargo] >> 1) & ~7); |
0 | 1612 |
} |
1613 |
} |
|
1614 |
||
1615 |
return true; |
|
1616 |
} |
|
1617 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
1618 |
static CommandCost AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag) |
0 | 1619 |
{ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
1620 |
CommandCost ret; |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
1621 |
CommandCost total_cost(EXPENSES_CONSTRUCTION); |
0 | 1622 |
Town *t = NULL; |
1623 |
int rating = 0; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
1624 |
int i, j, k; |
0 | 1625 |
|
2952 | 1626 |
for (;;) { |
0 | 1627 |
// This will seldomly overflow for valid reasons. Mask it to be on the safe side. |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1628 |
uint c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)); |
0 | 1629 |
|
1630 |
_cleared_town = NULL; |
|
1631 |
||
1632 |
if (p->mode < 2) { |
|
1633 |
if (p->mode == 0) { |
|
1634 |
// Depot |
|
3965
8c857c1da8c2
(svn r5128) Remove the global variable _cur_ai_player
tron
parents:
3964
diff
changeset
|
1635 |
ret = DoCommand(c, railtype, p->attr, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_TRAIN_DEPOT); |
0 | 1636 |
} else { |
1637 |
// Station |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
1638 |
ret = DoCommand(c, (p->attr & 1) | (p->attr >> 4) << 8 | (p->attr >> 1 & 7) << 16, railtype, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_RAILROAD_STATION); |
0 | 1639 |
} |
1640 |
||
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
1641 |
if (CmdFailed(ret)) return CMD_ERROR; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1642 |
total_cost.AddCost(ret); |
0 | 1643 |
|
1644 |
clear_town_stuff:; |
|
1645 |
if (_cleared_town != NULL) { |
|
1646 |
if (t != NULL && t != _cleared_town) |
|
1647 |
return CMD_ERROR; |
|
1648 |
t = _cleared_town; |
|
1649 |
rating += _cleared_town_rating; |
|
1650 |
} |
|
1651 |
} else if (p->mode == 2) { |
|
8502 | 1652 |
/* Rail */ |
2639 | 1653 |
if (IsTileType(c, MP_RAILWAY)) return CMD_ERROR; |
0 | 1654 |
|
1655 |
j = p->attr; |
|
1656 |
k = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1657 |
|
8502 | 1658 |
/* Build the rail |
1659 |
* note: FOR_EACH_SET_BIT cannot be used here |
|
1660 |
*/ |
|
1661 |
for (i = 0; i != 6; i++, j >>= 1) { |
|
1662 |
if (j & 1) { |
|
1663 |
k = i; |
|
1664 |
ret = DoCommand(c, railtype, i, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL); |
|
1665 |
if (CmdFailed(ret)) return CMD_ERROR; |
|
1666 |
total_cost.AddCost(ret); |
|
1667 |
} |
|
0 | 1668 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1669 |
|
0 | 1670 |
/* signals too? */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1671 |
if (j & 3) { |
5575
e33f975c5a4b
(svn r7575) -Codechange: Allow the AI to build signals under bridges (revert r4911)
celestar
parents:
5573
diff
changeset
|
1672 |
// Can't build signals on a road. |
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
1673 |
if (IsTileType(c, MP_ROAD)) return CMD_ERROR; |
0 | 1674 |
|
1675 |
if (flag & DC_EXEC) { |
|
1676 |
j = 4 - j; |
|
1677 |
do { |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
1678 |
ret = DoCommand(c, k, 0, flag, CMD_BUILD_SIGNALS); |
0 | 1679 |
} while (--j); |
1680 |
} else { |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1681 |
ret.AddCost(_price.build_signals); |
0 | 1682 |
} |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
1683 |
if (CmdFailed(ret)) return CMD_ERROR; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1684 |
total_cost.AddCost(ret); |
0 | 1685 |
} |
1686 |
} else if (p->mode == 3) { |
|
1687 |
//Clear stuff and then build single rail. |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
1688 |
if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
1689 |
ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
1690 |
if (CmdFailed(ret)) return CMD_ERROR; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1691 |
total_cost.AddCost(ret); |
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1692 |
total_cost.AddCost(_price.build_rail); |
0 | 1693 |
|
1694 |
if (flag & DC_EXEC) { |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
1695 |
DoCommand(c, railtype, p->attr & 1, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_SINGLE_RAIL); |
0 | 1696 |
} |
1697 |
||
1698 |
goto clear_town_stuff; |
|
1699 |
} else { |
|
1700 |
// Unk |
|
1701 |
break; |
|
1702 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1703 |
|
0 | 1704 |
p++; |
1705 |
} |
|
1706 |
||
1707 |
if (!(flag & DC_EXEC)) { |
|
1708 |
if (t != NULL && rating > t->ratings[_current_player]) { |
|
1709 |
return CMD_ERROR; |
|
1710 |
} |
|
1711 |
} |
|
1712 |
||
1713 |
return total_cost; |
|
1714 |
} |
|
1715 |
||
1716 |
// Returns rule and cost |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
1717 |
static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, CommandCost* cost) |
0 | 1718 |
{ |
1719 |
int i; |
|
1720 |
const AiDefaultRailBlock *p; |
|
1721 |
||
2639 | 1722 |
for (i = 0; (p = _default_rail_track_data[i]) != NULL; i++) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1723 |
if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 && |
2639 | 1724 |
(p->dir == 0xFF || p->dir == dir || ((p->dir - 1) & 3) == dir)) { |
3965
8c857c1da8c2
(svn r5128) Remove the global variable _cur_ai_player
tron
parents:
3964
diff
changeset
|
1725 |
*cost = AiDoBuildDefaultRailTrack(tile, p->data, railtype, DC_NO_TOWN_RATING); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1726 |
if (CmdSucceeded(*cost) && AiCheckTrackResources(tile, p->data, cargo)) |
0 | 1727 |
return i; |
1728 |
} |
|
1729 |
} |
|
1730 |
||
1731 |
return -1; |
|
1732 |
} |
|
1733 |
||
1734 |
static const byte _terraform_up_flags[] = { |
|
1735 |
14, 13, 12, 11, |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1736 |
10, 9, 8, 7, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1737 |
6, 5, 4, 3, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1738 |
2, 1, 0, 1, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1739 |
2, 1, 4, 1, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1740 |
2, 1, 8, 1, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1741 |
2, 1, 4, 2, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1742 |
2, 1 |
0 | 1743 |
}; |
1744 |
||
1745 |
static const byte _terraform_down_flags[] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1746 |
1, 2, 3, 4, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1747 |
5, 6, 1, 8, |
0 | 1748 |
9, 10, 8, 12, |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1749 |
4, 2, 0, 0, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1750 |
1, 2, 3, 4, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1751 |
5, 6, 2, 8, |
0 | 1752 |
9, 10, 1, 12, |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1753 |
8, 4 |
0 | 1754 |
}; |
1755 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1756 |
static void AiDoTerraformLand(TileIndex tile, DiagDirection dir, int unk, int mode) |
0 | 1757 |
{ |
2544 | 1758 |
PlayerID old_player; |
0 | 1759 |
uint32 r; |
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
1760 |
Slope slope; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1330
diff
changeset
|
1761 |
uint h; |
0 | 1762 |
|
1763 |
old_player = _current_player; |
|
1764 |
_current_player = OWNER_NONE; |
|
1765 |
||
1766 |
r = Random(); |
|
1767 |
||
1768 |
unk &= (int)r; |
|
1769 |
||
1770 |
do { |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1771 |
tile = TILE_MASK(tile + TileOffsByDiagDir(dir)); |
0 | 1772 |
|
1773 |
r >>= 2; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1774 |
if (r & 2) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1775 |
dir = ChangeDiagDir(dir, (r & 1) ? DIAGDIRDIFF_90LEFT : DIAGDIRDIFF_90RIGHT); |
0 | 1776 |
} |
1777 |
} while (--unk >= 0); |
|
1778 |
||
1779 |
slope = GetTileSlope(tile, &h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1780 |
|
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
1781 |
if (slope != SLOPE_FLAT) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1782 |
if (mode > 0 || (mode == 0 && !(r & 0xC))) { |
0 | 1783 |
// Terraform up |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
1784 |
DoCommand(tile, _terraform_up_flags[slope - 1], 1, |
0 | 1785 |
DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
1786 |
} else if (h != 0) { |
|
1787 |
// Terraform down |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
1788 |
DoCommand(tile, _terraform_down_flags[slope - 1], 0, |
0 | 1789 |
DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1790 |
} |
0 | 1791 |
} |
1792 |
||
1793 |
_current_player = old_player; |
|
1794 |
} |
|
1795 |
||
1796 |
static void AiStateBuildDefaultRailBlocks(Player *p) |
|
1797 |
{ |
|
2639 | 1798 |
uint i; |
1799 |
int j; |
|
0 | 1800 |
AiBuildRec *aib; |
1801 |
int rule; |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
1802 |
CommandCost cost; |
0 | 1803 |
|
1804 |
// time out? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1805 |
if (++_players_ai[p->index].timeout_counter == 1388) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1806 |
_players_ai[p->index].state = AIS_DELETE_RAIL_BLOCKS; |
0 | 1807 |
return; |
1808 |
} |
|
1809 |
||
1810 |
// do the following 8 times |
|
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2643
diff
changeset
|
1811 |
for (i = 0; i < 8; i++) { |
0 | 1812 |
// check if we can build the default track |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1813 |
aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1814 |
j = _players_ai[p->index].num_build_rec; |
0 | 1815 |
do { |
1816 |
// this item has already been built? |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1817 |
if (aib->cur_building_rule != 255) continue; |
0 | 1818 |
|
1819 |
// adjust the coordinate randomly, |
|
1820 |
// to make sure that we find a position. |
|
1821 |
aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng); |
|
1822 |
||
1823 |
// check if the track can be build there. |
|
1824 |
rule = AiBuildDefaultRailTrack(aib->use_tile, |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1825 |
_players_ai[p->index].build_kind, _players_ai[p->index].num_wagons, |
0 | 1826 |
aib->unk6, aib->unk7, |
3965
8c857c1da8c2
(svn r5128) Remove the global variable _cur_ai_player
tron
parents:
3964
diff
changeset
|
1827 |
aib->direction, aib->cargo, |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1828 |
_players_ai[p->index].railtype_to_use, |
3965
8c857c1da8c2
(svn r5128) Remove the global variable _cur_ai_player
tron
parents:
3964
diff
changeset
|
1829 |
&cost |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
1830 |
); |
0 | 1831 |
|
1832 |
if (rule == -1) { |
|
1833 |
// cannot build, terraform after a while |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1834 |
if (_players_ai[p->index].state_counter >= 600) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1835 |
AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)_players_ai[p->index].state_mode); |
0 | 1836 |
} |
1837 |
// also try the other terraform direction |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1838 |
if (++_players_ai[p->index].state_counter >= 1000) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1839 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1840 |
_players_ai[p->index].state_mode = -_players_ai[p->index].state_mode; |
0 | 1841 |
} |
1842 |
} else if (CheckPlayerHasMoney(cost)) { |
|
1843 |
// player has money, build it. |
|
1844 |
aib->cur_building_rule = rule; |
|
1845 |
||
7098
cfa4db4b59f7
(svn r9817) -Fix [FS#772]: an assertion that was triggered by the AI building when its rating for the town was not high enough.
rubidium
parents:
6987
diff
changeset
|
1846 |
AiDoBuildDefaultRailTrack( |
0 | 1847 |
aib->use_tile, |
1848 |
_default_rail_track_data[rule]->data, |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1849 |
_players_ai[p->index].railtype_to_use, |
0 | 1850 |
DC_EXEC | DC_NO_TOWN_RATING |
1851 |
); |
|
1852 |
} |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
1853 |
} while (++aib, --j); |
2648
72973ab76048
(svn r3190) Turn some loops into canonical for loop form
tron
parents:
2643
diff
changeset
|
1854 |
} |
0 | 1855 |
|
1856 |
// check if we're done with all of them |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1857 |
aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1858 |
j = _players_ai[p->index].num_build_rec; |
0 | 1859 |
do { |
2639 | 1860 |
if (aib->cur_building_rule == 255) return; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
1861 |
} while (++aib, --j); |
0 | 1862 |
|
1863 |
// yep, all are done. switch state to the rail building state. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1864 |
_players_ai[p->index].state = AIS_BUILD_RAIL; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1865 |
_players_ai[p->index].state_mode = 255; |
0 | 1866 |
} |
1867 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1868 |
static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd, DiagDirection *dir) |
0 | 1869 |
{ |
1870 |
const AiDefaultBlockData *p = _default_rail_track_data[rule]->data; |
|
1871 |
||
1872 |
while (p->mode != 3 || !((--cmd) & 0x80)) p++; |
|
1873 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1874 |
return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDiagDir(*dir = p->attr); |
0 | 1875 |
} |
1876 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1877 |
struct AiRailPathFindData { |
0 | 1878 |
TileIndex tile; |
1879 |
TileIndex tile2; |
|
1880 |
int count; |
|
1881 |
bool flag; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1882 |
}; |
0 | 1883 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
1884 |
static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length, byte *state) |
0 | 1885 |
{ |
2639 | 1886 |
if (a->flag) return true; |
0 | 1887 |
|
1888 |
if (length > 20 || tile == a->tile) { |
|
1889 |
a->flag = true; |
|
1890 |
return true; |
|
1891 |
} |
|
1892 |
||
2639 | 1893 |
if (DistanceMax(tile, a->tile2) < 4) a->count++; |
0 | 1894 |
|
1895 |
return false; |
|
1896 |
} |
|
1897 |
||
2643 | 1898 |
static bool AiDoFollowTrack(const Player* p) |
0 | 1899 |
{ |
1900 |
AiRailPathFindData arpfd; |
|
2639 | 1901 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1902 |
arpfd.tile = _players_ai[p->index].start_tile_a; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1903 |
arpfd.tile2 = _players_ai[p->index].cur_tile_a; |
0 | 1904 |
arpfd.flag = false; |
1905 |
arpfd.count = 0; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1906 |
FollowTrack(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a), 0x2000 | TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a), |
0 | 1907 |
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd); |
1908 |
return arpfd.count > 8; |
|
1909 |
} |
|
1910 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1911 |
struct AiRailFinder { |
0 | 1912 |
TileIndex final_tile; |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1913 |
DiagDirection final_dir; |
0 | 1914 |
byte depth; |
1915 |
byte recursive_mode; |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1916 |
DiagDirection cur_best_dir; |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1917 |
DiagDirection best_dir; |
0 | 1918 |
byte cur_best_depth; |
1919 |
byte best_depth; |
|
1920 |
uint cur_best_dist; |
|
1921 |
const byte *best_ptr; |
|
1922 |
uint best_dist; |
|
1923 |
TileIndex cur_best_tile, best_tile; |
|
1924 |
TileIndex bridge_end_tile; |
|
1925 |
Player *player; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1926 |
}; |
0 | 1927 |
|
1928 |
static const byte _ai_table_15[4][8] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1929 |
{0, 0, 4, 3, 3, 1, 128 + 0, 64}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1930 |
{1, 1, 2, 0, 4, 2, 128 + 1, 65}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1931 |
{0, 2, 2, 3, 5, 1, 128 + 2, 66}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1932 |
{1, 3, 5, 0, 3, 2, 128 + 3, 67} |
0 | 1933 |
}; |
1934 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1935 |
static const byte _dir_table_1[] = { 3, 9, 12, 6}; |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4342
diff
changeset
|
1936 |
static const byte _dir_table_2[] = {12, 6, 3, 9}; |
0 | 1937 |
|
1938 |
||
2630 | 1939 |
static bool AiIsTileBanned(const Player* p, TileIndex tile, byte val) |
1940 |
{ |
|
0 | 1941 |
int i; |
1942 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1943 |
for (i = 0; i != _players_ai[p->index].banned_tile_count; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1944 |
if (_players_ai[p->index].banned_tiles[i] == tile && _players_ai[p->index].banned_val[i] == val) { |
2639 | 1945 |
return true; |
1946 |
} |
|
1947 |
} |
|
0 | 1948 |
return false; |
1949 |
} |
|
1950 |
||
2639 | 1951 |
static void AiBanTile(Player* p, TileIndex tile, byte val) |
1952 |
{ |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
1953 |
uint i; |
0 | 1954 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1955 |
for (i = lengthof(_players_ai[p->index].banned_tiles) - 1; i != 0; i--) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1956 |
_players_ai[p->index].banned_tiles[i] = _players_ai[p->index].banned_tiles[i - 1]; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1957 |
_players_ai[p->index].banned_val[i] = _players_ai[p->index].banned_val[i - 1]; |
0 | 1958 |
} |
1959 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1960 |
_players_ai[p->index].banned_tiles[0] = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1961 |
_players_ai[p->index].banned_val[0] = val; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1962 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1963 |
if (_players_ai[p->index].banned_tile_count != lengthof(_players_ai[p->index].banned_tiles)) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1964 |
_players_ai[p->index].banned_tile_count++; |
2639 | 1965 |
} |
0 | 1966 |
} |
1967 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
1968 |
static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, DiagDirection dir); |
0 | 1969 |
|
1970 |
static bool AiCheckRailPathBetter(AiRailFinder *arf, const byte *p) |
|
1971 |
{ |
|
1972 |
bool better = false; |
|
1973 |
||
1974 |
if (arf->recursive_mode < 1) { |
|
1975 |
// Mode is 0. This means destination has not been found yet. |
|
1976 |
// If the found path is shorter than the current one, remember it. |
|
1977 |
if (arf->cur_best_dist < arf->best_dist) { |
|
1978 |
arf->best_dir = arf->cur_best_dir; |
|
1979 |
arf->best_dist = arf->cur_best_dist; |
|
1980 |
arf->best_ptr = p; |
|
1981 |
arf->best_tile = arf->cur_best_tile; |
|
1982 |
better = true; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
1983 |
} |
0 | 1984 |
} else if (arf->recursive_mode > 1) { |
1985 |
// Mode is 2. |
|
1986 |
if (arf->best_dist != 0 || arf->cur_best_depth < arf->best_depth) { |
|
1987 |
arf->best_depth = arf->cur_best_depth; |
|
1988 |
arf->best_dist = 0; |
|
1989 |
arf->best_ptr = p; |
|
1990 |
arf->best_tile = 0; |
|
1991 |
better = true; |
|
1992 |
} |
|
1993 |
} |
|
1994 |
arf->recursive_mode = 0; |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1995 |
arf->cur_best_dist = UINT_MAX; |
0 | 1996 |
arf->cur_best_depth = 0xff; |
1997 |
||
1998 |
return better; |
|
1999 |
} |
|
2000 |
||
536 | 2001 |
static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile, const byte *p) |
0 | 2002 |
{ |
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
2003 |
Slope tileh; |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2004 |
uint z; |
0 | 2005 |
bool flag; |
2006 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2007 |
DiagDirection dir2 = (DiagDirection)(p[0] & 3); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2008 |
|
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2009 |
tileh = GetTileSlope(tile, &z); |
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
2010 |
if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) { |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2011 |
TileIndex tile_new = tile; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2012 |
|
0 | 2013 |
// Allow bridges directly over bottom tiles |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2014 |
flag = z == 0; |
2952 | 2015 |
for (;;) { |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2016 |
TileType type; |
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2017 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2018 |
if ((TileIndexDiff)tile_new < -TileOffsByDiagDir(dir2)) return; // Wraping around map, no bridge possible! |
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2019 |
tile_new = TILE_MASK(tile_new + TileOffsByDiagDir(dir2)); |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2020 |
type = GetTileType(tile_new); |
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2021 |
|
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
2022 |
if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) { |
0 | 2023 |
if (!flag) return; |
2024 |
break; |
|
2025 |
} |
|
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
2026 |
if (type != MP_WATER && type != MP_RAILWAY && type != MP_ROAD) return; |
0 | 2027 |
flag = true; |
2028 |
} |
|
2029 |
||
2030 |
// Is building a (rail)bridge possible at this place (type doesn't matter)? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2031 |
if (CmdFailed(DoCommand(tile_new, tile, 0 | _players_ai[arf->player->index].railtype_to_use << 8, DC_AUTO, CMD_BUILD_BRIDGE))) { |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2032 |
return; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2033 |
} |
0 | 2034 |
AiBuildRailRecursive(arf, tile_new, dir2); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2035 |
|
0 | 2036 |
// At the bottom depth, check if the new path is better than the old one. |
2037 |
if (arf->depth == 1) { |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2038 |
if (AiCheckRailPathBetter(arf, p)) arf->bridge_end_tile = tile_new; |
0 | 2039 |
} |
2040 |
} |
|
2041 |
} |
|
2042 |
||
536 | 2043 |
static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile, const byte *p) |
0 | 2044 |
{ |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2045 |
uint z; |
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2046 |
|
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2047 |
if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2048 |
CommandCost cost = DoCommand(tile, _players_ai[arf->player->index].railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL); |
0 | 2049 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
2050 |
if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2051 |
AiBuildRailRecursive(arf, _build_tunnel_endtile, (DiagDirection)(p[0] & 3)); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2052 |
if (arf->depth == 1) AiCheckRailPathBetter(arf, p); |
0 | 2053 |
} |
2054 |
} |
|
2055 |
} |
|
2056 |
||
2057 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2058 |
static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, DiagDirection dir) |
0 | 2059 |
{ |
2060 |
const byte *p; |
|
2061 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2062 |
tile = TILE_MASK(tile + TileOffsByDiagDir(dir)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2063 |
|
0 | 2064 |
// Reached destination? |
2065 |
if (tile == arf->final_tile) { |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2066 |
if (arf->final_dir != ReverseDiagDir(dir)) { |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2067 |
if (arf->recursive_mode != 2) arf->recursive_mode = 1; |
0 | 2068 |
} else if (arf->recursive_mode != 2) { |
2069 |
arf->recursive_mode = 2; |
|
2070 |
arf->cur_best_depth = arf->depth; |
|
2071 |
} else { |
|
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2072 |
if (arf->depth < arf->cur_best_depth) arf->cur_best_depth = arf->depth; |
0 | 2073 |
} |
2074 |
return; |
|
2075 |
} |
|
2076 |
||
2077 |
// Depth too deep? |
|
2078 |
if (arf->depth >= 4) { |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
2079 |
uint dist = DistanceMaxPlusManhattan(tile, arf->final_tile); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2080 |
|
0 | 2081 |
if (dist < arf->cur_best_dist) { |
2082 |
// Store the tile that is closest to the final position. |
|
2083 |
arf->cur_best_depth = arf->depth; |
|
2084 |
arf->cur_best_dist = dist; |
|
2085 |
arf->cur_best_tile = tile; |
|
2086 |
arf->cur_best_dir = dir; |
|
2087 |
} |
|
2088 |
return; |
|
2089 |
} |
|
2090 |
||
2091 |
// Increase recursion depth |
|
2092 |
arf->depth++; |
|
2093 |
||
2094 |
// Grab pointer to list of stuff that is possible to build |
|
2095 |
p = _ai_table_15[dir]; |
|
2096 |
||
2097 |
// Try to build a single rail in all directions. |
|
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2098 |
if (GetTileZ(tile) == 0) { |
0 | 2099 |
p += 6; |
2100 |
} else { |
|
2101 |
do { |
|
2102 |
// Make sure the tile is not in the list of banned tiles and that a rail can be built here. |
|
2103 |
if (!AiIsTileBanned(arf->player, tile, p[0]) && |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2104 |
CmdSucceeded(DoCommand(tile, _players_ai[arf->player->index].railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2105 |
AiBuildRailRecursive(arf, tile, (DiagDirection)p[1]); |
0 | 2106 |
} |
2107 |
||
2108 |
// At the bottom depth? |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2109 |
if (arf->depth == 1) AiCheckRailPathBetter(arf, p); |
0 | 2110 |
|
2111 |
p += 2; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2112 |
} while (!(p[0] & 0x80)); |
0 | 2113 |
} |
2114 |
||
2115 |
AiCheckBuildRailBridgeHere(arf, tile, p); |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2116 |
AiCheckBuildRailTunnelHere(arf, tile, p + 1); |
0 | 2117 |
|
2118 |
arf->depth--; |
|
2119 |
} |
|
2120 |
||
2121 |
||
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2122 |
static const byte _dir_table_3[] = {0x25, 0x2A, 0x19, 0x16}; |
0 | 2123 |
|
2124 |
static void AiBuildRailConstruct(Player *p) |
|
2125 |
{ |
|
2126 |
AiRailFinder arf; |
|
2127 |
int i; |
|
2128 |
||
2129 |
// Check too much lookahead? |
|
2130 |
if (AiDoFollowTrack(p)) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2131 |
_players_ai[p->index].state_counter = (Random()&0xE)+6; // Destruct this amount of blocks |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2132 |
_players_ai[p->index].state_mode = 1; // Start destruct |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2133 |
|
0 | 2134 |
// Ban this tile and don't reach it for a while. |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2135 |
AiBanTile(p, _players_ai[p->index].cur_tile_a, FindFirstBit(GetRailTrackStatus(_players_ai[p->index].cur_tile_a))); |
0 | 2136 |
return; |
2137 |
} |
|
2138 |
||
2139 |
// Setup recursive finder and call it. |
|
2140 |
arf.player = p; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2141 |
arf.final_tile = _players_ai[p->index].cur_tile_b; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2142 |
arf.final_dir = _players_ai[p->index].cur_dir_b; |
0 | 2143 |
arf.depth = 0; |
2144 |
arf.recursive_mode = 0; |
|
2145 |
arf.best_ptr = NULL; |
|
2146 |
arf.cur_best_dist = (uint)-1; |
|
2147 |
arf.cur_best_depth = 0xff; |
|
2148 |
arf.best_dist = (uint)-1; |
|
2149 |
arf.best_depth = 0xff; |
|
2150 |
arf.cur_best_tile = 0; |
|
2151 |
arf.best_tile = 0; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2152 |
AiBuildRailRecursive(&arf, _players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a); |
0 | 2153 |
|
2154 |
// Reached destination? |
|
2155 |
if (arf.recursive_mode == 2 && arf.cur_best_depth == 0) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2156 |
_players_ai[p->index].state_mode = 255; |
0 | 2157 |
return; |
2158 |
} |
|
2159 |
||
2160 |
// Didn't find anything to build? |
|
2161 |
if (arf.best_ptr == NULL) { |
|
2162 |
// Terraform some |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2163 |
for (i = 0; i != 5; i++) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2164 |
AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2165 |
} |
0 | 2166 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2167 |
if (++_players_ai[p->index].state_counter == 21) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2168 |
_players_ai[p->index].state_counter = 40; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2169 |
_players_ai[p->index].state_mode = 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2170 |
|
0 | 2171 |
// Ban this tile |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2172 |
AiBanTile(p, _players_ai[p->index].cur_tile_a, FindFirstBit(GetRailTrackStatus(_players_ai[p->index].cur_tile_a))); |
0 | 2173 |
} |
2174 |
return; |
|
2175 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2176 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2177 |
_players_ai[p->index].cur_tile_a += TileOffsByDiagDir(_players_ai[p->index].cur_dir_a); |
0 | 2178 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2179 |
if (arf.best_ptr[0] & 0x80) { |
0 | 2180 |
int i; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2181 |
int32 bridge_len = GetBridgeLength(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2182 |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2183 |
/* Figure out which (rail)bridge type to build |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2184 |
* start with best bridge, then go down to worse and worse bridges |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2185 |
* unnecessary to check for worst bridge (i=0), since AI will always build |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2186 |
* that. AI is so fucked up that fixing this small thing will probably not |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2187 |
* solve a thing |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2188 |
*/ |
1562
a5507e041d97
(svn r2066) - Fix: [ 1164248 ] game crash while AI builds bridge. Also protect bridge building against invalid bridges and some safeguards when drawing.
Darkvater
parents:
1335
diff
changeset
|
2189 |
for (i = MAX_BRIDGES - 1; i != 0; i--) { |
0 | 2190 |
if (CheckBridge_Stuff(i, bridge_len)) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2191 |
CommandCost cost = DoCommand(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a, i | (_players_ai[p->index].railtype_to_use << 8), DC_AUTO, CMD_BUILD_BRIDGE); |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
2192 |
if (CmdSucceeded(cost) && cost.GetCost() < (p->player_money >> 5)) break; |
0 | 2193 |
} |
2194 |
} |
|
2195 |
||
2196 |
// Build it |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2197 |
DoCommand(arf.bridge_end_tile, _players_ai[p->index].cur_tile_a, i | (_players_ai[p->index].railtype_to_use << 8), DC_AUTO | DC_EXEC, CMD_BUILD_BRIDGE); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2198 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2199 |
_players_ai[p->index].cur_tile_a = arf.bridge_end_tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2200 |
_players_ai[p->index].state_counter = 0; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2201 |
} else if (arf.best_ptr[0] & 0x40) { |
0 | 2202 |
// tunnel |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2203 |
DoCommand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].railtype_to_use, 0, DC_AUTO | DC_EXEC, CMD_BUILD_TUNNEL); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2204 |
_players_ai[p->index].cur_tile_a = _build_tunnel_endtile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2205 |
_players_ai[p->index].state_counter = 0; |
0 | 2206 |
} else { |
2207 |
// rail |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2208 |
_players_ai[p->index].cur_dir_a = (DiagDirection)(arf.best_ptr[1] & 3); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2209 |
DoCommand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].railtype_to_use, arf.best_ptr[0], |
0 | 2210 |
DC_EXEC | DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2211 |
_players_ai[p->index].state_counter = 0; |
0 | 2212 |
} |
2213 |
||
2214 |
if (arf.best_tile != 0) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2215 |
for (i = 0; i != 2; i++) { |
0 | 2216 |
AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2217 |
} |
0 | 2218 |
} |
2219 |
} |
|
2220 |
||
2221 |
static bool AiRemoveTileAndGoForward(Player *p) |
|
2222 |
{ |
|
2223 |
byte b; |
|
2224 |
int bit; |
|
2225 |
const byte *ptr; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2226 |
TileIndex tile = _players_ai[p->index].cur_tile_a; |
0 | 2227 |
TileIndex tilenew; |
2228 |
||
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
2229 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3179
diff
changeset
|
2230 |
if (IsTunnel(tile)) { |
0 | 2231 |
// Clear the tunnel and continue at the other side of it. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2232 |
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) |
0 | 2233 |
return false; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2234 |
_players_ai[p->index].cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a)); |
0 | 2235 |
return true; |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5247
diff
changeset
|
2236 |
} else { |
0 | 2237 |
// Check if the bridge points in the right direction. |
2238 |
// This is not really needed the first place AiRemoveTileAndGoForward is called. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2239 |
if (DiagDirToAxis(GetTunnelBridgeDirection(tile)) != (_players_ai[p->index].cur_dir_a & 1)) return false; |
0 | 2240 |
|
3214
172b409bf612
(svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
3196
diff
changeset
|
2241 |
tile = GetOtherBridgeEnd(tile); |
172b409bf612
(svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
3196
diff
changeset
|
2242 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2243 |
tilenew = TILE_MASK(tile - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a)); |
0 | 2244 |
// And clear the bridge. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2245 |
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) |
0 | 2246 |
return false; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2247 |
_players_ai[p->index].cur_tile_a = tilenew; |
0 | 2248 |
return true; |
2249 |
} |
|
2250 |
} |
|
2251 |
||
2252 |
// Find the railtype at the position. Quit if no rail there. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2253 |
b = GetRailTrackStatus(tile) & _dir_table_3[_players_ai[p->index].cur_dir_a]; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2254 |
if (b == 0) return false; |
0 | 2255 |
|
2256 |
// Convert into a bit position that CMD_REMOVE_SINGLE_RAIL expects. |
|
2257 |
bit = FindFirstBit(b); |
|
2258 |
||
2259 |
// Then remove and signals if there are any. |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
2260 |
if (IsTileType(tile, MP_RAILWAY) && |
3792
2eb8388731bf
(svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents:
3644
diff
changeset
|
2261 |
GetRailTileType(tile) == RAIL_TILE_SIGNALS) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2262 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_SIGNALS); |
0 | 2263 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2264 |
|
0 | 2265 |
// And also remove the rail. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2266 |
if (CmdFailed(DoCommand(tile, 0, bit, DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) |
0 | 2267 |
return false; |
2268 |
||
2269 |
// Find the direction at the other edge of the rail. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2270 |
ptr = _ai_table_15[ReverseDiagDir(_players_ai[p->index].cur_dir_a)]; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2271 |
while (ptr[0] != bit) ptr += 2; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2272 |
_players_ai[p->index].cur_dir_a = ReverseDiagDir((DiagDirection)ptr[1]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2273 |
|
0 | 2274 |
// And then also switch tile. |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2275 |
_players_ai[p->index].cur_tile_a = TILE_MASK(_players_ai[p->index].cur_tile_a - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a)); |
0 | 2276 |
|
2277 |
return true; |
|
2278 |
} |
|
2279 |
||
2280 |
||
2281 |
static void AiBuildRailDestruct(Player *p) |
|
2282 |
{ |
|
2283 |
// Decrease timeout. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2284 |
if (!--_players_ai[p->index].state_counter) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2285 |
_players_ai[p->index].state_mode = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2286 |
_players_ai[p->index].state_counter = 0; |
0 | 2287 |
} |
2288 |
||
2289 |
// Don't do anything if the destination is already reached. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2290 |
if (_players_ai[p->index].cur_tile_a == _players_ai[p->index].start_tile_a) return; |
0 | 2291 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2292 |
AiRemoveTileAndGoForward(p); |
0 | 2293 |
} |
2294 |
||
2295 |
||
2296 |
static void AiBuildRail(Player *p) |
|
2297 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2298 |
switch (_players_ai[p->index].state_mode) { |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2299 |
case 0: // Construct mode, build new rail. |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2300 |
AiBuildRailConstruct(p); |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2301 |
break; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2302 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2303 |
case 1: // Destruct mode, destroy the rail currently built. |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2304 |
AiBuildRailDestruct(p); |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2305 |
break; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2306 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2307 |
case 2: { |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2308 |
uint i; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2309 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2310 |
// Terraform some and then try building again. |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2311 |
for (i = 0; i != 4; i++) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2312 |
AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0); |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2313 |
} |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2314 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2315 |
if (++_players_ai[p->index].state_counter == 4) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2316 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2317 |
_players_ai[p->index].state_mode = 0; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2318 |
} |
0 | 2319 |
} |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2320 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2321 |
default: break; |
0 | 2322 |
} |
2323 |
} |
|
2324 |
||
2325 |
static void AiStateBuildRail(Player *p) |
|
2326 |
{ |
|
2327 |
int num; |
|
2328 |
AiBuildRec *aib; |
|
2329 |
byte cmd; |
|
2330 |
TileIndex tile; |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2331 |
DiagDirection dir; |
0 | 2332 |
|
2333 |
// time out? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2334 |
if (++_players_ai[p->index].timeout_counter == 1388) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2335 |
_players_ai[p->index].state = AIS_DELETE_RAIL_BLOCKS; |
0 | 2336 |
return; |
2337 |
} |
|
2338 |
||
2339 |
// Currently building a rail between two points? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2340 |
if (_players_ai[p->index].state_mode != 255) { |
0 | 2341 |
AiBuildRail(p); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2342 |
|
0 | 2343 |
// Alternate between edges |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2344 |
Swap(_players_ai[p->index].start_tile_a, _players_ai[p->index].start_tile_b); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2345 |
Swap(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_tile_b); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2346 |
Swap(_players_ai[p->index].start_dir_a, _players_ai[p->index].start_dir_b); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2347 |
Swap(_players_ai[p->index].cur_dir_a, _players_ai[p->index].cur_dir_b); |
0 | 2348 |
return; |
2349 |
} |
|
2350 |
||
2351 |
// Now, find two new points to build between |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2352 |
num = _players_ai[p->index].num_build_rec; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2353 |
aib = &_players_ai[p->index].src; |
0 | 2354 |
|
2952 | 2355 |
for (;;) { |
0 | 2356 |
cmd = aib->buildcmd_a; |
2357 |
aib->buildcmd_a = 255; |
|
2358 |
if (cmd != 255) break; |
|
2359 |
||
2360 |
cmd = aib->buildcmd_b; |
|
2361 |
aib->buildcmd_b = 255; |
|
2362 |
if (cmd != 255) break; |
|
2363 |
||
2364 |
aib++; |
|
2365 |
if (--num == 0) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2366 |
_players_ai[p->index].state = AIS_BUILD_RAIL_VEH; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2367 |
_players_ai[p->index].state_counter = 0; // timeout |
0 | 2368 |
return; |
2369 |
} |
|
2370 |
} |
|
2371 |
||
2372 |
// Find first edge to build from. |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2373 |
tile = AiGetEdgeOfDefaultRailBlock(aib->cur_building_rule, aib->use_tile, cmd & 3, &dir); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2374 |
_players_ai[p->index].start_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2375 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2376 |
_players_ai[p->index].start_dir_a = dir; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2377 |
_players_ai[p->index].cur_dir_a = dir; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2378 |
DoCommand(TILE_MASK(tile + TileOffsByDiagDir(dir)), 0, (dir & 1) ? 1 : 0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL); |
0 | 2379 |
|
2380 |
assert(TILE_MASK(tile) != 0xFF00); |
|
2381 |
||
2382 |
// Find second edge to build to |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2383 |
aib = (&_players_ai[p->index].src) + ((cmd >> 4) & 0xF); |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2384 |
tile = AiGetEdgeOfDefaultRailBlock(aib->cur_building_rule, aib->use_tile, (cmd >> 2) & 3, &dir); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2385 |
_players_ai[p->index].start_tile_b = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2386 |
_players_ai[p->index].cur_tile_b = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2387 |
_players_ai[p->index].start_dir_b = dir; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2388 |
_players_ai[p->index].cur_dir_b = dir; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2389 |
DoCommand(TILE_MASK(tile + TileOffsByDiagDir(dir)), 0, (dir & 1) ? 1 : 0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL); |
0 | 2390 |
|
2391 |
assert(TILE_MASK(tile) != 0xFF00); |
|
2392 |
||
2393 |
// And setup state. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2394 |
_players_ai[p->index].state_mode = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2395 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2396 |
_players_ai[p->index].banned_tile_count = 0; |
0 | 2397 |
} |
2398 |
||
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
2399 |
static StationID AiGetStationIdByDef(TileIndex tile, int id) |
0 | 2400 |
{ |
2401 |
const AiDefaultBlockData *p = _default_rail_track_data[id]->data; |
|
2402 |
while (p->mode != 1) p++; |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
2403 |
return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); |
0 | 2404 |
} |
2405 |
||
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2406 |
static EngineID AiFindBestWagon(CargoID cargo, RailType railtype) |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2407 |
{ |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2408 |
EngineID best_veh_index = INVALID_ENGINE; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2409 |
EngineID i; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2410 |
uint16 best_capacity = 0; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2411 |
uint16 best_speed = 0; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2412 |
uint speed; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2413 |
|
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2414 |
for (i = 0; i < NUM_TRAIN_ENGINES; i++) { |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2415 |
const RailVehicleInfo *rvi = RailVehInfo(i); |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2416 |
const Engine* e = GetEngine(i); |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2417 |
|
6074 | 2418 |
if (!IsCompatibleRail(rvi->railtype, railtype) || |
6119
b47985557d1e
(svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents:
6105
diff
changeset
|
2419 |
rvi->railveh_type != RAILVEH_WAGON || |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8149
diff
changeset
|
2420 |
!HasBit(e->player_avail, _current_player)) { |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2421 |
continue; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2422 |
} |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2423 |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2424 |
if (rvi->cargo_type != cargo) continue; |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2425 |
|
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2426 |
/* max_speed of 0 indicates no speed limit */ |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2427 |
speed = rvi->max_speed == 0 ? 0xFFFF : rvi->max_speed; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2428 |
|
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2429 |
if (rvi->capacity >= best_capacity && speed >= best_speed) { |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2430 |
best_capacity = rvi->capacity; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2431 |
best_speed = best_speed; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2432 |
best_veh_index = i; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2433 |
} |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2434 |
} |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2435 |
|
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2436 |
return best_veh_index; |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2437 |
} |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2438 |
|
0 | 2439 |
static void AiStateBuildRailVeh(Player *p) |
2440 |
{ |
|
2441 |
const AiDefaultBlockData *ptr; |
|
2442 |
TileIndex tile; |
|
2544 | 2443 |
EngineID veh; |
2444 |
int i; |
|
3348 | 2445 |
CargoID cargo; |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2446 |
CommandCost cost; |
0 | 2447 |
Vehicle *v; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2448 |
VehicleID loco_id; |
0 | 2449 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2450 |
ptr = _default_rail_track_data[_players_ai[p->index].src.cur_building_rule]->data; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2451 |
while (ptr->mode != 0) ptr++; |
0 | 2452 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2453 |
tile = TILE_ADD(_players_ai[p->index].src.use_tile, ToTileIndexDiff(ptr->tileoffs)); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2454 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2455 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2456 |
cargo = _players_ai[p->index].cargo_type; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2457 |
for (i = 0;;) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2458 |
if (_players_ai[p->index].wagon_list[i] == INVALID_VEHICLE) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2459 |
veh = AiFindBestWagon(cargo, _players_ai[p->index].railtype_to_use); |
3355
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2460 |
/* veh will return INVALID_ENGINE if no suitable wagon is available. |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2461 |
* We shall treat this in the same way as having no money */ |
a653b8e47f27
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3348
diff
changeset
|
2462 |
if (veh == INVALID_ENGINE) goto handle_nocash; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2463 |
cost = DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
2464 |
if (CmdFailed(cost)) goto handle_nocash; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2465 |
_players_ai[p->index].wagon_list[i] = _new_vehicle_id; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2466 |
_players_ai[p->index].wagon_list[i + 1] = INVALID_VEHICLE; |
0 | 2467 |
return; |
2468 |
} |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2469 |
if (cargo == CT_MAIL) cargo = CT_PASSENGERS; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2470 |
if (++i == _players_ai[p->index].num_wagons * 2 - 1) break; |
0 | 2471 |
} |
2472 |
||
2473 |
// Which locomotive to build? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2474 |
veh = AiChooseTrainToBuild(_players_ai[p->index].railtype_to_use, p->player_money, cargo != CT_PASSENGERS ? 1 : 0, tile); |
2544 | 2475 |
if (veh == INVALID_ENGINE) { |
0 | 2476 |
handle_nocash: |
2477 |
// after a while, if AI still doesn't have cash, get out of this block by selling the wagons. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2478 |
if (++_players_ai[p->index].state_counter == 1000) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2479 |
for (i = 0; _players_ai[p->index].wagon_list[i] != INVALID_VEHICLE; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2480 |
cost = DoCommand(tile, _players_ai[p->index].wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
2481 |
assert(CmdSucceeded(cost)); |
0 | 2482 |
} |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2483 |
_players_ai[p->index].state = AIS_0; |
0 | 2484 |
} |
2485 |
return; |
|
2486 |
} |
|
2487 |
||
2488 |
// Try to build the locomotive |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2489 |
cost = DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
2490 |
assert(CmdSucceeded(cost)); |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3933
diff
changeset
|
2491 |
loco_id = _new_vehicle_id; |
0 | 2492 |
|
2493 |
// Sell a vehicle if the train is double headed. |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2494 |
v = GetVehicle(loco_id); |
7988
6075538f6111
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7986
diff
changeset
|
2495 |
if (v->Next() != NULL) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2496 |
i = _players_ai[p->index].wagon_list[_players_ai[p->index].num_wagons * 2 - 2]; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2497 |
_players_ai[p->index].wagon_list[_players_ai[p->index].num_wagons * 2 - 2] = INVALID_VEHICLE; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2498 |
DoCommand(tile, i, 0, DC_EXEC, CMD_SELL_RAIL_WAGON); |
0 | 2499 |
} |
2500 |
||
2501 |
// Move the wagons onto the train |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2502 |
for (i = 0; _players_ai[p->index].wagon_list[i] != INVALID_VEHICLE; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2503 |
DoCommand(tile, _players_ai[p->index].wagon_list[i] | (loco_id << 16), 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
0 | 2504 |
} |
2505 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2506 |
for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2507 |
const AiBuildRec* aib = &_players_ai[p->index].src + _players_ai[p->index].order_list_blocks[i]; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2508 |
bool is_pass = ( |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2509 |
_players_ai[p->index].cargo_type == CT_PASSENGERS || |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2510 |
_players_ai[p->index].cargo_type == CT_MAIL || |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2511 |
(_opt.landscape == LT_TEMPERATE && _players_ai[p->index].cargo_type == CT_VALUABLES) |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2512 |
); |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
2513 |
Order order; |
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
2514 |
|
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
2515 |
order.type = OT_GOTO_STATION; |
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
2516 |
order.flags = 0; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4495
diff
changeset
|
2517 |
order.dest = AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule); |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
2518 |
|
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
2519 |
if (!is_pass && i == 1) order.flags |= OFB_UNLOAD; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2520 |
if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0)) |
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
2521 |
order.flags |= OFB_FULL_LOAD; |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
2522 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
2523 |
DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
0 | 2524 |
} |
2525 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2526 |
DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_TRAIN); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2527 |
|
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2528 |
DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); |
0 | 2529 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2530 |
if (_players_ai[p->index].num_want_fullload != 0) _players_ai[p->index].num_want_fullload--; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2531 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2532 |
if (--_players_ai[p->index].num_loco_to_build != 0) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2533 |
// _players_ai[p->index].loco_id = INVALID_VEHICLE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2534 |
_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE; |
0 | 2535 |
} else { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2536 |
_players_ai[p->index].state = AIS_0; |
0 | 2537 |
} |
2538 |
} |
|
2539 |
||
2540 |
static void AiStateDeleteRailBlocks(Player *p) |
|
2541 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2542 |
const AiBuildRec* aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2543 |
uint num = _players_ai[p->index].num_build_rec; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2544 |
|
0 | 2545 |
do { |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2546 |
const AiDefaultBlockData* b; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2547 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2548 |
if (aib->cur_building_rule == 255) continue; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2549 |
for (b = _default_rail_track_data[aib->cur_building_rule]->data; b->mode != 4; b++) { |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2550 |
DoCommand(TILE_ADD(aib->use_tile, ToTileIndexDiff(b->tileoffs)), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 2551 |
} |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2552 |
} while (++aib, --num); |
0 | 2553 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2554 |
_players_ai[p->index].state = AIS_0; |
0 | 2555 |
} |
2556 |
||
2557 |
static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo) |
|
2558 |
{ |
|
2559 |
uint values[NUM_CARGO]; |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
2560 |
int rad; |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
2561 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
2562 |
if (_patches.modified_catchment) { |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
2563 |
rad = CA_TRUCK; // Same as CA_BUS at the moment? |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
2564 |
} else { // change that at some point? |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
2565 |
rad = 4; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
2566 |
} |
830
8114845804c9
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
679
diff
changeset
|
2567 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2568 |
for (;; p++) { |
0 | 2569 |
if (p->mode == 4) { |
2570 |
return true; |
|
2571 |
} else if (p->mode == 1) { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
2572 |
TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)); |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
2573 |
|
0 | 2574 |
if (cargo & 0x80) { |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
2575 |
GetProductionAroundTiles(values, tile2, 1, 1, rad); |
0 | 2576 |
return values[cargo & 0x7F] != 0; |
2577 |
} else { |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
2578 |
GetAcceptanceAroundTiles(values, tile2, 1, 1, rad); |
0 | 2579 |
return (values[cargo]&~7) != 0; |
2580 |
} |
|
2581 |
} |
|
2582 |
} |
|
2583 |
} |
|
2584 |
||
2585 |
static bool _want_road_truck_station; |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2586 |
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag); |
0 | 2587 |
|
2588 |
// Returns rule and cost |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2589 |
static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, CommandCost *cost) |
0 | 2590 |
{ |
2591 |
int i; |
|
2592 |
const AiDefaultRoadBlock *p; |
|
2593 |
||
2594 |
_want_road_truck_station = (cargo & 0x7F) != CT_PASSENGERS; |
|
2595 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2596 |
for (i = 0; (p = _road_default_block_data[i]) != NULL; i++) { |
0 | 2597 |
if (p->dir == direction) { |
2598 |
*cost = AiDoBuildDefaultRoadBlock(tile, p->data, 0); |
|
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
2599 |
if (CmdSucceeded(*cost) && AiCheckRoadResources(tile, p->data, cargo)) |
0 | 2600 |
return i; |
2601 |
} |
|
2602 |
} |
|
2603 |
||
2604 |
return -1; |
|
2605 |
} |
|
2606 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2607 |
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag) |
0 | 2608 |
{ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2609 |
CommandCost ret; |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
2610 |
CommandCost total_cost(EXPENSES_CONSTRUCTION); |
0 | 2611 |
Town *t = NULL; |
2612 |
int rating = 0; |
|
2613 |
int roadflag = 0; |
|
2614 |
||
2952 | 2615 |
for (;p->mode != 4;p++) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2616 |
TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)); |
0 | 2617 |
|
2618 |
_cleared_town = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2619 |
|
0 | 2620 |
if (p->mode == 2) { |
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
2621 |
if (IsTileType(c, MP_ROAD) && |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
2622 |
GetRoadTileType(c) == ROAD_TILE_NORMAL && |
7157
270bc5b64e08
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents:
7132
diff
changeset
|
2623 |
(GetRoadBits(c, ROADTYPE_ROAD) & p->attr) != 0) { |
0 | 2624 |
roadflag |= 2; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2625 |
|
0 | 2626 |
// all bits are already built? |
7157
270bc5b64e08
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents:
7132
diff
changeset
|
2627 |
if ((GetRoadBits(c, ROADTYPE_ROAD) & p->attr) == p->attr) continue; |
0 | 2628 |
} |
2629 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2630 |
ret = DoCommand(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
2631 |
if (CmdFailed(ret)) return CMD_ERROR; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
2632 |
total_cost.AddCost(ret); |
0 | 2633 |
|
2634 |
continue; |
|
2635 |
} |
|
2636 |
||
2637 |
if (p->mode == 0) { |
|
2638 |
// Depot |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2639 |
ret = DoCommand(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_DEPOT); |
0 | 2640 |
goto clear_town_stuff; |
2641 |
} else if (p->mode == 1) { |
|
2642 |
if (_want_road_truck_station) { |
|
2643 |
// Truck station |
|
7177
08330bb931a1
(svn r9912) -Fix: the AIs could build any road(station)s.
rubidium
parents:
7157
diff
changeset
|
2644 |
ret = DoCommand(c, p->attr, ROADTYPES_ROAD << 2 | RoadStop::TRUCK, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP); |
0 | 2645 |
} else { |
2646 |
// Bus station |
|
7177
08330bb931a1
(svn r9912) -Fix: the AIs could build any road(station)s.
rubidium
parents:
7157
diff
changeset
|
2647 |
ret = DoCommand(c, p->attr, ROADTYPES_ROAD << 2 | RoadStop::BUS, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP); |
0 | 2648 |
} |
2649 |
clear_town_stuff:; |
|
2650 |
||
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
2651 |
if (CmdFailed(ret)) return CMD_ERROR; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
2652 |
total_cost.AddCost(ret); |
0 | 2653 |
|
2654 |
if (_cleared_town != NULL) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2655 |
if (t != NULL && t != _cleared_town) return CMD_ERROR; |
0 | 2656 |
t = _cleared_town; |
2657 |
rating += _cleared_town_rating; |
|
2658 |
} |
|
2659 |
} else if (p->mode == 3) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2660 |
if (flag & DC_EXEC) continue; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2661 |
|
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
2662 |
if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2663 |
|
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
2664 |
if (!IsTileType(c, MP_ROAD) || GetRoadTileType(c) != ROAD_TILE_NORMAL) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
2665 |
ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
2666 |
if (CmdFailed(ret)) return CMD_ERROR; |
0 | 2667 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2668 |
|
0 | 2669 |
} |
2670 |
} |
|
2671 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2672 |
if (!_want_road_truck_station && !(roadflag & 2)) return CMD_ERROR; |
0 | 2673 |
|
2674 |
if (!(flag & DC_EXEC)) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2675 |
if (t != NULL && rating > t->ratings[_current_player]) return CMD_ERROR; |
0 | 2676 |
} |
2677 |
return total_cost; |
|
2678 |
} |
|
2679 |
||
2680 |
// Make sure the blocks are not too close to each other |
|
2681 |
static bool AiCheckBlockDistances(Player *p, TileIndex tile) |
|
2682 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2683 |
const AiBuildRec* aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2684 |
uint num = _players_ai[p->index].num_build_rec; |
0 | 2685 |
|
2686 |
do { |
|
2687 |
if (aib->cur_building_rule != 255) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2688 |
if (DistanceManhattan(aib->use_tile, tile) < 9) return false; |
0 | 2689 |
} |
2690 |
} while (++aib, --num); |
|
2691 |
||
2692 |
return true; |
|
2693 |
} |
|
2694 |
||
2695 |
||
2696 |
static void AiStateBuildDefaultRoadBlocks(Player *p) |
|
2697 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2698 |
uint i; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2699 |
int j; |
0 | 2700 |
AiBuildRec *aib; |
2701 |
int rule; |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2702 |
CommandCost cost; |
0 | 2703 |
|
2704 |
// time out? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2705 |
if (++_players_ai[p->index].timeout_counter == 1388) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2706 |
_players_ai[p->index].state = AIS_DELETE_RAIL_BLOCKS; |
0 | 2707 |
return; |
2708 |
} |
|
2709 |
||
2710 |
// do the following 8 times |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2711 |
for (i = 0; i != 8; i++) { |
0 | 2712 |
// check if we can build the default track |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2713 |
aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2714 |
j = _players_ai[p->index].num_build_rec; |
0 | 2715 |
do { |
2716 |
// this item has already been built? |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2717 |
if (aib->cur_building_rule != 255) continue; |
0 | 2718 |
|
2719 |
// adjust the coordinate randomly, |
|
2720 |
// to make sure that we find a position. |
|
2721 |
aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng); |
|
2722 |
||
2723 |
// check if the road can be built there. |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2724 |
rule = AiFindBestDefaultRoadBlock( |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2725 |
aib->use_tile, aib->direction, aib->cargo, &cost |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2726 |
); |
0 | 2727 |
|
2728 |
if (rule == -1) { |
|
2729 |
// cannot build, terraform after a while |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2730 |
if (_players_ai[p->index].state_counter >= 600) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2731 |
AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)_players_ai[p->index].state_mode); |
0 | 2732 |
} |
2733 |
// also try the other terraform direction |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2734 |
if (++_players_ai[p->index].state_counter >= 1000) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2735 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2736 |
_players_ai[p->index].state_mode = -_players_ai[p->index].state_mode; |
0 | 2737 |
} |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2738 |
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) { |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2739 |
CommandCost r; |
0 | 2740 |
|
2741 |
// player has money, build it. |
|
2742 |
aib->cur_building_rule = rule; |
|
2743 |
||
2744 |
r = AiDoBuildDefaultRoadBlock( |
|
2745 |
aib->use_tile, |
|
2746 |
_road_default_block_data[rule]->data, |
|
2747 |
DC_EXEC | DC_NO_TOWN_RATING |
|
2748 |
); |
|
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
2749 |
assert(CmdSucceeded(r)); |
0 | 2750 |
} |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2751 |
} while (++aib, --j); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2752 |
} |
0 | 2753 |
|
2754 |
// check if we're done with all of them |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2755 |
aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2756 |
j = _players_ai[p->index].num_build_rec; |
0 | 2757 |
do { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2758 |
if (aib->cur_building_rule == 255) return; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
2759 |
} while (++aib, --j); |
0 | 2760 |
|
2761 |
// yep, all are done. switch state to the rail building state. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2762 |
_players_ai[p->index].state = AIS_BUILD_ROAD; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2763 |
_players_ai[p->index].state_mode = 255; |
0 | 2764 |
} |
2765 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2766 |
struct AiRoadFinder { |
0 | 2767 |
TileIndex final_tile; |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2768 |
DiagDirection final_dir; |
0 | 2769 |
byte depth; |
2770 |
byte recursive_mode; |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2771 |
DiagDirection cur_best_dir; |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2772 |
DiagDirection best_dir; |
0 | 2773 |
byte cur_best_depth; |
2774 |
byte best_depth; |
|
2775 |
uint cur_best_dist; |
|
2776 |
const byte *best_ptr; |
|
2777 |
uint best_dist; |
|
2778 |
TileIndex cur_best_tile, best_tile; |
|
2779 |
TileIndex bridge_end_tile; |
|
2780 |
Player *player; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2781 |
}; |
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2782 |
|
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2783 |
struct AiRoadEnum { |
0 | 2784 |
TileIndex dest; |
2785 |
TileIndex best_tile; |
|
2786 |
int best_track; |
|
2787 |
uint best_dist; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
2788 |
}; |
0 | 2789 |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2790 |
static const DiagDirection _dir_by_track[] = { |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2791 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2792 |
DIAGDIR_NE, DIAGDIR_NE, |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2793 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, |
0 | 2794 |
}; |
2795 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2796 |
static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, DiagDirection dir); |
0 | 2797 |
|
2798 |
static bool AiCheckRoadPathBetter(AiRoadFinder *arf, const byte *p) |
|
2799 |
{ |
|
2800 |
bool better = false; |
|
2801 |
||
2802 |
if (arf->recursive_mode < 1) { |
|
2803 |
// Mode is 0. This means destination has not been found yet. |
|
2804 |
// If the found path is shorter than the current one, remember it. |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2805 |
if (arf->cur_best_dist < arf->best_dist || |
0 | 2806 |
(arf->cur_best_dist == arf->best_dist && arf->cur_best_depth < arf->best_depth)) { |
2807 |
arf->best_depth = arf->cur_best_depth; |
|
2808 |
arf->best_dist = arf->cur_best_dist; |
|
2809 |
arf->best_dir = arf->cur_best_dir; |
|
2810 |
arf->best_ptr = p; |
|
2811 |
arf->best_tile = arf->cur_best_tile; |
|
2812 |
better = true; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2813 |
} |
0 | 2814 |
} else if (arf->recursive_mode > 1) { |
2815 |
// Mode is 2. |
|
2816 |
if (arf->best_dist != 0 || arf->cur_best_depth < arf->best_depth) { |
|
2817 |
arf->best_depth = arf->cur_best_depth; |
|
2818 |
arf->best_dist = 0; |
|
2819 |
arf->best_ptr = p; |
|
2820 |
arf->best_tile = 0; |
|
2821 |
better = true; |
|
2822 |
} |
|
2823 |
} |
|
2824 |
arf->recursive_mode = 0; |
|
2825 |
arf->cur_best_dist = (uint)-1; |
|
2826 |
arf->cur_best_depth = 0xff; |
|
2827 |
||
2828 |
return better; |
|
2829 |
} |
|
2830 |
||
2831 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
2832 |
static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, int track, uint length, byte *state) |
0 | 2833 |
{ |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
2834 |
uint dist = DistanceManhattan(tile, a->dest); |
0 | 2835 |
|
2836 |
if (dist <= a->best_dist) { |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2837 |
TileIndex tile2 = TILE_MASK(tile + TileOffsByDiagDir(_dir_by_track[track])); |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
2838 |
|
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
2839 |
if (IsTileType(tile2, MP_ROAD) && GetRoadTileType(tile2) == ROAD_TILE_NORMAL) { |
0 | 2840 |
a->best_dist = dist; |
2841 |
a->best_tile = tile; |
|
2842 |
a->best_track = track; |
|
2843 |
} |
|
2844 |
} |
|
2845 |
||
2846 |
return false; |
|
2847 |
} |
|
2848 |
||
2849 |
static const uint16 _ai_road_table_and[4] = { |
|
2850 |
0x1009, |
|
2851 |
0x16, |
|
2852 |
0x520, |
|
2853 |
0x2A00, |
|
2854 |
}; |
|
2855 |
||
410 | 2856 |
static bool AiCheckRoadFinished(Player *p) |
0 | 2857 |
{ |
2858 |
AiRoadEnum are; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
2859 |
TileIndex tile; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2860 |
DiagDirection dir = _players_ai[p->index].cur_dir_a; |
0 | 2861 |
uint32 bits; |
2862 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2863 |
are.dest = _players_ai[p->index].cur_tile_b; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2864 |
tile = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(dir)); |
0 | 2865 |
|
5028
fef7184a6b6c
(svn r7069) -Fix: AI tried to build road from the back or side of road stop/depot (peter1138)
KUDr
parents:
5016
diff
changeset
|
2866 |
if (IsRoadStopTile(tile) || IsTileDepotType(tile, TRANSPORT_ROAD)) return false; |
7179
3e123c2b7c93
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
7177
diff
changeset
|
2867 |
bits = GetTileTrackStatus(tile, TRANSPORT_ROAD, ROADTYPES_ROAD) & _ai_road_table_and[dir]; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2868 |
if (bits == 0) return false; |
0 | 2869 |
|
2870 |
are.best_dist = (uint)-1; |
|
2871 |
||
8501
66d88113ba24
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
8463
diff
changeset
|
2872 |
uint i; |
66d88113ba24
(svn r11564) -Codechange: Increase the usage of the for_each_bit macro and rename it fitting to the naming style
skidd13
parents:
8463
diff
changeset
|
2873 |
FOR_EACH_SET_BIT(i, bits) { |
7179
3e123c2b7c93
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
7177
diff
changeset
|
2874 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, ROADTYPES_ROAD, (DiagDirection)_dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are); |
0 | 2875 |
} |
2876 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2877 |
if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2878 |
|
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2879 |
if (are.best_dist == 0) return true; |
0 | 2880 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2881 |
_players_ai[p->index].cur_tile_a = are.best_tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
2882 |
_players_ai[p->index].cur_dir_a = _dir_by_track[are.best_track]; |
0 | 2883 |
return false; |
2884 |
} |
|
2885 |
||
2886 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
2887 |
static bool AiBuildRoadHelper(TileIndex tile, int flags, int type) |
0 | 2888 |
{ |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2889 |
static const RoadBits _road_bits[] = { |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2890 |
ROAD_X, |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2891 |
ROAD_Y, |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2892 |
ROAD_NW | ROAD_NE, |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2893 |
ROAD_SW | ROAD_SE, |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2894 |
ROAD_NW | ROAD_SW, |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
2895 |
ROAD_SE | ROAD_NE |
0 | 2896 |
}; |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
2897 |
return CmdSucceeded(DoCommand(tile, _road_bits[type], 0, flags, CMD_BUILD_ROAD)); |
0 | 2898 |
} |
2899 |
||
536 | 2900 |
static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p) |
0 | 2901 |
{ |
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
2902 |
Slope tileh; |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2903 |
uint z; |
0 | 2904 |
bool flag; |
2905 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2906 |
DiagDirection dir2 = (DiagDirection)(p[0] & 3); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2907 |
|
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2908 |
tileh = GetTileSlope(tile, &z); |
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3609
diff
changeset
|
2909 |
if (tileh == _dir_table_1[dir2] || (tileh == SLOPE_FLAT && z != 0)) { |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2910 |
TileIndex tile_new = tile; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2911 |
|
0 | 2912 |
// Allow bridges directly over bottom tiles |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2913 |
flag = z == 0; |
2952 | 2914 |
for (;;) { |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2915 |
TileType type; |
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2916 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2917 |
if ((TileIndexDiff)tile_new < -TileOffsByDiagDir(dir2)) return; // Wraping around map, no bridge possible! |
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2918 |
tile_new = TILE_MASK(tile_new + TileOffsByDiagDir(dir2)); |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2919 |
type = GetTileType(tile_new); |
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2920 |
|
8847
98ccd8072daf
(svn r11917) -Fix (r3677): AI was reading wrong tile slope while building road bridge
smatz
parents:
8818
diff
changeset
|
2921 |
if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) { |
0 | 2922 |
// Allow a bridge if either we have a tile that's water, rail or street, |
2923 |
// or if we found an up tile. |
|
2924 |
if (!flag) return; |
|
2925 |
break; |
|
2926 |
} |
|
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
2927 |
if (type != MP_WATER && type != MP_RAILWAY && type != MP_ROAD) return; |
0 | 2928 |
flag = true; |
2929 |
} |
|
2930 |
||
2931 |
// Is building a (rail)bridge possible at this place (type doesn't matter)? |
|
7338
5bb335d2eb54
(svn r10081) -Fix [FS851]: towns/AIs didn't build bridges anymore (boekabart).
rubidium
parents:
7315
diff
changeset
|
2932 |
if (CmdFailed(DoCommand(tile_new, tile, ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE))) |
0 | 2933 |
return; |
2934 |
AiBuildRoadRecursive(arf, tile_new, dir2); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2935 |
|
0 | 2936 |
// At the bottom depth, check if the new path is better than the old one. |
2937 |
if (arf->depth == 1) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
2938 |
if (AiCheckRoadPathBetter(arf, p)) arf->bridge_end_tile = tile_new; |
0 | 2939 |
} |
2940 |
} |
|
2941 |
} |
|
2942 |
||
536 | 2943 |
static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile, const byte *p) |
0 | 2944 |
{ |
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2945 |
uint z; |
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2946 |
|
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2947 |
if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) { |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
2948 |
CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL); |
0 | 2949 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
2950 |
if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2951 |
AiBuildRoadRecursive(arf, _build_tunnel_endtile, (DiagDirection)(p[0] & 3)); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
2952 |
if (arf->depth == 1) AiCheckRoadPathBetter(arf, p); |
0 | 2953 |
} |
2954 |
} |
|
2955 |
} |
|
2956 |
||
2957 |
||
2958 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2959 |
static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, DiagDirection dir) |
0 | 2960 |
{ |
2961 |
const byte *p; |
|
2962 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
2963 |
tile = TILE_MASK(tile + TileOffsByDiagDir(dir)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2964 |
|
0 | 2965 |
// Reached destination? |
2966 |
if (tile == arf->final_tile) { |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
2967 |
if (ReverseDiagDir(arf->final_dir) == dir) { |
0 | 2968 |
arf->recursive_mode = 2; |
2969 |
arf->cur_best_depth = arf->depth; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
2970 |
} |
0 | 2971 |
return; |
2972 |
} |
|
2973 |
||
2974 |
// Depth too deep? |
|
2975 |
if (arf->depth >= 4) { |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
2976 |
uint dist = DistanceMaxPlusManhattan(tile, arf->final_tile); |
0 | 2977 |
if (dist < arf->cur_best_dist) { |
2978 |
// Store the tile that is closest to the final position. |
|
2979 |
arf->cur_best_dist = dist; |
|
2980 |
arf->cur_best_tile = tile; |
|
2981 |
arf->cur_best_dir = dir; |
|
2982 |
arf->cur_best_depth = arf->depth; |
|
2983 |
} |
|
2984 |
return; |
|
2985 |
} |
|
2986 |
||
2987 |
// Increase recursion depth |
|
2988 |
arf->depth++; |
|
2989 |
||
2990 |
// Grab pointer to list of stuff that is possible to build |
|
2991 |
p = _ai_table_15[dir]; |
|
2992 |
||
2993 |
// Try to build a single rail in all directions. |
|
3088
4570504ac734
(svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents:
3071
diff
changeset
|
2994 |
if (GetTileZ(tile) == 0) { |
0 | 2995 |
p += 6; |
2996 |
} else { |
|
2997 |
do { |
|
2998 |
// Make sure that a road can be built here. |
|
2999 |
if (AiBuildRoadHelper(tile, DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, p[0])) { |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
3000 |
AiBuildRoadRecursive(arf, tile, (DiagDirection)p[1]); |
0 | 3001 |
} |
3002 |
||
3003 |
// At the bottom depth? |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3004 |
if (arf->depth == 1) AiCheckRoadPathBetter(arf, p); |
0 | 3005 |
|
3006 |
p += 2; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3007 |
} while (!(p[0] & 0x80)); |
0 | 3008 |
} |
3009 |
||
3010 |
AiCheckBuildRoadBridgeHere(arf, tile, p); |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3011 |
AiCheckBuildRoadTunnelHere(arf, tile, p + 1); |
0 | 3012 |
|
3013 |
arf->depth--; |
|
3014 |
} |
|
3015 |
||
3016 |
||
3017 |
static void AiBuildRoadConstruct(Player *p) |
|
3018 |
{ |
|
3019 |
AiRoadFinder arf; |
|
3020 |
int i; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
3021 |
TileIndex tile; |
0 | 3022 |
|
3023 |
// Reached destination? |
|
3024 |
if (AiCheckRoadFinished(p)) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3025 |
_players_ai[p->index].state_mode = 255; |
0 | 3026 |
return; |
3027 |
} |
|
3028 |
||
3029 |
// Setup recursive finder and call it. |
|
3030 |
arf.player = p; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3031 |
arf.final_tile = _players_ai[p->index].cur_tile_b; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3032 |
arf.final_dir = _players_ai[p->index].cur_dir_b; |
0 | 3033 |
arf.depth = 0; |
3034 |
arf.recursive_mode = 0; |
|
3035 |
arf.best_ptr = NULL; |
|
3036 |
arf.cur_best_dist = (uint)-1; |
|
3037 |
arf.cur_best_depth = 0xff; |
|
3038 |
arf.best_dist = (uint)-1; |
|
3039 |
arf.best_depth = 0xff; |
|
3040 |
arf.cur_best_tile = 0; |
|
3041 |
arf.best_tile = 0; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3042 |
AiBuildRoadRecursive(&arf, _players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a); |
0 | 3043 |
|
3044 |
// Reached destination? |
|
3045 |
if (arf.recursive_mode == 2 && arf.cur_best_depth == 0) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3046 |
_players_ai[p->index].state_mode = 255; |
0 | 3047 |
return; |
3048 |
} |
|
3049 |
||
3050 |
// Didn't find anything to build? |
|
3051 |
if (arf.best_ptr == NULL) { |
|
3052 |
// Terraform some |
|
3053 |
do_some_terraform: |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3054 |
for (i = 0; i != 5; i++) |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3055 |
AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3056 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3057 |
if (++_players_ai[p->index].state_counter == 21) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3058 |
_players_ai[p->index].state_mode = 1; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3059 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3060 |
_players_ai[p->index].cur_tile_a = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a)); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3061 |
_players_ai[p->index].cur_dir_a = ReverseDiagDir(_players_ai[p->index].cur_dir_a); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3062 |
_players_ai[p->index].state_counter = 0; |
0 | 3063 |
} |
3064 |
return; |
|
3065 |
} |
|
3066 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3067 |
tile = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a)); |
0 | 3068 |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3069 |
if (arf.best_ptr[0] & 0x80) { |
0 | 3070 |
int i; |
3071 |
int32 bridge_len; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3072 |
_players_ai[p->index].cur_tile_a = arf.bridge_end_tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3073 |
bridge_len = GetBridgeLength(tile, _players_ai[p->index].cur_tile_a); // tile |
0 | 3074 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
3075 |
/* Figure out what (road)bridge type to build |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
3076 |
* start with best bridge, then go down to worse and worse bridges |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
3077 |
* unnecessary to check for worse bridge (i=0), since AI will always build that. |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
3078 |
*AI is so fucked up that fixing this small thing will probably not solve a thing |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
3079 |
*/ |
2952 | 3080 |
for (i = 10; i != 0; i--) { |
0 | 3081 |
if (CheckBridge_Stuff(i, bridge_len)) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3082 |
CommandCost cost = DoCommand(tile, _players_ai[p->index].cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE); |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
3083 |
if (CmdSucceeded(cost) && cost.GetCost() < (p->player_money >> 5)) break; |
0 | 3084 |
} |
3085 |
} |
|
3086 |
||
3087 |
// Build it |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3088 |
DoCommand(tile, _players_ai[p->index].cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO | DC_EXEC, CMD_BUILD_BRIDGE); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3089 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3090 |
_players_ai[p->index].state_counter = 0; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3091 |
} else if (arf.best_ptr[0] & 0x40) { |
0 | 3092 |
// tunnel |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3093 |
DoCommand(tile, 0x200, 0, DC_AUTO | DC_EXEC, CMD_BUILD_TUNNEL); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3094 |
_players_ai[p->index].cur_tile_a = _build_tunnel_endtile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3095 |
_players_ai[p->index].state_counter = 0; |
0 | 3096 |
} else { |
3097 |
// road |
|
3098 |
if (!AiBuildRoadHelper(tile, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, arf.best_ptr[0])) |
|
3099 |
goto do_some_terraform; |
|
3100 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3101 |
_players_ai[p->index].cur_dir_a = (DiagDirection)(arf.best_ptr[1] & 3); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3102 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3103 |
_players_ai[p->index].state_counter = 0; |
0 | 3104 |
} |
3105 |
||
3106 |
if (arf.best_tile != 0) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3107 |
for (i = 0; i != 2; i++) |
0 | 3108 |
AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0); |
3109 |
} |
|
3110 |
} |
|
3111 |
||
3112 |
||
3113 |
static void AiBuildRoad(Player *p) |
|
3114 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3115 |
if (_players_ai[p->index].state_mode < 1) { |
0 | 3116 |
// Construct mode, build new road. |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3117 |
AiBuildRoadConstruct(p); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3118 |
} else if (_players_ai[p->index].state_mode == 1) { |
0 | 3119 |
// Destruct mode, not implemented for roads. |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3120 |
_players_ai[p->index].state_mode = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3121 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3122 |
} else if (_players_ai[p->index].state_mode == 2) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3123 |
uint i; |
0 | 3124 |
|
3125 |
// Terraform some and then try building again. |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3126 |
for (i = 0; i != 4; i++) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3127 |
AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3128 |
} |
0 | 3129 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3130 |
if (++_players_ai[p->index].state_counter == 4) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3131 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3132 |
_players_ai[p->index].state_mode = 0; |
0 | 3133 |
} |
3134 |
} |
|
3135 |
} |
|
3136 |
||
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
3137 |
static TileIndex AiGetRoadBlockEdge(byte rule, TileIndex tile, DiagDirection *dir) |
0 | 3138 |
{ |
3139 |
const AiDefaultBlockData *p = _road_default_block_data[rule]->data; |
|
3140 |
while (p->mode != 1) p++; |
|
3141 |
*dir = p->attr; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
3142 |
return TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)); |
0 | 3143 |
} |
3144 |
||
3145 |
||
3146 |
static void AiStateBuildRoad(Player *p) |
|
3147 |
{ |
|
3148 |
int num; |
|
3149 |
AiBuildRec *aib; |
|
3150 |
byte cmd; |
|
3151 |
TileIndex tile; |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7486
diff
changeset
|
3152 |
DiagDirection dir; |
0 | 3153 |
|
3154 |
// time out? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3155 |
if (++_players_ai[p->index].timeout_counter == 1388) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3156 |
_players_ai[p->index].state = AIS_DELETE_ROAD_BLOCKS; |
0 | 3157 |
return; |
3158 |
} |
|
3159 |
||
3160 |
// Currently building a road between two points? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3161 |
if (_players_ai[p->index].state_mode != 255) { |
0 | 3162 |
AiBuildRoad(p); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3163 |
|
0 | 3164 |
// Alternate between edges |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3165 |
Swap(_players_ai[p->index].start_tile_a, _players_ai[p->index].start_tile_b); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3166 |
Swap(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_tile_b); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3167 |
Swap(_players_ai[p->index].start_dir_a, _players_ai[p->index].start_dir_b); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3168 |
Swap(_players_ai[p->index].cur_dir_a, _players_ai[p->index].cur_dir_b); |
0 | 3169 |
|
3170 |
return; |
|
3171 |
} |
|
3172 |
||
3173 |
// Now, find two new points to build between |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3174 |
num = _players_ai[p->index].num_build_rec; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3175 |
aib = &_players_ai[p->index].src; |
0 | 3176 |
|
2952 | 3177 |
for (;;) { |
0 | 3178 |
cmd = aib->buildcmd_a; |
3179 |
aib->buildcmd_a = 255; |
|
3180 |
if (cmd != 255) break; |
|
3181 |
||
3182 |
aib++; |
|
3183 |
if (--num == 0) { |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3184 |
_players_ai[p->index].state = AIS_BUILD_ROAD_VEHICLES; |
0 | 3185 |
return; |
3186 |
} |
|
3187 |
} |
|
3188 |
||
3189 |
// Find first edge to build from. |
|
3190 |
tile = AiGetRoadBlockEdge(aib->cur_building_rule, aib->use_tile, &dir); |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3191 |
_players_ai[p->index].start_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3192 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3193 |
_players_ai[p->index].start_dir_a = dir; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3194 |
_players_ai[p->index].cur_dir_a = dir; |
0 | 3195 |
|
3196 |
// Find second edge to build to |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3197 |
aib = (&_players_ai[p->index].src) + (cmd & 0xF); |
0 | 3198 |
tile = AiGetRoadBlockEdge(aib->cur_building_rule, aib->use_tile, &dir); |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3199 |
_players_ai[p->index].start_tile_b = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3200 |
_players_ai[p->index].cur_tile_b = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3201 |
_players_ai[p->index].start_dir_b = dir; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3202 |
_players_ai[p->index].cur_dir_b = dir; |
0 | 3203 |
|
3204 |
// And setup state. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3205 |
_players_ai[p->index].state_mode = 2; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3206 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3207 |
_players_ai[p->index].banned_tile_count = 0; |
0 | 3208 |
} |
3209 |
||
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
3210 |
static StationID AiGetStationIdFromRoadBlock(TileIndex tile, int id) |
0 | 3211 |
{ |
3212 |
const AiDefaultBlockData *p = _road_default_block_data[id]->data; |
|
3213 |
while (p->mode != 1) p++; |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
3214 |
return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); |
0 | 3215 |
} |
3216 |
||
3217 |
static void AiStateBuildRoadVehicles(Player *p) |
|
3218 |
{ |
|
3219 |
const AiDefaultBlockData *ptr; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
3220 |
TileIndex tile; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3221 |
VehicleID loco_id; |
2551
436aaaa22ba5
(svn r3080) byte -> PlayerID, int -> EngineID, -1 -> INVALID_ENGINE
tron
parents:
2544
diff
changeset
|
3222 |
EngineID veh; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3223 |
uint i; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3224 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3225 |
ptr = _road_default_block_data[_players_ai[p->index].src.cur_building_rule]->data; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3226 |
for (; ptr->mode != 0; ptr++) {} |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3227 |
tile = TILE_ADD(_players_ai[p->index].src.use_tile, ToTileIndexDiff(ptr->tileoffs)); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3228 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3229 |
veh = AiChooseRoadVehToBuild(_players_ai[p->index].cargo_type, p->player_money, tile); |
2551
436aaaa22ba5
(svn r3080) byte -> PlayerID, int -> EngineID, -1 -> INVALID_ENGINE
tron
parents:
2544
diff
changeset
|
3230 |
if (veh == INVALID_ENGINE) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3231 |
_players_ai[p->index].state = AIS_0; |
0 | 3232 |
return; |
3233 |
} |
|
3234 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3235 |
if (CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) return; |
0 | 3236 |
|
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3933
diff
changeset
|
3237 |
loco_id = _new_vehicle_id; |
0 | 3238 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3239 |
if (GetVehicle(loco_id)->cargo_type != _players_ai[p->index].cargo_type) { |
5031
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3240 |
/* Cargo type doesn't match, so refit it */ |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3241 |
if (CmdFailed(DoCommand(tile, loco_id, _players_ai[p->index].cargo_type, DC_EXEC, CMD_REFIT_ROAD_VEH))) { |
5031
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3242 |
/* Refit failed... sell the vehicle */ |
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3243 |
DoCommand(tile, loco_id, 0, DC_EXEC, CMD_SELL_ROAD_VEH); |
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3244 |
return; |
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3245 |
} |
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3246 |
} |
940b1fec4220
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents:
5029
diff
changeset
|
3247 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3248 |
for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3249 |
const AiBuildRec* aib = &_players_ai[p->index].src + _players_ai[p->index].order_list_blocks[i]; |
2639 | 3250 |
bool is_pass = ( |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3251 |
_players_ai[p->index].cargo_type == CT_PASSENGERS || |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3252 |
_players_ai[p->index].cargo_type == CT_MAIL || |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3253 |
(_opt.landscape == LT_TEMPERATE && _players_ai[p->index].cargo_type == CT_VALUABLES) |
2639 | 3254 |
); |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3255 |
Order order; |
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3256 |
|
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3257 |
order.type = OT_GOTO_STATION; |
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3258 |
order.flags = 0; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4495
diff
changeset
|
3259 |
order.dest = AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule); |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3260 |
|
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
3261 |
if (!is_pass && i == 1) order.flags |= OFB_UNLOAD; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3262 |
if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0)) |
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
3263 |
order.flags |= OFB_FULL_LOAD; |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3264 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4389
diff
changeset
|
3265 |
DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
0 | 3266 |
} |
3267 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3268 |
DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3269 |
DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); |
0 | 3270 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3271 |
if (_players_ai[p->index].num_want_fullload != 0) _players_ai[p->index].num_want_fullload--; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3272 |
if (--_players_ai[p->index].num_loco_to_build == 0) _players_ai[p->index].state = AIS_0; |
0 | 3273 |
} |
3274 |
||
3275 |
static void AiStateDeleteRoadBlocks(Player *p) |
|
3276 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3277 |
const AiBuildRec* aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3278 |
uint num = _players_ai[p->index].num_build_rec; |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3279 |
|
0 | 3280 |
do { |
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3281 |
const AiDefaultBlockData* b; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3282 |
|
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3283 |
if (aib->cur_building_rule == 255) continue; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3284 |
for (b = _road_default_block_data[aib->cur_building_rule]->data; b->mode != 4; b++) { |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3285 |
if (b->mode > 1) continue; |
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3286 |
DoCommand(TILE_ADD(aib->use_tile, ToTileIndexDiff(b->tileoffs)), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 3287 |
} |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3288 |
} while (++aib, --num); |
0 | 3289 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3290 |
_players_ai[p->index].state = AIS_0; |
0 | 3291 |
} |
3292 |
||
3293 |
||
3294 |
static void AiStateAirportStuff(Player *p) |
|
3295 |
{ |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3296 |
const Station* st; |
0 | 3297 |
int i; |
3298 |
AiBuildRec *aib; |
|
3299 |
byte rule; |
|
3300 |
||
3301 |
// Here we look for an airport we could use instead of building a new |
|
3302 |
// one. If we find such an aiport for any waypoint, |
|
3303 |
// AiStateBuildDefaultAirportBlocks() will kindly skip that one when |
|
3304 |
// building the waypoints. |
|
3305 |
||
3306 |
i = 0; |
|
3307 |
do { |
|
3308 |
// We do this all twice - once for the source (town in the case |
|
3309 |
// of oilrig route) and then for the destination (oilrig in the |
|
3310 |
// case of oilrig route). |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3311 |
aib = &_players_ai[p->index].src + i; |
0 | 3312 |
|
3313 |
FOR_ALL_STATIONS(st) { |
|
3314 |
// Is this an airport? |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3315 |
if (!(st->facilities & FACIL_AIRPORT)) continue; |
0 | 3316 |
|
3317 |
// Do we own the airport? (Oilrigs aren't owned, though.) |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3318 |
if (st->owner != OWNER_NONE && st->owner != _current_player) continue; |
0 | 3319 |
|
6358 | 3320 |
AirportFTAClass::Flags flags = st->Airport()->flags; |
6350 | 3321 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3322 |
if (!(flags & (_players_ai[p->index].build_kind == 1 && i == 0 ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES))) { |
0 | 3323 |
continue; |
6350 | 3324 |
} |
0 | 3325 |
|
3326 |
// Dismiss airports too far away. |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1224
diff
changeset
|
3327 |
if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng) |
0 | 3328 |
continue; |
3329 |
||
3330 |
// It's ideal airport, let's take it! |
|
3331 |
||
3332 |
/* XXX: This part is utterly broken - rule should |
|
3333 |
* contain number of the rule appropriate for the |
|
3334 |
* airport type (country, town, ...), see |
|
3335 |
* _airport_default_block_data (rule is just an index |
|
3336 |
* in this array). But the only difference between the |
|
3337 |
* currently existing two rules (rule 0 - town and rule |
|
3338 |
* 1 - country) is the attr field which is used only |
|
3339 |
* when building new airports - and that's irrelevant |
|
3340 |
* for us. So using just about any rule will suffice |
|
3341 |
* here for now (some of the new airport types would be |
|
3342 |
* broken because they will probably need different |
|
3343 |
* tileoff values etc), no matter that |
|
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3336
diff
changeset
|
3344 |
* IsHangarTile() makes no sense. --pasky */ |
6353
75b086ef8ef1
(svn r8750) -Fix (r8747): PLANES defined in wingdi.h caused compilation error under Win32. Changed to AIRPLANES
KUDr
parents:
6350
diff
changeset
|
3345 |
if (!(flags & AirportFTAClass::AIRPLANES)) { |
0 | 3346 |
/* Heliports should have maybe own rulesets but |
3347 |
* OTOH we don't want AI to pick them up when |
|
3348 |
* looking for a suitable airport type to build. |
|
3349 |
* So any of rules 0 or 1 would do for now. The |
|
3350 |
* original rule number was 2 but that's a bug |
|
3351 |
* because we have no such rule. */ |
|
3352 |
rule = 1; |
|
3353 |
} else { |
|
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3336
diff
changeset
|
3354 |
rule = IsHangarTile(st->airport_tile); |
0 | 3355 |
} |
3356 |
||
3357 |
aib->cur_building_rule = rule; |
|
3358 |
aib->use_tile = st->airport_tile; |
|
3359 |
break; |
|
3360 |
} |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3361 |
} while (++i != _players_ai[p->index].num_build_rec); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3362 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3363 |
_players_ai[p->index].state = AIS_BUILD_DEFAULT_AIRPORT_BLOCKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3364 |
_players_ai[p->index].state_mode = 255; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3365 |
_players_ai[p->index].state_counter = 0; |
0 | 3366 |
} |
3367 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
3368 |
static CommandCost AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag) |
0 | 3369 |
{ |
6222 | 3370 |
uint32 avail_airports = GetValidAirports(); |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8725
diff
changeset
|
3371 |
CommandCost ret,total_cost(EXPENSES_CONSTRUCTION); |
0 | 3372 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3373 |
for (; p->mode == 0; p++) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8149
diff
changeset
|
3374 |
if (!HasBit(avail_airports, p->attr)) return CMD_ERROR; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3375 |
ret = DoCommand(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_AIRPORT); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1640
diff
changeset
|
3376 |
if (CmdFailed(ret)) return CMD_ERROR; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
3377 |
total_cost.AddCost(ret); |
0 | 3378 |
} |
3379 |
||
3380 |
return total_cost; |
|
3381 |
} |
|
3382 |
||
3383 |
static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo) |
|
3384 |
{ |
|
3385 |
uint values[NUM_CARGO]; |
|
3386 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3387 |
for (; p->mode == 0; p++) { |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
3388 |
TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)); |
3876
c0d426e78b56
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3871
diff
changeset
|
3389 |
const AirportFTAClass* airport = GetAirport(p->attr); |
c0d426e78b56
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3871
diff
changeset
|
3390 |
uint w = airport->size_x; |
c0d426e78b56
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents:
3871
diff
changeset
|
3391 |
uint h = airport->size_y; |
6367 | 3392 |
uint rad = _patches.modified_catchment ? airport->catchment : 4; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3393 |
|
0 | 3394 |
if (cargo & 0x80) { |
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
3395 |
GetProductionAroundTiles(values, tile2, w, h, rad); |
0 | 3396 |
return values[cargo & 0x7F] != 0; |
3397 |
} else { |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
558
diff
changeset
|
3398 |
GetAcceptanceAroundTiles(values, tile2, w, h, rad); |
0 | 3399 |
return values[cargo] >= 8; |
3400 |
} |
|
3401 |
} |
|
3402 |
return true; |
|
3403 |
} |
|
3404 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
3405 |
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost) |
0 | 3406 |
{ |
3407 |
const AiDefaultBlockData *p; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3408 |
uint i; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3409 |
|
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3410 |
for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) { |
0 | 3411 |
// If we are doing a helicopter service, avoid building |
3412 |
// airports where they can't land. |
|
6350 | 3413 |
if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue; |
0 | 3414 |
|
3415 |
*cost = AiDoBuildDefaultAirportBlock(tile, p, 0); |
|
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
3416 |
if (CmdSucceeded(*cost) && AiCheckAirportResources(tile, p, cargo)) |
0 | 3417 |
return i; |
3418 |
} |
|
3419 |
return -1; |
|
3420 |
} |
|
3421 |
||
3422 |
static void AiStateBuildDefaultAirportBlocks(Player *p) |
|
3423 |
{ |
|
3424 |
int i, j; |
|
3425 |
AiBuildRec *aib; |
|
3426 |
int rule; |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
3427 |
CommandCost cost; |
0 | 3428 |
|
3429 |
// time out? |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3430 |
if (++_players_ai[p->index].timeout_counter == 1388) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3431 |
_players_ai[p->index].state = AIS_0; |
0 | 3432 |
return; |
3433 |
} |
|
3434 |
||
3435 |
// do the following 8 times |
|
3436 |
i = 8; |
|
3437 |
do { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3438 |
// check if we can build the default |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3439 |
aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3440 |
j = _players_ai[p->index].num_build_rec; |
0 | 3441 |
do { |
3442 |
// this item has already been built? |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3443 |
if (aib->cur_building_rule != 255) continue; |
0 | 3444 |
|
3445 |
// adjust the coordinate randomly, |
|
3446 |
// to make sure that we find a position. |
|
3447 |
aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng); |
|
3448 |
||
3449 |
// check if the aircraft stuff can be built there. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3450 |
rule = AiFindBestDefaultAirportBlock(aib->use_tile, aib->cargo, _players_ai[p->index].build_kind, &cost); |
0 | 3451 |
|
1861
8b6f1d021317
(svn r2367) Remove some unused functions, probably was some debug stuff
tron
parents:
1767
diff
changeset
|
3452 |
// SetRedErrorSquare(aib->use_tile); |
0 | 3453 |
|
3454 |
if (rule == -1) { |
|
3455 |
// cannot build, terraform after a while |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3456 |
if (_players_ai[p->index].state_counter >= 600) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3457 |
AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)_players_ai[p->index].state_mode); |
0 | 3458 |
} |
3459 |
// also try the other terraform direction |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3460 |
if (++_players_ai[p->index].state_counter >= 1000) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3461 |
_players_ai[p->index].state_counter = 0; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3462 |
_players_ai[p->index].state_mode = -_players_ai[p->index].state_mode; |
0 | 3463 |
} |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3464 |
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) { |
0 | 3465 |
// player has money, build it. |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7362
diff
changeset
|
3466 |
CommandCost r; |
0 | 3467 |
|
3468 |
aib->cur_building_rule = rule; |
|
3469 |
||
3470 |
r = AiDoBuildDefaultAirportBlock( |
|
3471 |
aib->use_tile, |
|
3472 |
_airport_default_block_data[rule], |
|
3473 |
DC_EXEC | DC_NO_TOWN_RATING |
|
3474 |
); |
|
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
3475 |
assert(CmdSucceeded(r)); |
0 | 3476 |
} |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3477 |
} while (++aib, --j); |
0 | 3478 |
} while (--i); |
3479 |
||
3480 |
// check if we're done with all of them |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3481 |
aib = &_players_ai[p->index].src; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3482 |
j = _players_ai[p->index].num_build_rec; |
0 | 3483 |
do { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3484 |
if (aib->cur_building_rule == 255) return; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3485 |
} while (++aib, --j); |
0 | 3486 |
|
3487 |
// yep, all are done. switch state. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3488 |
_players_ai[p->index].state = AIS_BUILD_AIRCRAFT_VEHICLES; |
0 | 3489 |
} |
3490 |
||
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
3491 |
static StationID AiGetStationIdFromAircraftBlock(TileIndex tile, int id) |
0 | 3492 |
{ |
3493 |
const AiDefaultBlockData *p = _airport_default_block_data[id]; |
|
3494 |
while (p->mode != 1) p++; |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3269
diff
changeset
|
3495 |
return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); |
0 | 3496 |
} |
3497 |
||
3498 |
static void AiStateBuildAircraftVehicles(Player *p) |
|
3499 |
{ |
|
3500 |
const AiDefaultBlockData *ptr; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1927
diff
changeset
|
3501 |
TileIndex tile; |
2544 | 3502 |
EngineID veh; |
0 | 3503 |
int i; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3504 |
VehicleID loco_id; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3505 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3506 |
ptr = _airport_default_block_data[_players_ai[p->index].src.cur_building_rule]; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3507 |
for (; ptr->mode != 0; ptr++) {} |
0 | 3508 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3509 |
tile = TILE_ADD(_players_ai[p->index].src.use_tile, ToTileIndexDiff(ptr->tileoffs)); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3510 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3511 |
veh = AiChooseAircraftToBuild(p->player_money, _players_ai[p->index].build_kind != 0 ? 0 : AIR_CTOL); |
2544 | 3512 |
if (veh == INVALID_ENGINE) return; |
2423
84222db5a01a
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2381
diff
changeset
|
3513 |
|
84222db5a01a
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2381
diff
changeset
|
3514 |
/* XXX - Have the AI pick the hangar terminal in an airport. Eg get airport-type |
84222db5a01a
(svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents:
2381
diff
changeset
|
3515 |
* and offset to the FIRST depot because the AI picks the st->xy tile */ |
6358 | 3516 |
tile += ToTileIndexDiff(GetStationByTile(tile)->Airport()->airport_depots[0]); |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3517 |
if (CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) return; |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3933
diff
changeset
|
3518 |
loco_id = _new_vehicle_id; |
0 | 3519 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3520 |
for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3521 |
AiBuildRec *aib = (&_players_ai[p->index].src) + _players_ai[p->index].order_list_blocks[i]; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3522 |
bool is_pass = (_players_ai[p->index].cargo_type == CT_PASSENGERS || _players_ai[p->index].cargo_type == CT_MAIL); |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3523 |
Order order; |
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3524 |
|
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3525 |
order.type = OT_GOTO_STATION; |
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3526 |
order.flags = 0; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4495
diff
changeset
|
3527 |
order.dest = AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule); |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3528 |
|
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
3529 |
if (!is_pass && i == 1) order.flags |= OFB_UNLOAD; |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3530 |
if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0)) |
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
3531 |
order.flags |= OFB_FULL_LOAD; |
558
9b115b39c515
(svn r960) -Fix: forgotten conversion of orders for the AI (Tron)
darkvater
parents:
555
diff
changeset
|
3532 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3533 |
DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
0 | 3534 |
} |
3535 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3536 |
DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3537 |
|
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3538 |
DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); |
0 | 3539 |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3540 |
if (_players_ai[p->index].num_want_fullload != 0) _players_ai[p->index].num_want_fullload--; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3541 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3542 |
if (--_players_ai[p->index].num_loco_to_build == 0) _players_ai[p->index].state = AIS_0; |
0 | 3543 |
} |
3544 |
||
3545 |
static void AiStateCheckShipStuff(Player *p) |
|
3546 |
{ |
|
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
3547 |
/* Ships are not implemented in this (broken) AI */ |
0 | 3548 |
} |
3549 |
||
3550 |
static void AiStateBuildDefaultShipBlocks(Player *p) |
|
3551 |
{ |
|
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
3552 |
/* Ships are not implemented in this (broken) AI */ |
0 | 3553 |
} |
3554 |
||
3555 |
static void AiStateDoShipStuff(Player *p) |
|
3556 |
{ |
|
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
3557 |
/* Ships are not implemented in this (broken) AI */ |
0 | 3558 |
} |
3559 |
||
3560 |
static void AiStateSellVeh(Player *p) |
|
3561 |
{ |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3562 |
Vehicle *v = _players_ai[p->index].cur_veh; |
0 | 3563 |
|
3564 |
if (v->owner == _current_player) { |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
3565 |
if (v->type == VEH_TRAIN) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3566 |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
3567 |
if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
539
diff
changeset
|
3568 |
if (v->current_order.type != OT_GOTO_DEPOT) |
4495
b44566fc9025
(svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents:
4434
diff
changeset
|
3569 |
DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_TRAIN_TO_DEPOT); |
0 | 3570 |
goto going_to_depot; |
3571 |
} |
|
3572 |
||
3573 |
// Sell whole train |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3574 |
DoCommand(v->tile, v->index, 1, DC_EXEC, CMD_SELL_RAIL_WAGON); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3575 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
3576 |
} else if (v->type == VEH_ROAD) { |
7986
881998b115c2
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7951
diff
changeset
|
3577 |
if (!v->IsStoppedInDepot()) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
539
diff
changeset
|
3578 |
if (v->current_order.type != OT_GOTO_DEPOT) |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3579 |
DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); |
0 | 3580 |
goto going_to_depot; |
3581 |
} |
|
3582 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3583 |
DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
3584 |
} else if (v->type == VEH_AIRCRAFT) { |
7986
881998b115c2
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7951
diff
changeset
|
3585 |
if (!v->IsStoppedInDepot()) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
539
diff
changeset
|
3586 |
if (v->current_order.type != OT_GOTO_DEPOT) |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3587 |
DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR); |
0 | 3588 |
goto going_to_depot; |
3589 |
} |
|
3590 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3591 |
DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT); |
7951
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
3592 |
} else if (v->type == VEH_SHIP) { |
477c5cef5797
(svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents:
7886
diff
changeset
|
3593 |
/* Ships are not implemented in this (broken) AI */ |
0 | 3594 |
} |
3595 |
} |
|
3596 |
||
3597 |
goto return_to_loop; |
|
3598 |
going_to_depot:; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3599 |
if (++_players_ai[p->index].state_counter <= 832) return; |
0 | 3600 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
539
diff
changeset
|
3601 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
539
diff
changeset
|
3602 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
539
diff
changeset
|
3603 |
v->current_order.flags = 0; |
0 | 3604 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
3605 |
} |
|
3606 |
return_to_loop:; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3607 |
_players_ai[p->index].state = AIS_VEH_LOOP; |
0 | 3608 |
} |
3609 |
||
3610 |
static void AiStateRemoveStation(Player *p) |
|
3611 |
{ |
|
3612 |
// Remove stations that aren't in use by any vehicle |
|
1043
123072ba6ced
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1035
diff
changeset
|
3613 |
const Order *ord; |
1640
55f4cbda781b
(svn r2144) - Fix: AI crash when trying to remove stations with index higher than 256.
darkvater
parents:
1576
diff
changeset
|
3614 |
const Station *st; |
55f4cbda781b
(svn r2144) - Fix: AI crash when trying to remove stations with index higher than 256.
darkvater
parents:
1576
diff
changeset
|
3615 |
TileIndex tile; |
0 | 3616 |
|
3617 |
// Go to this state when we're done. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3618 |
_players_ai[p->index].state = AIS_1; |
0 | 3619 |
|
3620 |
// Get a list of all stations that are in use by a vehicle |
|
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5853
diff
changeset
|
3621 |
byte *in_use = MallocT<byte>(GetMaxStationIndex() + 1); |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5031
diff
changeset
|
3622 |
memset(in_use, 0, GetMaxStationIndex() + 1); |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
959
diff
changeset
|
3623 |
FOR_ALL_ORDERS(ord) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4495
diff
changeset
|
3624 |
if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1; |
0 | 3625 |
} |
3626 |
||
3627 |
// Go through all stations and delete those that aren't in use |
|
3628 |
FOR_ALL_STATIONS(st) { |
|
5004
0fdfbb61f146
(svn r7020) -Fix r6047: AI tries to delete stations that are 'in use' because FOR_ALL_STATIONS skips invalid stations
glx
parents:
4845
diff
changeset
|
3629 |
if (st->owner == _current_player && !in_use[st->index] && |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1216
diff
changeset
|
3630 |
( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != 0) || |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1216
diff
changeset
|
3631 |
(st->truck_stops != NULL && (tile = st->truck_stops->xy)) != 0 || |
0 | 3632 |
(tile = st->train_tile) != 0 || |
3633 |
(tile = st->dock_tile) != 0 || |
|
3634 |
(tile = st->airport_tile) != 0)) { |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3635 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 3636 |
} |
3637 |
} |
|
3638 |
||
1640
55f4cbda781b
(svn r2144) - Fix: AI crash when trying to remove stations with index higher than 256.
darkvater
parents:
1576
diff
changeset
|
3639 |
free(in_use); |
0 | 3640 |
} |
3641 |
||
1576
a066e33fa297
(svn r2080) - Fix: [OldAI] p->ai.state_counter was uint16 but could hold a tile index, therefore overflowing - changed that to uint32 and bumped the savegame revision to 32. It *MIGHT* close bug 1151374 - it certainly caused AI to stop building anything sometimes.
pasky
parents:
1562
diff
changeset
|
3642 |
static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile) |
0 | 3643 |
{ |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3644 |
TrackBits rails; |
0 | 3645 |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
3646 |
if (IsTileType(tile, MP_RAILWAY)) { |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
3647 |
if (!IsTileOwner(tile, _current_player)) return; |
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
3648 |
|
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3649 |
if (IsPlainRailTile(tile)) { |
0 | 3650 |
is_rail_crossing:; |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3651 |
rails = GetRailTrackStatus(tile); |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3652 |
|
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3653 |
if (rails == TRACK_BIT_HORZ || rails == TRACK_BIT_VERT) return; |
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3654 |
|
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3655 |
if (rails & TRACK_BIT_3WAY_NE) { |
0 | 3656 |
pos_0: |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3657 |
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & TRACK_BIT_3WAY_SW) == 0) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3658 |
_players_ai[p->index].cur_dir_a = DIAGDIR_NE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3659 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3660 |
_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE; |
0 | 3661 |
return; |
3662 |
} |
|
3663 |
} |
|
3664 |
||
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3665 |
if (rails & TRACK_BIT_3WAY_SE) { |
0 | 3666 |
pos_1: |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3667 |
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & TRACK_BIT_3WAY_NW) == 0) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3668 |
_players_ai[p->index].cur_dir_a = DIAGDIR_SE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3669 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3670 |
_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE; |
0 | 3671 |
return; |
3672 |
} |
|
3673 |
} |
|
3674 |
||
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3675 |
if (rails & TRACK_BIT_3WAY_SW) { |
0 | 3676 |
pos_2: |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3677 |
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & TRACK_BIT_3WAY_NE) == 0) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3678 |
_players_ai[p->index].cur_dir_a = DIAGDIR_SW; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3679 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3680 |
_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE; |
0 | 3681 |
return; |
3682 |
} |
|
3683 |
} |
|
3684 |
||
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3685 |
if (rails & TRACK_BIT_3WAY_NW) { |
0 | 3686 |
pos_3: |
3269
95e7bffcb3c5
(svn r3981) More work for the rail accessing functions and enums
tron
parents:
3234
diff
changeset
|
3687 |
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & TRACK_BIT_3WAY_SE) == 0) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3688 |
_players_ai[p->index].cur_dir_a = DIAGDIR_NW; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3689 |
_players_ai[p->index].cur_tile_a = tile; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3690 |
_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE; |
0 | 3691 |
return; |
3692 |
} |
|
3693 |
} |
|
3694 |
} else { |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3695 |
static const byte _depot_bits[] = {0x19, 0x16, 0x25, 0x2A}; |
0 | 3696 |
|
3185 | 3697 |
DiagDirection dir = GetRailDepotDirection(tile); |
3698 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
3699 |
if (GetRailTrackStatus(tile + TileOffsByDiagDir(dir)) & _depot_bits[dir]) |
0 | 3700 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3701 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3702 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 3703 |
} |
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7813
diff
changeset
|
3704 |
} else if (IsTileType(tile, MP_ROAD)) { |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
3705 |
if (!IsTileOwner(tile, _current_player)) return; |
0 | 3706 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3707 |
if (IsLevelCrossing(tile)) goto is_rail_crossing; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3708 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3792
diff
changeset
|
3709 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) { |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
3710 |
DiagDirection dir; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3711 |
TileIndex t; |
0 | 3712 |
|
3713 |
// Check if there are any stations around. |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3714 |
t = tile + TileDiffXY(-1, 0); |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3715 |
if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3716 |
|
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3717 |
t = tile + TileDiffXY(1, 0); |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3718 |
if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3719 |
|
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3720 |
t = tile + TileDiffXY(0, -1); |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3721 |
if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3722 |
|
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3723 |
t = tile + TileDiffXY(0, 1); |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3977
diff
changeset
|
3724 |
if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return; |
0 | 3725 |
|
3179 | 3726 |
dir = GetRoadDepotDirection(tile); |
0 | 3727 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3728 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3729 |
DoCommand( |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
3730 |
TILE_MASK(tile + TileOffsByDiagDir(dir)), |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
3731 |
DiagDirToRoadBits(ReverseDiagDir(dir)), |
0 | 3732 |
0, |
3733 |
DC_EXEC, |
|
3734 |
CMD_REMOVE_ROAD); |
|
3735 |
} |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
3736 |
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
3234
986c30171e92
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3214
diff
changeset
|
3737 |
if (!IsTileOwner(tile, _current_player) || |
986c30171e92
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3214
diff
changeset
|
3738 |
!IsBridge(tile) || |
8579
3efbb430092e
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
8502
diff
changeset
|
3739 |
GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) { |
0 | 3740 |
return; |
3234
986c30171e92
(svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents:
3214
diff
changeset
|
3741 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3742 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3743 |
rails = TRACK_BIT_NONE; |
0 | 3744 |
|
8579
3efbb430092e
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
8502
diff
changeset
|
3745 |
switch (GetTunnelBridgeDirection(tile)) { |
3196 | 3746 |
default: |
3747 |
case DIAGDIR_NE: goto pos_2; |
|
3748 |
case DIAGDIR_SE: goto pos_3; |
|
3749 |
case DIAGDIR_SW: goto pos_0; |
|
3750 |
case DIAGDIR_NW: goto pos_1; |
|
3751 |
} |
|
0 | 3752 |
} |
3753 |
} |
|
3754 |
||
3755 |
static void AiStateRemoveTrack(Player *p) |
|
3756 |
{ |
|
1576
a066e33fa297
(svn r2080) - Fix: [OldAI] p->ai.state_counter was uint16 but could hold a tile index, therefore overflowing - changed that to uint32 and bumped the savegame revision to 32. It *MIGHT* close bug 1151374 - it certainly caused AI to stop building anything sometimes.
pasky
parents:
1562
diff
changeset
|
3757 |
/* Was 1000 for standard 8x8 maps. */ |
a066e33fa297
(svn r2080) - Fix: [OldAI] p->ai.state_counter was uint16 but could hold a tile index, therefore overflowing - changed that to uint32 and bumped the savegame revision to 32. It *MIGHT* close bug 1151374 - it certainly caused AI to stop building anything sometimes.
pasky
parents:
1562
diff
changeset
|
3758 |
int num = MapSizeX() * 4; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3759 |
|
0 | 3760 |
do { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3761 |
TileIndex tile = ++_players_ai[p->index].state_counter; |
0 | 3762 |
|
3763 |
// Iterated all tiles? |
|
1174
27e386195965
(svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents:
1141
diff
changeset
|
3764 |
if (tile >= MapSize()) { |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3765 |
_players_ai[p->index].state = AIS_REMOVE_STATION; |
0 | 3766 |
return; |
3767 |
} |
|
3768 |
||
3769 |
// Remove player stuff in that tile |
|
3770 |
AiRemovePlayerRailOrRoad(p, tile); |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3771 |
if (_players_ai[p->index].state != AIS_REMOVE_TRACK) return; |
0 | 3772 |
} while (--num); |
3773 |
} |
|
3774 |
||
3775 |
static void AiStateRemoveSingleRailTile(Player *p) |
|
3776 |
{ |
|
3777 |
// Remove until we can't remove more. |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3778 |
if (!AiRemoveTileAndGoForward(p)) _players_ai[p->index].state = AIS_REMOVE_TRACK; |
0 | 3779 |
} |
3780 |
||
3781 |
static AiStateAction * const _ai_actions[] = { |
|
3782 |
AiCase0, |
|
3783 |
AiCase1, |
|
3784 |
AiStateVehLoop, |
|
3785 |
AiStateCheckReplaceVehicle, |
|
3786 |
AiStateDoReplaceVehicle, |
|
3787 |
AiStateWantNewRoute, |
|
3788 |
||
3789 |
AiStateBuildDefaultRailBlocks, |
|
3790 |
AiStateBuildRail, |
|
3791 |
AiStateBuildRailVeh, |
|
3792 |
AiStateDeleteRailBlocks, |
|
3793 |
||
3794 |
AiStateBuildDefaultRoadBlocks, |
|
3795 |
AiStateBuildRoad, |
|
3796 |
AiStateBuildRoadVehicles, |
|
3797 |
AiStateDeleteRoadBlocks, |
|
3798 |
||
3799 |
AiStateAirportStuff, |
|
3800 |
AiStateBuildDefaultAirportBlocks, |
|
3801 |
AiStateBuildAircraftVehicles, |
|
3802 |
||
3803 |
AiStateCheckShipStuff, |
|
3804 |
AiStateBuildDefaultShipBlocks, |
|
3805 |
AiStateDoShipStuff, |
|
3806 |
||
3807 |
AiStateSellVeh, |
|
3808 |
AiStateRemoveStation, |
|
3809 |
AiStateRemoveTrack, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3810 |
|
0 | 3811 |
AiStateRemoveSingleRailTile |
3812 |
}; |
|
3813 |
||
3814 |
extern void ShowBuyCompanyDialog(uint player); |
|
3815 |
||
3816 |
static void AiHandleTakeover(Player *p) |
|
3817 |
{ |
|
3818 |
if (p->bankrupt_timeout != 0) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3819 |
p->bankrupt_timeout -= 8; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3820 |
if (p->bankrupt_timeout > 0) return; |
0 | 3821 |
p->bankrupt_timeout = 0; |
3822 |
DeleteWindowById(WC_BUY_COMPANY, _current_player); |
|
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2423
diff
changeset
|
3823 |
if (IsLocalPlayer()) { |
0 | 3824 |
AskExitToGameMenu(); |
3825 |
return; |
|
3826 |
} |
|
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4560
diff
changeset
|
3827 |
if (IsHumanPlayer(_current_player)) return; |
0 | 3828 |
} |
3829 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3022
diff
changeset
|
3830 |
if (p->bankrupt_asked == 255) return; |
0 | 3831 |
|
3832 |
{ |
|
3833 |
uint asked = p->bankrupt_asked; |
|
3834 |
Player *pp, *best_pl = NULL; |
|
3835 |
int32 best_val = -1; |
|
3836 |
||
3837 |
// Ask the guy with the highest performance hist. |
|
3838 |
FOR_ALL_PLAYERS(pp) { |
|
3839 |
if (pp->is_active && |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3840 |
!(asked & 1) && |
0 | 3841 |
pp->bankrupt_asked == 0 && |
3842 |
best_val < pp->old_economy[1].performance_history) { |
|
3843 |
best_val = pp->old_economy[1].performance_history; |
|
3844 |
best_pl = pp; |
|
3845 |
} |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3846 |
asked >>= 1; |
0 | 3847 |
} |
3848 |
||
3849 |
// Asked all players? |
|
3850 |
if (best_val == -1) { |
|
3851 |
p->bankrupt_asked = 255; |
|
3852 |
return; |
|
3853 |
} |
|
3854 |
||
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
3855 |
SetBit(p->bankrupt_asked, best_pl->index); |
0 | 3856 |
|
3857 |
if (best_pl->index == _local_player) { |
|
3858 |
p->bankrupt_timeout = 4440; |
|
3859 |
ShowBuyCompanyDialog(_current_player); |
|
3860 |
return; |
|
3861 |
} |
|
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4560
diff
changeset
|
3862 |
if (IsHumanPlayer(best_pl->index)) return; |
0 | 3863 |
|
3864 |
// Too little money for computer to buy it? |
|
3865 |
if (best_pl->player_money >> 1 >= p->bankrupt_value) { |
|
3866 |
// Computer wants to buy it. |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
3867 |
PlayerID old_p = _current_player; |
6900
872757461d92
(svn r9540) -Fix (r1): Bankrupt AIs no longer buy themselves (usage of wrong variable)
celestar
parents:
6896
diff
changeset
|
3868 |
_current_player = best_pl->index; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3869 |
DoCommand(0, old_p, 0, DC_EXEC, CMD_BUY_COMPANY); |
0 | 3870 |
_current_player = old_p; |
3871 |
} |
|
3872 |
} |
|
3873 |
} |
|
3874 |
||
4011
db5514de70cc
(svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents:
4000
diff
changeset
|
3875 |
static void AiAdjustLoan(const Player* p) |
0 | 3876 |
{ |
7486
d130c10f4dab
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
7446
diff
changeset
|
3877 |
Money base = AiGetBasePrice(p); |
0 | 3878 |
|
3879 |
if (p->player_money > base * 1400) { |
|
3880 |
// Decrease loan |
|
3881 |
if (p->current_loan != 0) { |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3882 |
DoCommand(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN); |
0 | 3883 |
} |
3884 |
} else if (p->player_money < base * 500) { |
|
3885 |
// Increase loan |
|
3886 |
if (p->current_loan < _economy.max_loan && |
|
3887 |
p->num_valid_stat_ent >= 2 && |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3888 |
-(p->old_economy[0].expenses + p->old_economy[1].expenses) < base * 60) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3889 |
DoCommand(0, 0, 0, DC_EXEC, CMD_INCREASE_LOAN); |
0 | 3890 |
} |
3891 |
} |
|
3892 |
} |
|
3893 |
||
3894 |
static void AiBuildCompanyHQ(Player *p) |
|
3895 |
{ |
|
3896 |
TileIndex tile; |
|
3897 |
||
3898 |
if (p->location_of_house == 0 && |
|
3899 |
p->last_build_coordinate != 0) { |
|
3900 |
tile = AdjustTileCoordRandomly(p->last_build_coordinate, 8); |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3473
diff
changeset
|
3901 |
DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ); |
0 | 3902 |
} |
3903 |
} |
|
3904 |
||
3905 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
192
diff
changeset
|
3906 |
void AiDoGameLoop(Player *p) |
0 | 3907 |
{ |
3908 |
if (p->bankrupt_asked != 0) { |
|
3909 |
AiHandleTakeover(p); |
|
3910 |
return; |
|
3911 |
} |
|
3912 |
||
192
614bba52258d
(svn r193) -Fix: [OldAI] If service-interval is in %, it works correct now.
truelight
parents:
159
diff
changeset
|
3913 |
// Ugly hack to make sure the service interval of the AI is good, not looking |
614bba52258d
(svn r193) -Fix: [OldAI] If service-interval is in %, it works correct now.
truelight
parents:
159
diff
changeset
|
3914 |
// to the patch-setting |
614bba52258d
(svn r193) -Fix: [OldAI] If service-interval is in %, it works correct now.
truelight
parents:
159
diff
changeset
|
3915 |
// Also, it takes into account the setting if the service-interval is in days |
614bba52258d
(svn r193) -Fix: [OldAI] If service-interval is in %, it works correct now.
truelight
parents:
159
diff
changeset
|
3916 |
// or in % |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3917 |
_ai_service_interval = _patches.servint_ispercent ? 80 : 180; |
192
614bba52258d
(svn r193) -Fix: [OldAI] If service-interval is in %, it works correct now.
truelight
parents:
159
diff
changeset
|
3918 |
|
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4560
diff
changeset
|
3919 |
if (IsHumanPlayer(_current_player)) return; |
0 | 3920 |
|
3921 |
AiAdjustLoan(p); |
|
3922 |
AiBuildCompanyHQ(p); |
|
3923 |
||
3924 |
#if 0 |
|
3925 |
{ |
|
3926 |
static byte old_state = 99; |
|
3927 |
static bool hasdots = false; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6949
diff
changeset
|
3928 |
char *_ai_state_names[] = { |
0 | 3929 |
"AiCase0", |
3930 |
"AiCase1", |
|
3931 |
"AiStateVehLoop", |
|
3932 |
"AiStateCheckReplaceVehicle", |
|
3933 |
"AiStateDoReplaceVehicle", |
|
3934 |
"AiStateWantNewRoute", |
|
3935 |
"AiStateBuildDefaultRailBlocks", |
|
3936 |
"AiStateBuildRail", |
|
3937 |
"AiStateBuildRailVeh", |
|
3938 |
"AiStateDeleteRailBlocks", |
|
3939 |
"AiStateBuildDefaultRoadBlocks", |
|
3940 |
"AiStateBuildRoad", |
|
3941 |
"AiStateBuildRoadVehicles", |
|
3942 |
"AiStateDeleteRoadBlocks", |
|
3943 |
"AiStateAirportStuff", |
|
3944 |
"AiStateBuildDefaultAirportBlocks", |
|
3945 |
"AiStateBuildAircraftVehicles", |
|
3946 |
"AiStateCheckShipStuff", |
|
3947 |
"AiStateBuildDefaultShipBlocks", |
|
3948 |
"AiStateDoShipStuff", |
|
3949 |
"AiStateSellVeh", |
|
3950 |
"AiStateRemoveStation", |
|
3951 |
"AiStateRemoveTrack", |
|
3952 |
"AiStateRemoveSingleRailTile" |
|
3953 |
}; |
|
3954 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3955 |
if (_players_ai[p->index].state != old_state) { |
0 | 3956 |
if (hasdots) |
3957 |
printf("\n"); |
|
3958 |
hasdots=false; |
|
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3959 |
printf("AiState: %s\n", _ai_state_names[old_state=_players_ai[p->index].state]); |
0 | 3960 |
} else { |
3961 |
printf("."); |
|
3962 |
hasdots=true; |
|
3963 |
} |
|
3964 |
} |
|
3965 |
#endif |
|
3966 |
||
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3967 |
_ai_actions[_players_ai[p->index].state](p); |
0 | 3968 |
} |
8725
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3969 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3970 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3971 |
static const SaveLoad _player_ai_desc[] = { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3972 |
SLE_VAR(PlayerAI, state, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3973 |
SLE_VAR(PlayerAI, tick, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3974 |
SLE_CONDVAR(PlayerAI, state_counter, SLE_FILE_U16 | SLE_VAR_U32, 0, 12), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3975 |
SLE_CONDVAR(PlayerAI, state_counter, SLE_UINT32, 13, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3976 |
SLE_VAR(PlayerAI, timeout_counter, SLE_UINT16), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3977 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3978 |
SLE_VAR(PlayerAI, state_mode, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3979 |
SLE_VAR(PlayerAI, banned_tile_count, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3980 |
SLE_VAR(PlayerAI, railtype_to_use, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3981 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3982 |
SLE_VAR(PlayerAI, cargo_type, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3983 |
SLE_VAR(PlayerAI, num_wagons, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3984 |
SLE_VAR(PlayerAI, build_kind, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3985 |
SLE_VAR(PlayerAI, num_build_rec, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3986 |
SLE_VAR(PlayerAI, num_loco_to_build, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3987 |
SLE_VAR(PlayerAI, num_want_fullload, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3988 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3989 |
SLE_VAR(PlayerAI, route_type_mask, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3990 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3991 |
SLE_CONDVAR(PlayerAI, start_tile_a, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3992 |
SLE_CONDVAR(PlayerAI, start_tile_a, SLE_UINT32, 6, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3993 |
SLE_CONDVAR(PlayerAI, cur_tile_a, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3994 |
SLE_CONDVAR(PlayerAI, cur_tile_a, SLE_UINT32, 6, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3995 |
SLE_VAR(PlayerAI, start_dir_a, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3996 |
SLE_VAR(PlayerAI, cur_dir_a, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3997 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3998 |
SLE_CONDVAR(PlayerAI, start_tile_b, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
3999 |
SLE_CONDVAR(PlayerAI, start_tile_b, SLE_UINT32, 6, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4000 |
SLE_CONDVAR(PlayerAI, cur_tile_b, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4001 |
SLE_CONDVAR(PlayerAI, cur_tile_b, SLE_UINT32, 6, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4002 |
SLE_VAR(PlayerAI, start_dir_b, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4003 |
SLE_VAR(PlayerAI, cur_dir_b, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4004 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4005 |
SLE_REF(PlayerAI, cur_veh, REF_VEHICLE), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4006 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4007 |
SLE_ARR(PlayerAI, wagon_list, SLE_UINT16, 9), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4008 |
SLE_ARR(PlayerAI, order_list_blocks, SLE_UINT8, 20), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4009 |
SLE_ARR(PlayerAI, banned_tiles, SLE_UINT16, 16), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4010 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4011 |
SLE_CONDNULL(64, 2, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4012 |
SLE_END() |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4013 |
}; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4014 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4015 |
static const SaveLoad _player_ai_build_rec_desc[] = { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4016 |
SLE_CONDVAR(AiBuildRec, spec_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4017 |
SLE_CONDVAR(AiBuildRec, spec_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4018 |
SLE_CONDVAR(AiBuildRec, use_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4019 |
SLE_CONDVAR(AiBuildRec, use_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4020 |
SLE_VAR(AiBuildRec, rand_rng, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4021 |
SLE_VAR(AiBuildRec, cur_building_rule, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4022 |
SLE_VAR(AiBuildRec, unk6, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4023 |
SLE_VAR(AiBuildRec, unk7, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4024 |
SLE_VAR(AiBuildRec, buildcmd_a, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4025 |
SLE_VAR(AiBuildRec, buildcmd_b, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4026 |
SLE_VAR(AiBuildRec, direction, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4027 |
SLE_VAR(AiBuildRec, cargo, SLE_UINT8), |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4028 |
SLE_END() |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4029 |
}; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4030 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4031 |
|
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4032 |
void SaveLoad_AI(PlayerID id) |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4033 |
{ |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4034 |
PlayerAI *pai = &_players_ai[id]; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4035 |
SlObject(pai, _player_ai_desc); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4036 |
for (int i = 0; i != pai->num_build_rec; i++) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4037 |
SlObject(&pai->src + i, _player_ai_build_rec_desc); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
4038 |
} |
8732
b18f578f7c16
(svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents:
8726
diff
changeset
|
4039 |
} |