author | rubidium |
Sat, 05 Apr 2008 23:36:54 +0000 | |
changeset 9332 | 2e120d0bd632 |
parent 9282 | 2bb9703aeb39 |
child 9335 | 18d3658adc60 |
permissions | -rw-r--r-- |
2549 | 1 |
/* $Id$ */ |
1490
6a13118e99f5
(svn r1994) Fix: 1159456 - hopefully prevent the new AI to get stuck in an infinite loop forlorny trying to build its haven. Unintentionally bundled with trivial tidyup.
pasky
parents:
1377
diff
changeset
|
2 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
3 |
/* |
2549 | 4 |
* This AI was created as a direct reaction to the big demand for some good AIs |
5 |
* in OTTD. Too bad it never left alpha-stage, and it is considered dead in its |
|
6 |
* current form. |
|
7 |
* By the time of writing this, we, the creator of this AI and a good friend of |
|
8 |
* mine, are designing a whole new AI-system that allows us to create AIs |
|
9 |
* easier and without all the fuzz we encountered while I was working on this |
|
10 |
* AI. By the time that system is finished, you can expect that this AI will |
|
11 |
* dissapear, because it is pretty obselete and bad programmed. |
|
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:
2365
diff
changeset
|
12 |
* |
2549 | 13 |
* Meanwhile I wish you all much fun with this AI; if you are interested as |
14 |
* AI-developer in this AI, I advise you not stare too long to some code, some |
|
15 |
* things in here really are... strange ;) But in either way: enjoy :) |
|
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:
2365
diff
changeset
|
16 |
* |
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:
2365
diff
changeset
|
17 |
* -- TrueLight :: 2005-09-01 |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
18 |
*/ |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
19 |
|
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:
2365
diff
changeset
|
20 |
#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:
2365
diff
changeset
|
21 |
#include "../../openttd.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:
2365
diff
changeset
|
22 |
#include "../../debug.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3071
diff
changeset
|
23 |
#include "../../road_map.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3179
diff
changeset
|
24 |
#include "../../station_map.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8604
diff
changeset
|
25 |
#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:
2365
diff
changeset
|
26 |
#include "trolly.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:
2365
diff
changeset
|
27 |
#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:
2365
diff
changeset
|
28 |
#include "../../industry.h" |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9280
diff
changeset
|
29 |
#include "../../station_base.h" |
9282
2bb9703aeb39
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents:
9281
diff
changeset
|
30 |
#include "../../engine_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:
2365
diff
changeset
|
31 |
#include "../../gui.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:
2365
diff
changeset
|
32 |
#include "../../depot.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
33 |
#include "../../vehicle_base.h" |
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
34 |
#include "../../vehicle_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
35 |
#include "../../date_func.h" |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
36 |
#include "../ai.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8725
diff
changeset
|
37 |
#include "../../player_base.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8725
diff
changeset
|
38 |
#include "../../player_func.h" |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
39 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
40 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
41 |
|
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
|
42 |
PlayerAiNew _players_ainew[MAX_PLAYERS]; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
43 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
44 |
// This function is called after StartUp. It is the init of an AI |
2365 | 45 |
static void AiNew_State_FirstTime(Player *p) |
46 |
{ |
|
47 |
// This assert is used to protect those function from misuse |
|
48 |
// You have quickly a small mistake in the state-array |
|
49 |
// With that, everything would go wrong. Finding that, is almost impossible |
|
50 |
// With this assert, that problem can never happen. |
|
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
|
51 |
assert(_players_ainew[p->index].state == AI_STATE_FIRST_TIME); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
52 |
// We first have to init some things |
145 | 53 |
|
4854
383ef523793f
(svn r6780) -Codechange: Remove GPMI leftovers (-b impersonisation of AI in MP).
Darkvater
parents:
4559
diff
changeset
|
54 |
if (_current_player == 1) ShowErrorMessage(INVALID_STRING_ID, TEMP_AI_IN_PROGRESS, 0, 0); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
55 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
56 |
// The PathFinder (AyStar) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
57 |
// TODO: Maybe when an AI goes bankrupt, this is de-init |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
58 |
// or when coming from a savegame.. should be checked 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
|
59 |
_players_ainew[p->index].path_info.start_tile_tl = 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
|
60 |
_players_ainew[p->index].path_info.start_tile_br = 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
|
61 |
_players_ainew[p->index].path_info.end_tile_tl = 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
|
62 |
_players_ainew[p->index].path_info.end_tile_br = 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
|
63 |
_players_ainew[p->index].pathfinder = new_AyStar_AiPathFinder(12, &_players_ainew[p->index].path_info); |
145 | 64 |
|
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
|
65 |
_players_ainew[p->index].idle = 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
|
66 |
_players_ainew[p->index].last_vehiclecheck_date = _date; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
67 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
68 |
// We ALWAYS start with a bus route.. just some basic 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
|
69 |
_players_ainew[p->index].action = AI_ACTION_BUS_ROUTE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
70 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
71 |
// Let's popup the news, and after that, start building.. |
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
|
72 |
_players_ainew[p->index].state = AI_STATE_WAKE_UP; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
73 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
74 |
|
2365 | 75 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
76 |
// This function just waste some time |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
77 |
// It keeps it more real. The AI can build on such tempo no normal user |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
78 |
// can ever keep up with that. The competitor_speed already delays a bit |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
79 |
// but after the AI finished a track it really needs to go to sleep. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
80 |
// |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
81 |
// Let's say, we sleep between one and three days if the AI is put on Very Fast. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
82 |
// This means that on Very Slow it will be between 16 and 48 days.. slow enough? |
2365 | 83 |
static void AiNew_State_Nothing(Player *p) |
84 |
{ |
|
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
|
85 |
assert(_players_ainew[p->index].state == AI_STATE_NOTHING); |
2365 | 86 |
// If we are done idling, start over again |
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
|
87 |
if (_players_ainew[p->index].idle == 0) _players_ainew[p->index].idle = AI_RandomRange(DAY_TICKS * 2) + DAY_TICKS; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
88 |
if (--_players_ainew[p->index].idle == 0) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
89 |
// We are done idling.. what you say? Let's do something! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
90 |
// I mean.. the next tick ;) |
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
|
91 |
_players_ainew[p->index].state = AI_STATE_WAKE_UP; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
92 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
93 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
94 |
|
2365 | 95 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
96 |
// This function picks out a task we are going to do. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
97 |
// Currently supported: |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
98 |
// - Make new route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
99 |
// - Check route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
100 |
// - Build HQ |
2365 | 101 |
static void AiNew_State_WakeUp(Player *p) |
102 |
{ |
|
1490
6a13118e99f5
(svn r1994) Fix: 1159456 - hopefully prevent the new AI to get stuck in an infinite loop forlorny trying to build its haven. Unintentionally bundled with trivial tidyup.
pasky
parents:
1377
diff
changeset
|
103 |
int c; |
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
|
104 |
assert(_players_ainew[p->index].state == AI_STATE_WAKE_UP); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
105 |
// First, check if we have a HQ |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
106 |
if (p->location_of_house == 0) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
107 |
// We have no HQ yet, build one on a random place |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
108 |
// Random till we found a place for it! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
109 |
// TODO: this should not be on a random place.. |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
110 |
AiNew_Build_CompanyHQ(p, AI_Random() % MapSize()); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
111 |
// Enough for now, but we want to come back here the next time |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
112 |
// so we do not change any status |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
113 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
114 |
} |
145 | 115 |
|
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
|
116 |
Money money = p->player_money - AI_MINIMUM_MONEY; |
145 | 117 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
118 |
// Let's pick an action! |
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
|
119 |
if (_players_ainew[p->index].action == AI_ACTION_NONE) { |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
120 |
c = AI_Random() & 0xFF; |
2365 | 121 |
if (p->current_loan > 0 && |
122 |
p->old_economy[1].income > AI_MINIMUM_INCOME_FOR_LOAN && |
|
123 |
c < 10) { |
|
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
|
124 |
_players_ainew[p->index].action = AI_ACTION_REPAY_LOAN; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
125 |
} else if (_players_ainew[p->index].last_vehiclecheck_date + AI_DAYS_BETWEEN_VEHICLE_CHECKS < _date) { |
145 | 126 |
// Check all vehicles once in 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
|
127 |
_players_ainew[p->index].action = AI_ACTION_CHECK_ALL_VEHICLES; |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].last_vehiclecheck_date = _date; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
129 |
} else if (c < 100 && !_patches.ai_disable_veh_roadveh) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
130 |
// Do we have any spots for road-vehicles left open? |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
131 |
if (GetFreeUnitNumber(VEH_ROAD) <= _patches.max_roadveh) { |
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:
3952
diff
changeset
|
132 |
if (c < 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
|
133 |
_players_ainew[p->index].action = AI_ACTION_TRUCK_ROUTE; |
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:
3952
diff
changeset
|
134 |
} 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
|
135 |
_players_ainew[p->index].action = AI_ACTION_BUS_ROUTE; |
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:
3952
diff
changeset
|
136 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
137 |
} |
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:
3952
diff
changeset
|
138 |
#if 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:
3952
diff
changeset
|
139 |
} else if (c < 200 && !_patches.ai_disable_veh_train) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
140 |
if (GetFreeUnitNumber(VEH_TRAIN) <= _patches.max_trains) { |
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
|
141 |
_players_ainew[p->index].action = AI_ACTION_TRAIN_ROUTE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
142 |
} |
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:
3952
diff
changeset
|
143 |
#endif |
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:
3952
diff
changeset
|
144 |
} |
145 | 145 |
|
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
|
146 |
_players_ainew[p->index].counter = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
147 |
} |
145 | 148 |
|
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
|
149 |
if (_players_ainew[p->index].counter++ > AI_MAX_TRIES_FOR_SAME_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
|
150 |
_players_ainew[p->index].action = AI_ACTION_NONE; |
145 | 151 |
return; |
152 |
} |
|
153 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
154 |
if (_patches.ai_disable_veh_roadveh && ( |
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
|
155 |
_players_ainew[p->index].action == AI_ACTION_BUS_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
|
156 |
_players_ainew[p->index].action == AI_ACTION_TRUCK_ROUTE |
2365 | 157 |
)) { |
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
|
158 |
_players_ainew[p->index].action = AI_ACTION_NONE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
159 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
160 |
} |
145 | 161 |
|
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
|
162 |
if (_players_ainew[p->index].action == AI_ACTION_REPAY_LOAN && |
2365 | 163 |
money > AI_MINIMUM_LOAN_REPAY_MONEY) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
164 |
// We start repaying some 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
|
165 |
_players_ainew[p->index].state = AI_STATE_REPAY_MONEY; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
166 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
167 |
} |
145 | 168 |
|
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
|
169 |
if (_players_ainew[p->index].action == AI_ACTION_CHECK_ALL_VEHICLES) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
170 |
_players_ainew[p->index].state = AI_STATE_CHECK_ALL_VEHICLES; |
145 | 171 |
return; |
172 |
} |
|
173 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
174 |
// It is useless to start finding a route if we don't have enough money |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
175 |
// to build the route anyway.. |
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
|
176 |
if (_players_ainew[p->index].action == AI_ACTION_BUS_ROUTE && |
2365 | 177 |
money > AI_MINIMUM_BUS_ROUTE_MONEY) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
178 |
if (GetFreeUnitNumber(VEH_ROAD) > _patches.max_roadveh) { |
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
|
179 |
_players_ainew[p->index].action = AI_ACTION_NONE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
180 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
181 |
} |
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
|
182 |
_players_ainew[p->index].cargo = AI_NEED_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
|
183 |
_players_ainew[p->index].state = AI_STATE_LOCATE_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
|
184 |
_players_ainew[p->index].tbt = AI_BUS; // Bus-route |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
185 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
186 |
} |
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
|
187 |
if (_players_ainew[p->index].action == AI_ACTION_TRUCK_ROUTE && |
2365 | 188 |
money > AI_MINIMUM_TRUCK_ROUTE_MONEY) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
189 |
if (GetFreeUnitNumber(VEH_ROAD) > _patches.max_roadveh) { |
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
|
190 |
_players_ainew[p->index].action = AI_ACTION_NONE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
191 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
192 |
} |
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
|
193 |
_players_ainew[p->index].cargo = AI_NEED_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
|
194 |
_players_ainew[p->index].last_id = 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
|
195 |
_players_ainew[p->index].state = AI_STATE_LOCATE_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
|
196 |
_players_ainew[p->index].tbt = AI_TRUCK; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
197 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
198 |
} |
145 | 199 |
|
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
|
200 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
201 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
202 |
|
2365 | 203 |
|
204 |
static void AiNew_State_ActionDone(Player *p) |
|
205 |
{ |
|
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
|
206 |
_players_ainew[p->index].action = AI_ACTION_NONE; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
207 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
208 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
209 |
|
2365 | 210 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
211 |
// Check if a city or industry is good enough to start a route there |
2365 | 212 |
static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) |
213 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
214 |
if (type == AI_CITY) { |
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:
3952
diff
changeset
|
215 |
const Town* t = GetTown(ic); |
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:
3952
diff
changeset
|
216 |
const Station* st; |
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1330
diff
changeset
|
217 |
uint count = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
218 |
int j = 0; |
145 | 219 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
220 |
// We don't like roadconstructions, don't even true such a city |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
221 |
if (t->road_build_months != 0) return false; |
145 | 222 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
223 |
// Check if the rating in a city is high enough |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
224 |
// If not, take a chance if we want to continue |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6585
diff
changeset
|
225 |
if (t->ratings[_current_player] < 0 && AI_CHANCE16(1, 4)) return false; |
145 | 226 |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6585
diff
changeset
|
227 |
if (t->max_pass - t->act_pass < AI_CHECKCITY_NEEDED_CARGO && !AI_CHANCE16(1, AI_CHECKCITY_CITY_CHANCE)) return false; |
145 | 228 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
229 |
// Check if we have build a station in this town the last 6 months |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
230 |
// else we don't do it. This is done, because stat updates can be slow |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
231 |
// and sometimes it takes up to 4 months before the stats are corectly. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
232 |
// This way we don't get 12 busstations in one city of 100 population ;) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
233 |
FOR_ALL_STATIONS(st) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
234 |
// Do we own it? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
235 |
if (st->owner == _current_player) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
236 |
// Are we talking busses? |
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
|
237 |
if (_players_ainew[p->index].tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) != FACIL_BUS_STOP) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
238 |
// Is it the same city as we are in now? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
239 |
if (st->town != t) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
240 |
// When was this station build? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
241 |
if (_date - st->build_date < AI_CHECKCITY_DATE_BETWEEN) return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
242 |
// Cound the amount of stations in this city that we own |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
243 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
244 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
245 |
// We do not own it, request some info about the station |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
246 |
// we want to know if this station gets the same good. If so, |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
247 |
// we want to know its rating. If it is too high, we are not going |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
248 |
// to build there |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
249 |
if (!st->goods[CT_PASSENGERS].last_speed) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
250 |
// Is it around our city |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
251 |
if (DistanceManhattan(st->xy, t->xy) > 10) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
252 |
// It does take this cargo.. what is his rating? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
253 |
if (st->goods[CT_PASSENGERS].rating < AI_CHECKCITY_CARGO_RATING) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
254 |
j++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
255 |
// When this is the first station, we build a second with no problem ;) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
256 |
if (j == 1) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
257 |
// The rating is high.. second station... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
258 |
// a little chance that we still continue |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
259 |
// But if there are 3 stations of this size, we never go on... |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
260 |
if (j == 2 && AI_CHANCE16(1, AI_CHECKCITY_CARGO_RATING_CHANCE)) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
261 |
// We don't like this station :( |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
262 |
return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
263 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
264 |
} |
145 | 265 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
266 |
// We are about to add one... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
267 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
268 |
// Check if we the city can provide enough cargo for this amount of stations.. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
269 |
if (count * AI_CHECKCITY_CARGO_PER_STATION > t->max_pass) return false; |
145 | 270 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
271 |
// All check are okay, so we can build here! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
272 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
273 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
274 |
if (type == AI_INDUSTRY) { |
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:
3952
diff
changeset
|
275 |
const Industry* i = GetIndustry(ic); |
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:
3952
diff
changeset
|
276 |
const Station* st; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
277 |
int count = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
278 |
int j = 0; |
145 | 279 |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6585
diff
changeset
|
280 |
if (i->town != NULL && i->town->ratings[_current_player] < 0 && AI_CHANCE16(1, 4)) return false; |
145 | 281 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
282 |
// No limits on delevering stations! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
283 |
// Or for industry that does not give anything yet |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
284 |
if (i->produced_cargo[0] == CT_INVALID || i->last_month_production[0] == 0) return true; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
285 |
|
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7290
diff
changeset
|
286 |
if (i->last_month_production[0] - i->last_month_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false; |
145 | 287 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
288 |
// Check if we have build a station in this town the last 6 months |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
289 |
// else we don't do it. This is done, because stat updates can be slow |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
290 |
// and sometimes it takes up to 4 months before the stats are corectly. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
291 |
FOR_ALL_STATIONS(st) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
292 |
// Do we own it? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
293 |
if (st->owner == _current_player) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
294 |
// Are we talking trucks? |
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
|
295 |
if (_players_ainew[p->index].tbt == AI_TRUCK && (FACIL_TRUCK_STOP & st->facilities) != FACIL_TRUCK_STOP) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
296 |
// Is it the same city as we are in now? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
297 |
if (st->town != i->town) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
298 |
// When was this station build? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
299 |
if (_date - st->build_date < AI_CHECKCITY_DATE_BETWEEN) return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
300 |
// Cound the amount of stations in this city that we own |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
301 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
302 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
303 |
// We do not own it, request some info about the station |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
304 |
// we want to know if this station gets the same good. If so, |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
305 |
// we want to know its rating. If it is too high, we are not going |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
306 |
// to build there |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
307 |
if (i->produced_cargo[0] == CT_INVALID) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
308 |
// It does not take this cargo |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
309 |
if (!st->goods[i->produced_cargo[0]].last_speed) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
310 |
// Is it around our industry |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
311 |
if (DistanceManhattan(st->xy, i->xy) > 5) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
312 |
// It does take this cargo.. what is his rating? |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
313 |
if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
314 |
j++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
315 |
// The rating is high.. a little chance that we still continue |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
316 |
// But if there are 2 stations of this size, we never go on... |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
317 |
if (j == 1 && AI_CHANCE16(1, AI_CHECKCITY_CARGO_RATING_CHANCE)) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
318 |
// We don't like this station :( |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
319 |
return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
320 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
321 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
322 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
323 |
// We are about to add one... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
324 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
325 |
// Check if we the city can provide enough cargo for this amount of stations.. |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7290
diff
changeset
|
326 |
if (count * AI_CHECKCITY_CARGO_PER_STATION > i->last_month_production[0]) return false; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
327 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
328 |
// All check are okay, so we can build here! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
329 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
330 |
} |
145 | 331 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
332 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
333 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
334 |
|
145 | 335 |
|
2365 | 336 |
// This functions tries to locate a good route |
337 |
static void AiNew_State_LocateRoute(Player *p) |
|
338 |
{ |
|
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
|
339 |
assert(_players_ainew[p->index].state == AI_STATE_LOCATE_ROUTE); |
2365 | 340 |
// For now, we only support PASSENGERS, CITY and BUSSES |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
341 |
|
2365 | 342 |
// We don't have a route yet |
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
|
343 |
if (_players_ainew[p->index].cargo == AI_NEED_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
|
344 |
_players_ainew[p->index].new_cost = 0; // No cost yet |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
345 |
_players_ainew[p->index].temp = -1; |
2365 | 346 |
// Reset the counter |
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
|
347 |
_players_ainew[p->index].counter = 0; |
2365 | 348 |
|
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
|
349 |
_players_ainew[p->index].from_ic = -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
|
350 |
_players_ainew[p->index].to_ic = -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
|
351 |
if (_players_ainew[p->index].tbt == AI_BUS) { |
2365 | 352 |
// For now we only have a passenger 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
|
353 |
_players_ainew[p->index].cargo = CT_PASSENGERS; |
2365 | 354 |
|
355 |
// Find a route to cities |
|
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
|
356 |
_players_ainew[p->index].from_type = AI_CITY; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
357 |
_players_ainew[p->index].to_type = AI_CITY; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
358 |
} else if (_players_ainew[p->index].tbt == AI_TRUCK) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
359 |
_players_ainew[p->index].cargo = AI_NO_CARGO; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
360 |
|
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
|
361 |
_players_ainew[p->index].from_type = AI_INDUSTRY; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
362 |
_players_ainew[p->index].to_type = AI_INDUSTRY; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
363 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
364 |
|
2365 | 365 |
// Now we are doing initing, we wait one tick |
366 |
return; |
|
367 |
} |
|
145 | 368 |
|
2365 | 369 |
// Increase the counter and abort if it is taking too long! |
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
|
370 |
_players_ainew[p->index].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
|
371 |
if (_players_ainew[p->index].counter > AI_LOCATE_ROUTE_MAX_COUNTER) { |
2365 | 372 |
// Switch back to doing nothing! |
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
|
373 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
2365 | 374 |
return; |
375 |
} |
|
145 | 376 |
|
2365 | 377 |
// We are going to locate a city from where we are going to connect |
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
|
378 |
if (_players_ainew[p->index].from_ic == -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
|
379 |
if (_players_ainew[p->index].temp == -1) { |
2365 | 380 |
// First, we pick a random spot to search from |
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
|
381 |
if (_players_ainew[p->index].from_type == AI_CITY) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
382 |
_players_ainew[p->index].temp = AI_RandomRange(GetMaxTownIndex() + 1); |
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:
3952
diff
changeset
|
383 |
} 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
|
384 |
_players_ainew[p->index].temp = AI_RandomRange(GetMaxIndustryIndex() + 1); |
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:
3952
diff
changeset
|
385 |
} |
2365 | 386 |
} |
145 | 387 |
|
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
|
388 |
if (!AiNew_Check_City_or_Industry(p, _players_ainew[p->index].temp, _players_ainew[p->index].from_type)) { |
2365 | 389 |
// It was not a valid city |
390 |
// increase the temp with one, and return. We will come back later here |
|
391 |
// to try again |
|
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
|
392 |
_players_ainew[p->index].temp++; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
393 |
if (_players_ainew[p->index].from_type == AI_CITY) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
394 |
if (_players_ainew[p->index].temp > GetMaxTownIndex()) _players_ainew[p->index].temp = 0; |
2365 | 395 |
} 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
|
396 |
if (_players_ainew[p->index].temp > GetMaxIndustryIndex()) _players_ainew[p->index].temp = 0; |
2365 | 397 |
} |
145 | 398 |
|
2365 | 399 |
// Don't do an attempt if we are trying the same id as the last time... |
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
|
400 |
if (_players_ainew[p->index].last_id == _players_ainew[p->index].temp) return; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
401 |
_players_ainew[p->index].last_id = _players_ainew[p->index].temp; |
2365 | 402 |
|
403 |
return; |
|
404 |
} |
|
405 |
||
406 |
// We found a good city/industry, save the data of 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
|
407 |
_players_ainew[p->index].from_ic = _players_ainew[p->index].temp; |
2365 | 408 |
|
409 |
// Start the next tick with finding a to-city |
|
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
|
410 |
_players_ainew[p->index].temp = -1; |
2365 | 411 |
return; |
412 |
} |
|
413 |
||
414 |
// Find a to-city |
|
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
|
415 |
if (_players_ainew[p->index].temp == -1) { |
2365 | 416 |
// First, we pick a random spot to search 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
|
417 |
if (_players_ainew[p->index].to_type == AI_CITY) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
418 |
_players_ainew[p->index].temp = AI_RandomRange(GetMaxTownIndex() + 1); |
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:
3952
diff
changeset
|
419 |
} 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
|
420 |
_players_ainew[p->index].temp = AI_RandomRange(GetMaxIndustryIndex() + 1); |
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:
3952
diff
changeset
|
421 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
422 |
} |
145 | 423 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
424 |
// The same city is not allowed |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
425 |
// Also check if the city is valid |
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 |
if (_players_ainew[p->index].temp != _players_ainew[p->index].from_ic && AiNew_Check_City_or_Industry(p, _players_ainew[p->index].temp, _players_ainew[p->index].to_type)) { |
2365 | 427 |
// Maybe it is valid.. |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
428 |
|
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:
3952
diff
changeset
|
429 |
/* We need to know if they are not to far apart from eachother.. |
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:
3952
diff
changeset
|
430 |
* We do that by checking how much cargo we have to move and how long the |
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:
3952
diff
changeset
|
431 |
* route is. |
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:
3952
diff
changeset
|
432 |
*/ |
145 | 433 |
|
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
|
434 |
if (_players_ainew[p->index].from_type == AI_CITY && _players_ainew[p->index].tbt == AI_BUS) { |
b769d0a63f06
(svn r11792) -Codechange: 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 Town* town_from = GetTown(_players_ainew[p->index].from_ic); |
b769d0a63f06
(svn r11792) -Codechange: 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 |
const Town* town_temp = GetTown(_players_ainew[p->index].temp); |
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
437 |
uint distance = DistanceManhattan(town_from->xy, town_temp->xy); |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
438 |
int max_cargo; |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
439 |
|
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
440 |
max_cargo = town_from->max_pass + town_temp->max_pass; |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
441 |
max_cargo -= town_from->act_pass + town_temp->act_pass; |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
442 |
|
2365 | 443 |
// max_cargo is now the amount of cargo we can move between the two cities |
444 |
// If it is more than the distance, we allow it |
|
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
445 |
if (distance <= max_cargo * AI_LOCATEROUTE_BUS_CARGO_DISTANCE) { |
2365 | 446 |
// We found a good city/industry, save the data of 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
|
447 |
_players_ainew[p->index].to_ic = _players_ainew[p->index].temp; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
448 |
_players_ainew[p->index].state = AI_STATE_FIND_STATION; |
2365 | 449 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
450 |
DEBUG(ai, 1, "[LocateRoute] found bus-route of %d tiles long (from %d to %d)", |
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
451 |
distance, |
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
|
452 |
_players_ainew[p->index].from_ic, |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
453 |
_players_ainew[p->index].temp |
2365 | 454 |
); |
455 |
||
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
|
456 |
_players_ainew[p->index].from_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
|
457 |
_players_ainew[p->index].to_tile = 0; |
2365 | 458 |
|
459 |
return; |
|
460 |
} |
|
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
|
461 |
} else if (_players_ainew[p->index].tbt == AI_TRUCK) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
462 |
const Industry* ind_from = GetIndustry(_players_ainew[p->index].from_ic); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
463 |
const Industry* ind_temp = GetIndustry(_players_ainew[p->index].temp); |
2365 | 464 |
bool found = false; |
465 |
int max_cargo = 0; |
|
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
466 |
uint i; |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
467 |
|
2365 | 468 |
// TODO: in max_cargo, also check other cargo (beside [0]) |
469 |
// First we check if the from_ic produces cargo that this ic accepts |
|
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
470 |
if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->last_month_production[0] != 0) { |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
471 |
for (i = 0; i < lengthof(ind_temp->accepts_cargo); i++) { |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
472 |
if (ind_temp->accepts_cargo[i] == CT_INVALID) break; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
473 |
if (ind_from->produced_cargo[0] == ind_temp->accepts_cargo[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:
3952
diff
changeset
|
474 |
// Found a compatible industry |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7290
diff
changeset
|
475 |
max_cargo = ind_from->last_month_production[0] - ind_from->last_month_transported[0]; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
476 |
found = true; |
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
|
477 |
_players_ainew[p->index].from_deliver = true; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
478 |
_players_ainew[p->index].to_deliver = false; |
2365 | 479 |
break; |
480 |
} |
|
481 |
} |
|
482 |
} |
|
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
483 |
if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->last_month_production[0] != 0) { |
2365 | 484 |
// If not check if the current ic produces cargo that the from_ic accepts |
8141
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
485 |
for (i = 0; i < lengthof(ind_from->accepts_cargo); i++) { |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
486 |
if (ind_from->accepts_cargo[i] == CT_INVALID) break; |
c052dc0dc029
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents:
7866
diff
changeset
|
487 |
if (ind_from->produced_cargo[0] == ind_from->accepts_cargo[i]) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
488 |
// Found a compatbiel industry |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
489 |
found = true; |
7315
f1b2591ad082
(svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents:
7290
diff
changeset
|
490 |
max_cargo = ind_temp->last_month_production[0] - ind_temp->last_month_transported[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
|
491 |
_players_ainew[p->index].from_deliver = false; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
492 |
_players_ainew[p->index].to_deliver = true; |
2365 | 493 |
break; |
494 |
} |
|
495 |
} |
|
496 |
} |
|
497 |
if (found) { |
|
498 |
// Yeah, they are compatible!!! |
|
499 |
// Check the length against the amount of goods |
|
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
500 |
uint distance = DistanceManhattan(ind_from->xy, ind_temp->xy); |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
501 |
|
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
502 |
if (distance > AI_LOCATEROUTE_TRUCK_MIN_DISTANCE && |
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
503 |
distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) { |
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
|
504 |
_players_ainew[p->index].to_ic = _players_ainew[p->index].temp; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
505 |
if (_players_ainew[p->index].from_deliver) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
506 |
_players_ainew[p->index].cargo = ind_from->produced_cargo[0]; |
2365 | 507 |
} 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
|
508 |
_players_ainew[p->index].cargo = ind_temp->produced_cargo[0]; |
2365 | 509 |
} |
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
|
510 |
_players_ainew[p->index].state = AI_STATE_FIND_STATION; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
511 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
512 |
DEBUG(ai, 1, "[LocateRoute] found truck-route of %d tiles long (from %d to %d)", |
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
513 |
distance, |
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
|
514 |
_players_ainew[p->index].from_ic, |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
515 |
_players_ainew[p->index].temp |
2365 | 516 |
); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
517 |
|
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
|
518 |
_players_ainew[p->index].from_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
|
519 |
_players_ainew[p->index].to_tile = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
520 |
|
2365 | 521 |
return; |
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
526 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
527 |
// It was not a valid city |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
528 |
// increase the temp with one, and return. We will come back later here |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
529 |
// to try again |
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
|
530 |
_players_ainew[p->index].temp++; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
531 |
if (_players_ainew[p->index].to_type == AI_CITY) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
532 |
if (_players_ainew[p->index].temp > GetMaxTownIndex()) _players_ainew[p->index].temp = 0; |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
533 |
} 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
|
534 |
if (_players_ainew[p->index].temp > GetMaxIndustryIndex()) _players_ainew[p->index].temp = 0; |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
535 |
} |
145 | 536 |
|
2365 | 537 |
// Don't do an attempt if we are trying the same id as the last time... |
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
|
538 |
if (_players_ainew[p->index].last_id == _players_ainew[p->index].temp) return; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
539 |
_players_ainew[p->index].last_id = _players_ainew[p->index].temp; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
540 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
541 |
|
2365 | 542 |
|
826 | 543 |
// Check if there are not more than a certain amount of vehicles pointed to a certain |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
544 |
// station. This to prevent 10 busses going to one station, which gives... problems ;) |
2365 | 545 |
static bool AiNew_CheckVehicleStation(Player *p, Station *st) |
546 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
547 |
int count = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
548 |
Vehicle *v; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
549 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
550 |
// Also check if we don't have already a lot of busses to this city... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
551 |
FOR_ALL_VEHICLES(v) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
552 |
if (v->owner == _current_player) { |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
553 |
const Order *order; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
554 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
555 |
FOR_VEHICLE_ORDERS(v, order) { |
9332
2e120d0bd632
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
9282
diff
changeset
|
556 |
if (order->IsType(OT_GOTO_STATION) && GetStation(order->dest) == st) { |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
557 |
// This vehicle has this city in its list |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
558 |
count++; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
559 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
560 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
561 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
562 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
563 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
564 |
if (count > AI_CHECK_MAX_VEHICLE_PER_STATION) return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
565 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
566 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
567 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
568 |
// This function finds a good spot for a station |
2365 | 569 |
static void AiNew_State_FindStation(Player *p) |
570 |
{ |
|
571 |
TileIndex tile; |
|
572 |
Station *st; |
|
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
573 |
int count = 0; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
574 |
EngineID i; |
2365 | 575 |
TileIndex new_tile = 0; |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
576 |
DiagDirection direction = DIAGDIR_NE; |
2365 | 577 |
Town *town = 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
|
578 |
assert(_players_ainew[p->index].state == AI_STATE_FIND_STATION); |
145 | 579 |
|
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
|
580 |
if (_players_ainew[p->index].from_tile == 0) { |
2365 | 581 |
// First we scan for a station in the from-city |
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
|
582 |
if (_players_ainew[p->index].from_type == AI_CITY) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
583 |
town = GetTown(_players_ainew[p->index].from_ic); |
2365 | 584 |
tile = town->xy; |
585 |
} 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
|
586 |
tile = GetIndustry(_players_ainew[p->index].from_ic)->xy; |
2365 | 587 |
} |
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
|
588 |
} else if (_players_ainew[p->index].to_tile == 0) { |
2365 | 589 |
// Second we scan for a station in the to-city |
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
|
590 |
if (_players_ainew[p->index].to_type == AI_CITY) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
591 |
town = GetTown(_players_ainew[p->index].to_ic); |
2365 | 592 |
tile = town->xy; |
593 |
} 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
|
594 |
tile = GetIndustry(_players_ainew[p->index].to_ic)->xy; |
2365 | 595 |
} |
596 |
} else { |
|
597 |
// Unsupported request |
|
598 |
// Go to FIND_PATH |
|
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
|
599 |
_players_ainew[p->index].temp = -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
|
600 |
_players_ainew[p->index].state = AI_STATE_FIND_PATH; |
2365 | 601 |
return; |
602 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
603 |
|
2365 | 604 |
// First, we are going to look at the stations that already exist inside the city |
605 |
// If there is enough cargo left in the station, we take that station |
|
606 |
// If that is not possible, and there are more than 2 stations in the city, abort |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
607 |
i = AiNew_PickVehicle(p); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
608 |
// Euhmz, this should not happen _EVER_ |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
609 |
// Quit finding a route... |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
610 |
if (i == 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
|
611 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
612 |
return; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
613 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
614 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
615 |
FOR_ALL_STATIONS(st) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
616 |
if (st->owner == _current_player) { |
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
|
617 |
if (_players_ainew[p->index].tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) == FACIL_BUS_STOP) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
618 |
if (st->town == town) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
619 |
// Check how much cargo there is left in the station |
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
|
620 |
if ((int)st->goods[_players_ainew[p->index].cargo].cargo.Count() > RoadVehInfo(i)->capacity * AI_STATION_REUSE_MULTIPLER) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
621 |
if (AiNew_CheckVehicleStation(p, st)) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
622 |
// We did found a station that was good enough! |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
623 |
new_tile = st->xy; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
624 |
direction = GetRoadStopDir(st->xy); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
625 |
break; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
626 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
627 |
} |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
628 |
count++; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
629 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
630 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
631 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
632 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
633 |
// We are going to add a new station... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
634 |
if (new_tile == 0) count++; |
826 | 635 |
// No more than 2 stations allowed in a city |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
636 |
// This is because only the best 2 stations of one cargo do get any cargo |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
637 |
if (count > 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
|
638 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
639 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
640 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
641 |
|
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
|
642 |
if (new_tile == 0 && _players_ainew[p->index].tbt == AI_BUS) { |
2365 | 643 |
uint x, y, i = 0; |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7420
diff
changeset
|
644 |
CommandCost r; |
2365 | 645 |
uint best; |
646 |
uint accepts[NUM_CARGO]; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6585
diff
changeset
|
647 |
TileIndex found_spot[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4]; |
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6585
diff
changeset
|
648 |
uint found_best[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE * 4]; |
2365 | 649 |
// To find a good spot we scan a range from the center, a get the point |
650 |
// where we get the most cargo and where it is buildable. |
|
651 |
// TODO: also check for station of myself and make sure we are not |
|
7420
bd7ebdf5a44a
(svn r10177) -Fix: Passengers has one A and two Es (ln)
peter1138
parents:
7315
diff
changeset
|
652 |
// taking eachothers passengers away (bad result when it does not) |
2365 | 653 |
for (x = TileX(tile) - AI_FINDSTATION_TILE_RANGE; x <= TileX(tile) + AI_FINDSTATION_TILE_RANGE; x++) { |
654 |
for (y = TileY(tile) - AI_FINDSTATION_TILE_RANGE; y <= TileY(tile) + AI_FINDSTATION_TILE_RANGE; y++) { |
|
655 |
new_tile = TileXY(x, y); |
|
656 |
if (IsTileType(new_tile, MP_CLEAR) || IsTileType(new_tile, MP_TREES)) { |
|
657 |
// This tile we can build on! |
|
658 |
// Check acceptance |
|
659 |
// XXX - Get the catchment area |
|
660 |
GetAcceptanceAroundTiles(accepts, new_tile, 1, 1, 4); |
|
661 |
// >> 3 == 0 means no 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
|
662 |
if (accepts[_players_ainew[p->index].cargo] >> 3 == 0) continue; |
2365 | 663 |
// See if we can build the station |
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
|
664 |
r = AiNew_Build_Station(p, _players_ainew[p->index].tbt, new_tile, 0, 0, 0, DC_QUERY_COST); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
665 |
if (CmdFailed(r)) continue; |
2365 | 666 |
// We can build it, so add it to found_spot |
667 |
found_spot[i] = new_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
|
668 |
found_best[i++] = accepts[_players_ainew[p->index].cargo]; |
2365 | 669 |
} |
670 |
} |
|
671 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
672 |
|
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:
3952
diff
changeset
|
673 |
// If i is still zero, we did not find anything |
2365 | 674 |
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
|
675 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
2365 | 676 |
return; |
677 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
678 |
|
2365 | 679 |
// Go through all the found_best and check which has the highest value |
680 |
best = 0; |
|
681 |
new_tile = 0; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
682 |
|
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:
3952
diff
changeset
|
683 |
for (x = 0; x < i; x++) { |
2365 | 684 |
if (found_best[x] > best || |
685 |
(found_best[x] == best && DistanceManhattan(tile, new_tile) > DistanceManhattan(tile, found_spot[x]))) { |
|
686 |
new_tile = found_spot[x]; |
|
687 |
best = found_best[x]; |
|
688 |
} |
|
689 |
} |
|
145 | 690 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
691 |
// See how much it is going to cost us... |
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
|
692 |
r = AiNew_Build_Station(p, _players_ainew[p->index].tbt, new_tile, 0, 0, 0, DC_QUERY_COST); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
693 |
_players_ainew[p->index].new_cost += r.GetCost(); |
145 | 694 |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
695 |
direction = (DiagDirection)AI_PATHFINDER_NO_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
|
696 |
} else if (new_tile == 0 && _players_ainew[p->index].tbt == AI_TRUCK) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
697 |
// Truck station locater works differently.. a station can be on any place |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
698 |
// as long as it is in range. So we give back code AI_STATION_RANGE |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
699 |
// so the pathfinder routine can work it out! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
700 |
new_tile = AI_STATION_RANGE; |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
701 |
direction = (DiagDirection)AI_PATHFINDER_NO_DIRECTION; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
702 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
703 |
|
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
|
704 |
if (_players_ainew[p->index].from_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
|
705 |
_players_ainew[p->index].from_tile = new_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
|
706 |
_players_ainew[p->index].from_direction = direction; |
2365 | 707 |
// Now we found thisone, go in for to_tile |
708 |
return; |
|
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
|
709 |
} else if (_players_ainew[p->index].to_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
|
710 |
_players_ainew[p->index].to_tile = new_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
|
711 |
_players_ainew[p->index].to_direction = direction; |
2365 | 712 |
// K, done placing stations! |
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
|
713 |
_players_ainew[p->index].temp = -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
|
714 |
_players_ainew[p->index].state = AI_STATE_FIND_PATH; |
2365 | 715 |
return; |
716 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
717 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
718 |
|
2365 | 719 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
720 |
// We try to find a path between 2 points |
2365 | 721 |
static void AiNew_State_FindPath(Player *p) |
722 |
{ |
|
723 |
int r; |
|
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
|
724 |
assert(_players_ainew[p->index].state == AI_STATE_FIND_PATH); |
145 | 725 |
|
2365 | 726 |
// First time, init some 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
|
727 |
if (_players_ainew[p->index].temp == -1) { |
2365 | 728 |
// Init path_info |
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
|
729 |
if (_players_ainew[p->index].from_tile == AI_STATION_RANGE) { |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
730 |
const Industry* i = GetIndustry(_players_ainew[p->index].from_ic); |
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
731 |
|
2365 | 732 |
// For truck routes we take a range around the industry |
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
|
733 |
_players_ainew[p->index].path_info.start_tile_tl = i->xy - TileDiffXY(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
|
734 |
_players_ainew[p->index].path_info.start_tile_br = i->xy + TileDiffXY(i->width + 1, i->height + 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
|
735 |
_players_ainew[p->index].path_info.start_direction = _players_ainew[p->index].from_direction; |
2365 | 736 |
} 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
|
737 |
_players_ainew[p->index].path_info.start_tile_tl = _players_ainew[p->index].from_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
|
738 |
_players_ainew[p->index].path_info.start_tile_br = _players_ainew[p->index].from_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
|
739 |
_players_ainew[p->index].path_info.start_direction = _players_ainew[p->index].from_direction; |
2365 | 740 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
741 |
|
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
|
742 |
if (_players_ainew[p->index].to_tile == AI_STATION_RANGE) { |
b769d0a63f06
(svn r11792) -Codechange: 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 |
const Industry* i = GetIndustry(_players_ainew[p->index].to_ic); |
3952
c51a2e094dde
(svn r5098) Do some manual CSE and replace a few magic numbers to improve the readability of the trolly AI
tron
parents:
3951
diff
changeset
|
744 |
|
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
|
745 |
_players_ainew[p->index].path_info.end_tile_tl = i->xy - TileDiffXY(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
|
746 |
_players_ainew[p->index].path_info.end_tile_br = i->xy + TileDiffXY(i->width + 1, i->height + 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
|
747 |
_players_ainew[p->index].path_info.end_direction = _players_ainew[p->index].to_direction; |
2365 | 748 |
} 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
|
749 |
_players_ainew[p->index].path_info.end_tile_tl = _players_ainew[p->index].to_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
|
750 |
_players_ainew[p->index].path_info.end_tile_br = _players_ainew[p->index].to_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_ainew[p->index].path_info.end_direction = _players_ainew[p->index].to_direction; |
2365 | 752 |
} |
145 | 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_ainew[p->index].path_info.rail_or_road = (_players_ainew[p->index].tbt == AI_TRAIN); |
145 | 755 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
756 |
// First, clean the pathfinder with our new begin and endpoints |
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
|
757 |
clean_AyStar_AiPathFinder(_players_ainew[p->index].pathfinder, &_players_ainew[p->index].path_info); |
145 | 758 |
|
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
|
759 |
_players_ainew[p->index].temp = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
760 |
} |
145 | 761 |
|
2365 | 762 |
// Start the pathfinder |
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
|
763 |
r = _players_ainew[p->index].pathfinder->main(_players_ainew[p->index].pathfinder); |
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:
3952
diff
changeset
|
764 |
switch (r) { |
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:
3952
diff
changeset
|
765 |
case AYSTAR_NO_PATH: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
766 |
DEBUG(ai, 1, "No route found by pathfinder"); |
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:
3952
diff
changeset
|
767 |
// Start all over again |
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
|
768 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
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:
3952
diff
changeset
|
769 |
break; |
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:
3952
diff
changeset
|
770 |
|
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:
3952
diff
changeset
|
771 |
case AYSTAR_FOUND_END_NODE: // We found the end-point |
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
|
772 |
_players_ainew[p->index].temp = -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
|
773 |
_players_ainew[p->index].state = AI_STATE_FIND_DEPOT; |
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:
3952
diff
changeset
|
774 |
break; |
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:
3952
diff
changeset
|
775 |
|
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:
3952
diff
changeset
|
776 |
// In any other case, we are still busy finding the route |
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:
3952
diff
changeset
|
777 |
default: break; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
778 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
779 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
780 |
|
2365 | 781 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
782 |
// This function tries to locate a good place for a depot! |
2365 | 783 |
static void AiNew_State_FindDepot(Player *p) |
784 |
{ |
|
785 |
// To place the depot, we walk through the route, and if we find a lovely spot (MP_CLEAR, MP_TREES), we place it there.. |
|
786 |
// Simple, easy, works! |
|
787 |
// To make the depot stand in the middle of the route, we start from the center.. |
|
788 |
// But first we walk through the route see if we can find a depot that is ours |
|
789 |
// this keeps things nice ;) |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7420
diff
changeset
|
790 |
int g, i; |
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7420
diff
changeset
|
791 |
CommandCost r; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
792 |
DiagDirection j; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
793 |
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
|
794 |
assert(_players_ainew[p->index].state == AI_STATE_FIND_DEPOT); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
795 |
|
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
|
796 |
_players_ainew[p->index].depot_tile = 0; |
145 | 797 |
|
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
|
798 |
for (i=2;i<_players_ainew[p->index].path_info.route_length-2;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
|
799 |
tile = _players_ainew[p->index].path_info.route[i]; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
800 |
for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) { |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
801 |
TileIndex t = tile + TileOffsByDiagDir(j); |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
802 |
|
9059
04edde3eb0c6
(svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents:
9052
diff
changeset
|
803 |
if (IsRoadDepotTile(t) && |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
804 |
IsTileOwner(t, _current_player) && |
3179 | 805 |
GetRoadDepotDirection(t) == ReverseDiagDir(j)) { |
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
|
806 |
_players_ainew[p->index].depot_tile = t; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
807 |
_players_ainew[p->index].depot_direction = ReverseDiagDir(j); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
808 |
_players_ainew[p->index].state = AI_STATE_VERIFY_ROUTE; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
809 |
return; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
810 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
811 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
812 |
} |
145 | 813 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
814 |
// This routine let depot finding start in the middle, and work his way to the stations |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
815 |
// It makes depot placing nicer :) |
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
|
816 |
i = _players_ainew[p->index].path_info.route_length / 2; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
817 |
g = 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
|
818 |
while (i > 1 && i < _players_ainew[p->index].path_info.route_length - 2) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
819 |
i += g; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
820 |
g *= -1; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
821 |
(g < 0?g--:g++); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
822 |
|
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
|
823 |
if (_players_ainew[p->index].path_info.route_extra[i] != 0 || _players_ainew[p->index].path_info.route_extra[i+1] != 0) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
824 |
// Bridge or tunnel.. we can't place a depot there |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
825 |
continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
826 |
} |
145 | 827 |
|
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
|
828 |
tile = _players_ainew[p->index].path_info.route[i]; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
829 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
830 |
for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) { |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
831 |
TileIndex t = tile + TileOffsByDiagDir(j); |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
832 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
833 |
// It may not be placed on the road/rail itself |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
834 |
// And because it is not build yet, we can't see it on the tile.. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
835 |
// So check the surrounding tiles :) |
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
|
836 |
if (t == _players_ainew[p->index].path_info.route[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
|
837 |
t == _players_ainew[p->index].path_info.route[i + 1]) { |
2365 | 838 |
continue; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
839 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
840 |
// Not around a bridge? |
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
|
841 |
if (_players_ainew[p->index].path_info.route_extra[i] != 0) continue; |
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
|
842 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
843 |
// Is the terrain clear? |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
844 |
if (IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)) { |
3644
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3577
diff
changeset
|
845 |
// If the current tile is on a slope then we do not allow this |
45a307767dc1
(svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents:
3577
diff
changeset
|
846 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
847 |
// Check if everything went okay.. |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
848 |
r = AiNew_Build_Depot(p, t, ReverseDiagDir(j), 0); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
849 |
if (CmdFailed(r)) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
850 |
// Found a spot! |
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
|
851 |
_players_ainew[p->index].new_cost += r.GetCost(); |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].depot_tile = t; |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].depot_direction = ReverseDiagDir(j); // Reverse 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
|
854 |
_players_ainew[p->index].state = AI_STATE_VERIFY_ROUTE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
855 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
856 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
857 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
858 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
859 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
860 |
// Failed to find a 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
|
861 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
862 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
863 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
864 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
865 |
// This function calculates how many vehicles there are needed on this |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
866 |
// traject. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
867 |
// It works pretty simple: get the length, see how much we move around |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
868 |
// and hussle that, and you know how many vehicles there are needed. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
869 |
// It returns the cost for the vehicles |
2365 | 870 |
static int AiNew_HowManyVehicles(Player *p) |
871 |
{ |
|
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
|
872 |
if (_players_ainew[p->index].tbt == AI_BUS) { |
2365 | 873 |
// For bus-routes we look at the time before we are back in the station |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
874 |
EngineID i; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
875 |
int length, tiles_a_day; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
876 |
int amount; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
877 |
i = AiNew_PickVehicle(p); |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
878 |
if (i == INVALID_ENGINE) return 0; |
2365 | 879 |
// Passenger run.. how long is the 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
|
880 |
length = _players_ainew[p->index].path_info.route_length; |
2365 | 881 |
// Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
882 |
tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
|
883 |
// We want a vehicle in a station once a month at least, so, calculate it! |
|
884 |
// (the * 2 is because we have 2 stations ;)) |
|
885 |
amount = length * 2 * 2 / tiles_a_day / 30; |
|
886 |
if (amount == 0) amount = 1; |
|
887 |
return amount; |
|
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 |
} else if (_players_ainew[p->index].tbt == AI_TRUCK) { |
2365 | 889 |
// For truck-routes we look at the cargo |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
890 |
EngineID i; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
891 |
int length, amount, tiles_a_day; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
892 |
int max_cargo; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
893 |
i = AiNew_PickVehicle(p); |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
894 |
if (i == INVALID_ENGINE) return 0; |
2365 | 895 |
// Passenger run.. how long is the 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
|
896 |
length = _players_ainew[p->index].path_info.route_length; |
2365 | 897 |
// Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
898 |
tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
|
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
|
899 |
if (_players_ainew[p->index].from_deliver) { |
b769d0a63f06
(svn r11792) -Codechange: 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 |
max_cargo = GetIndustry(_players_ainew[p->index].from_ic)->last_month_production[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:
3952
diff
changeset
|
901 |
} 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
|
902 |
max_cargo = GetIndustry(_players_ainew[p->index].to_ic)->last_month_production[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:
3952
diff
changeset
|
903 |
} |
145 | 904 |
|
2365 | 905 |
// This is because moving 60% is more than we can dream of! |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
906 |
max_cargo *= 6; |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
907 |
max_cargo /= 10; |
2365 | 908 |
// We want all the cargo to be gone in a month.. so, we know the cargo it delivers |
909 |
// we know what the vehicle takes with him, and we know the time it takes him |
|
910 |
// to get back here.. now let's do some math! |
|
911 |
amount = 2 * length * max_cargo / tiles_a_day / 30 / RoadVehInfo(i)->capacity; |
|
912 |
amount += 1; |
|
913 |
return amount; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
914 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
915 |
// Currently not supported |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
916 |
return 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
917 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
918 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
919 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
920 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
921 |
// This function checks: |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
922 |
// - If the route went okay |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
923 |
// - Calculates the amount of money needed to build the route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
924 |
// - Calculates how much vehicles needed for the route |
2365 | 925 |
static void AiNew_State_VerifyRoute(Player *p) |
926 |
{ |
|
927 |
int res, 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
|
928 |
assert(_players_ainew[p->index].state == AI_STATE_VERIFY_ROUTE); |
145 | 929 |
|
2365 | 930 |
// Let's calculate the cost of the path.. |
931 |
// new_cost already contains the cost of the stations |
|
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
|
932 |
_players_ainew[p->index].path_info.position = -1; |
145 | 933 |
|
2365 | 934 |
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
|
935 |
_players_ainew[p->index].path_info.position++; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
936 |
_players_ainew[p->index].new_cost += AiNew_Build_RoutePart(p, &_players_ainew[p->index].path_info, DC_QUERY_COST).GetCost(); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
937 |
} while (_players_ainew[p->index].path_info.position != -2); |
145 | 938 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
939 |
// Now we know the price of build station + path. Now check how many vehicles |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
940 |
// we need and what the price for that will be |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
941 |
res = AiNew_HowManyVehicles(p); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
942 |
// If res == 0, no vehicle was found, or an other problem did occour |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
943 |
if (res == 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
|
944 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
945 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
946 |
} |
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
|
947 |
_players_ainew[p->index].amount_veh = res; |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
948 |
_players_ainew[p->index].cur_veh = 0; |
145 | 949 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
950 |
// Check how much it it going to cost us.. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
951 |
for (i=0;i<res;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
|
952 |
_players_ainew[p->index].new_cost += AiNew_Build_Vehicle(p, 0, DC_QUERY_COST).GetCost(); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
953 |
} |
145 | 954 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
955 |
// Now we know how much the route is going to cost us |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
956 |
// Check if we have enough money for 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
|
957 |
if (_players_ainew[p->index].new_cost > p->player_money - AI_MINIMUM_MONEY) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
958 |
// Too bad.. |
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
|
959 |
DEBUG(ai, 1, "Insufficient funds to build route (%" OTTD_PRINTF64 "d)", (int64)_players_ainew[p->index].new_cost); |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
961 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
962 |
} |
145 | 963 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
964 |
// Now we can build the route, check the direction of the stations! |
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
|
965 |
if (_players_ainew[p->index].from_direction == AI_PATHFINDER_NO_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
|
966 |
_players_ainew[p->index].from_direction = AiNew_GetDirection(_players_ainew[p->index].path_info.route[_players_ainew[p->index].path_info.route_length - 1], _players_ainew[p->index].path_info.route[_players_ainew[p->index].path_info.route_length - 2]); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
967 |
} |
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
|
968 |
if (_players_ainew[p->index].to_direction == AI_PATHFINDER_NO_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
|
969 |
_players_ainew[p->index].to_direction = AiNew_GetDirection(_players_ainew[p->index].path_info.route[0], _players_ainew[p->index].path_info.route[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
|
970 |
} |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
971 |
if (_players_ainew[p->index].from_tile == AI_STATION_RANGE) |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].from_tile = _players_ainew[p->index].path_info.route[_players_ainew[p->index].path_info.route_length - 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
|
973 |
if (_players_ainew[p->index].to_tile == AI_STATION_RANGE) |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].to_tile = _players_ainew[p->index].path_info.route[0]; |
145 | 975 |
|
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
|
976 |
_players_ainew[p->index].state = AI_STATE_BUILD_STATION; |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].temp = 0; |
145 | 978 |
|
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
|
979 |
DEBUG(ai, 1, "The route is set and buildable, building 0x%X to 0x%X...", _players_ainew[p->index].from_tile, _players_ainew[p->index].to_tile); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
980 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
981 |
|
2365 | 982 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
983 |
// Build the stations |
2365 | 984 |
static void AiNew_State_BuildStation(Player *p) |
985 |
{ |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
986 |
CommandCost res; |
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 |
assert(_players_ainew[p->index].state == AI_STATE_BUILD_STATION); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
988 |
if (_players_ainew[p->index].temp == 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
|
989 |
if (!IsTileType(_players_ainew[p->index].from_tile, MP_STATION)) |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
990 |
res = AiNew_Build_Station(p, _players_ainew[p->index].tbt, _players_ainew[p->index].from_tile, 0, 0, _players_ainew[p->index].from_direction, DC_EXEC); |
2365 | 991 |
} 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
|
992 |
if (!IsTileType(_players_ainew[p->index].to_tile, MP_STATION)) |
b769d0a63f06
(svn r11792) -Codechange: 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 |
res = AiNew_Build_Station(p, _players_ainew[p->index].tbt, _players_ainew[p->index].to_tile, 0, 0, _players_ainew[p->index].to_direction, DC_EXEC); |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].state = AI_STATE_BUILD_PATH; |
2365 | 995 |
} |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
996 |
if (CmdFailed(res)) { |
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
|
997 |
DEBUG(ai, 0, "[BuildStation] station could not be built (0x%X)", _players_ainew[p->index].to_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
|
998 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
999 |
// If the first station _was_ build, destroy 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
|
1000 |
if (_players_ainew[p->index].temp != 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
|
1001 |
AI_DoCommand(_players_ainew[p->index].from_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1002 |
return; |
2365 | 1003 |
} |
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
|
1004 |
_players_ainew[p->index].temp++; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1005 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1006 |
|
2365 | 1007 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1008 |
// Build the path |
2365 | 1009 |
static void AiNew_State_BuildPath(Player *p) |
1010 |
{ |
|
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
|
1011 |
assert(_players_ainew[p->index].state == AI_STATE_BUILD_PATH); |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].temp is set to -1 when this function is called for the first time |
b769d0a63f06
(svn r11792) -Codechange: 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 |
if (_players_ainew[p->index].temp == -1) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
1014 |
DEBUG(ai, 1, "Starting to build new path"); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1015 |
// Init the counter |
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
|
1016 |
_players_ainew[p->index].counter = (4 - _opt.diff.competitor_speed) * AI_BUILDPATH_PAUSE + 1; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1017 |
// Set the position to the startingplace (-1 because in a minute we 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
|
1018 |
_players_ainew[p->index].path_info.position = -1; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1019 |
// And don't do this again |
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
|
1020 |
_players_ainew[p->index].temp = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1021 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1022 |
// Building goes very fast on normal rate, so we are going to slow it down.. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1023 |
// By let the counter count from AI_BUILDPATH_PAUSE to 0, we have a nice way :) |
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
|
1024 |
if (--_players_ainew[p->index].counter != 0) return; |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].counter = (4 - _opt.diff.competitor_speed) * AI_BUILDPATH_PAUSE + 1; |
145 | 1026 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1027 |
// Increase the building position |
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
|
1028 |
_players_ainew[p->index].path_info.position++; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1029 |
// Build 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
|
1030 |
AiNew_Build_RoutePart(p, &_players_ainew[p->index].path_info, DC_EXEC); |
b769d0a63f06
(svn r11792) -Codechange: 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 |
if (_players_ainew[p->index].path_info.position == -2) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1032 |
// This means we are done building! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1033 |
|
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
|
1034 |
if (_players_ainew[p->index].tbt == AI_TRUCK && !_patches.roadveh_queue) { |
2365 | 1035 |
// If they not queue, they have to go up and down to try again at a station... |
1036 |
// We don't want that, so try building some road left or right of the station |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1037 |
DiagDirection dir1, dir2, dir3; |
2365 | 1038 |
TileIndex tile; |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7420
diff
changeset
|
1039 |
CommandCost ret; |
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7420
diff
changeset
|
1040 |
for (int i = 0; i < 2; i++) { |
2365 | 1041 |
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
|
1042 |
tile = _players_ainew[p->index].from_tile + TileOffsByDiagDir(_players_ainew[p->index].from_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
|
1043 |
dir1 = ChangeDiagDir(_players_ainew[p->index].from_direction, DIAGDIRDIFF_90LEFT); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1044 |
dir2 = ChangeDiagDir(_players_ainew[p->index].from_direction, DIAGDIRDIFF_90RIGHT); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1045 |
dir3 = _players_ainew[p->index].from_direction; |
2365 | 1046 |
} 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
|
1047 |
tile = _players_ainew[p->index].to_tile + TileOffsByDiagDir(_players_ainew[p->index].to_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
|
1048 |
dir1 = ChangeDiagDir(_players_ainew[p->index].to_direction, DIAGDIRDIFF_90LEFT); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1049 |
dir2 = ChangeDiagDir(_players_ainew[p->index].to_direction, DIAGDIRDIFF_90RIGHT); |
b769d0a63f06
(svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents:
8640
diff
changeset
|
1050 |
dir3 = _players_ainew[p->index].to_direction; |
2365 | 1051 |
} |
145 | 1052 |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1053 |
ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1054 |
if (CmdSucceeded(ret)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1055 |
TileIndex offset = TileOffsByDiagDir(dir1); |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1056 |
if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) { |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1057 |
ret = AI_DoCommand(tile + offset, AiNew_GetRoadDirection(tile, tile + offset, tile + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1058 |
if (CmdSucceeded(ret)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1059 |
if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, MP_TREES)) |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1060 |
AI_DoCommand(tile + offset + offset, AiNew_GetRoadDirection(tile + offset, tile + offset + offset, tile + offset + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
146
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1061 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1062 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1063 |
} |
145 | 1064 |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1065 |
ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1066 |
if (CmdSucceeded(ret)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1067 |
TileIndex offset = TileOffsByDiagDir(dir2); |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1068 |
if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) { |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1069 |
ret = AI_DoCommand(tile + offset, AiNew_GetRoadDirection(tile, tile + offset, tile + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1070 |
if (CmdSucceeded(ret)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1071 |
if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, MP_TREES)) |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1072 |
AI_DoCommand(tile + offset + offset, AiNew_GetRoadDirection(tile + offset, tile + offset + offset, tile + offset + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
146
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1073 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1074 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1075 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1076 |
|
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1077 |
ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1078 |
if (CmdSucceeded(ret)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1079 |
TileIndex offset = TileOffsByDiagDir(dir3); |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1080 |
if (IsTileType(tile + offset, MP_CLEAR) || IsTileType(tile + offset, MP_TREES)) { |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1081 |
ret = AI_DoCommand(tile + offset, AiNew_GetRoadDirection(tile, tile + offset, tile + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1082 |
if (CmdSucceeded(ret)) { |
7813
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1083 |
if (IsTileType(tile + offset + offset, MP_CLEAR) || IsTileType(tile + offset + offset, MP_TREES)) |
49fbe41f8a04
(svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents:
7506
diff
changeset
|
1084 |
AI_DoCommand(tile + offset + offset, AiNew_GetRoadDirection(tile + offset, tile + offset + offset, tile + offset + offset + offset), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
146
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1085 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1086 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1087 |
} |
2365 | 1088 |
} |
1089 |
} |
|
145 | 1090 |
|
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
|
1091 |
DEBUG(ai, 1, "Finished building path, cost: %" OTTD_PRINTF64 "d", (int64)_players_ainew[p->index].new_cost); |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].state = AI_STATE_BUILD_DEPOT; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1093 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1094 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1095 |
|
2365 | 1096 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1097 |
// Builds the depot |
2365 | 1098 |
static void AiNew_State_BuildDepot(Player *p) |
1099 |
{ |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1100 |
CommandCost res; |
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
|
1101 |
assert(_players_ainew[p->index].state == AI_STATE_BUILD_DEPOT); |
145 | 1102 |
|
9059
04edde3eb0c6
(svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents:
9052
diff
changeset
|
1103 |
if (IsRoadDepotTile(_players_ainew[p->index].depot_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
|
1104 |
if (IsTileOwner(_players_ainew[p->index].depot_tile, _current_player)) { |
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:
3952
diff
changeset
|
1105 |
// The depot is already built |
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
|
1106 |
_players_ainew[p->index].state = AI_STATE_BUILD_VEHICLE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1107 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1108 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1109 |
// There is a depot, but not of our team! :( |
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
|
1110 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1111 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1112 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1113 |
} |
145 | 1114 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1115 |
// There is a bus on the tile we want to build road on... idle till he is gone! (BAD PERSON! :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
|
1116 |
if (!EnsureNoVehicleOnGround(_players_ainew[p->index].depot_tile + TileOffsByDiagDir(_players_ainew[p->index].depot_direction))) |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1117 |
return; |
145 | 1118 |
|
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
|
1119 |
res = AiNew_Build_Depot(p, _players_ainew[p->index].depot_tile, _players_ainew[p->index].depot_direction, DC_EXEC); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
1120 |
if (CmdFailed(res)) { |
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
|
1121 |
DEBUG(ai, 0, "[BuildDepot] depot could not be built (0x%X)", _players_ainew[p->index].depot_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
|
1122 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1123 |
return; |
2365 | 1124 |
} |
145 | 1125 |
|
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
|
1126 |
_players_ainew[p->index].state = AI_STATE_BUILD_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
|
1127 |
_players_ainew[p->index].idle = 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
|
1128 |
_players_ainew[p->index].veh_main_id = INVALID_VEHICLE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1129 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1130 |
|
145 | 1131 |
|
2365 | 1132 |
// Build vehicles |
1133 |
static void AiNew_State_BuildVehicle(Player *p) |
|
1134 |
{ |
|
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7420
diff
changeset
|
1135 |
CommandCost res; |
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
|
1136 |
assert(_players_ainew[p->index].state == AI_STATE_BUILD_VEHICLE); |
2365 | 1137 |
|
1138 |
// Check if we need to build a vehicle |
|
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
|
1139 |
if (_players_ainew[p->index].amount_veh == 0) { |
2365 | 1140 |
// Nope, we are done! |
1141 |
// This means: we are all done! The route is open.. go back to NOTHING |
|
1142 |
// He will idle some time and it will all start over again.. :) |
|
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
|
1143 |
_players_ainew[p->index].state = AI_STATE_ACTION_DONE; |
2365 | 1144 |
return; |
1145 |
} |
|
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
|
1146 |
if (--_players_ainew[p->index].idle != 0) return; |
2365 | 1147 |
// It is realistic that the AI can only build 1 vehicle a day.. |
1148 |
// This makes sure of that! |
|
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
|
1149 |
_players_ainew[p->index].idle = AI_BUILD_VEHICLE_TIME_BETWEEN; |
2365 | 1150 |
|
1151 |
// Build the vehicle |
|
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
|
1152 |
res = AiNew_Build_Vehicle(p, _players_ainew[p->index].depot_tile, DC_EXEC); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
1153 |
if (CmdFailed(res)) { |
2365 | 1154 |
// This happens when the AI can't build any more vehicles! |
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
|
1155 |
_players_ainew[p->index].state = AI_STATE_NOTHING; |
2365 | 1156 |
return; |
1157 |
} |
|
1158 |
// Increase the current counter |
|
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
|
1159 |
_players_ainew[p->index].cur_veh++; |
2365 | 1160 |
// Decrease the total counter |
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
|
1161 |
_players_ainew[p->index].amount_veh--; |
2365 | 1162 |
// Go give some orders! |
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_ainew[p->index].state = AI_STATE_WAIT_FOR_BUILD; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1164 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1165 |
|
2365 | 1166 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1167 |
// Put the stations in the order list |
2365 | 1168 |
static void AiNew_State_GiveOrders(Player *p) |
1169 |
{ |
|
1170 |
int idx; |
|
1171 |
Order order; |
|
145 | 1172 |
|
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
|
1173 |
assert(_players_ainew[p->index].state == AI_STATE_GIVE_ORDERS); |
145 | 1174 |
|
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
|
1175 |
if (_players_ainew[p->index].veh_main_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
|
1176 |
AI_DoCommand(0, _players_ainew[p->index].veh_id + (_players_ainew[p->index].veh_main_id << 16), CO_SHARE, DC_EXEC, CMD_CLONE_ORDER); |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1177 |
|
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
|
1178 |
_players_ainew[p->index].state = AI_STATE_START_VEHICLE; |
2365 | 1179 |
return; |
1180 |
} 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
|
1181 |
_players_ainew[p->index].veh_main_id = _players_ainew[p->index].veh_id; |
2365 | 1182 |
} |
1183 |
||
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1184 |
// Very handy for AI, goto depot.. but yeah, it needs to be activated ;) |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1185 |
if (_patches.gotodepot) { |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1186 |
idx = 0; |
9332
2e120d0bd632
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
9282
diff
changeset
|
1187 |
order.MakeGoToDepot(GetDepotByTile(_players_ainew[p->index].depot_tile)->index, true); |
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
|
1188 |
AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1189 |
} |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1190 |
|
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1191 |
idx = 0; |
9332
2e120d0bd632
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
9282
diff
changeset
|
1192 |
order.MakeGoToStation(GetStationIndex(_players_ainew[p->index].to_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
|
1193 |
if (_players_ainew[p->index].tbt == AI_TRUCK && _players_ainew[p->index].to_deliver) |
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:
8760
diff
changeset
|
1194 |
order.flags |= OFB_FULL_LOAD; |
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
|
1195 |
AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1196 |
|
2365 | 1197 |
idx = 0; |
9332
2e120d0bd632
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
9282
diff
changeset
|
1198 |
order.MakeGoToStation(GetStationIndex(_players_ainew[p->index].from_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
|
1199 |
if (_players_ainew[p->index].tbt == AI_TRUCK && _players_ainew[p->index].from_deliver) |
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:
8760
diff
changeset
|
1200 |
order.flags |= OFB_FULL_LOAD; |
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 |
AI_DoCommand(0, _players_ainew[p->index].veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1202 |
|
2365 | 1203 |
// Start the engines! |
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
|
1204 |
_players_ainew[p->index].state = AI_STATE_START_VEHICLE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1205 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1206 |
|
2365 | 1207 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1208 |
// Start the vehicle |
2365 | 1209 |
static void AiNew_State_StartVehicle(Player *p) |
1210 |
{ |
|
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
|
1211 |
assert(_players_ainew[p->index].state == AI_STATE_START_VEHICLE); |
145 | 1212 |
|
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1213 |
// Skip the first order if it is a second vehicle |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1214 |
// This to make vehicles go different ways.. |
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
|
1215 |
if (_players_ainew[p->index].cur_veh & 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
|
1216 |
AI_DoCommand(0, _players_ainew[p->index].veh_id, 1, DC_EXEC, CMD_SKIP_TO_ORDER); |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1217 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1218 |
// 3, 2, 1... go! (give START_STOP command ;)) |
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 |
AI_DoCommand(0, _players_ainew[p->index].veh_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1220 |
// Try to build an other vehicle (that function will stop building when needed) |
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
|
1221 |
_players_ainew[p->index].idle = 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
|
1222 |
_players_ainew[p->index].state = AI_STATE_BUILD_VEHICLE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1223 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1224 |
|
2365 | 1225 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1226 |
// Repays money |
2365 | 1227 |
static void AiNew_State_RepayMoney(Player *p) |
1228 |
{ |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1229 |
uint i; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1230 |
|
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1231 |
for (i = 0; i < AI_LOAN_REPAY; i++) { |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1232 |
AI_DoCommand(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1233 |
} |
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
|
1234 |
_players_ainew[p->index].state = AI_STATE_ACTION_DONE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1235 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1236 |
|
2365 | 1237 |
|
1238 |
static void AiNew_CheckVehicle(Player *p, Vehicle *v) |
|
1239 |
{ |
|
145 | 1240 |
// When a vehicle is under the 6 months, we don't check for anything |
1241 |
if (v->age < 180) return; |
|
1242 |
||
1243 |
// When a vehicle is older then 1 year, it should make money... |
|
1244 |
if (v->age > 360) { |
|
826 | 1245 |
// If both years together are not more than AI_MINIMUM_ROUTE_PROFIT, |
145 | 1246 |
// it is not worth the line I guess... |
9110
55864e1fc263
(svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents:
9059
diff
changeset
|
1247 |
if (v->profit_last_year + v->profit_this_year < (Money)256 * AI_MINIMUM_ROUTE_PROFIT || |
2365 | 1248 |
(v->reliability * 100 >> 16) < 40) { |
145 | 1249 |
// There is a possibility that the route is fucked up... |
7506
e52d89f5c7c1
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
7486
diff
changeset
|
1250 |
if (v->cargo.DaysInTransit() > AI_VEHICLE_LOST_DAYS) { |
145 | 1251 |
// The vehicle is lost.. check the route, or else, get the vehicle |
1252 |
// back to a depot |
|
1253 |
// TODO: make this piece of code |
|
1254 |
} |
|
1255 |
||
1256 |
||
1257 |
// We are already sending him back |
|
1258 |
if (AiNew_GetSpecialVehicleFlag(p, v) & AI_VEHICLEFLAG_SELL) { |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
1259 |
if (v->type == VEH_ROAD && IsTileDepotType(v->tile, TRANSPORT_ROAD) && |
2365 | 1260 |
(v->vehstatus&VS_STOPPED)) { |
145 | 1261 |
// We are at the depot, sell the vehicle |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1262 |
AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH); |
145 | 1263 |
} |
1264 |
return; |
|
1265 |
} |
|
1266 |
||
1267 |
if (!AiNew_SetSpecialVehicleFlag(p, v, AI_VEHICLEFLAG_SELL)) return; |
|
1268 |
{ |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1269 |
CommandCost ret; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
1270 |
if (v->type == VEH_ROAD) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1271 |
ret = AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); |
145 | 1272 |
// This means we can not find a depot :s |
2365 | 1273 |
// if (CmdFailed(ret)) |
145 | 1274 |
} |
1275 |
} |
|
1276 |
} |
|
1277 |
} |
|
1278 |
||
2365 | 1279 |
|
145 | 1280 |
// Checks all vehicles if they are still valid and make money and stuff |
2365 | 1281 |
static void AiNew_State_CheckAllVehicles(Player *p) |
1282 |
{ |
|
145 | 1283 |
Vehicle *v; |
1284 |
||
1285 |
FOR_ALL_VEHICLES(v) { |
|
1286 |
if (v->owner != p->index) continue; |
|
1287 |
// Currently, we only know how to handle road-vehicles |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
5907
diff
changeset
|
1288 |
if (v->type != VEH_ROAD) continue; |
145 | 1289 |
|
1290 |
AiNew_CheckVehicle(p, v); |
|
1291 |
} |
|
1292 |
||
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
|
1293 |
_players_ainew[p->index].state = AI_STATE_ACTION_DONE; |
145 | 1294 |
} |
1295 |
||
2365 | 1296 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1297 |
// Using the technique simular to the original AI |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1298 |
// Keeps things logical |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1299 |
// It really should be in the same order as the AI_STATE's are! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1300 |
static AiNew_StateFunction* const _ainew_state[] = { |
2365 | 1301 |
NULL, |
1302 |
AiNew_State_FirstTime, |
|
1303 |
AiNew_State_Nothing, |
|
1304 |
AiNew_State_WakeUp, |
|
1305 |
AiNew_State_LocateRoute, |
|
1306 |
AiNew_State_FindStation, |
|
1307 |
AiNew_State_FindPath, |
|
1308 |
AiNew_State_FindDepot, |
|
1309 |
AiNew_State_VerifyRoute, |
|
1310 |
AiNew_State_BuildStation, |
|
1311 |
AiNew_State_BuildPath, |
|
1312 |
AiNew_State_BuildDepot, |
|
1313 |
AiNew_State_BuildVehicle, |
|
3946
c9e039a60682
(svn r5092) -Fix: There was a gross race condition in the AI code which made it pretty random if the AI could give a new vehicle its orders
tron
parents:
3945
diff
changeset
|
1314 |
NULL, |
2365 | 1315 |
AiNew_State_GiveOrders, |
1316 |
AiNew_State_StartVehicle, |
|
1317 |
AiNew_State_RepayMoney, |
|
145 | 1318 |
AiNew_State_CheckAllVehicles, |
2365 | 1319 |
AiNew_State_ActionDone, |
1320 |
NULL, |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1321 |
}; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1322 |
|
2365 | 1323 |
static void AiNew_OnTick(Player *p) |
1324 |
{ |
|
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
|
1325 |
if (_ainew_state[_players_ainew[p->index].state] != 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
|
1326 |
_ainew_state[_players_ainew[p->index].state](p); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1327 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1328 |
|
2365 | 1329 |
|
1330 |
void AiNewDoGameLoop(Player *p) |
|
1331 |
{ |
|
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
|
1332 |
if (_players_ainew[p->index].state == AI_STATE_STARTUP) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1333 |
// The AI just got alive! |
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
|
1334 |
_players_ainew[p->index].state = AI_STATE_FIRST_TIME; |
b769d0a63f06
(svn r11792) -Codechange: 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_ainew[p->index].tick = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1336 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1337 |
// Only startup the AI |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1338 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1339 |
} |
145 | 1340 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1341 |
// We keep a ticker. We use it for competitor_speed |
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
|
1342 |
_players_ainew[p->index].tick++; |
145 | 1343 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1344 |
// If we come here, we can do a tick.. do so! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1345 |
AiNew_OnTick(p); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1346 |
} |