|
|
/* $Id$ */
|
|
|
|
|
|
/** @file pathfinder.cpp Pathfinder support for the trolly AI. */
|
|
|
|
|
|
#include "../../stdafx.h"
|
|
|
#include "../../openttd.h"
|
|
|
#include "../../bridge_map.h"
|
|
|
#include "../../debug.h"
|
|
|
#include "../../command_func.h"
|
|
|
#include "trolly.h"
|
|
|
#include "../../tunnel_map.h"
|
|
|
#include "../../bridge.h"
|
|
|
#include "../../tunnelbridge_map.h"
|
|
|
#include "../ai.h"
|
|
|
#include "../../variables.h"
|
|
|
#include "../../player_base.h"
|
|
|
#include "../../player_func.h"
|
|
|
#include "../../tunnelbridge.h"
|
|
|
|
|
|
|
|
|
#define TEST_STATION_NO_DIR 0xFF
|
|
|
|
|
|
// Tests if a station can be build on the given spot
|
|
|
// TODO: make it train compatible
|
|
|
static bool TestCanBuildStationHere(TileIndex tile, byte dir)
|
|
|
{
|
|
|
Player *p = GetPlayer(_current_player);
|
|
|
|
|
|
if (dir == TEST_STATION_NO_DIR) {
|
|
|
CommandCost ret;
|
|
|
// TODO: currently we only allow spots that can be access from al 4 directions...
|
|
|
// should be fixed!!!
|
|
|
for (dir = 0; dir < 4; dir++) {
|
|
|
ret = AiNew_Build_Station(p, _players_ainew[p->index].tbt, tile, 1, 1, dir, DC_QUERY_COST);
|
|
|
if (CmdSucceeded(ret)) return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// return true if command succeeded, so the inverse of CmdFailed()
|
|
|
return CmdSucceeded(AiNew_Build_Station(p, _players_ainew[p->index].tbt, tile, 1, 1, dir, DC_QUERY_COST));
|
|
|
}
|
|
|
|
|
|
|
|
|
static bool IsRoad(TileIndex tile)
|
|
|
{
|
|
|
return
|
|
|
// MP_ROAD, but not a road depot?
|
|
|
(IsTileType(tile, MP_ROAD) && !IsRoadDepot(tile)) ||
|
|
|
(IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD);
|
|
|
}
|
|
|
|