author | truebrain |
Wed, 23 Apr 2008 12:05:32 +0000 | |
branch | noai |
changeset 10308 | 0c81dfce3e9b |
parent 10249 | 58810805030e |
child 10339 | ce6cd68d9eb8 |
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" |
9794 | 7 |
#include "../../landscape.h" |
8 |
#include "../../tunnel_map.h" |
|
9 |
#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
|
10 |
#include "../../command_func.h" |
10249
58810805030e
(svn r12781) [NoAI] -Sync: with trunk r12711:12780.
rubidium
parents:
10088
diff
changeset
|
11 |
#include "../../tunnelbridge.h" |
9794 | 12 |
|
13 |
/* static */ bool AITunnel::IsTunnelTile(TileIndex tile) |
|
14 |
{ |
|
15 |
return ::IsTunnelTile(tile); |
|
16 |
} |
|
17 |
||
18 |
/* static */ TileIndex AITunnel::GetOtherTunnelEnd(TileIndex tile) |
|
19 |
{ |
|
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
|
20 |
if (!::IsValidTile(tile)) return INVALID_TILE; |
9794 | 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 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
|
23 |
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
|
24 |
|
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 |
::DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL); |
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 |
return _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile; |
9794 | 27 |
} |
28 |
||
29 |
/* static */ bool AITunnel::BuildTunnel(AIVehicle::VehicleType vehicle_type, TileIndex start) |
|
30 |
{ |
|
10088
922c6e6a8d3e
(svn r12612) [NoAI] -Add: support for GetLastError for AITunnel. Patch by Morloth.
rubidium
parents:
9833
diff
changeset
|
31 |
EnforcePrecondition(false, ::IsValidTile(start)); |
922c6e6a8d3e
(svn r12612) [NoAI] -Add: support for GetLastError for AITunnel. Patch by Morloth.
rubidium
parents:
9833
diff
changeset
|
32 |
EnforcePrecondition(false, vehicle_type == AIVehicle::VEHICLE_RAIL || vehicle_type == AIVehicle::VEHICLE_ROAD); |
9794 | 33 |
|
34 |
uint type = 0; |
|
35 |
if (vehicle_type == AIVehicle::VEHICLE_ROAD) { |
|
36 |
type |= (TRANSPORT_ROAD << 9); |
|
37 |
type |= ROADTYPES_ROAD; |
|
38 |
} else { |
|
39 |
type |= (TRANSPORT_RAIL << 9); |
|
40 |
type |= RAILTYPES_RAIL; |
|
41 |
} |
|
42 |
||
43 |
return AIObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL); |
|
44 |
} |
|
45 |
||
46 |
/* static */ bool AITunnel::RemoveTunnel(TileIndex tile) |
|
47 |
{ |
|
10088
922c6e6a8d3e
(svn r12612) [NoAI] -Add: support for GetLastError for AITunnel. Patch by Morloth.
rubidium
parents:
9833
diff
changeset
|
48 |
EnforcePrecondition(false, IsTunnelTile(tile)); |
9794 | 49 |
|
50 |
return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); |
|
51 |
} |