author | bjarni |
Mon, 05 Feb 2007 21:16:56 +0000 | |
changeset 6192 | c6adfc929c6b |
parent 5907 | 3ed575a60e1d |
child 6298 | c30fe89622df |
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" |
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
|
23 |
#include "../../functions.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3071
diff
changeset
|
24 |
#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
|
25 |
#include "../../station_map.h" |
5907 | 26 |
#include "table/strings.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
|
27 |
#include "../../map.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 "../../tile.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
|
29 |
#include "../../command.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
|
30 |
#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
|
31 |
#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
|
32 |
#include "../../industry.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2365
diff
changeset
|
33 |
#include "../../station.h" |
de9053fe2a2c
(svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
2365
diff
changeset
|
34 |
#include "../../engine.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
|
35 |
#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
|
36 |
#include "../../depot.h" |
3577
9e345c932ba2
(svn r4463) -Codechange. Include vehicle.h directly instead of implicitly via station.h in a number of source files
celestar
parents:
3404
diff
changeset
|
37 |
#include "../../vehicle.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4077
diff
changeset
|
38 |
#include "../../date.h" |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
39 |
#include "../ai.h" |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
40 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
41 |
// This function is called after StartUp. It is the init of an AI |
2365 | 42 |
static void AiNew_State_FirstTime(Player *p) |
43 |
{ |
|
44 |
// This assert is used to protect those function from misuse |
|
45 |
// You have quickly a small mistake in the state-array |
|
46 |
// With that, everything would go wrong. Finding that, is almost impossible |
|
47 |
// With this assert, that problem can never happen. |
|
48 |
assert(p->ainew.state == AI_STATE_FIRST_TIME); |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
49 |
// We first have to init some things |
145 | 50 |
|
4854
383ef523793f
(svn r6780) -Codechange: Remove GPMI leftovers (-b impersonisation of AI in MP).
Darkvater
parents:
4559
diff
changeset
|
51 |
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
|
52 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
53 |
// The PathFinder (AyStar) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
54 |
// 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
|
55 |
// or when coming from a savegame.. should be checked out! |
2365 | 56 |
p->ainew.path_info.start_tile_tl = 0; |
57 |
p->ainew.path_info.start_tile_br = 0; |
|
58 |
p->ainew.path_info.end_tile_tl = 0; |
|
59 |
p->ainew.path_info.end_tile_br = 0; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
60 |
p->ainew.pathfinder = new_AyStar_AiPathFinder(12, &p->ainew.path_info); |
145 | 61 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
62 |
p->ainew.idle = 0; |
145 | 63 |
p->ainew.last_vehiclecheck_date = _date; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
64 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
65 |
// We ALWAYS start with a bus route.. just some basic money ;) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
66 |
p->ainew.action = AI_ACTION_BUS_ROUTE; |
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 |
// Let's popup the news, and after that, start building.. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
69 |
p->ainew.state = AI_STATE_WAKE_UP; |
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 |
|
2365 | 72 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
73 |
// This function just waste some time |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
74 |
// 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
|
75 |
// 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
|
76 |
// 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
|
77 |
// |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
78 |
// 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
|
79 |
// This means that on Very Slow it will be between 16 and 48 days.. slow enough? |
2365 | 80 |
static void AiNew_State_Nothing(Player *p) |
81 |
{ |
|
82 |
assert(p->ainew.state == AI_STATE_NOTHING); |
|
83 |
// If we are done idling, start over again |
|
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
84 |
if (p->ainew.idle == 0) p->ainew.idle = AI_RandomRange(DAY_TICKS * 2) + DAY_TICKS; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
85 |
if (--p->ainew.idle == 0) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
86 |
// 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
|
87 |
// I mean.. the next tick ;) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
88 |
p->ainew.state = AI_STATE_WAKE_UP; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
89 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
90 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
91 |
|
2365 | 92 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
93 |
// 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
|
94 |
// Currently supported: |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
95 |
// - Make new route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
96 |
// - Check route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
97 |
// - Build HQ |
2365 | 98 |
static void AiNew_State_WakeUp(Player *p) |
99 |
{ |
|
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
|
100 |
int32 money; |
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
|
101 |
int c; |
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
|
102 |
assert(p->ainew.state == AI_STATE_WAKE_UP); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
103 |
// First, check if we have a HQ |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
104 |
if (p->location_of_house == 0) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
105 |
// 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
|
106 |
// Random till we found a place for it! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
107 |
// 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
|
108 |
AiNew_Build_CompanyHQ(p, AI_Random() % MapSize()); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
109 |
// 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
|
110 |
// so we do not change any status |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
111 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
112 |
} |
145 | 113 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
114 |
money = p->player_money - AI_MINIMUM_MONEY; |
145 | 115 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
116 |
// Let's pick an action! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
117 |
if (p->ainew.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
|
118 |
c = AI_Random() & 0xFF; |
2365 | 119 |
if (p->current_loan > 0 && |
120 |
p->old_economy[1].income > AI_MINIMUM_INCOME_FOR_LOAN && |
|
121 |
c < 10) { |
|
122 |
p->ainew.action = AI_ACTION_REPAY_LOAN; |
|
145 | 123 |
} else if (p->ainew.last_vehiclecheck_date + AI_DAYS_BETWEEN_VEHICLE_CHECKS < _date) { |
124 |
// Check all vehicles once in a while |
|
125 |
p->ainew.action = AI_ACTION_CHECK_ALL_VEHICLES; |
|
126 |
p->ainew.last_vehiclecheck_date = _date; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
127 |
} 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
|
128 |
// Do we have any spots for road-vehicles left open? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
129 |
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
|
130 |
if (c < 85) { |
2365 | 131 |
p->ainew.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
|
132 |
} else { |
2365 | 133 |
p->ainew.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
|
134 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
135 |
} |
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 |
#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
|
137 |
} else if (c < 200 && !_patches.ai_disable_veh_train) { |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
138 |
if (GetFreeUnitNumber(VEH_Train) <= _patches.max_trains) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
139 |
p->ainew.action = AI_ACTION_TRAIN_ROUTE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
140 |
} |
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
|
141 |
#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
|
142 |
} |
145 | 143 |
|
144 |
p->ainew.counter = 0; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
145 |
} |
145 | 146 |
|
147 |
if (p->ainew.counter++ > AI_MAX_TRIES_FOR_SAME_ROUTE) { |
|
148 |
p->ainew.action = AI_ACTION_NONE; |
|
149 |
return; |
|
150 |
} |
|
151 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
152 |
if (_patches.ai_disable_veh_roadveh && ( |
2365 | 153 |
p->ainew.action == AI_ACTION_BUS_ROUTE || |
154 |
p->ainew.action == AI_ACTION_TRUCK_ROUTE |
|
155 |
)) { |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
156 |
p->ainew.action = AI_ACTION_NONE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
157 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
158 |
} |
145 | 159 |
|
2365 | 160 |
if (p->ainew.action == AI_ACTION_REPAY_LOAN && |
161 |
money > AI_MINIMUM_LOAN_REPAY_MONEY) { |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
162 |
// We start repaying some money.. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
163 |
p->ainew.state = AI_STATE_REPAY_MONEY; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
164 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
165 |
} |
145 | 166 |
|
167 |
if (p->ainew.action == AI_ACTION_CHECK_ALL_VEHICLES) { |
|
168 |
p->ainew.state = AI_STATE_CHECK_ALL_VEHICLES; |
|
169 |
return; |
|
170 |
} |
|
171 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
172 |
// 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
|
173 |
// to build the route anyway.. |
2365 | 174 |
if (p->ainew.action == AI_ACTION_BUS_ROUTE && |
175 |
money > AI_MINIMUM_BUS_ROUTE_MONEY) { |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
176 |
if (GetFreeUnitNumber(VEH_Road) > _patches.max_roadveh) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
177 |
p->ainew.action = AI_ACTION_NONE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
178 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
179 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
180 |
p->ainew.cargo = AI_NEED_CARGO; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
181 |
p->ainew.state = AI_STATE_LOCATE_ROUTE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
182 |
p->ainew.tbt = AI_BUS; // Bus-route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
183 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
184 |
} |
2365 | 185 |
if (p->ainew.action == AI_ACTION_TRUCK_ROUTE && |
186 |
money > AI_MINIMUM_TRUCK_ROUTE_MONEY) { |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
187 |
if (GetFreeUnitNumber(VEH_Road) > _patches.max_roadveh) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
188 |
p->ainew.action = AI_ACTION_NONE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
189 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
190 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
191 |
p->ainew.cargo = AI_NEED_CARGO; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
192 |
p->ainew.last_id = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
193 |
p->ainew.state = AI_STATE_LOCATE_ROUTE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
194 |
p->ainew.tbt = AI_TRUCK; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
195 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
196 |
} |
145 | 197 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
198 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
199 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
200 |
|
2365 | 201 |
|
202 |
static void AiNew_State_ActionDone(Player *p) |
|
203 |
{ |
|
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
|
204 |
p->ainew.action = AI_ACTION_NONE; |
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
|
205 |
p->ainew.state = AI_STATE_NOTHING; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
206 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
207 |
|
2365 | 208 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
209 |
// Check if a city or industry is good enough to start a route there |
2365 | 210 |
static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type) |
211 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
212 |
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
|
213 |
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
|
214 |
const Station* st; |
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1330
diff
changeset
|
215 |
uint count = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
216 |
int j = 0; |
145 | 217 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
218 |
// 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
|
219 |
if (t->road_build_months != 0) return false; |
145 | 220 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
221 |
// 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
|
222 |
// If not, take a chance if we want to continue |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
223 |
if (t->ratings[_current_player] < 0 && AI_CHANCE16(1,4)) return false; |
145 | 224 |
|
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
225 |
if (t->max_pass - t->act_pass < AI_CHECKCITY_NEEDED_CARGO && !AI_CHANCE16(1,AI_CHECKCITY_CITY_CHANCE)) return false; |
145 | 226 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
227 |
// 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
|
228 |
// 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
|
229 |
// 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
|
230 |
// 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
|
231 |
FOR_ALL_STATIONS(st) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
232 |
// Do we own it? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
233 |
if (st->owner == _current_player) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
234 |
// Are we talking busses? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
235 |
if (p->ainew.tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) != FACIL_BUS_STOP) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
236 |
// 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
|
237 |
if (st->town != t) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
238 |
// When was this station build? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
239 |
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
|
240 |
// 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
|
241 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
242 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
243 |
// 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
|
244 |
// 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
|
245 |
// 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
|
246 |
// to build there |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
247 |
if (!st->goods[CT_PASSENGERS].last_speed) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
248 |
// 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
|
249 |
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
|
250 |
// 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
|
251 |
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
|
252 |
j++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
253 |
// 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
|
254 |
if (j == 1) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
255 |
// The rating is high.. second station... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
256 |
// a little chance that we still continue |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
257 |
// 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
|
258 |
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
|
259 |
// We don't like this station :( |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
260 |
return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
261 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
262 |
} |
145 | 263 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
264 |
// We are about to add one... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
265 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
266 |
// 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
|
267 |
if (count * AI_CHECKCITY_CARGO_PER_STATION > t->max_pass) return false; |
145 | 268 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
269 |
// 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
|
270 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
271 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
272 |
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
|
273 |
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
|
274 |
const Station* st; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
275 |
int count = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
276 |
int j = 0; |
145 | 277 |
|
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
278 |
if (i->town != NULL && i->town->ratings[_current_player] < 0 && AI_CHANCE16(1,4)) return false; |
145 | 279 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
280 |
// No limits on delevering stations! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
281 |
// Or for industry that does not give anything yet |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3338
diff
changeset
|
282 |
if (i->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
283 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
284 |
if (i->total_production[0] - i->total_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false; |
145 | 285 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
286 |
// 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
|
287 |
// 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
|
288 |
// 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
|
289 |
FOR_ALL_STATIONS(st) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
290 |
// Do we own it? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
291 |
if (st->owner == _current_player) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
292 |
// Are we talking trucks? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
293 |
if (p->ainew.tbt == AI_TRUCK && (FACIL_TRUCK_STOP & st->facilities) != FACIL_TRUCK_STOP) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
294 |
// 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
|
295 |
if (st->town != i->town) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
296 |
// When was this station build? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
297 |
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
|
298 |
// 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
|
299 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
300 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
301 |
// 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
|
302 |
// 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
|
303 |
// 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
|
304 |
// to build there |
3344
d86c852715fa
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3338
diff
changeset
|
305 |
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
|
306 |
// It does not take this cargo |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
307 |
if (!st->goods[i->produced_cargo[0]].last_speed) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
308 |
// 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
|
309 |
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
|
310 |
// 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
|
311 |
if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
312 |
j++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
313 |
// 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
|
314 |
// 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
|
315 |
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
|
316 |
// We don't like this station :( |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
317 |
return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
318 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
319 |
} |
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 |
// We are about to add one... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
322 |
count++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
323 |
// 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
|
324 |
if (count * AI_CHECKCITY_CARGO_PER_STATION > i->total_production[0]) return false; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
325 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
326 |
// 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
|
327 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
328 |
} |
145 | 329 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
330 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
331 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
332 |
|
145 | 333 |
|
2365 | 334 |
// This functions tries to locate a good route |
335 |
static void AiNew_State_LocateRoute(Player *p) |
|
336 |
{ |
|
337 |
assert(p->ainew.state == AI_STATE_LOCATE_ROUTE); |
|
338 |
// 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
|
339 |
|
2365 | 340 |
// We don't have a route yet |
341 |
if (p->ainew.cargo == AI_NEED_CARGO) { |
|
342 |
p->ainew.new_cost = 0; // No cost yet |
|
343 |
p->ainew.temp = -1; |
|
344 |
// Reset the counter |
|
345 |
p->ainew.counter = 0; |
|
346 |
||
347 |
p->ainew.from_ic = -1; |
|
348 |
p->ainew.to_ic = -1; |
|
349 |
if (p->ainew.tbt == AI_BUS) { |
|
350 |
// For now we only have a passenger route |
|
351 |
p->ainew.cargo = CT_PASSENGERS; |
|
352 |
||
353 |
// Find a route to cities |
|
354 |
p->ainew.from_type = AI_CITY; |
|
355 |
p->ainew.to_type = AI_CITY; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
356 |
} else if (p->ainew.tbt == AI_TRUCK) { |
2365 | 357 |
p->ainew.cargo = AI_NO_CARGO; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
358 |
|
2365 | 359 |
p->ainew.from_type = AI_INDUSTRY; |
360 |
p->ainew.to_type = AI_INDUSTRY; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
361 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
362 |
|
2365 | 363 |
// Now we are doing initing, we wait one tick |
364 |
return; |
|
365 |
} |
|
145 | 366 |
|
2365 | 367 |
// Increase the counter and abort if it is taking too long! |
368 |
p->ainew.counter++; |
|
369 |
if (p->ainew.counter > AI_LOCATE_ROUTE_MAX_COUNTER) { |
|
370 |
// Switch back to doing nothing! |
|
371 |
p->ainew.state = AI_STATE_NOTHING; |
|
372 |
return; |
|
373 |
} |
|
145 | 374 |
|
2365 | 375 |
// We are going to locate a city from where we are going to connect |
376 |
if (p->ainew.from_ic == -1) { |
|
377 |
if (p->ainew.temp == -1) { |
|
378 |
// First, we pick a random spot to search from |
|
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
|
379 |
if (p->ainew.from_type == AI_CITY) { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
380 |
p->ainew.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
|
381 |
} else { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
382 |
p->ainew.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
|
383 |
} |
2365 | 384 |
} |
145 | 385 |
|
2365 | 386 |
if (!AiNew_Check_City_or_Industry(p, p->ainew.temp, p->ainew.from_type)) { |
387 |
// It was not a valid city |
|
388 |
// increase the temp with one, and return. We will come back later here |
|
389 |
// to try again |
|
390 |
p->ainew.temp++; |
|
391 |
if (p->ainew.from_type == AI_CITY) { |
|
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
392 |
if (p->ainew.temp > GetMaxTownIndex()) p->ainew.temp = 0; |
2365 | 393 |
} else { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
394 |
if (p->ainew.temp > GetMaxIndustryIndex()) p->ainew.temp = 0; |
2365 | 395 |
} |
145 | 396 |
|
2365 | 397 |
// Don't do an attempt if we are trying the same id as the last time... |
398 |
if (p->ainew.last_id == p->ainew.temp) return; |
|
399 |
p->ainew.last_id = p->ainew.temp; |
|
400 |
||
401 |
return; |
|
402 |
} |
|
403 |
||
404 |
// We found a good city/industry, save the data of it |
|
405 |
p->ainew.from_ic = p->ainew.temp; |
|
406 |
||
407 |
// Start the next tick with finding a to-city |
|
408 |
p->ainew.temp = -1; |
|
409 |
return; |
|
410 |
} |
|
411 |
||
412 |
// Find a to-city |
|
413 |
if (p->ainew.temp == -1) { |
|
414 |
// First, we pick a random spot to search to |
|
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
|
415 |
if (p->ainew.to_type == AI_CITY) { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
416 |
p->ainew.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
|
417 |
} else { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
418 |
p->ainew.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
|
419 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
420 |
} |
145 | 421 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
422 |
// The same city is not allowed |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
423 |
// Also check if the city is valid |
2365 | 424 |
if (p->ainew.temp != p->ainew.from_ic && AiNew_Check_City_or_Industry(p, p->ainew.temp, p->ainew.to_type)) { |
425 |
// Maybe it is valid.. |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
426 |
|
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
|
427 |
/* 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
|
428 |
* 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
|
429 |
* 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
|
430 |
*/ |
145 | 431 |
|
2365 | 432 |
if (p->ainew.from_type == AI_CITY && p->ainew.tbt == AI_BUS) { |
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
|
433 |
const Town* town_from = GetTown(p->ainew.from_ic); |
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
|
434 |
const Town* town_temp = GetTown(p->ainew.temp); |
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
|
435 |
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
|
436 |
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
|
437 |
|
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 |
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
|
439 |
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
|
440 |
|
2365 | 441 |
// max_cargo is now the amount of cargo we can move between the two cities |
442 |
// 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
|
443 |
if (distance <= max_cargo * AI_LOCATEROUTE_BUS_CARGO_DISTANCE) { |
2365 | 444 |
// We found a good city/industry, save the data of it |
445 |
p->ainew.to_ic = p->ainew.temp; |
|
446 |
p->ainew.state = AI_STATE_FIND_STATION; |
|
447 |
||
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
448 |
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
|
449 |
distance, |
2365 | 450 |
p->ainew.from_ic, |
451 |
p->ainew.temp |
|
452 |
); |
|
453 |
||
454 |
p->ainew.from_tile = 0; |
|
455 |
p->ainew.to_tile = 0; |
|
456 |
||
457 |
return; |
|
458 |
} |
|
459 |
} else if (p->ainew.tbt == AI_TRUCK) { |
|
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
|
460 |
const Industry* ind_from = GetIndustry(p->ainew.from_ic); |
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
|
461 |
const Industry* ind_temp = GetIndustry(p->ainew.temp); |
2365 | 462 |
bool found = false; |
463 |
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
|
464 |
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
|
465 |
|
2365 | 466 |
// TODO: in max_cargo, also check other cargo (beside [0]) |
467 |
// First we check if the from_ic produces cargo that this ic accepts |
|
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
|
468 |
if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) { |
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
|
469 |
for (i = 0; i < lengthof(ind_temp->accepts_cargo); 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
|
470 |
if (ind_temp->accepts_cargo[i] == CT_INVALID) break; |
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
|
471 |
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
|
472 |
// Found a compatible industry |
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
|
473 |
max_cargo = ind_from->total_production[0] - ind_from->total_transported[0]; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
474 |
found = true; |
2365 | 475 |
p->ainew.from_deliver = true; |
476 |
p->ainew.to_deliver = false; |
|
477 |
break; |
|
478 |
} |
|
479 |
} |
|
480 |
} |
|
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
|
481 |
if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) { |
2365 | 482 |
// If not check if the current ic produces cargo that the from_ic accepts |
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
|
483 |
for (i = 0; i < lengthof(ind_from->accepts_cargo); 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
|
484 |
if (ind_from->accepts_cargo[i] == CT_INVALID) break; |
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
|
485 |
if (ind_temp->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
|
486 |
// Found a compatbiel industry |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
487 |
found = true; |
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
|
488 |
max_cargo = ind_temp->total_production[0] - ind_temp->total_transported[0]; |
2365 | 489 |
p->ainew.from_deliver = false; |
490 |
p->ainew.to_deliver = true; |
|
491 |
break; |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
if (found) { |
|
496 |
// Yeah, they are compatible!!! |
|
497 |
// 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
|
498 |
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
|
499 |
|
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 |
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
|
501 |
distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) { |
2365 | 502 |
p->ainew.to_ic = p->ainew.temp; |
503 |
if (p->ainew.from_deliver) { |
|
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
|
504 |
p->ainew.cargo = ind_from->produced_cargo[0]; |
2365 | 505 |
} else { |
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
|
506 |
p->ainew.cargo = ind_temp->produced_cargo[0]; |
2365 | 507 |
} |
508 |
p->ainew.state = AI_STATE_FIND_STATION; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
509 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
510 |
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
|
511 |
distance, |
2365 | 512 |
p->ainew.from_ic, |
513 |
p->ainew.temp |
|
514 |
); |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
515 |
|
2365 | 516 |
p->ainew.from_tile = 0; |
517 |
p->ainew.to_tile = 0; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
518 |
|
2365 | 519 |
return; |
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
524 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
525 |
// 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
|
526 |
// 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
|
527 |
// to try again |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
528 |
p->ainew.temp++; |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1253
diff
changeset
|
529 |
if (p->ainew.to_type == AI_CITY) { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
530 |
if (p->ainew.temp > GetMaxTownIndex()) p->ainew.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
|
531 |
} else { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5015
diff
changeset
|
532 |
if (p->ainew.temp > GetMaxIndustryIndex()) p->ainew.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 |
} |
145 | 534 |
|
2365 | 535 |
// Don't do an attempt if we are trying the same id as the last time... |
536 |
if (p->ainew.last_id == p->ainew.temp) return; |
|
537 |
p->ainew.last_id = p->ainew.temp; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
538 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
539 |
|
2365 | 540 |
|
826 | 541 |
// 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
|
542 |
// station. This to prevent 10 busses going to one station, which gives... problems ;) |
2365 | 543 |
static bool AiNew_CheckVehicleStation(Player *p, Station *st) |
544 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
545 |
int count = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
546 |
Vehicle *v; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
547 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
548 |
// 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
|
549 |
FOR_ALL_VEHICLES(v) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
550 |
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
|
551 |
const Order *order; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
552 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
553 |
FOR_VEHICLE_ORDERS(v, order) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
554 |
if (order->type == 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
|
555 |
// 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
|
556 |
count++; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
557 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
558 |
} |
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 |
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
|
563 |
return true; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
564 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
565 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
566 |
// This function finds a good spot for a station |
2365 | 567 |
static void AiNew_State_FindStation(Player *p) |
568 |
{ |
|
569 |
TileIndex tile; |
|
570 |
Station *st; |
|
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
571 |
int count = 0; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
572 |
EngineID i; |
2365 | 573 |
TileIndex new_tile = 0; |
574 |
byte direction = 0; |
|
575 |
Town *town = NULL; |
|
576 |
assert(p->ainew.state == AI_STATE_FIND_STATION); |
|
145 | 577 |
|
2365 | 578 |
if (p->ainew.from_tile == 0) { |
579 |
// First we scan for a station in the from-city |
|
580 |
if (p->ainew.from_type == AI_CITY) { |
|
581 |
town = GetTown(p->ainew.from_ic); |
|
582 |
tile = town->xy; |
|
583 |
} else { |
|
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
|
584 |
tile = GetIndustry(p->ainew.from_ic)->xy; |
2365 | 585 |
} |
586 |
} else if (p->ainew.to_tile == 0) { |
|
587 |
// Second we scan for a station in the to-city |
|
588 |
if (p->ainew.to_type == AI_CITY) { |
|
589 |
town = GetTown(p->ainew.to_ic); |
|
590 |
tile = town->xy; |
|
591 |
} else { |
|
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
|
592 |
tile = GetIndustry(p->ainew.to_ic)->xy; |
2365 | 593 |
} |
594 |
} else { |
|
595 |
// Unsupported request |
|
596 |
// Go to FIND_PATH |
|
597 |
p->ainew.temp = -1; |
|
598 |
p->ainew.state = AI_STATE_FIND_PATH; |
|
599 |
return; |
|
600 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
601 |
|
2365 | 602 |
// First, we are going to look at the stations that already exist inside the city |
603 |
// If there is enough cargo left in the station, we take that station |
|
604 |
// 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
|
605 |
i = AiNew_PickVehicle(p); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
606 |
// Euhmz, this should not happen _EVER_ |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
607 |
// Quit finding a route... |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
608 |
if (i == INVALID_ENGINE) { |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
609 |
p->ainew.state = AI_STATE_NOTHING; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
610 |
return; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
611 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
612 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
613 |
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
|
614 |
if (st->owner == _current_player) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
615 |
if (p->ainew.tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) == FACIL_BUS_STOP) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
616 |
if (st->town == town) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
617 |
// Check how much cargo there is left in the station |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
618 |
if ((st->goods[p->ainew.cargo].waiting_acceptance & 0xFFF) > RoadVehInfo(i)->capacity * AI_STATION_REUSE_MULTIPLER) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
619 |
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
|
620 |
// 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
|
621 |
new_tile = st->xy; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
622 |
direction = GetRoadStopDir(st->xy); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
623 |
break; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
624 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
625 |
} |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4261
diff
changeset
|
626 |
count++; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
627 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
628 |
} |
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 |
// We are going to add a new station... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
632 |
if (new_tile == 0) count++; |
826 | 633 |
// 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
|
634 |
// 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
|
635 |
if (count > 2) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
636 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
637 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
638 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
639 |
|
2365 | 640 |
if (new_tile == 0 && p->ainew.tbt == AI_BUS) { |
641 |
uint x, y, i = 0; |
|
642 |
int r; |
|
643 |
uint best; |
|
644 |
uint accepts[NUM_CARGO]; |
|
645 |
TileIndex found_spot[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE*4]; |
|
646 |
uint found_best[AI_FINDSTATION_TILE_RANGE*AI_FINDSTATION_TILE_RANGE*4]; |
|
647 |
// To find a good spot we scan a range from the center, a get the point |
|
648 |
// where we get the most cargo and where it is buildable. |
|
649 |
// TODO: also check for station of myself and make sure we are not |
|
650 |
// taking eachothers passangers away (bad result when it does not) |
|
651 |
for (x = TileX(tile) - AI_FINDSTATION_TILE_RANGE; x <= TileX(tile) + AI_FINDSTATION_TILE_RANGE; x++) { |
|
652 |
for (y = TileY(tile) - AI_FINDSTATION_TILE_RANGE; y <= TileY(tile) + AI_FINDSTATION_TILE_RANGE; y++) { |
|
653 |
new_tile = TileXY(x, y); |
|
654 |
if (IsTileType(new_tile, MP_CLEAR) || IsTileType(new_tile, MP_TREES)) { |
|
655 |
// This tile we can build on! |
|
656 |
// Check acceptance |
|
657 |
// XXX - Get the catchment area |
|
658 |
GetAcceptanceAroundTiles(accepts, new_tile, 1, 1, 4); |
|
659 |
// >> 3 == 0 means no cargo |
|
660 |
if (accepts[p->ainew.cargo] >> 3 == 0) continue; |
|
661 |
// See if we can build the station |
|
662 |
r = AiNew_Build_Station(p, p->ainew.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
|
663 |
if (CmdFailed(r)) continue; |
2365 | 664 |
// We can build it, so add it to found_spot |
665 |
found_spot[i] = new_tile; |
|
666 |
found_best[i++] = accepts[p->ainew.cargo]; |
|
667 |
} |
|
668 |
} |
|
669 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
670 |
|
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
|
671 |
// If i is still zero, we did not find anything |
2365 | 672 |
if (i == 0) { |
673 |
p->ainew.state = AI_STATE_NOTHING; |
|
674 |
return; |
|
675 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
676 |
|
2365 | 677 |
// Go through all the found_best and check which has the highest value |
678 |
best = 0; |
|
679 |
new_tile = 0; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
680 |
|
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
|
681 |
for (x = 0; x < i; x++) { |
2365 | 682 |
if (found_best[x] > best || |
683 |
(found_best[x] == best && DistanceManhattan(tile, new_tile) > DistanceManhattan(tile, found_spot[x]))) { |
|
684 |
new_tile = found_spot[x]; |
|
685 |
best = found_best[x]; |
|
686 |
} |
|
687 |
} |
|
145 | 688 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
689 |
// See how much it is going to cost us... |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
690 |
r = AiNew_Build_Station(p, p->ainew.tbt, new_tile, 0, 0, 0, DC_QUERY_COST); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
691 |
p->ainew.new_cost += r; |
145 | 692 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
693 |
direction = AI_PATHFINDER_NO_DIRECTION; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
694 |
} else if (new_tile == 0 && p->ainew.tbt == AI_TRUCK) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
695 |
// 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
|
696 |
// 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
|
697 |
// so the pathfinder routine can work it out! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
698 |
new_tile = AI_STATION_RANGE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
699 |
direction = AI_PATHFINDER_NO_DIRECTION; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
700 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
701 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
702 |
if (p->ainew.from_tile == 0) { |
2365 | 703 |
p->ainew.from_tile = new_tile; |
704 |
p->ainew.from_direction = direction; |
|
705 |
// Now we found thisone, go in for to_tile |
|
706 |
return; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
707 |
} else if (p->ainew.to_tile == 0) { |
2365 | 708 |
p->ainew.to_tile = new_tile; |
709 |
p->ainew.to_direction = direction; |
|
710 |
// K, done placing stations! |
|
711 |
p->ainew.temp = -1; |
|
712 |
p->ainew.state = AI_STATE_FIND_PATH; |
|
713 |
return; |
|
714 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
715 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
716 |
|
2365 | 717 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
718 |
// We try to find a path between 2 points |
2365 | 719 |
static void AiNew_State_FindPath(Player *p) |
720 |
{ |
|
721 |
int r; |
|
722 |
assert(p->ainew.state == AI_STATE_FIND_PATH); |
|
145 | 723 |
|
2365 | 724 |
// First time, init some data |
725 |
if (p->ainew.temp == -1) { |
|
726 |
// Init path_info |
|
727 |
if (p->ainew.from_tile == AI_STATION_RANGE) { |
|
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
|
728 |
const Industry* i = GetIndustry(p->ainew.from_ic); |
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
|
729 |
|
2365 | 730 |
// For truck routes we take a range around the industry |
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 |
p->ainew.path_info.start_tile_tl = i->xy - TileDiffXY(1, 1); |
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
|
732 |
p->ainew.path_info.start_tile_br = i->xy + TileDiffXY(i->width + 1, i->height + 1); |
2365 | 733 |
p->ainew.path_info.start_direction = p->ainew.from_direction; |
734 |
} else { |
|
735 |
p->ainew.path_info.start_tile_tl = p->ainew.from_tile; |
|
736 |
p->ainew.path_info.start_tile_br = p->ainew.from_tile; |
|
737 |
p->ainew.path_info.start_direction = p->ainew.from_direction; |
|
738 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
739 |
|
2365 | 740 |
if (p->ainew.to_tile == AI_STATION_RANGE) { |
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
|
741 |
const Industry* i = GetIndustry(p->ainew.to_ic); |
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
|
742 |
|
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
|
743 |
p->ainew.path_info.end_tile_tl = i->xy - TileDiffXY(1, 1); |
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 |
p->ainew.path_info.end_tile_br = i->xy + TileDiffXY(i->width + 1, i->height + 1); |
2365 | 745 |
p->ainew.path_info.end_direction = p->ainew.to_direction; |
746 |
} else { |
|
747 |
p->ainew.path_info.end_tile_tl = p->ainew.to_tile; |
|
748 |
p->ainew.path_info.end_tile_br = p->ainew.to_tile; |
|
749 |
p->ainew.path_info.end_direction = p->ainew.to_direction; |
|
750 |
} |
|
145 | 751 |
|
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
|
752 |
p->ainew.path_info.rail_or_road = (p->ainew.tbt == AI_TRAIN); |
145 | 753 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
754 |
// First, clean the pathfinder with our new begin and endpoints |
2365 | 755 |
clean_AyStar_AiPathFinder(p->ainew.pathfinder, &p->ainew.path_info); |
145 | 756 |
|
2365 | 757 |
p->ainew.temp = 0; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
758 |
} |
145 | 759 |
|
2365 | 760 |
// Start the pathfinder |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
761 |
r = p->ainew.pathfinder->main(p->ainew.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
|
762 |
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
|
763 |
case AYSTAR_NO_PATH: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
764 |
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
|
765 |
// Start all over again |
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
|
766 |
p->ainew.state = AI_STATE_NOTHING; |
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 |
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
|
768 |
|
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 |
case AYSTAR_FOUND_END_NODE: // We found the end-point |
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 |
p->ainew.temp = -1; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3952
diff
changeset
|
771 |
p->ainew.state = AI_STATE_FIND_DEPOT; |
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
|
772 |
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
|
773 |
|
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 |
// 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
|
775 |
default: break; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
776 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
777 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
778 |
|
2365 | 779 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
780 |
// This function tries to locate a good place for a depot! |
2365 | 781 |
static void AiNew_State_FindDepot(Player *p) |
782 |
{ |
|
783 |
// To place the depot, we walk through the route, and if we find a lovely spot (MP_CLEAR, MP_TREES), we place it there.. |
|
784 |
// Simple, easy, works! |
|
785 |
// To make the depot stand in the middle of the route, we start from the center.. |
|
786 |
// But first we walk through the route see if we can find a depot that is ours |
|
787 |
// this keeps things nice ;) |
|
2635 | 788 |
int g, i, r; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
789 |
DiagDirection j; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
790 |
TileIndex tile; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
791 |
assert(p->ainew.state == AI_STATE_FIND_DEPOT); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
792 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
793 |
p->ainew.depot_tile = 0; |
145 | 794 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
795 |
for (i=2;i<p->ainew.path_info.route_length-2;i++) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
796 |
tile = p->ainew.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
|
797 |
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
|
798 |
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
|
799 |
|
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
800 |
if (IsTileType(t, MP_STREET) && |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3644
diff
changeset
|
801 |
GetRoadTileType(t) == ROAD_TILE_DEPOT && |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
802 |
IsTileOwner(t, _current_player) && |
3179 | 803 |
GetRoadDepotDirection(t) == ReverseDiagDir(j)) { |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
804 |
p->ainew.depot_tile = t; |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
805 |
p->ainew.depot_direction = ReverseDiagDir(j); |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
806 |
p->ainew.state = AI_STATE_VERIFY_ROUTE; |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
807 |
return; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
808 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
809 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
810 |
} |
145 | 811 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
812 |
// 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
|
813 |
// It makes depot placing nicer :) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
814 |
i = p->ainew.path_info.route_length / 2; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
815 |
g = 1; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
816 |
while (i > 1 && i < p->ainew.path_info.route_length - 2) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
817 |
i += g; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
818 |
g *= -1; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
819 |
(g < 0?g--:g++); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
820 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
821 |
if (p->ainew.path_info.route_extra[i] != 0 || p->ainew.path_info.route_extra[i+1] != 0) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
822 |
// 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
|
823 |
continue; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
824 |
} |
145 | 825 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
826 |
tile = p->ainew.path_info.route[i]; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
827 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
828 |
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
|
829 |
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
|
830 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
831 |
// 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
|
832 |
// 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
|
833 |
// So check the surrounding tiles :) |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
834 |
if (t == p->ainew.path_info.route[i - 1] || |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
835 |
t == p->ainew.path_info.route[i + 1]) { |
2365 | 836 |
continue; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
837 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
838 |
// Not around a bridge? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
839 |
if (p->ainew.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
|
840 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
841 |
// Is the terrain clear? |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
842 |
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
|
843 |
// 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
|
844 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
845 |
// 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
|
846 |
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
|
847 |
if (CmdFailed(r)) continue; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
848 |
// Found a spot! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
849 |
p->ainew.new_cost += r; |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
850 |
p->ainew.depot_tile = t; |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
851 |
p->ainew.depot_direction = ReverseDiagDir(j); // Reverse direction |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
852 |
p->ainew.state = AI_STATE_VERIFY_ROUTE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
853 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
854 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
855 |
} |
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 |
// Failed to find a depot? |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
859 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
860 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
861 |
|
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 |
// 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
|
864 |
// traject. |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
865 |
// 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
|
866 |
// 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
|
867 |
// It returns the cost for the vehicles |
2365 | 868 |
static int AiNew_HowManyVehicles(Player *p) |
869 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
870 |
if (p->ainew.tbt == AI_BUS) { |
2365 | 871 |
// 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
|
872 |
EngineID i; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
873 |
int length, tiles_a_day; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
874 |
int amount; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
875 |
i = AiNew_PickVehicle(p); |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
876 |
if (i == INVALID_ENGINE) return 0; |
2365 | 877 |
// Passenger run.. how long is the route? |
878 |
length = p->ainew.path_info.route_length; |
|
879 |
// Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
|
880 |
tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
|
881 |
// We want a vehicle in a station once a month at least, so, calculate it! |
|
882 |
// (the * 2 is because we have 2 stations ;)) |
|
883 |
amount = length * 2 * 2 / tiles_a_day / 30; |
|
884 |
if (amount == 0) amount = 1; |
|
885 |
return amount; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
886 |
} else if (p->ainew.tbt == AI_TRUCK) { |
2365 | 887 |
// 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
|
888 |
EngineID i; |
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
889 |
int length, amount, tiles_a_day; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
890 |
int max_cargo; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
891 |
i = AiNew_PickVehicle(p); |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
892 |
if (i == INVALID_ENGINE) return 0; |
2365 | 893 |
// Passenger run.. how long is the route? |
894 |
length = p->ainew.path_info.route_length; |
|
895 |
// Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
|
896 |
tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
|
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
|
897 |
if (p->ainew.from_deliver) { |
2365 | 898 |
max_cargo = GetIndustry(p->ainew.from_ic)->total_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
|
899 |
} else { |
2365 | 900 |
max_cargo = GetIndustry(p->ainew.to_ic)->total_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 |
} |
145 | 902 |
|
2365 | 903 |
// 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
|
904 |
max_cargo *= 6; |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
905 |
max_cargo /= 10; |
2365 | 906 |
// We want all the cargo to be gone in a month.. so, we know the cargo it delivers |
907 |
// we know what the vehicle takes with him, and we know the time it takes him |
|
908 |
// to get back here.. now let's do some math! |
|
909 |
amount = 2 * length * max_cargo / tiles_a_day / 30 / RoadVehInfo(i)->capacity; |
|
910 |
amount += 1; |
|
911 |
return amount; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
912 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
913 |
// Currently not supported |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
914 |
return 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
915 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
916 |
} |
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 |
// This function checks: |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
920 |
// - If the route went okay |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
921 |
// - 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
|
922 |
// - Calculates how much vehicles needed for the route |
2365 | 923 |
static void AiNew_State_VerifyRoute(Player *p) |
924 |
{ |
|
925 |
int res, i; |
|
926 |
assert(p->ainew.state == AI_STATE_VERIFY_ROUTE); |
|
145 | 927 |
|
2365 | 928 |
// Let's calculate the cost of the path.. |
929 |
// new_cost already contains the cost of the stations |
|
930 |
p->ainew.path_info.position = -1; |
|
145 | 931 |
|
2365 | 932 |
do { |
933 |
p->ainew.path_info.position++; |
|
934 |
p->ainew.new_cost += AiNew_Build_RoutePart(p, &p->ainew.path_info, DC_QUERY_COST); |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
935 |
} while (p->ainew.path_info.position != -2); |
145 | 936 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
937 |
// 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
|
938 |
// 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
|
939 |
res = AiNew_HowManyVehicles(p); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
940 |
// 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
|
941 |
if (res == 0) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
942 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
943 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
944 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
945 |
p->ainew.amount_veh = res; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
946 |
p->ainew.cur_veh = 0; |
145 | 947 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
948 |
// 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
|
949 |
for (i=0;i<res;i++) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
950 |
p->ainew.new_cost += AiNew_Build_Vehicle(p, 0, DC_QUERY_COST); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
951 |
} |
145 | 952 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
953 |
// 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
|
954 |
// Check if we have enough money for it! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
955 |
if (p->ainew.new_cost > p->player_money - AI_MINIMUM_MONEY) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
956 |
// Too bad.. |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
957 |
DEBUG(ai, 1, "Insufficient funds to build route (%d)", p->ainew.new_cost); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
958 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
959 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
960 |
} |
145 | 961 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
962 |
// Now we can build the route, check the direction of the stations! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
963 |
if (p->ainew.from_direction == AI_PATHFINDER_NO_DIRECTION) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
964 |
p->ainew.from_direction = AiNew_GetDirection(p->ainew.path_info.route[p->ainew.path_info.route_length-1], p->ainew.path_info.route[p->ainew.path_info.route_length-2]); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
965 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
966 |
if (p->ainew.to_direction == AI_PATHFINDER_NO_DIRECTION) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
967 |
p->ainew.to_direction = AiNew_GetDirection(p->ainew.path_info.route[0], p->ainew.path_info.route[1]); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
968 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
969 |
if (p->ainew.from_tile == AI_STATION_RANGE) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
970 |
p->ainew.from_tile = p->ainew.path_info.route[p->ainew.path_info.route_length-1]; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
971 |
if (p->ainew.to_tile == AI_STATION_RANGE) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
972 |
p->ainew.to_tile = p->ainew.path_info.route[0]; |
145 | 973 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
974 |
p->ainew.state = AI_STATE_BUILD_STATION; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
975 |
p->ainew.temp = 0; |
145 | 976 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
977 |
DEBUG(ai, 1, "The route is set and buildable, building 0x%X to 0x%X...", p->ainew.from_tile, p->ainew.to_tile); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
978 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
979 |
|
2365 | 980 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
981 |
// Build the stations |
2365 | 982 |
static void AiNew_State_BuildStation(Player *p) |
983 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
984 |
int res = 0; |
2365 | 985 |
assert(p->ainew.state == AI_STATE_BUILD_STATION); |
986 |
if (p->ainew.temp == 0) { |
|
987 |
if (!IsTileType(p->ainew.from_tile, MP_STATION)) |
|
988 |
res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.from_tile, 0, 0, p->ainew.from_direction, DC_EXEC); |
|
989 |
} else { |
|
990 |
if (!IsTileType(p->ainew.to_tile, MP_STATION)) |
|
991 |
res = AiNew_Build_Station(p, p->ainew.tbt, p->ainew.to_tile, 0, 0, p->ainew.to_direction, DC_EXEC); |
|
992 |
p->ainew.state = AI_STATE_BUILD_PATH; |
|
993 |
} |
|
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
994 |
if (CmdFailed(res)) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
995 |
DEBUG(ai, 0, "[BuildStation] station could not be built (0x%X)", p->ainew.to_tile); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
996 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
997 |
// If the first station _was_ build, destroy it |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
998 |
if (p->ainew.temp != 0) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
999 |
AI_DoCommand(p->ainew.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
|
1000 |
return; |
2365 | 1001 |
} |
1002 |
p->ainew.temp++; |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1003 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1004 |
|
2365 | 1005 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1006 |
// Build the path |
2365 | 1007 |
static void AiNew_State_BuildPath(Player *p) |
1008 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1009 |
assert(p->ainew.state == AI_STATE_BUILD_PATH); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1010 |
// p->ainew.temp is set to -1 when this function is called for the first time |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1011 |
if (p->ainew.temp == -1) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
1012 |
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
|
1013 |
// Init the counter |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1014 |
p->ainew.counter = (4 - _opt.diff.competitor_speed) * AI_BUILDPATH_PAUSE + 1; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1015 |
// Set the position to the startingplace (-1 because in a minute we do ++) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1016 |
p->ainew.path_info.position = -1; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1017 |
// And don't do this again |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1018 |
p->ainew.temp = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1019 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1020 |
// 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
|
1021 |
// By let the counter count from AI_BUILDPATH_PAUSE to 0, we have a nice way :) |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1022 |
if (--p->ainew.counter != 0) return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1023 |
p->ainew.counter = (4 - _opt.diff.competitor_speed) * AI_BUILDPATH_PAUSE + 1; |
145 | 1024 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1025 |
// Increase the building position |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1026 |
p->ainew.path_info.position++; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1027 |
// Build route |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1028 |
AiNew_Build_RoutePart(p, &p->ainew.path_info, DC_EXEC); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1029 |
if (p->ainew.path_info.position == -2) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1030 |
// This means we are done building! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1031 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1032 |
if (p->ainew.tbt == AI_TRUCK && !_patches.roadveh_queue) { |
2365 | 1033 |
// If they not queue, they have to go up and down to try again at a station... |
1034 |
// We don't want that, so try building some road left or right of the station |
|
1035 |
int dir1, dir2, dir3; |
|
1036 |
TileIndex tile; |
|
1037 |
int i, ret; |
|
1038 |
for (i=0;i<2;i++) { |
|
1039 |
if (i == 0) { |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1040 |
tile = p->ainew.from_tile + TileOffsByDiagDir(p->ainew.from_direction); |
2365 | 1041 |
dir1 = p->ainew.from_direction - 1; |
1042 |
if (dir1 < 0) dir1 = 3; |
|
1043 |
dir2 = p->ainew.from_direction + 1; |
|
1044 |
if (dir2 > 3) dir2 = 0; |
|
1045 |
dir3 = p->ainew.from_direction; |
|
1046 |
} else { |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1047 |
tile = p->ainew.to_tile + TileOffsByDiagDir(p->ainew.to_direction); |
2365 | 1048 |
dir1 = p->ainew.to_direction - 1; |
1049 |
if (dir1 < 0) dir1 = 3; |
|
1050 |
dir2 = p->ainew.to_direction + 1; |
|
1051 |
if (dir2 > 3) dir2 = 0; |
|
1052 |
dir3 = p->ainew.to_direction; |
|
1053 |
} |
|
145 | 1054 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1055 |
ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1056 |
if (!CmdFailed(ret)) { |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1057 |
dir1 = TileOffsByDiagDir(dir1); |
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
|
1058 |
if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) { |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1059 |
ret = AI_DoCommand(tile+dir1, AiNew_GetRoadDirection(tile, tile+dir1, tile+dir1+dir1), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1060 |
if (!CmdFailed(ret)) { |
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
|
1061 |
if (IsTileType(tile + dir1 + dir1, MP_CLEAR) || IsTileType(tile + dir1 + dir1, MP_TREES)) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1062 |
AI_DoCommand(tile+dir1+dir1, AiNew_GetRoadDirection(tile+dir1, tile+dir1+dir1, tile+dir1+dir1+dir1), 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
|
1063 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1064 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1065 |
} |
145 | 1066 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1067 |
ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1068 |
if (!CmdFailed(ret)) { |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1069 |
dir2 = TileOffsByDiagDir(dir2); |
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
|
1070 |
if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) { |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1071 |
ret = AI_DoCommand(tile+dir2, AiNew_GetRoadDirection(tile, tile+dir2, tile+dir2+dir2), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1072 |
if (!CmdFailed(ret)) { |
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
|
1073 |
if (IsTileType(tile + dir2 + dir2, MP_CLEAR) || IsTileType(tile + dir2 + dir2, MP_TREES)) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1074 |
AI_DoCommand(tile+dir2+dir2, AiNew_GetRoadDirection(tile+dir2, tile+dir2+dir2, tile+dir2+dir2+dir2), 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
|
1075 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1076 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1077 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1078 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1079 |
ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1080 |
if (!CmdFailed(ret)) { |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1081 |
dir3 = TileOffsByDiagDir(dir3); |
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
|
1082 |
if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) { |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1083 |
ret = AI_DoCommand(tile+dir3, AiNew_GetRoadDirection(tile, tile+dir3, tile+dir3+dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD); |
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1084 |
if (!CmdFailed(ret)) { |
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
|
1085 |
if (IsTileType(tile + dir3 + dir3, MP_CLEAR) || IsTileType(tile + dir3 + dir3, MP_TREES)) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1086 |
AI_DoCommand(tile+dir3+dir3, AiNew_GetRoadDirection(tile+dir3, tile+dir3+dir3, tile+dir3+dir3+dir3), 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
|
1087 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1088 |
} |
7632a1ddadc0
(svn r147) -Fix [NewAI]: small fix for road-building when RoadQueueing is disabled
truelight
parents:
145
diff
changeset
|
1089 |
} |
2365 | 1090 |
} |
1091 |
} |
|
145 | 1092 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
1093 |
DEBUG(ai, 1, "Finished building path, cost: %d", p->ainew.new_cost); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1094 |
p->ainew.state = AI_STATE_BUILD_DEPOT; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1095 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1096 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1097 |
|
2365 | 1098 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1099 |
// Builds the depot |
2365 | 1100 |
static void AiNew_State_BuildDepot(Player *p) |
1101 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1102 |
int res = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1103 |
assert(p->ainew.state == AI_STATE_BUILD_DEPOT); |
145 | 1104 |
|
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3644
diff
changeset
|
1105 |
if (IsTileType(p->ainew.depot_tile, MP_STREET) && GetRoadTileType(p->ainew.depot_tile) == ROAD_TILE_DEPOT) { |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1106 |
if (IsTileOwner(p->ainew.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
|
1107 |
// The depot is already built |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1108 |
p->ainew.state = AI_STATE_BUILD_VEHICLE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1109 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1110 |
} else { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1111 |
// There is a depot, but not of our team! :( |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1112 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1113 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1114 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1115 |
} |
145 | 1116 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1117 |
// There is a bus on the tile we want to build road on... idle till he is gone! (BAD PERSON! :p) |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4527
diff
changeset
|
1118 |
if (!EnsureNoVehicle(p->ainew.depot_tile + TileOffsByDiagDir(p->ainew.depot_direction))) |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1119 |
return; |
145 | 1120 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1121 |
res = AiNew_Build_Depot(p, p->ainew.depot_tile, p->ainew.depot_direction, DC_EXEC); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
1122 |
if (CmdFailed(res)) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5247
diff
changeset
|
1123 |
DEBUG(ai, 0, "[BuildDepot] depot could not be built (0x%X)", p->ainew.depot_tile); |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1124 |
p->ainew.state = AI_STATE_NOTHING; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1125 |
return; |
2365 | 1126 |
} |
145 | 1127 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1128 |
p->ainew.state = AI_STATE_BUILD_VEHICLE; |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1129 |
p->ainew.idle = 10; |
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
1130 |
p->ainew.veh_main_id = INVALID_VEHICLE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1131 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1132 |
|
145 | 1133 |
|
2365 | 1134 |
// Build vehicles |
1135 |
static void AiNew_State_BuildVehicle(Player *p) |
|
1136 |
{ |
|
1137 |
int res; |
|
1138 |
assert(p->ainew.state == AI_STATE_BUILD_VEHICLE); |
|
1139 |
||
1140 |
// Check if we need to build a vehicle |
|
1141 |
if (p->ainew.amount_veh == 0) { |
|
1142 |
// Nope, we are done! |
|
1143 |
// This means: we are all done! The route is open.. go back to NOTHING |
|
1144 |
// He will idle some time and it will all start over again.. :) |
|
1145 |
p->ainew.state = AI_STATE_ACTION_DONE; |
|
1146 |
return; |
|
1147 |
} |
|
1148 |
if (--p->ainew.idle != 0) return; |
|
1149 |
// It is realistic that the AI can only build 1 vehicle a day.. |
|
1150 |
// This makes sure of that! |
|
1151 |
p->ainew.idle = AI_BUILD_VEHICLE_TIME_BETWEEN; |
|
1152 |
||
1153 |
// Build the vehicle |
|
1154 |
res = AiNew_Build_Vehicle(p, p->ainew.depot_tile, DC_EXEC); |
|
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2684
diff
changeset
|
1155 |
if (CmdFailed(res)) { |
2365 | 1156 |
// This happens when the AI can't build any more vehicles! |
1157 |
p->ainew.state = AI_STATE_NOTHING; |
|
1158 |
return; |
|
1159 |
} |
|
1160 |
// Increase the current counter |
|
1161 |
p->ainew.cur_veh++; |
|
1162 |
// Decrease the total counter |
|
1163 |
p->ainew.amount_veh--; |
|
1164 |
// Go give some orders! |
|
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
|
1165 |
p->ainew.state = AI_STATE_WAIT_FOR_BUILD; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1166 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1167 |
|
2365 | 1168 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1169 |
// Put the stations in the order list |
2365 | 1170 |
static void AiNew_State_GiveOrders(Player *p) |
1171 |
{ |
|
1172 |
int idx; |
|
1173 |
Order order; |
|
145 | 1174 |
|
2365 | 1175 |
assert(p->ainew.state == AI_STATE_GIVE_ORDERS); |
145 | 1176 |
|
3885
327cdee1f0b6
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3793
diff
changeset
|
1177 |
if (p->ainew.veh_main_id != INVALID_VEHICLE) { |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1178 |
AI_DoCommand(0, p->ainew.veh_id + (p->ainew.veh_main_id << 16), 0, DC_EXEC, CMD_CLONE_ORDER); |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1179 |
|
2365 | 1180 |
p->ainew.state = AI_STATE_START_VEHICLE; |
1181 |
return; |
|
1182 |
} else { |
|
1183 |
p->ainew.veh_main_id = p->ainew.veh_id; |
|
1184 |
} |
|
1185 |
||
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1186 |
// 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
|
1187 |
if (_patches.gotodepot) { |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1188 |
idx = 0; |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1189 |
order.type = OT_GOTO_DEPOT; |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1190 |
order.flags = OF_UNLOAD; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
1191 |
order.dest = GetDepotByTile(p->ainew.depot_tile)->index; |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1192 |
AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1193 |
} |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1194 |
|
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1195 |
idx = 0; |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1196 |
order.type = OT_GOTO_STATION; |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1197 |
order.flags = 0; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
1198 |
order.dest = GetStationIndex(p->ainew.to_tile); |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1199 |
if (p->ainew.tbt == AI_TRUCK && p->ainew.to_deliver) |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1200 |
order.flags |= OF_FULL_LOAD; |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1201 |
AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER); |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1202 |
|
2365 | 1203 |
idx = 0; |
1204 |
order.type = OT_GOTO_STATION; |
|
1205 |
order.flags = 0; |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4389
diff
changeset
|
1206 |
order.dest = GetStationIndex(p->ainew.from_tile); |
2365 | 1207 |
if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver) |
1208 |
order.flags |= OF_FULL_LOAD; |
|
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1209 |
AI_DoCommand(0, p->ainew.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
|
1210 |
|
2365 | 1211 |
// Start the engines! |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1212 |
p->ainew.state = AI_STATE_START_VEHICLE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1213 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1214 |
|
2365 | 1215 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1216 |
// Start the vehicle |
2365 | 1217 |
static void AiNew_State_StartVehicle(Player *p) |
1218 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1219 |
assert(p->ainew.state == AI_STATE_START_VEHICLE); |
145 | 1220 |
|
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1221 |
// 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
|
1222 |
// This to make vehicles go different ways.. |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1223 |
if (p->ainew.cur_veh & 1) |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1224 |
AI_DoCommand(0, p->ainew.veh_id, 0, DC_EXEC, CMD_SKIP_ORDER); |
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1225 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1226 |
// 3, 2, 1... go! (give START_STOP command ;)) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1227 |
AI_DoCommand(0, p->ainew.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
|
1228 |
// Try to build an other vehicle (that function will stop building when needed) |
2682
94ca0b4dc53f
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2635
diff
changeset
|
1229 |
p->ainew.idle = 10; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1230 |
p->ainew.state = AI_STATE_BUILD_VEHICLE; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1231 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1232 |
|
2365 | 1233 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1234 |
// Repays money |
2365 | 1235 |
static void AiNew_State_RepayMoney(Player *p) |
1236 |
{ |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1237 |
uint i; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1238 |
|
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1239 |
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
|
1240 |
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
|
1241 |
} |
2365 | 1242 |
p->ainew.state = AI_STATE_ACTION_DONE; |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1243 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1244 |
|
2365 | 1245 |
|
1246 |
static void AiNew_CheckVehicle(Player *p, Vehicle *v) |
|
1247 |
{ |
|
145 | 1248 |
// When a vehicle is under the 6 months, we don't check for anything |
1249 |
if (v->age < 180) return; |
|
1250 |
||
1251 |
// When a vehicle is older then 1 year, it should make money... |
|
1252 |
if (v->age > 360) { |
|
826 | 1253 |
// If both years together are not more than AI_MINIMUM_ROUTE_PROFIT, |
145 | 1254 |
// it is not worth the line I guess... |
1255 |
if (v->profit_last_year + v->profit_this_year < AI_MINIMUM_ROUTE_PROFIT || |
|
2365 | 1256 |
(v->reliability * 100 >> 16) < 40) { |
145 | 1257 |
// There is a possibility that the route is fucked up... |
1258 |
if (v->cargo_days > AI_VEHICLE_LOST_DAYS) { |
|
1259 |
// The vehicle is lost.. check the route, or else, get the vehicle |
|
1260 |
// back to a depot |
|
1261 |
// TODO: make this piece of code |
|
1262 |
} |
|
1263 |
||
1264 |
||
1265 |
// We are already sending him back |
|
1266 |
if (AiNew_GetSpecialVehicleFlag(p, v) & AI_VEHICLEFLAG_SELL) { |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
1267 |
if (v->type == VEH_Road && IsTileDepotType(v->tile, TRANSPORT_ROAD) && |
2365 | 1268 |
(v->vehstatus&VS_STOPPED)) { |
145 | 1269 |
// 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
|
1270 |
AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH); |
145 | 1271 |
} |
1272 |
return; |
|
1273 |
} |
|
1274 |
||
1275 |
if (!AiNew_SetSpecialVehicleFlag(p, v, AI_VEHICLEFLAG_SELL)) return; |
|
1276 |
{ |
|
1713
d970350410b2
(svn r2217) - Fix: [ 1184201 ] AI orders its vehicles to a competitor's truck stop. Added a CmdFailed() check to all command returns of the AI instead of the simple == / != CMD_ERROR check. This should fix the problem.
Darkvater
parents:
1490
diff
changeset
|
1277 |
int ret = 0; |
145 | 1278 |
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
|
1279 |
ret = AI_DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT); |
145 | 1280 |
// This means we can not find a depot :s |
2365 | 1281 |
// if (CmdFailed(ret)) |
145 | 1282 |
} |
1283 |
} |
|
1284 |
} |
|
1285 |
} |
|
1286 |
||
2365 | 1287 |
|
145 | 1288 |
// Checks all vehicles if they are still valid and make money and stuff |
2365 | 1289 |
static void AiNew_State_CheckAllVehicles(Player *p) |
1290 |
{ |
|
145 | 1291 |
Vehicle *v; |
1292 |
||
1293 |
FOR_ALL_VEHICLES(v) { |
|
1294 |
if (v->owner != p->index) continue; |
|
1295 |
// Currently, we only know how to handle road-vehicles |
|
1296 |
if (v->type != VEH_Road) continue; |
|
1297 |
||
1298 |
AiNew_CheckVehicle(p, v); |
|
1299 |
} |
|
1300 |
||
1301 |
p->ainew.state = AI_STATE_ACTION_DONE; |
|
1302 |
} |
|
1303 |
||
2365 | 1304 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1305 |
// Using the technique simular to the original AI |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1306 |
// Keeps things logical |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1307 |
// 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
|
1308 |
static AiNew_StateFunction* const _ainew_state[] = { |
2365 | 1309 |
NULL, |
1310 |
AiNew_State_FirstTime, |
|
1311 |
AiNew_State_Nothing, |
|
1312 |
AiNew_State_WakeUp, |
|
1313 |
AiNew_State_LocateRoute, |
|
1314 |
AiNew_State_FindStation, |
|
1315 |
AiNew_State_FindPath, |
|
1316 |
AiNew_State_FindDepot, |
|
1317 |
AiNew_State_VerifyRoute, |
|
1318 |
AiNew_State_BuildStation, |
|
1319 |
AiNew_State_BuildPath, |
|
1320 |
AiNew_State_BuildDepot, |
|
1321 |
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
|
1322 |
NULL, |
2365 | 1323 |
AiNew_State_GiveOrders, |
1324 |
AiNew_State_StartVehicle, |
|
1325 |
AiNew_State_RepayMoney, |
|
145 | 1326 |
AiNew_State_CheckAllVehicles, |
2365 | 1327 |
AiNew_State_ActionDone, |
1328 |
NULL, |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1329 |
}; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1330 |
|
2365 | 1331 |
static void AiNew_OnTick(Player *p) |
1332 |
{ |
|
1333 |
if (_ainew_state[p->ainew.state] != NULL) |
|
1334 |
_ainew_state[p->ainew.state](p); |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1335 |
} |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1336 |
|
2365 | 1337 |
|
1338 |
void AiNewDoGameLoop(Player *p) |
|
1339 |
{ |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1340 |
if (p->ainew.state == AI_STATE_STARTUP) { |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1341 |
// The AI just got alive! |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1342 |
p->ainew.state = AI_STATE_FIRST_TIME; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1343 |
p->ainew.tick = 0; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1344 |
|
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1345 |
// Only startup the AI |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1346 |
return; |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1347 |
} |
145 | 1348 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1349 |
// We keep a ticker. We use it for competitor_speed |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1350 |
p->ainew.tick++; |
145 | 1351 |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1352 |
// 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
|
1353 |
AiNew_OnTick(p); |
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
95
diff
changeset
|
1354 |
} |