author | truebrain |
Sun, 08 Jun 2008 21:20:48 +0000 | |
branch | noai |
changeset 10871 | 326ee226e9d7 |
parent 10691 | a60393d87c0b |
child 10977 | 6c1a6657c7db |
permissions | -rw-r--r-- |
9833
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9807
diff
changeset
|
1 |
/* $Id$ */ |
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9807
diff
changeset
|
2 |
|
89a64246458f
(svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents:
9807
diff
changeset
|
3 |
/** @file ai_tunnel.cpp Implementation of AITunnel. */ |
9794 | 4 |
|
5 |
#include "ai_tunnel.hpp" |
|
9807
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
6 |
#include "ai_map.hpp" |
10339
ce6cd68d9eb8
(svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents:
10249
diff
changeset
|
7 |
#include "../../openttd.h" |
9794 | 8 |
#include "../../landscape.h" |
9 |
#include "../../tunnel_map.h" |
|
10 |
#include "../../road_type.h" |
|
9807
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
11 |
#include "../../command_func.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10088
diff
changeset
|
12 |
#include "../../tunnelbridge.h" |
10679
fcd493243794
(svn r13223) [NoAI] -Fix (r13212): tunnels and bridges were not tram aware
glx
parents:
10339
diff
changeset
|
13 |
#include "../../road_func.h" |
9794 | 14 |
|
15 |
/* static */ bool AITunnel::IsTunnelTile(TileIndex tile) |
|
16 |
{ |
|
17 |
return ::IsTunnelTile(tile); |
|
18 |
} |
|
19 |
||
20 |
/* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile) |
|
21 |
{ |
|
9807
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
22 |
if (!::IsValidTile(tile)) return INVALID_TILE; |
9794 | 23 |
|
9807
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
24 |
/* If it's a tunnel alread, take the easy way out! */ |
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
25 |
if (IsTunnelTile(tile)) return ::GetOtherTunnelEnd(tile); |
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
26 |
|
5b3be41b3ce6
(svn r12315) [NoAI] -Fix: AITunnel::GetOtherTunnelEnd() now also works to estimate where a non-existing tunnel would end (Morloth / glx)
truebrain
parents:
9794
diff
changeset
|
27 |
::DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL); |
10691
a60393d87c0b
(svn r13235) [NoAI] -Change [API CHANGE]: AITunnel.GetOtherTunnelEnd() now returns INVALID_TILE if no other end is found
glx
parents:
10679
diff
changeset
|
28 |
return _build_tunnel_endtile == 0 ? INVALID_TILE : _build_tunnel_endtile; |
9794 | 29 |
} |
30 |
||
31 |
/* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start) |
|
32 |
{ |
|
10088
922c6e6a8d3e
(svn r12612) [NoAI] -Add: support for GetLastError for AITunnel. Patch by Morloth.
rubidium
parents:
9833
diff
changeset
|
33 |
EnforcePrecondition(false, ::IsValidTile(start)); |
922c6e6a8d3e
(svn r12612) [NoAI] -Add: support for GetLastError for AITunnel. Patch by Morloth.
rubidium
parents:
9833
diff
changeset
|
34 |
EnforcePrecondition(false, vehicle_type == AIVehicle::VEHICLE_RAIL || vehicle_type == AIVehicle::VEHICLE_ROAD); |
9794 | 35 |
|
36 |
uint type = 0; |
|
37 |
if (vehicle_type == AIVehicle::VEHICLE_ROAD) { |
|
38 |
type |= (TRANSPORT_ROAD << 9); |
|
10679
fcd493243794
(svn r13223) [NoAI] -Fix (r13212): tunnels and bridges were not tram aware
glx
parents:
10339
diff
changeset
|
39 |
type |= RoadTypeToRoadTypes((::RoadType)AIObject::GetRoadType()); |
9794 | 40 |
} else { |
41 |
type |= (TRANSPORT_RAIL << 9); |
|
42 |
type |= RAILTYPES_RAIL; |
|
43 |
} |
|
44 |
||
45 |
return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL); |
|
46 |
} |
|
47 |
||
48 |
/* static */ bool AITunnel::RemoveTunnel(TileIndex tile) |
|
49 |
{ |
|
10088
922c6e6a8d3e
(svn r12612) [NoAI] -Add: support for GetLastError for AITunnel. Patch by Morloth.
rubidium
parents:
9833
diff
changeset
|
50 |
EnforcePrecondition(false, IsTunnelTile(tile)); |
9794 | 51 |
|
52 |
return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); |
|
53 |
} |