|
@@ -133,13 +133,13 @@ static void AiStateVehLoop(Player *p)
|
|
|
}
|
|
|
|
|
|
static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, TileIndex tile)
|
|
|
{
|
|
|
EngineID best_veh_index = INVALID_ENGINE;
|
|
|
byte best_veh_score = 0;
|
|
|
int32 ret;
|
|
|
CommandCost ret;
|
|
|
EngineID i;
|
|
|
|
|
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(i);
|
|
|
const Engine* e = GetEngine(i);
|
|
|
|
|
@@ -169,13 +169,13 @@ static EngineID AiChooseRoadVehToBuild(C
|
|
|
EngineID end = i + NUM_ROAD_ENGINES;
|
|
|
|
|
|
for (; i != end; i++) {
|
|
|
const RoadVehicleInfo *rvi = RoadVehInfo(i);
|
|
|
const Engine* e = GetEngine(i);
|
|
|
int32 rating;
|
|
|
int32 ret;
|
|
|
CommandCost ret;
|
|
|
|
|
|
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
/* Skip vehicles which can't take our cargo type */
|
|
@@ -204,13 +204,13 @@ static EngineID AiChooseAircraftToBuild(
|
|
|
EngineID best_veh_index = INVALID_ENGINE;
|
|
|
int32 best_veh_cost = 0;
|
|
|
EngineID i;
|
|
|
|
|
|
for (i = AIRCRAFT_ENGINES_INDEX; i != AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
|
|
|
const Engine* e = GetEngine(i);
|
|
|
int32 ret;
|
|
|
CommandCost ret;
|
|
|
|
|
|
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if ((AircraftVehInfo(i)->subtype & AIR_CTOL) != flag) continue;
|
|
@@ -1635,16 +1635,16 @@ static bool AiCheckTrackResources(TileIn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
static int32 AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
|
|
|
static CommandCost AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
|
|
|
{
|
|
|
int32 ret;
|
|
|
int32 total_cost = 0;
|
|
|
CommandCost ret;
|
|
|
CommandCost total_cost = 0;
|
|
|
Town *t = NULL;
|
|
|
int rating = 0;
|
|
|
int i, j, k;
|
|
|
|
|
|
for (;;) {
|
|
|
// This will seldomly overflow for valid reasons. Mask it to be on the safe side.
|
|
@@ -1731,13 +1731,13 @@ clear_town_stuff:;
|
|
|
}
|
|
|
|
|
|
return total_cost;
|
|
|
}
|
|
|
|
|
|
// Returns rule and cost
|
|
|
static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, int32* cost)
|
|
|
static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, CommandCost* cost)
|
|
|
{
|
|
|
int i;
|
|
|
const AiDefaultRailBlock *p;
|
|
|
|
|
|
for (i = 0; (p = _default_rail_track_data[i]) != NULL; i++) {
|
|
|
if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 &&
|
|
@@ -1818,13 +1818,13 @@ static void AiDoTerraformLand(TileIndex
|
|
|
static void AiStateBuildDefaultRailBlocks(Player *p)
|
|
|
{
|
|
|
uint i;
|
|
|
int j;
|
|
|
AiBuildRec *aib;
|
|
|
int rule;
|
|
|
int32 cost;
|
|
|
CommandCost cost;
|
|
|
|
|
|
// time out?
|
|
|
if (++p->ai.timeout_counter == 1388) {
|
|
|
p->ai.state = AIS_DELETE_RAIL_BLOCKS;
|
|
|
return;
|
|
|
}
|
|
@@ -2064,13 +2064,13 @@ static inline void AiCheckBuildRailBridg
|
|
|
|
|
|
static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile, const byte *p)
|
|
|
{
|
|
|
uint z;
|
|
|
|
|
|
if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
|
|
|
int32 cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
|
|
|
CommandCost cost = DoCommand(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
|
|
|
|
|
|
if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
|
|
|
AiBuildRailRecursive(arf, _build_tunnel_endtile, p[0] & 3);
|
|
|
if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
|
|
|
}
|
|
|
}
|
|
@@ -2462,13 +2462,13 @@ static void AiStateBuildRailVeh(Player *
|
|
|
{
|
|
|
const AiDefaultBlockData *ptr;
|
|
|
TileIndex tile;
|
|
|
EngineID veh;
|
|
|
int i;
|
|
|
CargoID cargo;
|
|
|
int32 cost;
|
|
|
CommandCost cost;
|
|
|
Vehicle *v;
|
|
|
VehicleID loco_id;
|
|
|
|
|
|
ptr = _default_rail_track_data[p->ai.src.cur_building_rule]->data;
|
|
|
while (ptr->mode != 0) ptr++;
|
|
|
|
|
@@ -2602,16 +2602,16 @@ static bool AiCheckRoadResources(TileInd
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static bool _want_road_truck_station;
|
|
|
static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
|
|
|
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
|
|
|
|
|
|
// Returns rule and cost
|
|
|
static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, int32 *cost)
|
|
|
static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, CommandCost *cost)
|
|
|
{
|
|
|
int i;
|
|
|
const AiDefaultRoadBlock *p;
|
|
|
|
|
|
_want_road_truck_station = (cargo & 0x7F) != CT_PASSENGERS;
|
|
|
|
|
@@ -2623,16 +2623,16 @@ static int AiFindBestDefaultRoadBlock(Ti
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
static int32 AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
|
|
|
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
|
|
|
{
|
|
|
int32 ret;
|
|
|
int32 total_cost = 0;
|
|
|
CommandCost ret;
|
|
|
CommandCost total_cost = 0;
|
|
|
Town *t = NULL;
|
|
|
int rating = 0;
|
|
|
int roadflag = 0;
|
|
|
|
|
|
for (;p->mode != 4;p++) {
|
|
|
TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
|
|
@@ -2718,13 +2718,13 @@ static bool AiCheckBlockDistances(Player
|
|
|
static void AiStateBuildDefaultRoadBlocks(Player *p)
|
|
|
{
|
|
|
uint i;
|
|
|
int j;
|
|
|
AiBuildRec *aib;
|
|
|
int rule;
|
|
|
int32 cost;
|
|
|
CommandCost cost;
|
|
|
|
|
|
// time out?
|
|
|
if (++p->ai.timeout_counter == 1388) {
|
|
|
p->ai.state = AIS_DELETE_RAIL_BLOCKS;
|
|
|
return;
|
|
|
}
|
|
@@ -2755,13 +2755,13 @@ static void AiStateBuildDefaultRoadBlock
|
|
|
// also try the other terraform direction
|
|
|
if (++p->ai.state_counter >= 1000) {
|
|
|
p->ai.state_counter = 0;
|
|
|
p->ai.state_mode = -p->ai.state_mode;
|
|
|
}
|
|
|
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
|
|
|
int32 r;
|
|
|
CommandCost r;
|
|
|
|
|
|
// player has money, build it.
|
|
|
aib->cur_building_rule = rule;
|
|
|
|
|
|
r = AiDoBuildDefaultRoadBlock(
|
|
|
aib->use_tile,
|
|
@@ -2964,13 +2964,13 @@ static inline void AiCheckBuildRoadBridg
|
|
|
|
|
|
static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
|
|
|
{
|
|
|
uint z;
|
|
|
|
|
|
if (GetTileSlope(tile, &z) == _dir_table_2[p[0] & 3] && z != 0) {
|
|
|
int32 cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
|
|
|
CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
|
|
|
|
|
|
if (!CmdFailed(cost) && cost <= (arf->player->player_money >> 4)) {
|
|
|
AiBuildRoadRecursive(arf, _build_tunnel_endtile, p[0] & 3);
|
|
|
if (arf->depth == 1) AiCheckRoadPathBetter(arf, p);
|
|
|
}
|
|
|
}
|
|
@@ -3098,13 +3098,13 @@ do_some_terraform:
|
|
|
* start with best bridge, then go down to worse and worse bridges
|
|
|
* unnecessary to check for worse bridge (i=0), since AI will always build that.
|
|
|
*AI is so fucked up that fixing this small thing will probably not solve a thing
|
|
|
*/
|
|
|
for (i = 10; i != 0; i--) {
|
|
|
if (CheckBridge_Stuff(i, bridge_len)) {
|
|
|
int32 cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
|
|
|
CommandCost cost = DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
|
|
|
if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Build it
|
|
|
DoCommand(tile, p->ai.cur_tile_a, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO | DC_EXEC, CMD_BUILD_BRIDGE);
|
|
@@ -3384,16 +3384,16 @@ static void AiStateAirportStuff(Player *
|
|
|
|
|
|
p->ai.state = AIS_BUILD_DEFAULT_AIRPORT_BLOCKS;
|
|
|
p->ai.state_mode = 255;
|
|
|
p->ai.state_counter = 0;
|
|
|
}
|
|
|
|
|
|
static int32 AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
|
|
|
static CommandCost AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
|
|
|
{
|
|
|
uint32 avail_airports = GetValidAirports();
|
|
|
int32 total_cost = 0, ret;
|
|
|
CommandCost total_cost = 0, ret;
|
|
|
|
|
|
for (; p->mode == 0; p++) {
|
|
|
if (!HASBIT(avail_airports, p->attr)) return CMD_ERROR;
|
|
|
ret = DoCommand(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_AIRPORT);
|
|
|
if (CmdFailed(ret)) return CMD_ERROR;
|
|
|
total_cost += ret;
|
|
@@ -3421,13 +3421,13 @@ static bool AiCheckAirportResources(Tile
|
|
|
return values[cargo] >= 8;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, int32 *cost)
|
|
|
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost)
|
|
|
{
|
|
|
const AiDefaultBlockData *p;
|
|
|
uint i;
|
|
|
|
|
|
for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
|
|
|
// If we are doing a helicopter service, avoid building
|
|
@@ -3443,13 +3443,13 @@ static int AiFindBestDefaultAirportBlock
|
|
|
|
|
|
static void AiStateBuildDefaultAirportBlocks(Player *p)
|
|
|
{
|
|
|
int i, j;
|
|
|
AiBuildRec *aib;
|
|
|
int rule;
|
|
|
int32 cost;
|
|
|
CommandCost cost;
|
|
|
|
|
|
// time out?
|
|
|
if (++p->ai.timeout_counter == 1388) {
|
|
|
p->ai.state = AIS_0;
|
|
|
return;
|
|
|
}
|
|
@@ -3482,13 +3482,13 @@ static void AiStateBuildDefaultAirportBl
|
|
|
if (++p->ai.state_counter >= 1000) {
|
|
|
p->ai.state_counter = 0;
|
|
|
p->ai.state_mode = -p->ai.state_mode;
|
|
|
}
|
|
|
} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
|
|
|
// player has money, build it.
|
|
|
int32 r;
|
|
|
CommandCost r;
|
|
|
|
|
|
aib->cur_building_rule = rule;
|
|
|
|
|
|
r = AiDoBuildDefaultAirportBlock(
|
|
|
aib->use_tile,
|
|
|
_airport_default_block_data[rule],
|