author | tron |
Mon, 05 Jun 2006 16:08:06 +0000 | |
changeset 3968 | 3dbc765cc171 |
parent 3946 | 3c8c78208dbb |
child 4000 | 4009d092b306 |
permissions | -rw-r--r-- |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
1 |
/* $Id$ */ |
9a5ed6c0a2e6
(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:
diff
changeset
|
2 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
3 |
#include "../../stdafx.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
4 |
#include "../../openttd.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
5 |
#include "../../debug.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
6 |
#include "../../functions.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
7 |
#include "../../map.h" |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3033
diff
changeset
|
8 |
#include "../../road_map.h" |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
9 |
#include "../../tile.h" |
3946
3c8c78208dbb
(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:
3887
diff
changeset
|
10 |
#include "../../vehicle.h" |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
11 |
#include "../../command.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
12 |
#include "trolly.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
13 |
#include "../../engine.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
14 |
#include "../../station.h" |
9a5ed6c0a2e6
(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:
diff
changeset
|
15 |
#include "../../variables.h" |
3359
633290bf1117
(svn r4154) -Moved MAX_BRIDGES in bridge.h and made it an enum. This makes two drops ...
celestar
parents:
3157
diff
changeset
|
16 |
#include "../../bridge.h" |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
17 |
#include "../ai.h" |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
18 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
19 |
// Build HQ |
9a5ed6c0a2e6
(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:
diff
changeset
|
20 |
// Params: |
9a5ed6c0a2e6
(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:
diff
changeset
|
21 |
// tile : tile where HQ is going to be build |
9a5ed6c0a2e6
(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:
diff
changeset
|
22 |
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile) |
9a5ed6c0a2e6
(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:
diff
changeset
|
23 |
{ |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
24 |
if (CmdFailed(AI_DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ))) |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
25 |
return false; |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
26 |
AI_DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
27 |
return true; |
9a5ed6c0a2e6
(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:
diff
changeset
|
28 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
29 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
30 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
31 |
// Build station |
9a5ed6c0a2e6
(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:
diff
changeset
|
32 |
// Params: |
9a5ed6c0a2e6
(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:
diff
changeset
|
33 |
// type : AI_TRAIN/AI_BUS/AI_TRUCK : indicates the type of station |
9a5ed6c0a2e6
(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:
diff
changeset
|
34 |
// tile : tile where station is going to be build |
9a5ed6c0a2e6
(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:
diff
changeset
|
35 |
// length : in case of AI_TRAIN: length of station |
9a5ed6c0a2e6
(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:
diff
changeset
|
36 |
// numtracks : in case of AI_TRAIN: tracks of station |
9a5ed6c0a2e6
(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:
diff
changeset
|
37 |
// direction : the direction of the station |
9a5ed6c0a2e6
(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:
diff
changeset
|
38 |
// flag : flag passed to DoCommand (normally 0 to get the cost or DC_EXEC to build it) |
9a5ed6c0a2e6
(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:
diff
changeset
|
39 |
int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag) |
9a5ed6c0a2e6
(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:
diff
changeset
|
40 |
{ |
9a5ed6c0a2e6
(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:
diff
changeset
|
41 |
if (type == AI_TRAIN) |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
42 |
return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
43 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
44 |
if (type == AI_BUS) |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
45 |
return AI_DoCommand(tile, direction, RS_BUS, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
46 |
|
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
47 |
return AI_DoCommand(tile, direction, RS_TRUCK, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
48 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
49 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
50 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
51 |
// Builds a brdige. The second best out of the ones available for this player |
9a5ed6c0a2e6
(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:
diff
changeset
|
52 |
// Params: |
9a5ed6c0a2e6
(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:
diff
changeset
|
53 |
// tile_a : starting point |
9a5ed6c0a2e6
(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:
diff
changeset
|
54 |
// tile_b : end point |
9a5ed6c0a2e6
(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:
diff
changeset
|
55 |
// flag : flag passed to DoCommand |
9a5ed6c0a2e6
(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:
diff
changeset
|
56 |
int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag) |
9a5ed6c0a2e6
(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:
diff
changeset
|
57 |
{ |
9a5ed6c0a2e6
(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:
diff
changeset
|
58 |
int bridge_type, bridge_len, type, type2; |
9a5ed6c0a2e6
(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:
diff
changeset
|
59 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
60 |
// Find a good bridgetype (the best money can buy) |
9a5ed6c0a2e6
(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:
diff
changeset
|
61 |
bridge_len = GetBridgeLength(tile_a, tile_b); |
9a5ed6c0a2e6
(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:
diff
changeset
|
62 |
type = type2 = 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
63 |
for (bridge_type = MAX_BRIDGES-1; bridge_type >= 0; bridge_type--) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
64 |
if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
65 |
type2 = type; |
9a5ed6c0a2e6
(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:
diff
changeset
|
66 |
type = bridge_type; |
9a5ed6c0a2e6
(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:
diff
changeset
|
67 |
// We found two bridges, exit |
9a5ed6c0a2e6
(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:
diff
changeset
|
68 |
if (type2 != 0) break; |
9a5ed6c0a2e6
(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:
diff
changeset
|
69 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
70 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
71 |
// There is only one bridge that can be build.. |
9a5ed6c0a2e6
(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:
diff
changeset
|
72 |
if (type2 == 0 && type != 0) type2 = type; |
9a5ed6c0a2e6
(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:
diff
changeset
|
73 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
74 |
// Now, simply, build the bridge! |
9a5ed6c0a2e6
(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:
diff
changeset
|
75 |
if (p->ainew.tbt == AI_TRAIN) |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
76 |
return AI_DoCommand(tile_a, tile_b, (0<<8) + type2, flag | DC_AUTO, CMD_BUILD_BRIDGE); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
77 |
|
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
78 |
return AI_DoCommand(tile_a, tile_b, (0x80 << 8) + type2, flag | DC_AUTO, CMD_BUILD_BRIDGE); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
79 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
80 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
81 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
82 |
// Build the route part by part |
9a5ed6c0a2e6
(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:
diff
changeset
|
83 |
// Basicly what this function do, is build that amount of parts of the route |
9a5ed6c0a2e6
(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:
diff
changeset
|
84 |
// that go in the same direction. It sets 'part' to the last part of the route builded. |
9a5ed6c0a2e6
(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:
diff
changeset
|
85 |
// The return value is the cost for the builded parts |
9a5ed6c0a2e6
(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:
diff
changeset
|
86 |
// |
9a5ed6c0a2e6
(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:
diff
changeset
|
87 |
// Params: |
9a5ed6c0a2e6
(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:
diff
changeset
|
88 |
// PathFinderInfo : Pointer to the PathFinderInfo used for AiPathFinder |
9a5ed6c0a2e6
(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:
diff
changeset
|
89 |
// part : Which part we need to build |
9a5ed6c0a2e6
(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:
diff
changeset
|
90 |
// |
9a5ed6c0a2e6
(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:
diff
changeset
|
91 |
// TODO: skip already builded road-pieces (e.g.: cityroad) |
9a5ed6c0a2e6
(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:
diff
changeset
|
92 |
int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag) |
9a5ed6c0a2e6
(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:
diff
changeset
|
93 |
{ |
9a5ed6c0a2e6
(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:
diff
changeset
|
94 |
int part = PathFinderInfo->position; |
9a5ed6c0a2e6
(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:
diff
changeset
|
95 |
byte *route_extra = PathFinderInfo->route_extra; |
9a5ed6c0a2e6
(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:
diff
changeset
|
96 |
TileIndex *route = PathFinderInfo->route; |
9a5ed6c0a2e6
(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:
diff
changeset
|
97 |
int dir; |
9a5ed6c0a2e6
(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:
diff
changeset
|
98 |
int old_dir = -1; |
9a5ed6c0a2e6
(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:
diff
changeset
|
99 |
int cost = 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
100 |
int res; |
9a5ed6c0a2e6
(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:
diff
changeset
|
101 |
// We need to calculate the direction with the parent of the parent.. so we skip |
9a5ed6c0a2e6
(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:
diff
changeset
|
102 |
// the first pieces and the last piece |
9a5ed6c0a2e6
(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:
diff
changeset
|
103 |
if (part < 1) part = 1; |
9a5ed6c0a2e6
(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:
diff
changeset
|
104 |
// When we are done, stop it |
9a5ed6c0a2e6
(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:
diff
changeset
|
105 |
if (part >= PathFinderInfo->route_length - 1) { PathFinderInfo->position = -2; return 0; } |
9a5ed6c0a2e6
(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:
diff
changeset
|
106 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
107 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
108 |
if (PathFinderInfo->rail_or_road) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
109 |
// Tunnel code |
9a5ed6c0a2e6
(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:
diff
changeset
|
110 |
if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) { |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
111 |
cost += AI_DoCommand(route[part], 0, 0, flag, CMD_BUILD_TUNNEL); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
112 |
PathFinderInfo->position++; |
9a5ed6c0a2e6
(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:
diff
changeset
|
113 |
// TODO: problems! |
9a5ed6c0a2e6
(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:
diff
changeset
|
114 |
if (CmdFailed(cost)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
115 |
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: tunnel could not be build!"); |
9a5ed6c0a2e6
(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:
diff
changeset
|
116 |
return 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
117 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
118 |
return cost; |
9a5ed6c0a2e6
(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:
diff
changeset
|
119 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
120 |
// Bridge code |
9a5ed6c0a2e6
(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:
diff
changeset
|
121 |
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
122 |
cost += AiNew_Build_Bridge(p, route[part], route[part-1], flag); |
9a5ed6c0a2e6
(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:
diff
changeset
|
123 |
PathFinderInfo->position++; |
9a5ed6c0a2e6
(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:
diff
changeset
|
124 |
// TODO: problems! |
9a5ed6c0a2e6
(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:
diff
changeset
|
125 |
if (CmdFailed(cost)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
126 |
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: bridge could not be build!"); |
9a5ed6c0a2e6
(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:
diff
changeset
|
127 |
return 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
128 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
129 |
return cost; |
9a5ed6c0a2e6
(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:
diff
changeset
|
130 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
131 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
132 |
// Build normal rail |
9a5ed6c0a2e6
(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:
diff
changeset
|
133 |
// Keep it doing till we go an other way |
9a5ed6c0a2e6
(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:
diff
changeset
|
134 |
if (route_extra[part-1] == 0 && route_extra[part] == 0) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
135 |
while (route_extra[part] == 0) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
136 |
// Get the current direction |
9a5ed6c0a2e6
(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:
diff
changeset
|
137 |
dir = AiNew_GetRailDirection(route[part-1], route[part], route[part+1]); |
9a5ed6c0a2e6
(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:
diff
changeset
|
138 |
// Is it the same as the last one? |
9a5ed6c0a2e6
(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:
diff
changeset
|
139 |
if (old_dir != -1 && old_dir != dir) break; |
9a5ed6c0a2e6
(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:
diff
changeset
|
140 |
old_dir = dir; |
9a5ed6c0a2e6
(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:
diff
changeset
|
141 |
// Build the tile |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
142 |
res = AI_DoCommand(route[part], 0, dir, flag, CMD_BUILD_SINGLE_RAIL); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
143 |
if (CmdFailed(res)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
144 |
// Problem.. let's just abort it all! |
9a5ed6c0a2e6
(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:
diff
changeset
|
145 |
p->ainew.state = AI_STATE_NOTHING; |
9a5ed6c0a2e6
(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:
diff
changeset
|
146 |
return 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
147 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
148 |
cost += res; |
9a5ed6c0a2e6
(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:
diff
changeset
|
149 |
// Go to the next tile |
9a5ed6c0a2e6
(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:
diff
changeset
|
150 |
part++; |
9a5ed6c0a2e6
(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:
diff
changeset
|
151 |
// Check if it is still in range.. |
9a5ed6c0a2e6
(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:
diff
changeset
|
152 |
if (part >= PathFinderInfo->route_length - 1) break; |
9a5ed6c0a2e6
(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:
diff
changeset
|
153 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
154 |
part--; |
9a5ed6c0a2e6
(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:
diff
changeset
|
155 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
156 |
// We want to return the last position, so we go back one |
9a5ed6c0a2e6
(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:
diff
changeset
|
157 |
PathFinderInfo->position = part; |
9a5ed6c0a2e6
(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:
diff
changeset
|
158 |
} else { |
9a5ed6c0a2e6
(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:
diff
changeset
|
159 |
// Tunnel code |
9a5ed6c0a2e6
(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:
diff
changeset
|
160 |
if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) { |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
161 |
cost += AI_DoCommand(route[part], 0x200, 0, flag, CMD_BUILD_TUNNEL); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
162 |
PathFinderInfo->position++; |
9a5ed6c0a2e6
(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:
diff
changeset
|
163 |
// TODO: problems! |
9a5ed6c0a2e6
(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:
diff
changeset
|
164 |
if (CmdFailed(cost)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
165 |
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: tunnel could not be build!"); |
9a5ed6c0a2e6
(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:
diff
changeset
|
166 |
return 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
167 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
168 |
return cost; |
9a5ed6c0a2e6
(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:
diff
changeset
|
169 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
170 |
// Bridge code |
9a5ed6c0a2e6
(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:
diff
changeset
|
171 |
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
172 |
cost += AiNew_Build_Bridge(p, route[part], route[part+1], flag); |
9a5ed6c0a2e6
(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:
diff
changeset
|
173 |
PathFinderInfo->position++; |
9a5ed6c0a2e6
(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:
diff
changeset
|
174 |
// TODO: problems! |
9a5ed6c0a2e6
(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:
diff
changeset
|
175 |
if (CmdFailed(cost)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
176 |
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: bridge could not be build!"); |
9a5ed6c0a2e6
(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:
diff
changeset
|
177 |
return 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
178 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
179 |
return cost; |
9a5ed6c0a2e6
(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:
diff
changeset
|
180 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
181 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
182 |
// Build normal road |
9a5ed6c0a2e6
(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:
diff
changeset
|
183 |
// Keep it doing till we go an other way |
9a5ed6c0a2e6
(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:
diff
changeset
|
184 |
// EnsureNoVehicle makes sure we don't build on a tile where a vehicle is. This way |
9a5ed6c0a2e6
(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:
diff
changeset
|
185 |
// it will wait till the vehicle is gone.. |
9a5ed6c0a2e6
(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:
diff
changeset
|
186 |
if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
187 |
while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
188 |
// Get the current direction |
9a5ed6c0a2e6
(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:
diff
changeset
|
189 |
dir = AiNew_GetRoadDirection(route[part-1], route[part], route[part+1]); |
9a5ed6c0a2e6
(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:
diff
changeset
|
190 |
// Is it the same as the last one? |
9a5ed6c0a2e6
(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:
diff
changeset
|
191 |
if (old_dir != -1 && old_dir != dir) break; |
9a5ed6c0a2e6
(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:
diff
changeset
|
192 |
old_dir = dir; |
9a5ed6c0a2e6
(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:
diff
changeset
|
193 |
// There is already some road, and it is a bridge.. don't build!!! |
9a5ed6c0a2e6
(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:
diff
changeset
|
194 |
if (!IsTileType(route[part], MP_TUNNELBRIDGE)) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
195 |
// Build the tile |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
196 |
res = AI_DoCommand(route[part], dir, 0, flag | DC_NO_WATER, CMD_BUILD_ROAD); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
197 |
// Currently, we ignore CMD_ERRORs! |
9a5ed6c0a2e6
(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:
diff
changeset
|
198 |
if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_STREET) && !EnsureNoVehicle(route[part])) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
199 |
// Problem.. let's just abort it all! |
9a5ed6c0a2e6
(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:
diff
changeset
|
200 |
DEBUG(ai,0)("Darn, the route could not be builded.. aborting!"); |
9a5ed6c0a2e6
(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:
diff
changeset
|
201 |
p->ainew.state = AI_STATE_NOTHING; |
9a5ed6c0a2e6
(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:
diff
changeset
|
202 |
return 0; |
9a5ed6c0a2e6
(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:
diff
changeset
|
203 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
204 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
205 |
if (!CmdFailed(res)) cost += res; |
9a5ed6c0a2e6
(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:
diff
changeset
|
206 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
207 |
// Go to the next tile |
9a5ed6c0a2e6
(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:
diff
changeset
|
208 |
part++; |
9a5ed6c0a2e6
(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:
diff
changeset
|
209 |
// Check if it is still in range.. |
9a5ed6c0a2e6
(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:
diff
changeset
|
210 |
if (part >= PathFinderInfo->route_length - 1) break; |
9a5ed6c0a2e6
(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:
diff
changeset
|
211 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
212 |
part--; |
9a5ed6c0a2e6
(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:
diff
changeset
|
213 |
// We want to return the last position, so we go back one |
9a5ed6c0a2e6
(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:
diff
changeset
|
214 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
215 |
if (!EnsureNoVehicle(route[part]) && flag == DC_EXEC) part--; |
9a5ed6c0a2e6
(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:
diff
changeset
|
216 |
PathFinderInfo->position = part; |
9a5ed6c0a2e6
(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:
diff
changeset
|
217 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
218 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
219 |
return cost; |
9a5ed6c0a2e6
(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:
diff
changeset
|
220 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
221 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
222 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
223 |
// This functions tries to find the best vehicle for this type of cargo |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
224 |
// It returns INVALID_ENGINE if not suitable engine is found |
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
225 |
EngineID AiNew_PickVehicle(Player *p) |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
226 |
{ |
9a5ed6c0a2e6
(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:
diff
changeset
|
227 |
if (p->ainew.tbt == AI_TRAIN) { |
9a5ed6c0a2e6
(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:
diff
changeset
|
228 |
// Not supported yet |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
229 |
return INVALID_ENGINE; |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
230 |
} else { |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
231 |
EngineID start = _cargoc.ai_roadveh_start[p->ainew.cargo]; |
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
232 |
EngineID end = start + _cargoc.ai_roadveh_count[p->ainew.cargo]; |
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
233 |
EngineID i; |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
234 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
235 |
// Let's check it backwards.. we simply want to best engine available.. |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
236 |
for (i = end - 1; i >= start; i--) { |
3887
ece644bbf459
(svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents:
3885
diff
changeset
|
237 |
const Engine* e = GetEngine(i); |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
238 |
int32 ret; |
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
239 |
|
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
240 |
// Is it availiable? |
9a5ed6c0a2e6
(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:
diff
changeset
|
241 |
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY |
3887
ece644bbf459
(svn r4943) uint tile -> TileIndex tile, byte player -> PlayerID player
tron
parents:
3885
diff
changeset
|
242 |
if (!HASBIT(e->player_avail, _current_player) || e->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue; |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
243 |
// Can we build it? |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
244 |
ret = AI_DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_ROAD_VEH); |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
245 |
if (!CmdFailed(ret)) return i; |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
246 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
247 |
// We did not find a vehicle :( |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
248 |
return INVALID_ENGINE; |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
249 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
250 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
251 |
|
9a5ed6c0a2e6
(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:
diff
changeset
|
252 |
|
3946
3c8c78208dbb
(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:
3887
diff
changeset
|
253 |
void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2) |
3c8c78208dbb
(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:
3887
diff
changeset
|
254 |
{ |
3c8c78208dbb
(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:
3887
diff
changeset
|
255 |
Player* p = GetPlayer(_current_player); |
3c8c78208dbb
(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:
3887
diff
changeset
|
256 |
|
3c8c78208dbb
(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:
3887
diff
changeset
|
257 |
if (success) { |
3c8c78208dbb
(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:
3887
diff
changeset
|
258 |
p->ainew.state = AI_STATE_GIVE_ORDERS; |
3c8c78208dbb
(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:
3887
diff
changeset
|
259 |
p->ainew.veh_id = _new_vehicle_id; |
3c8c78208dbb
(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:
3887
diff
changeset
|
260 |
} else { |
3c8c78208dbb
(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:
3887
diff
changeset
|
261 |
/* XXX this should be handled more gracefully */ |
3c8c78208dbb
(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:
3887
diff
changeset
|
262 |
p->ainew.state = AI_STATE_NOTHING; |
3c8c78208dbb
(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:
3887
diff
changeset
|
263 |
} |
3c8c78208dbb
(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:
3887
diff
changeset
|
264 |
} |
3c8c78208dbb
(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:
3887
diff
changeset
|
265 |
|
3c8c78208dbb
(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:
3887
diff
changeset
|
266 |
|
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
267 |
// Builds the best vehicle possible |
9a5ed6c0a2e6
(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:
diff
changeset
|
268 |
int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag) |
9a5ed6c0a2e6
(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:
diff
changeset
|
269 |
{ |
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
270 |
EngineID i = AiNew_PickVehicle(p); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
271 |
|
3885
e67faccf52f5
(svn r4941) Replace some ints and magic numbers by proper types and enums
tron
parents:
3359
diff
changeset
|
272 |
if (i == INVALID_ENGINE) return CMD_ERROR; |
2639 | 273 |
if (p->ainew.tbt == AI_TRAIN) return CMD_ERROR; |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
274 |
|
3946
3c8c78208dbb
(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:
3887
diff
changeset
|
275 |
if (flag & DC_EXEC) { |
3c8c78208dbb
(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:
3887
diff
changeset
|
276 |
return AI_DoCommandCc(tile, i, 0, flag, CMD_BUILD_ROAD_VEH, CcAI); |
3c8c78208dbb
(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:
3887
diff
changeset
|
277 |
} else { |
3c8c78208dbb
(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:
3887
diff
changeset
|
278 |
return AI_DoCommand(tile, i, 0, flag, CMD_BUILD_ROAD_VEH); |
3c8c78208dbb
(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:
3887
diff
changeset
|
279 |
} |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
280 |
} |
9a5ed6c0a2e6
(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:
diff
changeset
|
281 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3033
diff
changeset
|
282 |
int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag) |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
283 |
{ |
9a5ed6c0a2e6
(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:
diff
changeset
|
284 |
int ret, ret2; |
9a5ed6c0a2e6
(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:
diff
changeset
|
285 |
if (p->ainew.tbt == AI_TRAIN) |
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
286 |
return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
287 |
|
2682
7fa4b202b9f0
(svn r3224) -Add: Allow the NewAI to work in Multiplayer Games (switchable via patch
truelight
parents:
2639
diff
changeset
|
288 |
ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
289 |
if (CmdFailed(ret)) return ret; |
9a5ed6c0a2e6
(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:
diff
changeset
|
290 |
// Try to build the road from the depot |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3033
diff
changeset
|
291 |
ret2 = AI_DoCommand(tile + TileOffsByDir(direction), DiagDirToRoadBits(ReverseDiagDir(direction)), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD); |
2381
9a5ed6c0a2e6
(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:
diff
changeset
|
292 |
// If it fails, ignore it.. |
9a5ed6c0a2e6
(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:
diff
changeset
|
293 |
if (CmdFailed(ret2)) return ret; |
9a5ed6c0a2e6
(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:
diff
changeset
|
294 |
return ret + ret2; |
9a5ed6c0a2e6
(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:
diff
changeset
|
295 |
} |