src/ai/default/default.cpp
changeset 8083 ad22eade501f
parent 8006 d56d68c938b5
child 8108 b42a0e5c67ef
equal deleted inserted replaced
8082:63240e1bd6cc 8083:ad22eade501f
    26 #include "../../depot.h"
    26 #include "../../depot.h"
    27 #include "../../variables.h"
    27 #include "../../variables.h"
    28 #include "../../bridge.h"
    28 #include "../../bridge.h"
    29 #include "../../date.h"
    29 #include "../../date.h"
    30 #include "../../helpers.hpp"
    30 #include "../../helpers.hpp"
       
    31 #include "../../tunnelbridge_map.h"
    31 #include "default.h"
    32 #include "default.h"
       
    33 
    32 
    34 
    33 // remove some day perhaps?
    35 // remove some day perhaps?
    34 static uint _ai_service_interval;
    36 static uint _ai_service_interval;
    35 
    37 
    36 typedef void AiStateAction(Player *p);
    38 typedef void AiStateAction(Player *p);
  2231 			p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDiagDir(p->ai.cur_dir_a));
  2233 			p->ai.cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDiagDir(p->ai.cur_dir_a));
  2232 			return true;
  2234 			return true;
  2233 		} else {
  2235 		} else {
  2234 			// Check if the bridge points in the right direction.
  2236 			// Check if the bridge points in the right direction.
  2235 			// This is not really needed the first place AiRemoveTileAndGoForward is called.
  2237 			// This is not really needed the first place AiRemoveTileAndGoForward is called.
  2236 			if (DiagDirToAxis(GetBridgeRampDirection(tile)) != (p->ai.cur_dir_a & 1)) return false;
  2238 			if (DiagDirToAxis(GetTunnelBridgeDirection(tile)) != (p->ai.cur_dir_a & 1)) return false;
  2237 
  2239 
  2238 			tile = GetOtherBridgeEnd(tile);
  2240 			tile = GetOtherBridgeEnd(tile);
  2239 
  2241 
  2240 			tilenew = TILE_MASK(tile - TileOffsByDiagDir(p->ai.cur_dir_a));
  2242 			tilenew = TILE_MASK(tile - TileOffsByDiagDir(p->ai.cur_dir_a));
  2241 			// And clear the bridge.
  2243 			// And clear the bridge.
  3731 				CMD_REMOVE_ROAD);
  3733 				CMD_REMOVE_ROAD);
  3732 		}
  3734 		}
  3733 	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
  3735 	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
  3734 		if (!IsTileOwner(tile, _current_player) ||
  3736 		if (!IsTileOwner(tile, _current_player) ||
  3735 				!IsBridge(tile) ||
  3737 				!IsBridge(tile) ||
  3736 				GetBridgeTransportType(tile) != TRANSPORT_RAIL) {
  3738 				GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) {
  3737 			return;
  3739 			return;
  3738 		}
  3740 		}
  3739 
  3741 
  3740 		rails = TRACK_BIT_NONE;
  3742 		rails = TRACK_BIT_NONE;
  3741 
  3743 
  3742 		switch (GetBridgeRampDirection(tile)) {
  3744 		switch (GetTunnelBridgeDirection(tile)) {
  3743 			default:
  3745 			default:
  3744 			case DIAGDIR_NE: goto pos_2;
  3746 			case DIAGDIR_NE: goto pos_2;
  3745 			case DIAGDIR_SE: goto pos_3;
  3747 			case DIAGDIR_SE: goto pos_3;
  3746 			case DIAGDIR_SW: goto pos_0;
  3748 			case DIAGDIR_SW: goto pos_0;
  3747 			case DIAGDIR_NW: goto pos_1;
  3749 			case DIAGDIR_NW: goto pos_1;