author | truebrain |
Mon, 31 Mar 2008 18:33:33 +0000 | |
branch | noai |
changeset 9851 | a5f5a7cf2b61 |
parent 9833 | 89a64246458f |
child 10088 | 922c6e6a8d3e |
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" |
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 "../../variables.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 |
{ |
|
31 |
if (!::IsValidTile(start)) return false; |
|
32 |
if (vehicle_type != AIVehicle::VEHICLE_RAIL && vehicle_type != AIVehicle::VEHICLE_ROAD) return false; |
|
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 |
{ |
|
48 |
if (!IsTunnelTile(tile)) return false; |
|
49 |
||
50 |
return AIObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR); |
|
51 |
} |