src/ai/default/default.cpp
author rubidium
Mon, 07 Apr 2008 20:03:46 +0000
changeset 8855 6d841d5d4789
parent 8843 45fdf630deaa
child 8954 3993bae3bfb8
permissions -rw-r--r--
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
2423
4266590b549d (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2381
diff changeset
     1
/* $Id$ */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
     2
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
     3
#include "../../stdafx.h"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
     4
#include "../../openttd.h"
3964
49e0d356d3ae (svn r5127) Use IsRoadVehInDepotStopped() and IsAircraftInHangarStopped()
tron
parents: 3948
diff changeset
     5
#include "../../aircraft.h"
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
     6
#include "../../bridge_map.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
     7
#include "../../tile_cmd.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6404
diff changeset
     8
#include "../../landscape.h"
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3184
diff changeset
     9
#include "../../rail_map.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3088
diff changeset
    10
#include "../../road_map.h"
3964
49e0d356d3ae (svn r5127) Use IsRoadVehInDepotStopped() and IsAircraftInHangarStopped()
tron
parents: 3948
diff changeset
    11
#include "../../roadveh.h"
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
    12
#include "../../station_map.h"
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3179
diff changeset
    13
#include "../../tunnel_map.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8108
diff changeset
    14
#include "../../command_func.h"
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    15
#include "../../town.h"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    16
#include "../../industry.h"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    17
#include "../../pathfind.h"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    18
#include "../../airport.h"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    19
#include "../../depot.h"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    20
#include "../../variables.h"
3359
633290bf1117 (svn r4154) -Moved MAX_BRIDGES in bridge.h and made it an enum. This makes two drops ...
celestar
parents: 3355
diff changeset
    21
#include "../../bridge.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    22
#include "../../date_func.h"
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8006
diff changeset
    23
#include "../../tunnelbridge_map.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    24
#include "../../window_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    25
#include "../../vehicle_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    26
#include "../../functions.h"
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    27
#include "../../saveload.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8236
diff changeset
    28
#include "../../player_func.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8236
diff changeset
    29
#include "../../player_base.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    30
#include "../../settings_type.h"
2447
071e4afe707c (svn r2973) Move a function declaration somewhere where it belongs
tron
parents: 2425
diff changeset
    31
#include "default.h"
8398
1e181e2e4e15 (svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents: 8392
diff changeset
    32
#include "../../tunnelbridge.h"
8784
c2e9d649a9ce (svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents: 8755
diff changeset
    33
#include "../../order_func.h"
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    34
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    35
#include "../../table/ai_rail.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    36
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    37
// remove some day perhaps?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    38
static uint _ai_service_interval;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    39
PlayerAI _players_ai[MAX_PLAYERS];
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    40
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    41
typedef void AiStateAction(Player *p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    42
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    43
enum {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    44
	AIS_0                            =  0,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    45
	AIS_1                            =  1,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    46
	AIS_VEH_LOOP                     =  2,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    47
	AIS_VEH_CHECK_REPLACE_VEHICLE    =  3,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    48
	AIS_VEH_DO_REPLACE_VEHICLE       =  4,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    49
	AIS_WANT_NEW_ROUTE               =  5,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    50
	AIS_BUILD_DEFAULT_RAIL_BLOCKS    =  6,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    51
	AIS_BUILD_RAIL                   =  7,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    52
	AIS_BUILD_RAIL_VEH               =  8,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    53
	AIS_DELETE_RAIL_BLOCKS           =  9,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    54
	AIS_BUILD_DEFAULT_ROAD_BLOCKS    = 10,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    55
	AIS_BUILD_ROAD                   = 11,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    56
	AIS_BUILD_ROAD_VEHICLES          = 12,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    57
	AIS_DELETE_ROAD_BLOCKS           = 13,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    58
	AIS_AIRPORT_STUFF                = 14,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    59
	AIS_BUILD_DEFAULT_AIRPORT_BLOCKS = 15,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    60
	AIS_BUILD_AIRCRAFT_VEHICLES      = 16,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    61
	AIS_CHECK_SHIP_STUFF             = 17,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    62
	AIS_BUILD_DEFAULT_SHIP_BLOCKS    = 18,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    63
	AIS_DO_SHIP_STUFF                = 19,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    64
	AIS_SELL_VEHICLE                 = 20,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    65
	AIS_REMOVE_STATION               = 21,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    66
	AIS_REMOVE_TRACK                 = 22,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
    67
	AIS_REMOVE_SINGLE_RAIL_TILE      = 23
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    68
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    69
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    70
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8614
diff changeset
    71
static inline TrackBits GetRailTrackStatus(TileIndex tile)
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
    72
{
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8614
diff changeset
    73
	return TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    74
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    75
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    76
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    77
static void AiCase0(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    78
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    79
	_players_ai[p->index].state = AIS_REMOVE_TRACK;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    80
	_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    81
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    82
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    83
static void AiCase1(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    84
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    85
	_players_ai[p->index].cur_veh = NULL;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    86
	_players_ai[p->index].state = AIS_VEH_LOOP;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    87
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    88
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    89
static void AiStateVehLoop(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    90
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    91
	Vehicle *v;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    92
	uint index;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    93
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
    94
	index = (_players_ai[p->index].cur_veh == NULL) ? 0 : _players_ai[p->index].cur_veh->index + 1;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    95
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
    96
	FOR_ALL_VEHICLES_FROM(v, index) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    97
		if (v->owner != _current_player) continue;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
    98
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
    99
		if ((v->type == VEH_TRAIN && v->subtype == 0) ||
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   100
				v->type == VEH_ROAD ||
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   101
				(v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) ||
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   102
				v->type == VEH_SHIP) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   103
			/* replace engine? */
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   104
			if (v->type == VEH_TRAIN && v->engine_type < 3 &&
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   105
					(_price.build_railvehicle >> 3) < p->player_money) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   106
				_players_ai[p->index].state = AIS_VEH_CHECK_REPLACE_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   107
				_players_ai[p->index].cur_veh = v;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   108
				return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   109
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   110
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   111
			/* not profitable? */
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   112
			if (v->age >= 730 &&
8614
4c67a883c4c4 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents: 8611
diff changeset
   113
					v->profit_last_year < _price.station_value * 5 * 256 &&
4c67a883c4c4 (svn r12197) -Fix [FS#1788](r12134): show correct last year profit when the train had negative income
smatz
parents: 8611
diff changeset
   114
					v->profit_this_year < _price.station_value * 5 * 256) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   115
				_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   116
				_players_ai[p->index].state = AIS_SELL_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   117
				_players_ai[p->index].cur_veh = v;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   118
				return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   119
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   120
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   121
			/* not reliable? */
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   122
			if (v->age >= v->max_age || (
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   123
						v->age != 0 &&
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   124
						GetEngine(v->engine_type)->reliability < 35389
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   125
					)) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   126
				_players_ai[p->index].state = AIS_VEH_CHECK_REPLACE_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   127
				_players_ai[p->index].cur_veh = v;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   128
				return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   129
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   130
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   131
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   132
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   133
	_players_ai[p->index].state = AIS_WANT_NEW_ROUTE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   134
	_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   135
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   136
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   137
static EngineID AiChooseTrainToBuild(RailType railtype, Money money, byte flag, TileIndex tile)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   138
{
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   139
	EngineID best_veh_index = INVALID_ENGINE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   140
	byte best_veh_score = 0;
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   141
	EngineID i;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   142
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   143
	FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_TRAIN) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   144
		const RailVehicleInfo *rvi = RailVehInfo(i);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   145
		const Engine* e = GetEngine(i);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   146
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5733
diff changeset
   147
		if (!IsCompatibleRail(rvi->railtype, railtype) ||
5868
94430141c189 (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 5854
diff changeset
   148
				rvi->railveh_type == RAILVEH_WAGON ||
94430141c189 (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 5854
diff changeset
   149
				(rvi->railveh_type == RAILVEH_MULTIHEAD && flag & 1) ||
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7653
diff changeset
   150
				!HasBit(e->player_avail, _current_player) ||
2529
429ac415da43 (svn r3058) The default AI may not build dual headed trains under certain circumstances.
tron
parents: 2523
diff changeset
   151
				e->reliability < 0x8A3D) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   152
			continue;
2529
429ac415da43 (svn r3058) The default AI may not build dual headed trains under certain circumstances.
tron
parents: 2523
diff changeset
   153
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   154
8449
64c872ab3ed3 (svn r12019) -Codechange: Add support for passenger engine designation for AI-use, NewGRF property 0x08 for trains.
peter1138
parents: 8402
diff changeset
   155
		/* Don't choose an engine designated for passenger use for freight. */
64c872ab3ed3 (svn r12019) -Codechange: Add support for passenger engine designation for AI-use, NewGRF property 0x08 for trains.
peter1138
parents: 8402
diff changeset
   156
		if (rvi->ai_passenger_only != 0 && flag == 1) continue;
64c872ab3ed3 (svn r12019) -Codechange: Add support for passenger engine designation for AI-use, NewGRF property 0x08 for trains.
peter1138
parents: 8402
diff changeset
   157
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   158
		CommandCost ret = DoCommand(tile, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   159
		if (CmdSucceeded(ret) && ret.GetCost() <= money && rvi->ai_rank >= best_veh_score) {
3022
d4b90d0b5b24 (svn r3602) - Move _railveh_score data to _rail_vehicle_info->ai_rank and remove global variable to return data as we can now access this directly.
peter1138
parents: 2989
diff changeset
   160
			best_veh_score = rvi->ai_rank;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   161
			best_veh_index = i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   162
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   163
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   164
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   165
	return best_veh_index;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   166
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   167
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   168
static EngineID AiChooseRoadVehToBuild(CargoID cargo, Money money, TileIndex tile)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   169
{
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   170
	EngineID best_veh_index = INVALID_ENGINE;
5029
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   171
	int32 best_veh_rating = 0;
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   172
	EngineID i;
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   173
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   174
	FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_ROAD) {
5029
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   175
		const RoadVehicleInfo *rvi = RoadVehInfo(i);
3034
4b1161fb9221 (svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents: 3033
diff changeset
   176
		const Engine* e = GetEngine(i);
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   177
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7653
diff changeset
   178
		if (!HasBit(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   179
			continue;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   180
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   181
5016
abe2d67ce392 (svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.
peter1138
parents: 5004
diff changeset
   182
		/* Skip vehicles which can't take our cargo type */
5031
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
   183
		if (rvi->cargo_type != cargo && !CanRefitTo(i, cargo)) continue;
5029
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   184
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   185
		/* Rate and compare the engine by speed & capacity */
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   186
		int rating = rvi->max_speed * rvi->capacity;
5029
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   187
		if (rating <= best_veh_rating) continue;
5016
abe2d67ce392 (svn r7057) -Codechange: Remove hardcoded lists of road vehicles for each cargo type in favour of just checking the cargo type of each vehicle.
peter1138
parents: 5004
diff changeset
   188
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   189
		CommandCost ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH);
5031
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
   190
		if (CmdFailed(ret)) continue;
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
   191
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
   192
		/* Add the cost of refitting */
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   193
		if (rvi->cargo_type != cargo) ret.AddCost(GetRefitCost(i));
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   194
		if (ret.GetCost() > money) continue;
5029
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   195
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   196
		best_veh_rating = rating;
455ac4f14c9b (svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
peter1138
parents: 5028
diff changeset
   197
		best_veh_index = i;
3034
4b1161fb9221 (svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents: 3033
diff changeset
   198
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   199
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   200
	return best_veh_index;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   201
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   202
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   203
/**
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   204
 * Choose aircraft to build.
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   205
 * @param money current AI money
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   206
 * @param forbidden forbidden flags - AIR_HELI = 0 (always allowed), AIR_CTOL = 1 (bit 0), AIR_FAST = 2 (bit 1)
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   207
 * @return EngineID of aircraft to build
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   208
 */
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   209
static EngineID AiChooseAircraftToBuild(Money money, byte forbidden)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   210
{
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   211
	EngineID best_veh_index = INVALID_ENGINE;
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   212
	Money best_veh_cost = 0;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   213
	EngineID i;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   214
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   215
	FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_AIRCRAFT) {
3034
4b1161fb9221 (svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents: 3033
diff changeset
   216
		const Engine* e = GetEngine(i);
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   217
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7653
diff changeset
   218
		if (!HasBit(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   219
			continue;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   220
		}
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   221
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   222
		if ((AircraftVehInfo(i)->subtype & forbidden) != 0) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   223
8389
b1e7f7ae2b32 (svn r11959) -Codechange: Use macro to loop for specific engine types instead of using specific indexes each time.
peter1138
parents: 8351
diff changeset
   224
		CommandCost ret = DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT);
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   225
		if (CmdSucceeded(ret) && ret.GetCost() <= money && ret.GetCost() >= best_veh_cost) {
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   226
			best_veh_cost = ret.GetCost();
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   227
			best_veh_index = i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   228
		}
3034
4b1161fb9221 (svn r3614) turn 2 do-while-loop with 2 induction variables each into canocical for loops
tron
parents: 3033
diff changeset
   229
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   230
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   231
	return best_veh_index;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   232
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   233
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   234
static Money AiGetBasePrice(const Player* p)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   235
{
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   236
	Money base = _price.station_value;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   237
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   238
	// adjust base price when more expensive vehicles are available
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   239
	switch (_players_ai[p->index].railtype_to_use) {
3966
5da20f144ab0 (svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents: 3965
diff changeset
   240
		default: NOT_REACHED();
5da20f144ab0 (svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents: 3965
diff changeset
   241
		case RAILTYPE_RAIL:     break;
5da20f144ab0 (svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents: 3965
diff changeset
   242
		case RAILTYPE_ELECTRIC: break;
5da20f144ab0 (svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents: 3965
diff changeset
   243
		case RAILTYPE_MONO:     base = (base * 3) >> 1; break;
5da20f144ab0 (svn r5129) Accommodate the default AI for the new railtype: It used hard coded numbers instead of enums to calculate prices
tron
parents: 3965
diff changeset
   244
		case RAILTYPE_MAGLEV:   base *= 2; break;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   245
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   246
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   247
	return base;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   248
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   249
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   250
static EngineID AiChooseRoadVehToReplaceWith(const Player* p, const Vehicle* v)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   251
{
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   252
	Money avail_money = p->player_money + v->value;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   253
	return AiChooseRoadVehToBuild(v->cargo_type, avail_money, v->tile);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   254
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   255
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   256
static EngineID AiChooseAircraftToReplaceWith(const Player* p, const Vehicle* v)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   257
{
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   258
	Money avail_money = p->player_money + v->value;
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   259
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   260
	/* determine forbidden aircraft bits */
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   261
	byte forbidden = 0;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   262
	const Order *o;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   263
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   264
	FOR_VEHICLE_ORDERS(v, o) {
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   265
		if (!o->IsValid()) continue;
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8839
diff changeset
   266
		if (!IsValidStationID(o->GetDestination())) continue;
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8839
diff changeset
   267
		const Station *st = GetStation(o->GetDestination());
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   268
		if (!(st->facilities & FACIL_AIRPORT)) continue;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   269
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   270
		AirportFTAClass::Flags flags = st->Airport()->flags;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   271
		if (!(flags & AirportFTAClass::AIRPLANES)) forbidden |= AIR_CTOL | AIR_FAST; // no planes for heliports / oil rigs
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   272
		if (flags & AirportFTAClass::SHORT_STRIP) forbidden |= AIR_FAST; // no fast planes for small airports
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   273
	}
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   274
4024
6b3809fd45e0 (svn r5263) Use the flag which denotes if it's a plane or helicopter instead of magical engine numbers
tron
parents: 4015
diff changeset
   275
	return AiChooseAircraftToBuild(
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
   276
		avail_money, forbidden
4024
6b3809fd45e0 (svn r5263) Use the flag which denotes if it's a plane or helicopter instead of magical engine numbers
tron
parents: 4015
diff changeset
   277
	);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   278
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   279
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   280
static EngineID AiChooseTrainToReplaceWith(const Player* p, const Vehicle* v)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   281
{
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
   282
	Money avail_money = p->player_money + v->value;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   283
	const Vehicle* u = v;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   284
	int num = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   285
7492
35acee076719 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7490
diff changeset
   286
	while (++num, u->Next() != NULL) {
35acee076719 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7490
diff changeset
   287
		u = u->Next();
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   288
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   289
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   290
	// XXX: check if a wagon
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   291
	return AiChooseTrainToBuild(v->u.rail.railtype, avail_money, 0, v->tile);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   292
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   293
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   294
static EngineID AiChooseShipToReplaceWith(const Player* p, const Vehicle* v)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   295
{
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
   296
	/* Ships are not implemented in this (broken) AI */
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   297
	return INVALID_ENGINE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   298
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   299
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   300
static void AiHandleGotoDepot(Player *p, int cmd)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   301
{
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
   302
	if (!_players_ai[p->index].cur_veh->current_order.IsType(OT_GOTO_DEPOT))
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   303
		DoCommand(0, _players_ai[p->index].cur_veh->index, 0, DC_EXEC, cmd);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   304
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   305
	if (++_players_ai[p->index].state_counter <= 1387) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   306
		_players_ai[p->index].state = AIS_VEH_DO_REPLACE_VEHICLE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   307
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   308
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   309
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
   310
	if (_players_ai[p->index].cur_veh->current_order.IsType(OT_GOTO_DEPOT)) {
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
   311
		_players_ai[p->index].cur_veh->current_order.MakeDummy();
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   312
		InvalidateWindow(WC_VEHICLE_VIEW, _players_ai[p->index].cur_veh->index);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   313
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   314
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   315
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   316
static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   317
{
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   318
	if (bak->order == NULL) return;
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   319
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
   320
	for (uint i = 0; !bak->order[i].IsType(OT_NOTHING); i++) {
8839
6337281b393b (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents: 8836
diff changeset
   321
		if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   322
			break;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   323
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   324
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   325
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   326
static void AiHandleReplaceTrain(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   327
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   328
	const Vehicle* v = _players_ai[p->index].cur_veh;
7653
dd252420d9c2 (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7645
diff changeset
   329
	BackuppedOrders orderbak;
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   330
	EngineID veh;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   331
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   332
	// wait until the vehicle reaches the depot.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   333
	if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) {
4495
b6381e4bcb61 (svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents: 4434
diff changeset
   334
		AiHandleGotoDepot(p, CMD_SEND_TRAIN_TO_DEPOT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   335
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   336
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   337
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   338
	veh = AiChooseTrainToReplaceWith(p, v);
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   339
	if (veh != INVALID_ENGINE) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   340
		TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   341
7653
dd252420d9c2 (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7645
diff changeset
   342
		BackupVehicleOrders(v, &orderbak);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   343
		tile = v->tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   344
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
   345
		if (CmdSucceeded(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) &&
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
   346
				CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) {
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3933
diff changeset
   347
			VehicleID veh = _new_vehicle_id;
7653
dd252420d9c2 (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7645
diff changeset
   348
			AiRestoreVehicleOrders(GetVehicle(veh), &orderbak);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   349
			DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_TRAIN);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   350
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   351
			DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   352
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   353
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   354
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   355
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   356
static void AiHandleReplaceRoadVeh(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   357
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   358
	const Vehicle* v = _players_ai[p->index].cur_veh;
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   359
	BackuppedOrders orderbak;
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   360
	EngineID veh;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   361
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7455
diff changeset
   362
	if (!v->IsStoppedInDepot()) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   363
		AiHandleGotoDepot(p, CMD_SEND_ROADVEH_TO_DEPOT);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   364
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   365
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   366
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   367
	veh = AiChooseRoadVehToReplaceWith(p, v);
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   368
	if (veh != INVALID_ENGINE) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   369
		TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   370
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   371
		BackupVehicleOrders(v, &orderbak);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   372
		tile = v->tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   373
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
   374
		if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH)) &&
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
   375
				CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) {
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3933
diff changeset
   376
			VehicleID veh = _new_vehicle_id;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
   377
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   378
			AiRestoreVehicleOrders(GetVehicle(veh), &orderbak);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   379
			DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   380
			DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   381
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   382
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   383
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   384
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   385
static void AiHandleReplaceAircraft(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   386
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   387
	const Vehicle* v = _players_ai[p->index].cur_veh;
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   388
	BackuppedOrders orderbak;
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   389
	EngineID veh;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   390
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7455
diff changeset
   391
	if (!v->IsStoppedInDepot()) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   392
		AiHandleGotoDepot(p, CMD_SEND_AIRCRAFT_TO_HANGAR);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   393
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   394
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   395
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   396
	veh = AiChooseAircraftToReplaceWith(p, v);
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   397
	if (veh != INVALID_ENGINE) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   398
		TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   399
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   400
		BackupVehicleOrders(v, &orderbak);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   401
		tile = v->tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   402
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
   403
		if (CmdSucceeded(DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT)) &&
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
   404
				CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) {
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3933
diff changeset
   405
			VehicleID veh = _new_vehicle_id;
8322
916ef2361569 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8302
diff changeset
   406
			AiRestoreVehicleOrders(GetVehicle(veh), &orderbak);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   407
			DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   408
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
   409
			DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   410
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   411
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   412
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   413
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   414
static void AiHandleReplaceShip(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   415
{
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
   416
	/* Ships are not implemented in this (broken) AI */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   417
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   418
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   419
typedef EngineID CheckReplaceProc(const Player* p, const Vehicle* v);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   420
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   421
static CheckReplaceProc* const _veh_check_replace_proc[] = {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   422
	AiChooseTrainToReplaceWith,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   423
	AiChooseRoadVehToReplaceWith,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   424
	AiChooseShipToReplaceWith,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   425
	AiChooseAircraftToReplaceWith,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   426
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   427
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   428
typedef void DoReplaceProc(Player *p);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   429
static DoReplaceProc* const _veh_do_replace_proc[] = {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   430
	AiHandleReplaceTrain,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   431
	AiHandleReplaceRoadVeh,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   432
	AiHandleReplaceShip,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   433
	AiHandleReplaceAircraft
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   434
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   435
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   436
static void AiStateCheckReplaceVehicle(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   437
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   438
	const Vehicle* v = _players_ai[p->index].cur_veh;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   439
7387
c81fff74048b (svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
rubidium
parents: 7370
diff changeset
   440
	if (!v->IsValid() ||
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
   441
			v->owner != _current_player ||
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   442
			v->type > VEH_SHIP ||
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   443
			_veh_check_replace_proc[v->type - VEH_TRAIN](p, v) == INVALID_ENGINE) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   444
		_players_ai[p->index].state = AIS_VEH_LOOP;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   445
	} else {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   446
		_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   447
		_players_ai[p->index].state = AIS_VEH_DO_REPLACE_VEHICLE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   448
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   449
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   450
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   451
static void AiStateDoReplaceVehicle(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   452
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   453
	const Vehicle* v = _players_ai[p->index].cur_veh;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   454
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   455
	_players_ai[p->index].state = AIS_VEH_LOOP;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   456
	// vehicle is not owned by the player anymore, something went very wrong.
7387
c81fff74048b (svn r10756) -Codechange: use vehicle->IsValid in favour of IsValidVehicle(vehicle).
rubidium
parents: 7370
diff changeset
   457
	if (!v->IsValid() || v->owner != _current_player) return;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
   458
	_veh_do_replace_proc[v->type - VEH_TRAIN](p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   459
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   460
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   461
struct FoundRoute {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   462
	int distance;
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   463
	CargoID cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   464
	void *from;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   465
	void *to;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   466
};
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   467
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6106
diff changeset
   468
static Town *AiFindRandomTown()
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   469
{
4356
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   470
	return GetRandomTown();
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   471
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   472
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6106
diff changeset
   473
static Industry *AiFindRandomIndustry()
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   474
{
6314
38513b9f91ec (svn r9251) -Fix(r6057, FS#644): Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game. The AI now sucks a even a bit more than before (if that's even possible).
celestar
parents: 6259
diff changeset
   475
	int num = RandomRange(GetMaxIndustryIndex());
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7387
diff changeset
   476
	if (IsValidIndustryID(num)) return GetIndustry(num);
6314
38513b9f91ec (svn r9251) -Fix(r6057, FS#644): Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game. The AI now sucks a even a bit more than before (if that's even possible).
celestar
parents: 6259
diff changeset
   477
38513b9f91ec (svn r9251) -Fix(r6057, FS#644): Use a less CPU-intensive algorithm to find a random industry for the AI to prevent it slowing down the game. The AI now sucks a even a bit more than before (if that's even possible).
celestar
parents: 6259
diff changeset
   478
	return NULL;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   479
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   480
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   481
static void AiFindSubsidyIndustryRoute(FoundRoute *fr)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   482
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   483
	uint i;
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   484
	CargoID cargo;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   485
	const Subsidy* s;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   486
	Industry* from;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   487
	TileIndex to_xy;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   488
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   489
	// initially error
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   490
	fr->distance = -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   491
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   492
	// Randomize subsidy index..
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   493
	i = RandomRange(lengthof(_subsidies) * 3);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   494
	if (i >= lengthof(_subsidies)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   495
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   496
	s = &_subsidies[i];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   497
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   498
	// Don't want passengers or mail
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   499
	cargo = s->cargo_type;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   500
	if (cargo == CT_INVALID ||
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   501
			cargo == CT_PASSENGERS ||
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   502
			cargo == CT_MAIL ||
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   503
			s->age > 7) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   504
		return;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   505
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   506
	fr->cargo = cargo;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   507
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   508
	fr->from = from = GetIndustry(s->from);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   509
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   510
	if (cargo == CT_GOODS || cargo == CT_FOOD) {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   511
		Town* to_tow = GetTown(s->to);
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   512
4015
4f67e077e30e (svn r5228) Suppress MSVC warnings about signed/unsigned comparison
KUDr
parents: 4011
diff changeset
   513
		if (to_tow->population < (cargo == CT_FOOD ? 200U : 900U)) return; // error
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   514
		fr->to = to_tow;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   515
		to_xy = to_tow->xy;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   516
	} else {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   517
		Industry* to_ind = GetIndustry(s->to);
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   518
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   519
		fr->to = to_ind;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   520
		to_xy = to_ind->xy;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   521
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   522
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   523
	fr->distance = DistanceManhattan(from->xy, to_xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   524
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   525
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   526
static void AiFindSubsidyPassengerRoute(FoundRoute *fr)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   527
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   528
	uint i;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   529
	const Subsidy* s;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
   530
	Town *from, *to;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   531
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   532
	// initially error
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   533
	fr->distance = -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   534
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   535
	// Randomize subsidy index..
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   536
	i = RandomRange(lengthof(_subsidies) * 3);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   537
	if (i >= lengthof(_subsidies)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   538
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   539
	s = &_subsidies[i];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   540
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   541
	// Only want passengers
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   542
	if (s->cargo_type != CT_PASSENGERS || s->age > 7) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   543
	fr->cargo = s->cargo_type;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   544
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   545
	fr->from = from = GetTown(s->from);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   546
	fr->to = to = GetTown(s->to);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   547
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   548
	// They must be big enough
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   549
	if (from->population < 400 || to->population < 400) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   550
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   551
	fr->distance = DistanceManhattan(from->xy, to->xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   552
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   553
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   554
static void AiFindRandomIndustryRoute(FoundRoute *fr)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   555
{
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   556
	Industry* i;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   557
	uint32 r;
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   558
	CargoID cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   559
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   560
	// initially error
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   561
	fr->distance = -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   562
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   563
	r = Random();
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   564
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   565
	// pick a source
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   566
	fr->from = i = AiFindRandomIndustry();
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   567
	if (i == NULL) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   568
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   569
	// pick a random produced cargo
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   570
	cargo = i->produced_cargo[0];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   571
	if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1];
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   572
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   573
	fr->cargo = cargo;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   574
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   575
	// don't allow passengers
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   576
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   577
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   578
	if (cargo != CT_GOODS && cargo != CT_FOOD) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   579
		// pick a dest, and see if it can receive
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   580
		Industry* i2 = AiFindRandomIndustry();
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   581
		if (i2 == NULL || i == i2 ||
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   582
				(i2->accepts_cargo[0] != cargo &&
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   583
				i2->accepts_cargo[1] != cargo &&
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   584
				i2->accepts_cargo[2] != cargo)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   585
			return;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   586
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   587
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   588
		fr->to = i2;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   589
		fr->distance = DistanceManhattan(i->xy, i2->xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   590
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   591
		// pick a dest town, and see if it's big enough
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   592
		Town* t = AiFindRandomTown();
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   593
4015
4f67e077e30e (svn r5228) Suppress MSVC warnings about signed/unsigned comparison
KUDr
parents: 4011
diff changeset
   594
		if (t == NULL || t->population < (cargo == CT_FOOD ? 200U : 900U)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   595
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   596
		fr->to = t;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   597
		fr->distance = DistanceManhattan(i->xy, t->xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   598
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   599
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   600
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   601
static void AiFindRandomPassengerRoute(FoundRoute *fr)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   602
{
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   603
	Town* source;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   604
	Town* dest;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   605
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   606
	// initially error
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   607
	fr->distance = -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   608
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   609
	fr->from = source = AiFindRandomTown();
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   610
	if (source == NULL || source->population < 400) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   611
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   612
	fr->to = dest = AiFindRandomTown();
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   613
	if (dest == NULL || source == dest || dest->population < 400) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   614
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   615
	fr->distance = DistanceManhattan(source->xy, dest->xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   616
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   617
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   618
// Warn: depends on 'xy' being the first element in both Town and Industry
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   619
#define GET_TOWN_OR_INDUSTRY_TILE(p) (((Town*)(p))->xy)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   620
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   621
static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   622
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   623
	TileIndex from_tile, to_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   624
	Station *st;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   625
	int dist;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   626
	uint same_station = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   627
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   628
	from_tile = GET_TOWN_OR_INDUSTRY_TILE(fr->from);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   629
	to_tile = GET_TOWN_OR_INDUSTRY_TILE(fr->to);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   630
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   631
	dist = 0xFFFF;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   632
	FOR_ALL_STATIONS(st) {
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   633
		int cur;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   634
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   635
		if (st->owner != _current_player) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   636
		cur = DistanceMax(from_tile, st->xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   637
		if (cur < dist) dist = cur;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   638
		cur = DistanceMax(to_tile, st->xy);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   639
		if (cur < dist) dist = cur;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   640
		if (to_tile == from_tile && st->xy == to_tile) same_station++;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   641
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   642
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   643
	// To prevent the AI from building ten busstations in the same town, do some calculations
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   644
	//  For each road or airport station, we want 350 of population!
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   645
	if ((bitmask == 2 || bitmask == 4) &&
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   646
			same_station > 2 &&
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   647
			((Town*)fr->from)->population < same_station * 350) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   648
		return false;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   649
	}
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   650
6858
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   651
	/* Requiring distance to nearest station to be always under 37 tiles may be suboptimal,
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   652
	 * Especially for longer aircraft routes that start and end pretty at any arbitrary place on map
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   653
	 * While it may be nice for AI to cluster their creations together, hardcoded limit is not ideal.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   654
	 * If AI will randomly start on some isolated spot, it will never get out of there.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   655
	 * AI will have chance of randomly rejecting routes further than 37 tiles from their network,
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   656
	 * so there will be some attempt to cluster the network together */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   657
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   658
	/* Random value between 37 and 292. Low values are exponentially more likely
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   659
	 * With 50% chance the value will be under 52 tiles */
6866
a147f0465258 (svn r10106) -Fix (r10098): there's always a compiler complaining about something...
rubidium
parents: 6858
diff changeset
   660
	int min_distance = 36 + (1 << (Random() % 9)); // 0..8
6858
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   661
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   662
	/* Make sure distance to closest station is < min_distance tiles. */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
   663
	if (dist != 0xFFFF && dist > min_distance) return false;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   664
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   665
	if (_players_ai[p->index].route_type_mask != 0 &&
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   666
			!(_players_ai[p->index].route_type_mask & bitmask) &&
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7954
diff changeset
   667
			!Chance16(1, 5)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   668
		return false;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   669
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   670
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   671
	if (fr->cargo == CT_PASSENGERS || fr->cargo == CT_MAIL) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   672
		const Town* from = (const Town*)fr->from;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   673
		const Town* to   = (const Town*)fr->to;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   674
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   675
		if (from->pct_pass_transported > 0x99 ||
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   676
				to->pct_pass_transported > 0x99) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   677
			return false;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   678
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   679
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   680
		// Make sure it has a reasonably good rating
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   681
		if (from->ratings[_current_player] < -100 ||
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   682
				to->ratings[_current_player] < -100) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   683
			return false;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   684
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   685
	} else {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   686
		const Industry* i = (const Industry*)fr->from;
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   687
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   688
		if (i->last_month_pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 ||
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7492
diff changeset
   689
				i->last_month_production[fr->cargo != i->produced_cargo[0]] == 0) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   690
			return false;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
   691
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   692
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   693
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   694
	_players_ai[p->index].route_type_mask |= bitmask;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   695
	return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   696
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   697
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   698
static byte AiGetDirectionBetweenTiles(TileIndex a, TileIndex b)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   699
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   700
	byte i = (TileX(a) < TileX(b)) ? 1 : 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   701
	if (TileY(a) >= TileY(b)) i ^= 3;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   702
	return i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   703
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   704
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   705
static TileIndex AiGetPctTileBetween(TileIndex a, TileIndex b, byte pct)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   706
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   707
	return TileXY(
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   708
		TileX(a) + ((TileX(b) - TileX(a)) * pct >> 8),
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   709
		TileY(a) + ((TileY(b) - TileY(a)) * pct >> 8)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   710
	);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   711
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   712
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   713
static void AiWantLongIndustryRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   714
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   715
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   716
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   717
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   718
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   719
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   720
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   721
		AiFindSubsidyIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   722
		if (IsInsideMM(fr.distance, 60, 90 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   723
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   724
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   725
		AiFindRandomIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   726
		if (IsInsideMM(fr.distance, 60, 90 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   727
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   728
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   729
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   730
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   731
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   732
	if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   733
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   734
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   735
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   736
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   737
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   738
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   739
	_players_ai[p->index].src.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   740
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   741
	_players_ai[p->index].src.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   742
	_players_ai[p->index].src.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   743
	_players_ai[p->index].src.buildcmd_a = 0x24;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   744
	_players_ai[p->index].src.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   745
	_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles(
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   746
		_players_ai[p->index].src.spec_tile,
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   747
		_players_ai[p->index].dst.spec_tile
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   748
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   749
	_players_ai[p->index].src.cargo = fr.cargo | 0x80;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   750
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   751
	// Fill the dest field
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   752
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   753
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   754
	_players_ai[p->index].dst.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   755
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   756
	_players_ai[p->index].dst.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   757
	_players_ai[p->index].dst.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   758
	_players_ai[p->index].dst.buildcmd_a = 0x34;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   759
	_players_ai[p->index].dst.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   760
	_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles(
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   761
		_players_ai[p->index].dst.spec_tile,
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   762
		_players_ai[p->index].src.spec_tile
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   763
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   764
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   765
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   766
	// Fill middle field 1
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   767
	_players_ai[p->index].mid1.spec_tile = AiGetPctTileBetween(
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   768
		_players_ai[p->index].src.spec_tile,
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   769
		_players_ai[p->index].dst.spec_tile,
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   770
		0x55
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   771
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   772
	_players_ai[p->index].mid1.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   773
	_players_ai[p->index].mid1.rand_rng = 6;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   774
	_players_ai[p->index].mid1.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   775
	_players_ai[p->index].mid1.unk6 = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   776
	_players_ai[p->index].mid1.unk7 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   777
	_players_ai[p->index].mid1.buildcmd_a = 0x30;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   778
	_players_ai[p->index].mid1.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   779
	_players_ai[p->index].mid1.direction = _players_ai[p->index].src.direction;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   780
	_players_ai[p->index].mid1.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   781
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   782
	// Fill middle field 2
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   783
	_players_ai[p->index].mid2.spec_tile = AiGetPctTileBetween(
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   784
		_players_ai[p->index].src.spec_tile,
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   785
		_players_ai[p->index].dst.spec_tile,
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   786
		0xAA
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   787
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   788
	_players_ai[p->index].mid2.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   789
	_players_ai[p->index].mid2.rand_rng = 6;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   790
	_players_ai[p->index].mid2.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   791
	_players_ai[p->index].mid2.unk6 = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   792
	_players_ai[p->index].mid2.unk7 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   793
	_players_ai[p->index].mid2.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   794
	_players_ai[p->index].mid2.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   795
	_players_ai[p->index].mid2.direction = _players_ai[p->index].dst.direction;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   796
	_players_ai[p->index].mid2.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   797
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   798
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   799
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   800
	_players_ai[p->index].num_wagons = 3;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   801
	_players_ai[p->index].build_kind = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   802
	_players_ai[p->index].num_build_rec = 4;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   803
	_players_ai[p->index].num_loco_to_build = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   804
	_players_ai[p->index].num_want_fullload = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   805
	_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   806
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   807
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   808
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   809
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   810
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   811
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   812
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   813
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   814
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   815
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   816
static void AiWantMediumIndustryRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   817
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   818
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   819
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   820
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   821
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   822
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   823
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   824
		AiFindSubsidyIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   825
		if (IsInsideMM(fr.distance, 40, 60 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   826
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   827
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   828
		AiFindRandomIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   829
		if (IsInsideMM(fr.distance, 40, 60 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   830
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   831
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   832
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   833
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   834
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   835
	if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   836
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   837
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   838
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   839
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   840
	_players_ai[p->index].src.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   841
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   842
	_players_ai[p->index].src.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   843
	_players_ai[p->index].src.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   844
	_players_ai[p->index].src.buildcmd_a = 0x10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   845
	_players_ai[p->index].src.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   846
	_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   847
		GET_TOWN_OR_INDUSTRY_TILE(fr.from),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   848
		GET_TOWN_OR_INDUSTRY_TILE(fr.to)
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   849
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   850
	_players_ai[p->index].src.cargo = fr.cargo | 0x80;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   851
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   852
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   853
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   854
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   855
	_players_ai[p->index].dst.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   856
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   857
	_players_ai[p->index].dst.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   858
	_players_ai[p->index].dst.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   859
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   860
	_players_ai[p->index].dst.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   861
	_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   862
		GET_TOWN_OR_INDUSTRY_TILE(fr.to),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   863
		GET_TOWN_OR_INDUSTRY_TILE(fr.from)
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   864
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   865
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   866
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   867
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   868
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   869
	_players_ai[p->index].num_wagons = 3;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   870
	_players_ai[p->index].build_kind = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   871
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   872
	_players_ai[p->index].num_loco_to_build = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   873
	_players_ai[p->index].num_want_fullload = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   874
	_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   875
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   876
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   877
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   878
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   879
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   880
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   881
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   882
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   883
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   884
static void AiWantShortIndustryRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   885
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   886
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   887
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   888
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   889
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   890
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   891
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   892
		AiFindSubsidyIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   893
		if (IsInsideMM(fr.distance, 15, 40 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   894
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   895
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   896
		AiFindRandomIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   897
		if (IsInsideMM(fr.distance, 15, 40 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   898
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   899
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   900
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   901
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   902
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   903
	if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   904
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   905
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   906
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   907
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   908
	_players_ai[p->index].src.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   909
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   910
	_players_ai[p->index].src.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   911
	_players_ai[p->index].src.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   912
	_players_ai[p->index].src.buildcmd_a = 0x10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   913
	_players_ai[p->index].src.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   914
	_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   915
		GET_TOWN_OR_INDUSTRY_TILE(fr.from),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   916
		GET_TOWN_OR_INDUSTRY_TILE(fr.to)
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   917
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   918
	_players_ai[p->index].src.cargo = fr.cargo | 0x80;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   919
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   920
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   921
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   922
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   923
	_players_ai[p->index].dst.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   924
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   925
	_players_ai[p->index].dst.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   926
	_players_ai[p->index].dst.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   927
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   928
	_players_ai[p->index].dst.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   929
	_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   930
		GET_TOWN_OR_INDUSTRY_TILE(fr.to),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   931
		GET_TOWN_OR_INDUSTRY_TILE(fr.from)
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   932
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   933
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   934
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   935
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   936
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   937
	_players_ai[p->index].num_wagons = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   938
	_players_ai[p->index].build_kind = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   939
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   940
	_players_ai[p->index].num_loco_to_build = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   941
	_players_ai[p->index].num_want_fullload = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   942
	_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   943
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   944
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   945
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   946
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   947
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   948
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   949
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   950
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   951
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   952
static void AiWantMailRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   953
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   954
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   955
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   956
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   957
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
   958
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   959
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   960
		AiFindSubsidyPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   961
		if (IsInsideMM(fr.distance, 60, 110 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   962
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   963
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   964
		AiFindRandomPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
   965
		if (IsInsideMM(fr.distance, 60, 110 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   966
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   967
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   968
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   969
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   970
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   971
	fr.cargo = CT_MAIL;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   972
	if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   973
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   974
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   975
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   976
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   977
	_players_ai[p->index].src.rand_rng = 7;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   978
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   979
	_players_ai[p->index].src.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   980
	_players_ai[p->index].src.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   981
	_players_ai[p->index].src.buildcmd_a = 0x24;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   982
	_players_ai[p->index].src.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   983
	_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   984
		GET_TOWN_OR_INDUSTRY_TILE(fr.from),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   985
		GET_TOWN_OR_INDUSTRY_TILE(fr.to)
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   986
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   987
	_players_ai[p->index].src.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   988
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
   989
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   990
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   991
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   992
	_players_ai[p->index].dst.rand_rng = 7;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   993
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   994
	_players_ai[p->index].dst.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   995
	_players_ai[p->index].dst.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   996
	_players_ai[p->index].dst.buildcmd_a = 0x34;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   997
	_players_ai[p->index].dst.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
   998
	_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
   999
		GET_TOWN_OR_INDUSTRY_TILE(fr.to),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1000
		GET_TOWN_OR_INDUSTRY_TILE(fr.from)
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1001
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1002
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1003
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1004
	// Fill middle field 1
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1005
	_players_ai[p->index].mid1.spec_tile = AiGetPctTileBetween(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1006
		GET_TOWN_OR_INDUSTRY_TILE(fr.from),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1007
		GET_TOWN_OR_INDUSTRY_TILE(fr.to),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1008
		0x55
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1009
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1010
	_players_ai[p->index].mid1.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1011
	_players_ai[p->index].mid1.rand_rng = 6;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1012
	_players_ai[p->index].mid1.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1013
	_players_ai[p->index].mid1.unk6 = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1014
	_players_ai[p->index].mid1.unk7 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1015
	_players_ai[p->index].mid1.buildcmd_a = 0x30;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1016
	_players_ai[p->index].mid1.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1017
	_players_ai[p->index].mid1.direction = _players_ai[p->index].src.direction;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1018
	_players_ai[p->index].mid1.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1019
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1020
	// Fill middle field 2
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1021
	_players_ai[p->index].mid2.spec_tile = AiGetPctTileBetween(
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1022
		GET_TOWN_OR_INDUSTRY_TILE(fr.from),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1023
		GET_TOWN_OR_INDUSTRY_TILE(fr.to),
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1024
		0xAA
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1025
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1026
	_players_ai[p->index].mid2.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1027
	_players_ai[p->index].mid2.rand_rng = 6;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1028
	_players_ai[p->index].mid2.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1029
	_players_ai[p->index].mid2.unk6 = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1030
	_players_ai[p->index].mid2.unk7 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1031
	_players_ai[p->index].mid2.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1032
	_players_ai[p->index].mid2.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1033
	_players_ai[p->index].mid2.direction = _players_ai[p->index].dst.direction;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1034
	_players_ai[p->index].mid2.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1035
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1036
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1037
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1038
	_players_ai[p->index].num_wagons = 3;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1039
	_players_ai[p->index].build_kind = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1040
	_players_ai[p->index].num_build_rec = 4;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1041
	_players_ai[p->index].num_loco_to_build = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1042
	_players_ai[p->index].num_want_fullload = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1043
	_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1044
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1045
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1046
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1047
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1048
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1049
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1050
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1051
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1052
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1053
static void AiWantPassengerRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1054
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1055
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1056
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1057
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1058
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1059
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1060
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1061
		AiFindSubsidyPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1062
		if (IsInsideMM(fr.distance, 0, 55 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1063
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1064
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1065
		AiFindRandomPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1066
		if (IsInsideMM(fr.distance, 0, 55 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1067
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1068
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1069
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1070
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1071
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1072
	fr.cargo = CT_PASSENGERS;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1073
	if (!AiCheckIfRouteIsGood(p, &fr, 1)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1074
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1075
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1076
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1077
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1078
	_players_ai[p->index].src.rand_rng = 7;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1079
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1080
	_players_ai[p->index].src.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1081
	_players_ai[p->index].src.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1082
	_players_ai[p->index].src.buildcmd_a = 0x10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1083
	_players_ai[p->index].src.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1084
	_players_ai[p->index].src.direction = AiGetDirectionBetweenTiles(
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1085
		GET_TOWN_OR_INDUSTRY_TILE(fr.from),
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1086
		GET_TOWN_OR_INDUSTRY_TILE(fr.to)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1087
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1088
	_players_ai[p->index].src.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1089
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1090
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1091
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1092
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1093
	_players_ai[p->index].dst.rand_rng = 7;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1094
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1095
	_players_ai[p->index].dst.unk6 = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1096
	_players_ai[p->index].dst.unk7 = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1097
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1098
	_players_ai[p->index].dst.buildcmd_b = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1099
	_players_ai[p->index].dst.direction = AiGetDirectionBetweenTiles(
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1100
		GET_TOWN_OR_INDUSTRY_TILE(fr.to),
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1101
		GET_TOWN_OR_INDUSTRY_TILE(fr.from)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1102
	);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1103
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1104
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1105
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1106
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1107
	_players_ai[p->index].num_wagons = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1108
	_players_ai[p->index].build_kind = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1109
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1110
	_players_ai[p->index].num_loco_to_build = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1111
	_players_ai[p->index].num_want_fullload = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1112
	_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1113
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1114
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1115
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1116
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1117
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1118
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1119
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1120
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1121
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1122
static void AiWantTrainRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1123
{
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
  1124
	uint16 r = GB(Random(), 0, 16);
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
  1125
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
  1126
	_players_ai[p->index].railtype_to_use = GetBestRailtype(p->index);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1127
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1128
	if (r > 0xD000) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1129
		AiWantLongIndustryRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1130
	} else if (r > 0x6000) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1131
		AiWantMediumIndustryRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1132
	} else if (r > 0x1000) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1133
		AiWantShortIndustryRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1134
	} else if (r > 0x800) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1135
		AiWantPassengerRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1136
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1137
		AiWantMailRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1138
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1139
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1140
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1141
static void AiWantLongRoadIndustryRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1142
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1143
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1144
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1145
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1146
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1147
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1148
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1149
		AiFindSubsidyIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1150
		if (IsInsideMM(fr.distance, 35, 55 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1151
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1152
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1153
		AiFindRandomIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1154
		if (IsInsideMM(fr.distance, 35, 55 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1155
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1156
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1157
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1158
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1159
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1160
	if (!AiCheckIfRouteIsGood(p, &fr, 2)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1161
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1162
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1163
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1164
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1165
	_players_ai[p->index].src.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1166
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1167
	_players_ai[p->index].src.buildcmd_a = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1168
	_players_ai[p->index].src.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1169
	_players_ai[p->index].src.cargo = fr.cargo | 0x80;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1170
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1171
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1172
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1173
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1174
	_players_ai[p->index].dst.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1175
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1176
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1177
	_players_ai[p->index].dst.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1178
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1179
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1180
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1181
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1182
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1183
	_players_ai[p->index].num_loco_to_build = 5;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1184
	_players_ai[p->index].num_want_fullload = 5;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1185
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1186
//	_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1187
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1188
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1189
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1190
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1191
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1192
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1193
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1194
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1195
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1196
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1197
static void AiWantMediumRoadIndustryRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1198
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1199
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1200
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1201
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1202
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1203
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1204
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1205
		AiFindSubsidyIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1206
		if (IsInsideMM(fr.distance, 15, 40 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1207
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1208
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1209
		AiFindRandomIndustryRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1210
		if (IsInsideMM(fr.distance, 15, 40 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1211
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1212
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1213
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1214
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1215
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1216
	if (!AiCheckIfRouteIsGood(p, &fr, 2)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1217
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1218
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1219
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1220
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1221
	_players_ai[p->index].src.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1222
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1223
	_players_ai[p->index].src.buildcmd_a = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1224
	_players_ai[p->index].src.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1225
	_players_ai[p->index].src.cargo = fr.cargo | 0x80;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1226
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1227
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1228
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1229
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1230
	_players_ai[p->index].dst.rand_rng = 9;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1231
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1232
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1233
	_players_ai[p->index].dst.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1234
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1235
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1236
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1237
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1238
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1239
	_players_ai[p->index].num_loco_to_build = 3;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1240
	_players_ai[p->index].num_want_fullload = 3;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1241
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1242
//	_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1243
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1244
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1245
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1246
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1247
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1248
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1249
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1250
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1251
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1252
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1253
static void AiWantLongRoadPassengerRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1254
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1255
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1256
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1257
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1258
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1259
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1260
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1261
		AiFindSubsidyPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1262
		if (IsInsideMM(fr.distance, 55, 180 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1263
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1264
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1265
		AiFindRandomPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1266
		if (IsInsideMM(fr.distance, 55, 180 + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1267
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1268
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1269
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1270
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1271
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1272
	fr.cargo = CT_PASSENGERS;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1273
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1274
	if (!AiCheckIfRouteIsGood(p, &fr, 2)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1275
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1276
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1277
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1278
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1279
	_players_ai[p->index].src.rand_rng = 10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1280
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1281
	_players_ai[p->index].src.buildcmd_a = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1282
	_players_ai[p->index].src.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1283
	_players_ai[p->index].src.cargo = CT_PASSENGERS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1284
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1285
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1286
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1287
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1288
	_players_ai[p->index].dst.rand_rng = 10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1289
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1290
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1291
	_players_ai[p->index].dst.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1292
	_players_ai[p->index].dst.cargo = CT_PASSENGERS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1293
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1294
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1295
	_players_ai[p->index].cargo_type = CT_PASSENGERS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1296
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1297
	_players_ai[p->index].num_loco_to_build = 4;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1298
	_players_ai[p->index].num_want_fullload = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1299
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1300
//	_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1301
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1302
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1303
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1304
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1305
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1306
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1307
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1308
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1309
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1310
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1311
static void AiWantPassengerRouteInsideTown(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1312
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1313
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1314
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1315
	Town *t;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1316
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1317
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1318
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1319
		// Find a town big enough
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1320
		t = AiFindRandomTown();
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1321
		if (t != NULL && t->population >= 700) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1322
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1323
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1324
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1325
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1326
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1327
	fr.cargo = CT_PASSENGERS;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1328
	fr.from = fr.to = t;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1329
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1330
	if (!AiCheckIfRouteIsGood(p, &fr, 2)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1331
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1332
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1333
	_players_ai[p->index].src.spec_tile = t->xy;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1334
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1335
	_players_ai[p->index].src.rand_rng = 10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1336
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1337
	_players_ai[p->index].src.buildcmd_a = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1338
	_players_ai[p->index].src.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1339
	_players_ai[p->index].src.cargo = CT_PASSENGERS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1340
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1341
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1342
	_players_ai[p->index].dst.spec_tile = t->xy;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1343
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1344
	_players_ai[p->index].dst.rand_rng = 10;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1345
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1346
	_players_ai[p->index].dst.buildcmd_a = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1347
	_players_ai[p->index].dst.direction = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1348
	_players_ai[p->index].dst.cargo = CT_PASSENGERS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1349
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1350
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1351
	_players_ai[p->index].cargo_type = CT_PASSENGERS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1352
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1353
	_players_ai[p->index].num_loco_to_build = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1354
	_players_ai[p->index].num_want_fullload = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1355
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1356
//	_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1357
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1358
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1359
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1360
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1361
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1362
	_players_ai[p->index].state_mode = UCHAR_MAX;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1363
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1364
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1365
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1366
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1367
static void AiWantRoadRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1368
{
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
  1369
	uint16 r = GB(Random(), 0, 16);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1370
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1371
	if (r > 0x4000) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1372
		AiWantLongRoadIndustryRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1373
	} else if (r > 0x2000) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1374
		AiWantMediumRoadIndustryRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1375
	} else if (r > 0x1000) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1376
		AiWantLongRoadPassengerRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1377
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1378
		AiWantPassengerRouteInsideTown(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1379
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1380
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1382
static void AiWantPassengerAircraftRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1383
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1384
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1385
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1386
6858
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1387
	/* Get aircraft that would be bought for this route
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1388
	 * (probably, as conditions may change before the route is fully built,
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1389
	 * like running out of money and having to select different aircraft, etc ...) */
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  1390
	EngineID veh = AiChooseAircraftToBuild(p->player_money, _players_ai[p->index].build_kind != 0 ? AIR_CTOL : 0);
6858
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1391
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1392
	/* No aircraft buildable mean no aircraft route */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1393
	if (veh == INVALID_ENGINE) return;
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1394
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1395
	const AircraftVehicleInfo *avi = AircraftVehInfo(veh);
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1396
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1397
	/* For passengers, "optimal" number of days in transit is about 80 to 100
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1398
	 * Calculate "maximum optimal number of squares" from speed for 80 days
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1399
	 * 20 days should be enough for takeoff, land, taxi, etc ...
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1400
	 *
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1401
	 * "A vehicle traveling at 100kph will cross 5.6 tiles per day" ->
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1402
	 * Since in table aircraft speeds are in "real km/h", this should be accurate
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1403
	 * We get max_squares = avi->max_speed * 5.6 / 100.0 * 80 */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1404
	int max_squares = avi->max_speed * 448 / 100;
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1405
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1406
	/* For example this will be 10456 tiles for 2334 km/h aircrafts with realistic aircraft speeds
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1407
	 * and 836 with "unrealistic" speeds, much more than the original 95 squares limit
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1408
	 *
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1409
	 * Size of the map, if not rectangular, it is the larger dimension of it
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1410
	 */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1411
	int map_size = max(MapSizeX(), MapSizeY());
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1412
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1413
	/* Minimum distance between airports is half of map size, clamped between 1% and 20% of optimum.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1414
	 * May prevent building plane routes at all on small maps, but they will be ineffective there, so
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1415
	 * it is feature, not a bug.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1416
	 * On smaller distances, buses or trains are usually more effective approach anyway.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1417
	 * Additional safeguard is needing at least 20 squares,
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1418
	 * which may trigger in highly unusual configurations */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1419
	int min_squares = max(20, max(max_squares / 100, min(max_squares / 5, map_size / 2)));
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1420
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1421
	/* Should not happen, unless aircraft with real speed under approx. 5 km/h is selected.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1422
	 * No such exist, unless using some NewGRF with ballons, zeppelins or similar
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1423
	 * slow-moving stuff. In that case, bail out, it is faster to walk by foot anyway :). */
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1424
	if (max_squares < min_squares) return;
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1425
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1426
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1427
	for (;;) {
6858
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1428
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1429
		// look for one from the subsidy list
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1430
		AiFindSubsidyPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1431
		if (IsInsideMM(fr.distance, min_squares, max_squares + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1432
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1433
		// try a random one
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1434
		AiFindRandomPassengerRoute(&fr);
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7931
diff changeset
  1435
		if (IsInsideMM(fr.distance, min_squares, max_squares + 1)) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1436
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1437
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1438
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1439
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1440
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1441
	fr.cargo = CT_PASSENGERS;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1442
	if (!AiCheckIfRouteIsGood(p, &fr, 4)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1443
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1444
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1445
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1446
	_players_ai[p->index].src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1447
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1448
	_players_ai[p->index].src.rand_rng = 12;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1449
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1450
	_players_ai[p->index].src.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1451
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1452
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1453
	_players_ai[p->index].dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1454
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1455
	_players_ai[p->index].dst.rand_rng = 12;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1456
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1457
	_players_ai[p->index].dst.cargo = fr.cargo;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1458
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1459
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1460
	_players_ai[p->index].cargo_type = fr.cargo;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1461
	_players_ai[p->index].build_kind = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1462
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1463
	_players_ai[p->index].num_loco_to_build = 1;
6858
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1464
	/* Using full load always may not be the best.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1465
	 * Pick random value and rely on selling the vehicle & route
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1466
	 * afterwards if the choice was utterly wrong (or maybe altering the value if AI is improved)
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1467
	 * When traffic is very low or very assymetric, is is better not to full load
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1468
	 * When traffic is high, full/non-full make no difference
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1469
	 * It should be better to run with aircraft only one way full 6 times per year,
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1470
	 * rather than two way full 1 times.
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1471
	 * Practical experiments with AI show that the non-full-load aircrafts are usually
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1472
	 * those that survive
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1473
	 * Also, non-full load is more resistant against starving (by building better stations
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1474
	 * or using exclusive rights)
36b50a8fe66b (svn r10098) -Codechange: bilbo cared about the performance of the AI with respect to the airport placement, so he rewrote the aircraft handling of the AI; now it can actually make lots of money again :)
rubidium
parents: 6842
diff changeset
  1475
	 */
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1476
	_players_ai[p->index].num_want_fullload = Chance16(1, 5); // 20% chance
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1477
//	_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1478
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1479
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1480
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1481
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1482
	_players_ai[p->index].state = AIS_AIRPORT_STUFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1483
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1484
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1485
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1486
static void AiWantOilRigAircraftRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1487
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1488
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1489
	FoundRoute fr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1490
	Town *t;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1491
	Industry *in;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1492
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1493
	i = 60;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1494
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1495
		// Find a town
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1496
		t = AiFindRandomTown();
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1497
		if (t != NULL) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1498
			// Find a random oil rig industry
4342
fbbc2390c895 (svn r6043) -Codechange: use wrapper if they are available
truelight
parents: 4322
diff changeset
  1499
			in = AiFindRandomIndustry();
6400
bc0ee88fb279 (svn r9530) -Codechange: Replace a direct industry type access by a behaviour
belugas
parents: 6357
diff changeset
  1500
			if (in != NULL && GetIndustrySpec(in->type)->behaviour & INDUSTRYBEH_AI_AIRSHIP_ROUTES) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1501
				if (DistanceManhattan(t->xy, in->xy) < 60)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1502
					break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1503
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1504
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1505
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1506
		// only test 60 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1507
		if (--i == 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1508
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1509
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1510
	fr.cargo = CT_PASSENGERS;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1511
	fr.from = fr.to = t;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1512
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1513
	if (!AiCheckIfRouteIsGood(p, &fr, 4)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1514
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1515
	// Fill the source field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1516
	_players_ai[p->index].src.spec_tile = t->xy;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1517
	_players_ai[p->index].src.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1518
	_players_ai[p->index].src.rand_rng = 12;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1519
	_players_ai[p->index].src.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1520
	_players_ai[p->index].src.cargo = CT_PASSENGERS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1521
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1522
	// Fill the dest field
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1523
	_players_ai[p->index].dst.spec_tile = in->xy;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1524
	_players_ai[p->index].dst.use_tile = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1525
	_players_ai[p->index].dst.rand_rng = 5;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1526
	_players_ai[p->index].dst.cur_building_rule = 0xFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1527
	_players_ai[p->index].dst.cargo = CT_PASSENGERS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1528
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1529
	// Fill common fields
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1530
	_players_ai[p->index].cargo_type = CT_PASSENGERS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1531
	_players_ai[p->index].build_kind = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1532
	_players_ai[p->index].num_build_rec = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1533
	_players_ai[p->index].num_loco_to_build = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1534
	_players_ai[p->index].num_want_fullload = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1535
//	_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1536
	_players_ai[p->index].order_list_blocks[0] = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1537
	_players_ai[p->index].order_list_blocks[1] = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1538
	_players_ai[p->index].order_list_blocks[2] = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1539
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1540
	_players_ai[p->index].state = AIS_AIRPORT_STUFF;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1541
	_players_ai[p->index].timeout_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1542
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1543
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1544
static void AiWantAircraftRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1545
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1546
	uint16 r = (uint16)Random();
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1547
4322
f40bbdf476b3 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4261
diff changeset
  1548
	if (r >= 0x2AAA || _date < 0x3912 + DAYS_TILL_ORIGINAL_BASE_YEAR) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1549
		AiWantPassengerAircraftRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1550
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1551
		AiWantOilRigAircraftRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1552
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1553
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1554
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1555
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1556
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1557
static void AiStateWantNewRoute(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1558
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1559
	uint16 r;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1560
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1561
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1562
	if (p->player_money < AiGetBasePrice(p) * 500) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1563
		_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1564
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1565
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1566
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1567
	i = 200;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1568
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1569
		r = (uint16)Random();
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1570
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1571
		if (_patches.ai_disable_veh_train &&
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1572
				_patches.ai_disable_veh_roadveh &&
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1573
				_patches.ai_disable_veh_aircraft &&
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1574
				_patches.ai_disable_veh_ship) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1575
			return;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1576
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1577
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1578
		if (r < 0x7626) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1579
			if (_patches.ai_disable_veh_train) continue;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1580
			AiWantTrainRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1581
		} else if (r < 0xC4EA) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1582
			if (_patches.ai_disable_veh_roadveh) continue;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1583
			AiWantRoadRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1584
		} else if (r < 0xD89B) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1585
			if (_patches.ai_disable_veh_aircraft) continue;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1586
			AiWantAircraftRoute(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1587
		} else {
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
  1588
			/* Ships are not implemented in this (broken) AI */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1589
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1590
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1591
		// got a route?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1592
		if (_players_ai[p->index].state != AIS_WANT_NEW_ROUTE) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1593
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1594
		// time out?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1595
		if (--i == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1596
			if (++_players_ai[p->index].state_counter == 556) _players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1597
			break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1598
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1599
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1600
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1601
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1602
static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1603
{
8573
a0a5f36a982e (svn r12154) -Codechange: removed a magic number
glx
parents: 8563
diff changeset
  1604
	uint rad = (_patches.modified_catchment) ? CA_TRAIN : CA_UNMODIFIED;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1605
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1606
	for (; p->mode != 4; p++) {
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1607
		AcceptedCargo values;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1608
		TileIndex tile2;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1609
		uint w;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1610
		uint h;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1611
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1612
		if (p->mode != 1) continue;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1613
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1614
		tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1615
		w = GB(p->attr, 1, 3);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1616
		h = GB(p->attr, 4, 3);
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1617
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6041
diff changeset
  1618
		if (p->attr & 1) Swap(w, h);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1619
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1620
		if (cargo & 0x80) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1621
			GetProductionAroundTiles(values, tile2, w, h, rad);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1622
			return values[cargo & 0x7F] != 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1623
		} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1624
			GetAcceptanceAroundTiles(values, tile2, w, h, rad);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1625
			if (!(values[cargo] & ~7))
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1626
				return false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1627
			if (cargo != CT_MAIL)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1628
				return true;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  1629
			return !!((values[cargo] >> 1) & ~7);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1630
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1631
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1632
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1633
	return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1634
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1635
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  1636
static CommandCost AiDoBuildDefaultRailTrack(TileIndex tile, const AiDefaultBlockData* p, RailType railtype, byte flag)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1637
{
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  1638
	CommandCost ret;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8229
diff changeset
  1639
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1640
	Town *t = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1641
	int rating = 0;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  1642
	int i, j, k;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1643
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  1644
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1645
		// This will seldomly overflow for valid reasons. Mask it to be on the safe side.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1646
		uint c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1647
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1648
		_cleared_town = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1649
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1650
		if (p->mode < 2) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1651
			if (p->mode == 0) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1652
				// Depot
3965
13c75ab166d0 (svn r5128) Remove the global variable _cur_ai_player
tron
parents: 3964
diff changeset
  1653
				ret = DoCommand(c, railtype, p->attr, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_TRAIN_DEPOT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1654
			} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1655
				// Station
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  1656
				ret = DoCommand(c, (p->attr & 1) | (p->attr >> 4) << 8 | (p->attr >> 1 & 7) << 16, railtype, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_RAILROAD_STATION);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1657
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1658
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1659
			if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1660
			total_cost.AddCost(ret);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1661
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1662
clear_town_stuff:;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1663
			if (_cleared_town != NULL) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1664
				if (t != NULL && t != _cleared_town)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1665
					return CMD_ERROR;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1666
				t = _cleared_town;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1667
				rating += _cleared_town_rating;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1668
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1669
		} else if (p->mode == 2) {
8006
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1670
			/* Rail */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1671
			if (IsTileType(c, MP_RAILWAY)) return CMD_ERROR;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1672
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1673
			j = p->attr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1674
			k = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1675
8006
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1676
			/* Build the rail
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1677
			 * note: FOR_EACH_SET_BIT cannot be used here
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1678
			 */
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1679
			for (i = 0; i != 6; i++, j >>= 1) {
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1680
				if (j & 1) {
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1681
					k = i;
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1682
					ret = DoCommand(c, railtype, i, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL);
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1683
					if (CmdFailed(ret)) return CMD_ERROR;
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1684
					total_cost.AddCost(ret);
d56d68c938b5 (svn r11565) -Revert: part of r11564
smatz
parents: 8005
diff changeset
  1685
				}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1686
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1687
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1688
			/* signals too? */
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1689
			if (j & 3) {
5387
843c3d90823e (svn r7575) -Codechange: Allow the AI to build signals under bridges (revert r4911)
celestar
parents: 5385
diff changeset
  1690
				// Can't build signals on a road.
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7317
diff changeset
  1691
				if (IsTileType(c, MP_ROAD)) return CMD_ERROR;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1692
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1693
				if (flag & DC_EXEC) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1694
					j = 4 - j;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1695
					do {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  1696
						ret = DoCommand(c, k, 0, flag, CMD_BUILD_SIGNALS);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1697
					} while (--j);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1698
				} else {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1699
					ret.AddCost(_price.build_signals);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1700
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1701
				if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1702
				total_cost.AddCost(ret);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1703
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1704
		} else if (p->mode == 3) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1705
			//Clear stuff and then build single rail.
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  1706
			if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  1707
			ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1708
			if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1709
			total_cost.AddCost(ret);
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1710
			total_cost.AddCost(_price.build_rail);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1711
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1712
			if (flag & DC_EXEC) {
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  1713
				DoCommand(c, railtype, p->attr & 1, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_SINGLE_RAIL);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1714
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1715
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1716
			goto clear_town_stuff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1717
		} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1718
			// Unk
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1719
			break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1720
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1721
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1722
		p++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1723
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1724
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1725
	if (!(flag & DC_EXEC)) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1726
		if (t != NULL && rating > t->ratings[_current_player]) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1727
			return CMD_ERROR;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1728
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1729
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1730
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1731
	return total_cost;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1732
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1733
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1734
// Returns rule and cost
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  1735
static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, byte p3, byte dir, byte cargo, RailType railtype, CommandCost* cost)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1736
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1737
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1738
	const AiDefaultRailBlock *p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1739
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1740
	for (i = 0; (p = _default_rail_track_data[i]) != NULL; i++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1741
		if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1742
				(p->dir == 0xFF || p->dir == dir || ((p->dir - 1) & 3) == dir)) {
3965
13c75ab166d0 (svn r5128) Remove the global variable _cur_ai_player
tron
parents: 3964
diff changeset
  1743
			*cost = AiDoBuildDefaultRailTrack(tile, p->data, railtype, DC_NO_TOWN_RATING);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  1744
			if (CmdSucceeded(*cost) && AiCheckTrackResources(tile, p->data, cargo))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1745
				return i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1746
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1747
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1748
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1749
	return -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1750
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1751
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1752
static const byte _terraform_up_flags[] = {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1753
	14, 13, 12, 11,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1754
	10,  9,  8,  7,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1755
	 6,  5,  4,  3,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1756
	 2,  1,  0,  1,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1757
	 2,  1,  4,  1,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1758
	 2,  1,  8,  1,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1759
	 2,  1,  4,  2,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1760
	 2,  1
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1761
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1762
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1763
static const byte _terraform_down_flags[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1764
	1,  2, 3,  4,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1765
	5,  6, 1,  8,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1766
	9, 10, 8, 12,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1767
	4,  2, 0,  0,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1768
	1,  2, 3,  4,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1769
	5,  6, 2,  8,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1770
	9, 10, 1, 12,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1771
	8,  4
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1772
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1773
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1774
static void AiDoTerraformLand(TileIndex tile, DiagDirection dir, int unk, int mode)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1775
{
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
  1776
	PlayerID old_player;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1777
	uint32 r;
3644
7c9a6a91873b (svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents: 3609
diff changeset
  1778
	Slope slope;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1779
	uint h;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1780
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1781
	old_player = _current_player;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1782
	_current_player = OWNER_NONE;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1783
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1784
	r = Random();
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1785
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1786
	unk &= (int)r;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1787
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1788
	do {
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  1789
		tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1790
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1791
		r >>= 2;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1792
		if (r & 2) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1793
			dir = ChangeDiagDir(dir, (r & 1) ? DIAGDIRDIFF_90LEFT : DIAGDIRDIFF_90RIGHT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1794
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1795
	} while (--unk >= 0);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1796
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1797
	slope = GetTileSlope(tile, &h);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1798
3644
7c9a6a91873b (svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents: 3609
diff changeset
  1799
	if (slope != SLOPE_FLAT) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1800
		if (mode > 0 || (mode == 0 && !(r & 0xC))) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1801
			// Terraform up
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  1802
			DoCommand(tile, _terraform_up_flags[slope - 1], 1,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1803
				DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1804
		} else if (h != 0) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1805
			// Terraform down
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  1806
			DoCommand(tile, _terraform_down_flags[slope - 1], 0,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1807
				DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1808
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1809
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1810
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1811
	_current_player = old_player;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1812
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1813
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1814
static void AiStateBuildDefaultRailBlocks(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1815
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1816
	uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1817
	int j;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1818
	AiBuildRec *aib;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1819
	int rule;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  1820
	CommandCost cost;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1821
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1822
	// time out?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1823
	if (++_players_ai[p->index].timeout_counter == 1388) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1824
		_players_ai[p->index].state = AIS_DELETE_RAIL_BLOCKS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1825
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1826
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1827
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1828
	// do the following 8 times
2648
677ba48b2549 (svn r3190) Turn some loops into canonical for loop form
tron
parents: 2643
diff changeset
  1829
	for (i = 0; i < 8; i++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1830
		// check if we can build the default track
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1831
		aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1832
		j = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1833
		do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1834
			// this item has already been built?
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1835
			if (aib->cur_building_rule != 255) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1836
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1837
			// adjust the coordinate randomly,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1838
			// to make sure that we find a position.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1839
			aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1840
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1841
			// check if the track can be build there.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1842
			rule = AiBuildDefaultRailTrack(aib->use_tile,
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1843
				_players_ai[p->index].build_kind, _players_ai[p->index].num_wagons,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1844
				aib->unk6, aib->unk7,
3965
13c75ab166d0 (svn r5128) Remove the global variable _cur_ai_player
tron
parents: 3964
diff changeset
  1845
				aib->direction, aib->cargo,
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1846
				_players_ai[p->index].railtype_to_use,
3965
13c75ab166d0 (svn r5128) Remove the global variable _cur_ai_player
tron
parents: 3964
diff changeset
  1847
				&cost
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  1848
			);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1849
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1850
			if (rule == -1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1851
				// cannot build, terraform after a while
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1852
				if (_players_ai[p->index].state_counter >= 600) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1853
					AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)_players_ai[p->index].state_mode);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1854
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1855
				// also try the other terraform direction
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1856
				if (++_players_ai[p->index].state_counter >= 1000) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1857
					_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1858
					_players_ai[p->index].state_mode = -_players_ai[p->index].state_mode;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1859
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1860
			} else if (CheckPlayerHasMoney(cost)) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1861
				// player has money, build it.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1862
				aib->cur_building_rule = rule;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1863
6602
4f62a8312298 (svn r9817) -Fix [FS#772]: an assertion that was triggered by the AI building when its rating for the town was not high enough.
rubidium
parents: 6491
diff changeset
  1864
				AiDoBuildDefaultRailTrack(
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1865
					aib->use_tile,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1866
					_default_rail_track_data[rule]->data,
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1867
					_players_ai[p->index].railtype_to_use,
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1868
					DC_EXEC | DC_NO_TOWN_RATING
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1869
				);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1870
			}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  1871
		} while (++aib, --j);
2648
677ba48b2549 (svn r3190) Turn some loops into canonical for loop form
tron
parents: 2643
diff changeset
  1872
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1873
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1874
	// check if we're done with all of them
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1875
	aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1876
	j = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1877
	do {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1878
		if (aib->cur_building_rule == 255) return;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  1879
	} while (++aib, --j);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1880
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1881
	// yep, all are done. switch state to the rail building state.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1882
	_players_ai[p->index].state = AIS_BUILD_RAIL;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1883
	_players_ai[p->index].state_mode = 255;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1884
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1885
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1886
static TileIndex AiGetEdgeOfDefaultRailBlock(byte rule, TileIndex tile, byte cmd, DiagDirection *dir)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1887
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1888
	const AiDefaultBlockData *p = _default_rail_track_data[rule]->data;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1889
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1890
	while (p->mode != 3 || !((--cmd) & 0x80)) p++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1891
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  1892
	return tile + ToTileIndexDiff(p->tileoffs) - TileOffsByDiagDir(*dir = p->attr);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1893
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1894
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1895
struct AiRailPathFindData {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1896
	TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1897
	TileIndex tile2;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1898
	int count;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1899
	bool flag;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1900
};
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1901
8611
9037a4227d67 (svn r12193) -Codechange: Rename a magic variable, give it a decent type, and remove a 'goto'.
frosch
parents: 8602
diff changeset
  1902
static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1903
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1904
	if (a->flag) return true;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1905
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1906
	if (length > 20 || tile == a->tile) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1907
		a->flag = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1908
		return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1909
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1910
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1911
	if (DistanceMax(tile, a->tile2) < 4) a->count++;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1912
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1913
	return false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1914
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1915
2643
f1fec6d1559a (svn r3185) const
tron
parents: 2639
diff changeset
  1916
static bool AiDoFollowTrack(const Player* p)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1917
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1918
	AiRailPathFindData arpfd;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1919
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1920
	arpfd.tile = _players_ai[p->index].start_tile_a;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1921
	arpfd.tile2 = _players_ai[p->index].cur_tile_a;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1922
	arpfd.flag = false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1923
	arpfd.count = 0;
8800
c30102fee110 (svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents: 8795
diff changeset
  1924
	FollowTrack(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a), PATHFIND_FLAGS_NONE, TRANSPORT_RAIL, 0, ReverseDiagDir(_players_ai[p->index].cur_dir_a),
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1925
		(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1926
	return arpfd.count > 8;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1927
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1928
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1929
struct AiRailFinder {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1930
	TileIndex final_tile;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1931
	DiagDirection final_dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1932
	byte depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1933
	byte recursive_mode;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1934
	DiagDirection cur_best_dir;
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1935
	DiagDirection best_dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1936
	byte cur_best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1937
	byte best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1938
	uint cur_best_dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1939
	const byte *best_ptr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1940
	uint best_dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1941
	TileIndex cur_best_tile, best_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1942
	TileIndex bridge_end_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1943
	Player *player;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  1944
};
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1945
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1946
static const byte _ai_table_15[4][8] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1947
	{0, 0, 4, 3, 3, 1, 128 + 0, 64},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1948
	{1, 1, 2, 0, 4, 2, 128 + 1, 65},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1949
	{0, 2, 2, 3, 5, 1, 128 + 2, 66},
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4342
diff changeset
  1950
	{1, 3, 5, 0, 3, 2, 128 + 3, 67}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1951
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1952
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1953
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2551
diff changeset
  1954
static bool AiIsTileBanned(const Player* p, TileIndex tile, byte val)
7206058a7e82 (svn r3172) static, const
tron
parents: 2551
diff changeset
  1955
{
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1956
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1957
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1958
	for (i = 0; i != _players_ai[p->index].banned_tile_count; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1959
		if (_players_ai[p->index].banned_tiles[i] == tile && _players_ai[p->index].banned_val[i] == val) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1960
			return true;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1961
		}
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1962
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1963
	return false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1964
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1965
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1966
static void AiBanTile(Player* p, TileIndex tile, byte val)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1967
{
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  1968
	uint i;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1969
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1970
	for (i = lengthof(_players_ai[p->index].banned_tiles) - 1; i != 0; i--) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1971
		_players_ai[p->index].banned_tiles[i] = _players_ai[p->index].banned_tiles[i - 1];
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1972
		_players_ai[p->index].banned_val[i] = _players_ai[p->index].banned_val[i - 1];
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1973
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1974
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1975
	_players_ai[p->index].banned_tiles[0] = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1976
	_players_ai[p->index].banned_val[0] = val;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1977
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1978
	if (_players_ai[p->index].banned_tile_count != lengthof(_players_ai[p->index].banned_tiles)) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  1979
		_players_ai[p->index].banned_tile_count++;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  1980
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1981
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1982
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  1983
static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, DiagDirection dir);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1984
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1985
static bool AiCheckRailPathBetter(AiRailFinder *arf, const byte *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1986
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1987
	bool better = false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1988
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1989
	if (arf->recursive_mode < 1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1990
		// Mode is 0. This means destination has not been found yet.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1991
		// If the found path is shorter than the current one, remember it.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1992
		if (arf->cur_best_dist < arf->best_dist) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1993
			arf->best_dir = arf->cur_best_dir;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1994
			arf->best_dist = arf->cur_best_dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1995
			arf->best_ptr = p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1996
			arf->best_tile = arf->cur_best_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1997
			better = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1998
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  1999
	} else if (arf->recursive_mode > 1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2000
		// Mode is 2.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2001
		if (arf->best_dist != 0 || arf->cur_best_depth < arf->best_depth) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2002
			arf->best_depth = arf->cur_best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2003
			arf->best_dist = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2004
			arf->best_ptr = p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2005
			arf->best_tile = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2006
			better = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2007
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2008
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2009
	arf->recursive_mode = 0;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2010
	arf->cur_best_dist = UINT_MAX;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2011
	arf->cur_best_depth = 0xff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2012
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2013
	return better;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2014
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2015
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2016
static inline void AiCheckBuildRailBridgeHere(AiRailFinder *arf, TileIndex tile, const byte *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2017
{
3644
7c9a6a91873b (svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents: 3609
diff changeset
  2018
	Slope tileh;
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2019
	uint z;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2020
	bool flag;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2021
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2022
	DiagDirection dir2 = (DiagDirection)(p[0] & 3);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2023
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2024
	tileh = GetTileSlope(tile, &z);
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2025
	if (tileh == InclinedSlope(ReverseDiagDir(dir2)) || (tileh == SLOPE_FLAT && z != 0)) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2026
		TileIndex tile_new = tile;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2027
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2028
		// Allow bridges directly over bottom tiles
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2029
		flag = z == 0;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  2030
		for (;;) {
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2031
			TileType type;
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2032
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  2033
			if ((TileIndexDiff)tile_new < -TileOffsByDiagDir(dir2)) return; // Wraping around map, no bridge possible!
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  2034
			tile_new = TILE_MASK(tile_new + TileOffsByDiagDir(dir2));
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2035
			type = GetTileType(tile_new);
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2036
3644
7c9a6a91873b (svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents: 3609
diff changeset
  2037
			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2038
				if (!flag) return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2039
				break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2040
			}
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7317
diff changeset
  2041
			if (type != MP_WATER && type != MP_RAILWAY && type != MP_ROAD) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2042
			flag = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2043
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2044
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2045
		// Is building a (rail)bridge possible at this place (type doesn't matter)?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2046
		if (CmdFailed(DoCommand(tile_new, tile, 0 | _players_ai[arf->player->index].railtype_to_use << 8, DC_AUTO, CMD_BUILD_BRIDGE))) {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2047
			return;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2048
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2049
		AiBuildRailRecursive(arf, tile_new, dir2);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2050
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2051
		// At the bottom depth, check if the new path is better than the old one.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2052
		if (arf->depth == 1) {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2053
			if (AiCheckRailPathBetter(arf, p)) arf->bridge_end_tile = tile_new;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2054
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2055
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2056
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2057
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2058
static inline void AiCheckBuildRailTunnelHere(AiRailFinder *arf, TileIndex tile, const byte *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2059
{
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2060
	uint z;
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2061
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2062
	if (GetTileSlope(tile, &z) == InclinedSlope((DiagDirection)(p[0] & 3)) && z != 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2063
		CommandCost cost = DoCommand(tile, _players_ai[arf->player->index].railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2064
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2065
		if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2066
			AiBuildRailRecursive(arf, _build_tunnel_endtile, (DiagDirection)(p[0] & 3));
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2067
			if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2068
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2069
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2070
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2071
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2072
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2073
static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, DiagDirection dir)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2074
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2075
	const byte *p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2076
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  2077
	tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2078
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2079
	// Reached destination?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2080
	if (tile == arf->final_tile) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2081
		if (arf->final_dir != ReverseDiagDir(dir)) {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2082
			if (arf->recursive_mode != 2) arf->recursive_mode = 1;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2083
		} else if (arf->recursive_mode != 2) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2084
			arf->recursive_mode = 2;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2085
			arf->cur_best_depth = arf->depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2086
		} else {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2087
			if (arf->depth < arf->cur_best_depth) arf->cur_best_depth = arf->depth;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2088
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2089
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2090
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2091
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2092
	// Depth too deep?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2093
	if (arf->depth >= 4) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2094
		uint dist = DistanceMaxPlusManhattan(tile, arf->final_tile);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2095
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2096
		if (dist < arf->cur_best_dist) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2097
			// Store the tile that is closest to the final position.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2098
			arf->cur_best_depth = arf->depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2099
			arf->cur_best_dist = dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2100
			arf->cur_best_tile = tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2101
			arf->cur_best_dir = dir;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2102
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2103
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2104
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2105
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2106
	// Increase recursion depth
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2107
	arf->depth++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2108
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2109
	// Grab pointer to list of stuff that is possible to build
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2110
	p = _ai_table_15[dir];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2111
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2112
	// Try to build a single rail in all directions.
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2113
	if (GetTileZ(tile) == 0) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2114
		p += 6;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2115
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2116
		do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2117
			// Make sure the tile is not in the list of banned tiles and that a rail can be built here.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2118
			if (!AiIsTileBanned(arf->player, tile, p[0]) &&
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2119
					CmdSucceeded(DoCommand(tile, _players_ai[arf->player->index].railtype_to_use, p[0], DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL))) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2120
				AiBuildRailRecursive(arf, tile, (DiagDirection)p[1]);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2121
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2122
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2123
			// At the bottom depth?
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2124
			if (arf->depth == 1) AiCheckRailPathBetter(arf, p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2125
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2126
			p += 2;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2127
		} while (!(p[0] & 0x80));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2128
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2129
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2130
	AiCheckBuildRailBridgeHere(arf, tile, p);
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2131
	AiCheckBuildRailTunnelHere(arf, tile, p + 1);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2132
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2133
	arf->depth--;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2134
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2135
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2136
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2137
static void AiBuildRailConstruct(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2138
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2139
	AiRailFinder arf;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2140
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2141
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2142
	// Check too much lookahead?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2143
	if (AiDoFollowTrack(p)) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2144
		_players_ai[p->index].state_counter = (Random()&0xE)+6; // Destruct this amount of blocks
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2145
		_players_ai[p->index].state_mode = 1; // Start destruct
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2146
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2147
		// Ban this tile and don't reach it for a while.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2148
		AiBanTile(p, _players_ai[p->index].cur_tile_a, FindFirstBit(GetRailTrackStatus(_players_ai[p->index].cur_tile_a)));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2149
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2150
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2151
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2152
	// Setup recursive finder and call it.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2153
	arf.player = p;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2154
	arf.final_tile = _players_ai[p->index].cur_tile_b;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2155
	arf.final_dir = _players_ai[p->index].cur_dir_b;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2156
	arf.depth = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2157
	arf.recursive_mode = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2158
	arf.best_ptr = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2159
	arf.cur_best_dist = (uint)-1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2160
	arf.cur_best_depth = 0xff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2161
	arf.best_dist = (uint)-1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2162
	arf.best_depth = 0xff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2163
	arf.cur_best_tile = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2164
	arf.best_tile = 0;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2165
	AiBuildRailRecursive(&arf, _players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2166
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2167
	// Reached destination?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2168
	if (arf.recursive_mode == 2 && arf.cur_best_depth == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2169
		_players_ai[p->index].state_mode = 255;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2170
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2171
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2172
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2173
	// Didn't find anything to build?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2174
	if (arf.best_ptr == NULL) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2175
		// Terraform some
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2176
		for (i = 0; i != 5; i++) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2177
			AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2178
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2179
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2180
		if (++_players_ai[p->index].state_counter == 21) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2181
			_players_ai[p->index].state_counter = 40;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2182
			_players_ai[p->index].state_mode = 1;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2183
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2184
			// Ban this tile
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2185
			AiBanTile(p, _players_ai[p->index].cur_tile_a, FindFirstBit(GetRailTrackStatus(_players_ai[p->index].cur_tile_a)));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2186
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2187
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2188
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2189
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2190
	_players_ai[p->index].cur_tile_a += TileOffsByDiagDir(_players_ai[p->index].cur_dir_a);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2191
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2192
	if (arf.best_ptr[0] & 0x80) {
8617
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2193
		TileIndex t1 = _players_ai[p->index].cur_tile_a;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2194
		TileIndex t2 = arf.bridge_end_tile;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2195
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2196
		int32 bridge_len = GetTunnelBridgeLength(t1, t2);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2197
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2198
		DiagDirection dir = (TileX(t1) == TileX(t2) ? DIAGDIR_SE : DIAGDIR_SW);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2199
		Track track = AxisToTrack(DiagDirToAxis(dir));
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2200
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2201
		if (t2 < t1) dir = ReverseDiagDir(dir);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2202
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2203
		/* try to build a long rail instead of bridge... */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2204
		bool fail = false;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2205
		CommandCost cost;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2206
		TileIndex t = t1;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2207
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2208
		/* try to build one rail on each tile - can't use CMD_BUILD_RAILROAD_TRACK now, it can build one part of track without failing */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2209
		do {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2210
			cost = DoCommand(t, _players_ai[p->index].railtype_to_use, track, DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2211
			/* do not allow building over existing track */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2212
			if (CmdFailed(cost) || IsTileType(t, MP_RAILWAY)) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2213
				fail = true;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2214
				break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2215
			}
8617
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2216
			t += TileOffsByDiagDir(dir);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2217
		} while (t != t2);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2218
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2219
		/* can we build long track? */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2220
		if (!fail) cost = DoCommand(t1, t2, _players_ai[p->index].railtype_to_use | (track << 4), DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_TRACK);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2221
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2222
		if (!fail && CmdSucceeded(cost) && cost.GetCost() <= p->player_money) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2223
			DoCommand(t1, t2, _players_ai[p->index].railtype_to_use | (track << 4), DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_BUILD_RAILROAD_TRACK);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2224
		} else {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2225
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2226
			/* Figure out which (rail)bridge type to build
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2227
			 * start with best bridge, then go down to worse and worse bridges
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2228
			 * unnecessary to check for worst bridge (i=0), since AI will always build that. */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2229
			int i;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2230
			for (i = MAX_BRIDGES - 1; i != 0; i--) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2231
				if (CheckBridge_Stuff(i, bridge_len)) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2232
					CommandCost cost = DoCommand(t1, t2, i | (_players_ai[p->index].railtype_to_use << 8), DC_AUTO, CMD_BUILD_BRIDGE);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2233
					if (CmdSucceeded(cost) && cost.GetCost() < (p->player_money >> 1) && cost.GetCost() < ((p->player_money + _economy.max_loan - p->current_loan) >> 5)) break;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2234
				}
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2235
			}
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2236
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2237
			/* Build it */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2238
			DoCommand(t1, t2, i | (_players_ai[p->index].railtype_to_use << 8), DC_AUTO | DC_EXEC, CMD_BUILD_BRIDGE);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2239
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2240
8617
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  2241
		_players_ai[p->index].cur_tile_a = t2;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2242
		_players_ai[p->index].state_counter = 0;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2243
	} else if (arf.best_ptr[0] & 0x40) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2244
		// tunnel
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2245
		DoCommand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].railtype_to_use, 0, DC_AUTO | DC_EXEC, CMD_BUILD_TUNNEL);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2246
		_players_ai[p->index].cur_tile_a = _build_tunnel_endtile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2247
		_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2248
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2249
		// rail
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2250
		_players_ai[p->index].cur_dir_a = (DiagDirection)(arf.best_ptr[1] & 3);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2251
		DoCommand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].railtype_to_use, arf.best_ptr[0],
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2252
			DC_EXEC | DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2253
		_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2254
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2255
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2256
	if (arf.best_tile != 0) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2257
		for (i = 0; i != 2; i++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2258
			AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2259
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2260
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2261
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2262
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2263
static bool AiRemoveTileAndGoForward(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2264
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2265
	const byte *ptr;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2266
	TileIndex tile = _players_ai[p->index].cur_tile_a;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2267
	TileIndex tilenew;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2268
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2269
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3179
diff changeset
  2270
		if (IsTunnel(tile)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2271
			// Clear the tunnel and continue at the other side of it.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2272
			if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2273
				return false;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2274
			_players_ai[p->index].cur_tile_a = TILE_MASK(_build_tunnel_endtile - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2275
			return true;
8390
f88f515e6557 (svn r11960) -Cleanup: simplify some IsTunnel(Tile) / IsBridge(Tile) conditions
smatz
parents: 8389
diff changeset
  2276
		} else { // IsBridge(tile)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2277
			// Check if the bridge points in the right direction.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2278
			// This is not really needed the first place AiRemoveTileAndGoForward is called.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2279
			if (DiagDirToAxis(GetTunnelBridgeDirection(tile)) != (_players_ai[p->index].cur_dir_a & 1)) return false;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2280
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents: 3196
diff changeset
  2281
			tile = GetOtherBridgeEnd(tile);
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents: 3196
diff changeset
  2282
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2283
			tilenew = TILE_MASK(tile - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2284
			// And clear the bridge.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2285
			if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR)))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2286
				return false;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2287
			_players_ai[p->index].cur_tile_a = tilenew;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2288
			return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2289
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2290
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2291
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2292
	// Find the railtype at the position. Quit if no rail there.
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2293
	TrackBits bits = GetRailTrackStatus(tile) & DiagdirReachesTracks(ReverseDiagDir(_players_ai[p->index].cur_dir_a));
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2294
	if (bits == TRACK_BIT_NONE) return false;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2295
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2296
	// Convert into a bit position that CMD_REMOVE_SINGLE_RAIL expects.
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2297
	Track track = FindFirstTrack(bits);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2298
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2299
	// Then remove and signals if there are any.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2300
	if (IsTileType(tile, MP_RAILWAY) &&
3792
67c865c9315c (svn r4788) - Codechange: RAILTYPE_{NORMAL,ELECTRIC,...} and RAIL_TYPE_{NORMAL,SIGNAL,...} have nearly the same name, rename RAIL_TYPE_* to RAIL_TILE_* of extra clarity
rubidium
parents: 3644
diff changeset
  2301
			GetRailTileType(tile) == RAIL_TILE_SIGNALS) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2302
		DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_SIGNALS);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2303
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2304
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2305
	// And also remove the rail.
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2306
	if (CmdFailed(DoCommand(tile, 0, track, DC_EXEC, CMD_REMOVE_SINGLE_RAIL)))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2307
		return false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2308
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2309
	// Find the direction at the other edge of the rail.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2310
	ptr = _ai_table_15[ReverseDiagDir(_players_ai[p->index].cur_dir_a)];
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2311
	while (ptr[0] != track) ptr += 2;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2312
	_players_ai[p->index].cur_dir_a = ReverseDiagDir((DiagDirection)ptr[1]);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2313
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2314
	// And then also switch tile.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2315
	_players_ai[p->index].cur_tile_a = TILE_MASK(_players_ai[p->index].cur_tile_a - TileOffsByDiagDir(_players_ai[p->index].cur_dir_a));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2316
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2317
	return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2318
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2319
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2320
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2321
static void AiBuildRailDestruct(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2322
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2323
	// Decrease timeout.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2324
	if (!--_players_ai[p->index].state_counter) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2325
		_players_ai[p->index].state_mode = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2326
		_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2327
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2328
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2329
	// Don't do anything if the destination is already reached.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2330
	if (_players_ai[p->index].cur_tile_a == _players_ai[p->index].start_tile_a) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2331
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2332
	AiRemoveTileAndGoForward(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2333
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2334
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2335
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2336
static void AiBuildRail(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2337
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2338
	switch (_players_ai[p->index].state_mode) {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2339
		case 0: // Construct mode, build new rail.
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2340
			AiBuildRailConstruct(p);
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2341
			break;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2342
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2343
		case 1: // Destruct mode, destroy the rail currently built.
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2344
			AiBuildRailDestruct(p);
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2345
			break;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2346
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2347
		case 2: {
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2348
			uint i;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2349
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2350
			// Terraform some and then try building again.
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2351
			for (i = 0; i != 4; i++) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2352
				AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0);
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2353
			}
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2354
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2355
			if (++_players_ai[p->index].state_counter == 4) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2356
				_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2357
				_players_ai[p->index].state_mode = 0;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2358
			}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2359
		}
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2360
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2361
		default: break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2362
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2363
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2364
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2365
static void AiStateBuildRail(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2366
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2367
	int num;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2368
	AiBuildRec *aib;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2369
	byte cmd;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2370
	TileIndex tile;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2371
	DiagDirection dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2372
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2373
	// time out?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2374
	if (++_players_ai[p->index].timeout_counter == 1388) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2375
		_players_ai[p->index].state = AIS_DELETE_RAIL_BLOCKS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2376
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2377
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2378
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2379
	// Currently building a rail between two points?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2380
	if (_players_ai[p->index].state_mode != 255) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2381
		AiBuildRail(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2382
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2383
		// Alternate between edges
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2384
		Swap(_players_ai[p->index].start_tile_a, _players_ai[p->index].start_tile_b);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2385
		Swap(_players_ai[p->index].cur_tile_a,   _players_ai[p->index].cur_tile_b);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2386
		Swap(_players_ai[p->index].start_dir_a,  _players_ai[p->index].start_dir_b);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2387
		Swap(_players_ai[p->index].cur_dir_a,    _players_ai[p->index].cur_dir_b);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2388
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2389
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2390
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2391
	// Now, find two new points to build between
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2392
	num = _players_ai[p->index].num_build_rec;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2393
	aib = &_players_ai[p->index].src;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2394
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  2395
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2396
		cmd = aib->buildcmd_a;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2397
		aib->buildcmd_a = 255;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2398
		if (cmd != 255) break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2399
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2400
		cmd = aib->buildcmd_b;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2401
		aib->buildcmd_b = 255;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2402
		if (cmd != 255) break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2403
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2404
		aib++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2405
		if (--num == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2406
			_players_ai[p->index].state = AIS_BUILD_RAIL_VEH;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2407
			_players_ai[p->index].state_counter = 0; // timeout
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2408
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2409
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2410
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2411
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2412
	// Find first edge to build from.
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2413
	tile = AiGetEdgeOfDefaultRailBlock(aib->cur_building_rule, aib->use_tile, cmd & 3, &dir);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2414
	_players_ai[p->index].start_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2415
	_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2416
	_players_ai[p->index].start_dir_a = dir;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2417
	_players_ai[p->index].cur_dir_a = dir;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2418
	DoCommand(TILE_MASK(tile + TileOffsByDiagDir(dir)), 0, (dir & 1) ? 1 : 0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2419
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2420
	assert(TILE_MASK(tile) != 0xFF00);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2421
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2422
	// Find second edge to build to
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2423
	aib = (&_players_ai[p->index].src) + ((cmd >> 4) & 0xF);
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2424
	tile = AiGetEdgeOfDefaultRailBlock(aib->cur_building_rule, aib->use_tile, (cmd >> 2) & 3, &dir);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2425
	_players_ai[p->index].start_tile_b = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2426
	_players_ai[p->index].cur_tile_b = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2427
	_players_ai[p->index].start_dir_b = dir;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2428
	_players_ai[p->index].cur_dir_b = dir;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2429
	DoCommand(TILE_MASK(tile + TileOffsByDiagDir(dir)), 0, (dir & 1) ? 1 : 0, DC_EXEC, CMD_REMOVE_SINGLE_RAIL);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2430
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2431
	assert(TILE_MASK(tile) != 0xFF00);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2432
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2433
	// And setup state.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2434
	_players_ai[p->index].state_mode = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2435
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2436
	_players_ai[p->index].banned_tile_count = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2437
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2438
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
  2439
static StationID AiGetStationIdByDef(TileIndex tile, int id)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2440
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2441
	const AiDefaultBlockData *p = _default_rail_track_data[id]->data;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2442
	while (p->mode != 1) p++;
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
  2443
	return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2444
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2445
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2446
static EngineID AiFindBestWagon(CargoID cargo, RailType railtype)
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2447
{
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2448
	EngineID best_veh_index = INVALID_ENGINE;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2449
	EngineID i;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2450
	uint16 best_capacity = 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2451
	uint16 best_speed    = 0;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2452
	uint speed;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2453
8755
c7afa0b1df35 (svn r12451) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8617
diff changeset
  2454
	FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_TRAIN) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2455
		const RailVehicleInfo *rvi = RailVehInfo(i);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2456
		const Engine* e = GetEngine(i);
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2457
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5733
diff changeset
  2458
		if (!IsCompatibleRail(rvi->railtype, railtype) ||
5868
94430141c189 (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 5854
diff changeset
  2459
				rvi->railveh_type != RAILVEH_WAGON ||
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7653
diff changeset
  2460
				!HasBit(e->player_avail, _current_player)) {
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2461
			continue;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2462
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2463
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2464
		if (rvi->cargo_type != cargo) continue;
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2465
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2466
		/* max_speed of 0 indicates no speed limit */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2467
		speed = rvi->max_speed == 0 ? 0xFFFF : rvi->max_speed;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2468
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2469
		if (rvi->capacity >= best_capacity && speed >= best_speed) {
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2470
			best_capacity = rvi->capacity;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2471
			best_speed    = best_speed;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2472
			best_veh_index = i;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2473
		}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2474
	}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2475
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2476
	return best_veh_index;
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2477
}
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2478
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2479
static void AiStateBuildRailVeh(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2480
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2481
	const AiDefaultBlockData *ptr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2482
	TileIndex tile;
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
  2483
	EngineID veh;
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
  2484
	int i;
3348
0d0442be01d4 (svn r4132) - Missed 3 CargoID's
Darkvater
parents: 3344
diff changeset
  2485
	CargoID cargo;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2486
	CommandCost cost;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2487
	Vehicle *v;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2488
	VehicleID loco_id;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2489
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2490
	ptr = _default_rail_track_data[_players_ai[p->index].src.cur_building_rule]->data;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2491
	while (ptr->mode != 0) ptr++;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2492
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2493
	tile = TILE_ADD(_players_ai[p->index].src.use_tile, ToTileIndexDiff(ptr->tileoffs));
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2494
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2495
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2496
	cargo = _players_ai[p->index].cargo_type;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2497
	for (i = 0;;) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2498
		if (_players_ai[p->index].wagon_list[i] == INVALID_VEHICLE) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2499
			veh = AiFindBestWagon(cargo, _players_ai[p->index].railtype_to_use);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2500
			/* veh will return INVALID_ENGINE if no suitable wagon is available.
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2501
			 * We shall treat this in the same way as having no money */
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3348
diff changeset
  2502
			if (veh == INVALID_ENGINE) goto handle_nocash;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2503
			cost = DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2504
			if (CmdFailed(cost)) goto handle_nocash;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2505
			_players_ai[p->index].wagon_list[i] = _new_vehicle_id;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2506
			_players_ai[p->index].wagon_list[i + 1] = INVALID_VEHICLE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2507
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2508
		}
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2509
		if (cargo == CT_MAIL) cargo = CT_PASSENGERS;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2510
		if (++i == _players_ai[p->index].num_wagons * 2 - 1) break;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2511
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2512
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2513
	// Which locomotive to build?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2514
	veh = AiChooseTrainToBuild(_players_ai[p->index].railtype_to_use, p->player_money, cargo != CT_PASSENGERS ? 1 : 0, tile);
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
  2515
	if (veh == INVALID_ENGINE) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2516
handle_nocash:
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2517
		// after a while, if AI still doesn't have cash, get out of this block by selling the wagons.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2518
		if (++_players_ai[p->index].state_counter == 1000) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2519
			for (i = 0; _players_ai[p->index].wagon_list[i] != INVALID_VEHICLE; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2520
				cost = DoCommand(tile, _players_ai[p->index].wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  2521
				assert(CmdSucceeded(cost));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2522
			}
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2523
			_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2524
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2525
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2526
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2527
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2528
	// Try to build the locomotive
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2529
	cost = DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  2530
	assert(CmdSucceeded(cost));
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3933
diff changeset
  2531
	loco_id = _new_vehicle_id;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2532
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2533
	// Sell a vehicle if the train is double headed.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2534
	v = GetVehicle(loco_id);
7492
35acee076719 (svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents: 7490
diff changeset
  2535
	if (v->Next() != NULL) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2536
		i = _players_ai[p->index].wagon_list[_players_ai[p->index].num_wagons * 2 - 2];
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2537
		_players_ai[p->index].wagon_list[_players_ai[p->index].num_wagons * 2 - 2] = INVALID_VEHICLE;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2538
		DoCommand(tile, i, 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2539
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2540
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2541
	// Move the wagons onto the train
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2542
	for (i = 0; _players_ai[p->index].wagon_list[i] != INVALID_VEHICLE; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2543
		DoCommand(tile, _players_ai[p->index].wagon_list[i] | (loco_id << 16), 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2544
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2545
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2546
	for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2547
		const AiBuildRec* aib = &_players_ai[p->index].src + _players_ai[p->index].order_list_blocks[i];
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2548
		bool is_pass = (
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2549
			_players_ai[p->index].cargo_type == CT_PASSENGERS ||
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2550
			_players_ai[p->index].cargo_type == CT_MAIL ||
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2551
			(_opt.landscape == LT_TEMPERATE && _players_ai[p->index].cargo_type == CT_VALUABLES)
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2552
		);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2553
		Order order;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2554
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  2555
		order.MakeGoToStation(AiGetStationIdByDef(aib->use_tile, aib->cur_building_rule));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2556
8855
6d841d5d4789 (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents: 8843
diff changeset
  2557
		if (!is_pass && i == 1) order.SetUnloadType(OUFB_UNLOAD);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2558
		if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0))
8855
6d841d5d4789 (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents: 8843
diff changeset
  2559
			order.SetLoadType(OLFB_FULL_LOAD);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2560
8839
6337281b393b (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents: 8836
diff changeset
  2561
		DoCommand(0, loco_id + (i << 16), order.Pack(), DC_EXEC, CMD_INSERT_ORDER);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2562
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2563
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2564
	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_TRAIN);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2565
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2566
	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2567
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2568
	if (_players_ai[p->index].num_want_fullload != 0) _players_ai[p->index].num_want_fullload--;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2569
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2570
	if (--_players_ai[p->index].num_loco_to_build != 0) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2571
//		_players_ai[p->index].loco_id = INVALID_VEHICLE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2572
		_players_ai[p->index].wagon_list[0] = INVALID_VEHICLE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2573
	} else {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2574
		_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2575
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2576
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2577
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2578
static void AiStateDeleteRailBlocks(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2579
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2580
	const AiBuildRec* aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2581
	uint num = _players_ai[p->index].num_build_rec;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2582
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2583
	do {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2584
		const AiDefaultBlockData* b;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2585
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2586
		if (aib->cur_building_rule == 255) continue;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2587
		for (b = _default_rail_track_data[aib->cur_building_rule]->data; b->mode != 4; b++) {
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2588
			DoCommand(TILE_ADD(aib->use_tile, ToTileIndexDiff(b->tileoffs)), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2589
		}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2590
	} while (++aib, --num);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2591
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2592
	_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2593
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2594
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2595
static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2596
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2597
	uint values[NUM_CARGO];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2598
	int rad;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2599
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2600
	if (_patches.modified_catchment) {
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4389
diff changeset
  2601
		rad = CA_TRUCK; // Same as CA_BUS at the moment?
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4389
diff changeset
  2602
	} else { // change that at some point?
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2603
		rad = 4;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2604
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2605
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2606
	for (;; p++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2607
		if (p->mode == 4) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2608
			return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2609
		} else if (p->mode == 1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2610
			TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2611
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2612
			if (cargo & 0x80) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2613
				GetProductionAroundTiles(values, tile2, 1, 1, rad);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2614
				return values[cargo & 0x7F] != 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2615
			} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2616
				GetAcceptanceAroundTiles(values, tile2, 1, 1, rad);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2617
				return (values[cargo]&~7) != 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2618
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2619
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2620
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2621
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2622
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2623
static bool _want_road_truck_station;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2624
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2625
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2626
// Returns rule and cost
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2627
static int AiFindBestDefaultRoadBlock(TileIndex tile, byte direction, byte cargo, CommandCost *cost)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2628
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2629
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2630
	const AiDefaultRoadBlock *p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2631
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2632
	_want_road_truck_station = (cargo & 0x7F) != CT_PASSENGERS;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2633
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2634
	for (i = 0; (p = _road_default_block_data[i]) != NULL; i++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2635
		if (p->dir == direction) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2636
			*cost = AiDoBuildDefaultRoadBlock(tile, p->data, 0);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  2637
			if (CmdSucceeded(*cost) && AiCheckRoadResources(tile, p->data, cargo))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2638
				return i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2639
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2640
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2641
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2642
	return -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2643
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2644
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2645
static CommandCost AiDoBuildDefaultRoadBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2646
{
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2647
	CommandCost ret;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8229
diff changeset
  2648
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2649
	Town *t = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2650
	int rating = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2651
	int roadflag = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2652
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  2653
	for (;p->mode != 4;p++) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2654
		TileIndex c = TILE_MASK(tile + ToTileIndexDiff(p->tileoffs));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2655
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2656
		_cleared_town = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2657
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2658
		if (p->mode == 2) {
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8556
diff changeset
  2659
			if (IsNormalRoadTile(c) &&
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6636
diff changeset
  2660
					(GetRoadBits(c, ROADTYPE_ROAD) & p->attr) != 0) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2661
				roadflag |= 2;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2662
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2663
				// all bits are already built?
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6636
diff changeset
  2664
				if ((GetRoadBits(c, ROADTYPE_ROAD) & p->attr) == p->attr) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2665
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2666
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2667
			ret = DoCommand(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2668
			if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2669
			total_cost.AddCost(ret);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2670
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2671
			continue;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2672
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2673
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2674
		if (p->mode == 0) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2675
			// Depot
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2676
			ret = DoCommand(c, p->attr, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_DEPOT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2677
			goto clear_town_stuff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2678
		} else if (p->mode == 1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2679
			if (_want_road_truck_station) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2680
				// Truck station
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8784
diff changeset
  2681
				ret = DoCommand(c, p->attr, ROADTYPES_ROAD << 2 | ROADSTOP_TRUCK, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2682
			} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2683
				// Bus station
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8784
diff changeset
  2684
				ret = DoCommand(c, p->attr, ROADTYPES_ROAD << 2 | ROADSTOP_BUS, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_BUILD_ROAD_STOP);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2685
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2686
clear_town_stuff:;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2687
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2688
			if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2689
			total_cost.AddCost(ret);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2690
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2691
			if (_cleared_town != NULL) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2692
				if (t != NULL && t != _cleared_town) return CMD_ERROR;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2693
				t = _cleared_town;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2694
				rating += _cleared_town_rating;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2695
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2696
		} else if (p->mode == 3) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2697
			if (flag & DC_EXEC) continue;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2698
3644
7c9a6a91873b (svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents: 3609
diff changeset
  2699
			if (GetTileSlope(c, NULL) != SLOPE_FLAT) return CMD_ERROR;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2700
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8556
diff changeset
  2701
			if (!IsNormalRoadTile(c)) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  2702
				ret = DoCommand(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2703
				if (CmdFailed(ret)) return CMD_ERROR;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2704
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2705
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2706
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2707
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2708
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2709
	if (!_want_road_truck_station && !(roadflag & 2)) return CMD_ERROR;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2710
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2711
	if (!(flag & DC_EXEC)) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2712
		if (t != NULL && rating > t->ratings[_current_player]) return CMD_ERROR;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2713
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2714
	return total_cost;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2715
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2716
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2717
// Make sure the blocks are not too close to each other
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2718
static bool AiCheckBlockDistances(Player *p, TileIndex tile)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2719
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2720
	const AiBuildRec* aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2721
	uint num = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2722
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2723
	do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2724
		if (aib->cur_building_rule != 255) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2725
			if (DistanceManhattan(aib->use_tile, tile) < 9) return false;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2726
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2727
	} while (++aib, --num);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2728
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2729
	return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2730
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2731
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2732
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2733
static void AiStateBuildDefaultRoadBlocks(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2734
{
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2735
	uint i;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2736
	int j;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2737
	AiBuildRec *aib;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2738
	int rule;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2739
	CommandCost cost;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2740
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2741
	// time out?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2742
	if (++_players_ai[p->index].timeout_counter == 1388) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2743
		_players_ai[p->index].state = AIS_DELETE_RAIL_BLOCKS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2744
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2745
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2746
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2747
	// do the following 8 times
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2748
	for (i = 0; i != 8; i++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2749
		// check if we can build the default track
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2750
		aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2751
		j = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2752
		do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2753
			// this item has already been built?
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2754
			if (aib->cur_building_rule != 255) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2755
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2756
			// adjust the coordinate randomly,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2757
			// to make sure that we find a position.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2758
			aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2759
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2760
			// check if the road can be built there.
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2761
			rule = AiFindBestDefaultRoadBlock(
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2762
				aib->use_tile, aib->direction, aib->cargo, &cost
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2763
			);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2764
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2765
			if (rule == -1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2766
				// cannot build, terraform after a while
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2767
				if (_players_ai[p->index].state_counter >= 600) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2768
					AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)_players_ai[p->index].state_mode);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2769
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2770
				// also try the other terraform direction
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2771
				if (++_players_ai[p->index].state_counter >= 1000) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2772
					_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2773
					_players_ai[p->index].state_mode = -_players_ai[p->index].state_mode;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2774
				}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2775
			} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2776
				CommandCost r;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2777
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2778
				// player has money, build it.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2779
				aib->cur_building_rule = rule;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2780
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2781
				r = AiDoBuildDefaultRoadBlock(
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2782
					aib->use_tile,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2783
					_road_default_block_data[rule]->data,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2784
					DC_EXEC | DC_NO_TOWN_RATING
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2785
				);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  2786
				assert(CmdSucceeded(r));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2787
			}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2788
		} while (++aib, --j);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2789
	}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2790
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2791
	// check if we're done with all of them
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2792
	aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2793
	j = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2794
	do {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2795
		if (aib->cur_building_rule == 255) return;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  2796
	} while (++aib, --j);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2797
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2798
	// yep, all are done. switch state to the rail building state.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2799
	_players_ai[p->index].state = AIS_BUILD_ROAD;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2800
	_players_ai[p->index].state_mode = 255;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2801
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2802
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2803
struct AiRoadFinder {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2804
	TileIndex final_tile;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2805
	DiagDirection final_dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2806
	byte depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2807
	byte recursive_mode;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2808
	DiagDirection cur_best_dir;
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2809
	DiagDirection best_dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2810
	byte cur_best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2811
	byte best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2812
	uint cur_best_dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2813
	const byte *best_ptr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2814
	uint best_dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2815
	TileIndex cur_best_tile, best_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2816
	TileIndex bridge_end_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2817
	Player *player;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2818
};
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2819
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2820
struct AiRoadEnum {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2821
	TileIndex dest;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2822
	TileIndex best_tile;
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2823
	Trackdir best_track;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2824
	uint best_dist;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2825
};
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2826
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2827
static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, DiagDirection dir);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2828
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2829
static bool AiCheckRoadPathBetter(AiRoadFinder *arf, const byte *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2830
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2831
	bool better = false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2832
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2833
	if (arf->recursive_mode < 1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2834
		// Mode is 0. This means destination has not been found yet.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2835
		// If the found path is shorter than the current one, remember it.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2836
		if (arf->cur_best_dist < arf->best_dist ||
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2837
			(arf->cur_best_dist == arf->best_dist && arf->cur_best_depth < arf->best_depth)) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2838
			arf->best_depth = arf->cur_best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2839
			arf->best_dist = arf->cur_best_dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2840
			arf->best_dir = arf->cur_best_dir;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2841
			arf->best_ptr = p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2842
			arf->best_tile = arf->cur_best_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2843
			better = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2844
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2845
	} else if (arf->recursive_mode > 1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2846
		// Mode is 2.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2847
		if (arf->best_dist != 0 || arf->cur_best_depth < arf->best_depth) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2848
			arf->best_depth = arf->cur_best_depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2849
			arf->best_dist = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2850
			arf->best_ptr = p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2851
			arf->best_tile = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2852
			better = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2853
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2854
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2855
	arf->recursive_mode = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2856
	arf->cur_best_dist = (uint)-1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2857
	arf->cur_best_depth = 0xff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2858
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2859
	return better;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2860
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2861
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2862
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2863
static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, Trackdir track, uint length)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2864
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2865
	uint dist = DistanceManhattan(tile, a->dest);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2866
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2867
	if (dist <= a->best_dist) {
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2868
		TileIndex tile2 = TILE_MASK(tile + TileOffsByDiagDir(TrackdirToExitdir(track)));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2869
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8556
diff changeset
  2870
		if (IsNormalRoadTile(tile2)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2871
			a->best_dist = dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2872
			a->best_tile = tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2873
			a->best_track = track;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2874
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2875
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2876
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2877
	return false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2878
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2879
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2880
static bool AiCheckRoadFinished(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2881
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2882
	AiRoadEnum are;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2883
	TileIndex tile;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2884
	DiagDirection dir = _players_ai[p->index].cur_dir_a;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2885
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2886
	are.dest = _players_ai[p->index].cur_tile_b;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2887
	tile = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(dir));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2888
5028
1dbceed7bedc (svn r7069) -Fix: AI tried to build road from the back or side of road stop/depot (peter1138)
KUDr
parents: 5016
diff changeset
  2889
	if (IsRoadStopTile(tile) || IsTileDepotType(tile, TRANSPORT_ROAD)) return false;
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2890
	TrackdirBits bits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, ROADTYPES_ROAD)) & DiagdirReachesTrackdirs(dir);
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2891
	if (bits == TRACKDIR_BIT_NONE) return false;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2892
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2893
	are.best_dist = (uint)-1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2894
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2895
	while (bits != TRACKDIR_BIT_NONE) {
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2896
		Trackdir trackdir = RemoveFirstTrackdir(&bits);
8800
c30102fee110 (svn r12540) -Codechange: Enumify some values in original pathfinder and remove an unused variable.
frosch
parents: 8795
diff changeset
  2897
		FollowTrack(tile, PATHFIND_FLAGS_DISABLE_TILE_HASH, TRANSPORT_ROAD, ROADTYPES_ROAD, TrackdirToExitdir(trackdir), (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2898
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2899
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2900
	if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2901
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2902
	if (are.best_dist == 0) return true;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2903
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  2904
	_players_ai[p->index].cur_tile_a = are.best_tile;
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2905
	_players_ai[p->index].cur_dir_a = TrackdirToExitdir(are.best_track);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2906
	return false;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2907
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2908
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2909
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2910
static bool AiBuildRoadHelper(TileIndex tile, int flags, int type)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2911
{
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2912
	static const RoadBits _road_bits[] = {
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2913
		ROAD_X,
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2914
		ROAD_Y,
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2915
		ROAD_NW | ROAD_NE,
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2916
		ROAD_SW | ROAD_SE,
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2917
		ROAD_NW | ROAD_SW,
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  2918
		ROAD_SE | ROAD_NE
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2919
	};
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  2920
	return CmdSucceeded(DoCommand(tile, _road_bits[type], 0, flags, CMD_BUILD_ROAD));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2921
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2922
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2923
static inline void AiCheckBuildRoadBridgeHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2924
{
3644
7c9a6a91873b (svn r4553) int and magic numbers -> Slope and DiagDirection
tron
parents: 3609
diff changeset
  2925
	Slope tileh;
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2926
	uint z;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2927
	bool flag;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2928
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2929
	DiagDirection dir2 = (DiagDirection)(p[0] & 3);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2930
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2931
	tileh = GetTileSlope(tile, &z);
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2932
	if (tileh == InclinedSlope(ReverseDiagDir(dir2)) || (tileh == SLOPE_FLAT && z != 0)) {
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2933
		TileIndex tile_new = tile;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2934
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2935
		// Allow bridges directly over bottom tiles
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2936
		flag = z == 0;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  2937
		for (;;) {
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2938
			TileType type;
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2939
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  2940
			if ((TileIndexDiff)tile_new < -TileOffsByDiagDir(dir2)) return; // Wraping around map, no bridge possible!
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  2941
			tile_new = TILE_MASK(tile_new + TileOffsByDiagDir(dir2));
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2942
			type = GetTileType(tile_new);
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2943
8351
252b35f04eda (svn r11917) -Fix (r3677): AI was reading wrong tile slope while building road bridge
smatz
parents: 8322
diff changeset
  2944
			if (type == MP_CLEAR || type == MP_TREES || GetTileSlope(tile_new, NULL) != SLOPE_FLAT) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2945
				// Allow a bridge if either we have a tile that's water, rail or street,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2946
				// or if we found an up tile.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2947
				if (!flag) return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2948
				break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2949
			}
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7317
diff changeset
  2950
			if (type != MP_WATER && type != MP_RAILWAY && type != MP_ROAD) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2951
			flag = true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2952
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2953
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2954
		// Is building a (rail)bridge possible at this place (type doesn't matter)?
6842
f3c7bbd39a86 (svn r10081) -Fix [FS851]: towns/AIs didn't build bridges anymore (boekabart).
rubidium
parents: 6819
diff changeset
  2955
		if (CmdFailed(DoCommand(tile_new, tile, ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE)))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2956
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2957
		AiBuildRoadRecursive(arf, tile_new, dir2);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2958
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2959
		// At the bottom depth, check if the new path is better than the old one.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2960
		if (arf->depth == 1) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  2961
			if (AiCheckRoadPathBetter(arf, p)) arf->bridge_end_tile = tile_new;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2962
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2963
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2964
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2965
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2966
static inline void AiCheckBuildRoadTunnelHere(AiRoadFinder *arf, TileIndex tile, const byte *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2967
{
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2968
	uint z;
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  2969
8795
33530273bd31 (svn r12533) -Cleanup: Remove some wizardry from default ai by using existings enums and helper functions.
frosch
parents: 8786
diff changeset
  2970
	if (GetTileSlope(tile, &z) == InclinedSlope((DiagDirection)(p[0] & 3)) && z != 0) {
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  2971
		CommandCost cost = DoCommand(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2972
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2973
		if (CmdSucceeded(cost) && cost.GetCost() <= (arf->player->player_money >> 4)) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2974
			AiBuildRoadRecursive(arf, _build_tunnel_endtile, (DiagDirection)(p[0] & 3));
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  2975
			if (arf->depth == 1)  AiCheckRoadPathBetter(arf, p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2976
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2977
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2978
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2979
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2980
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2981
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2982
static void AiBuildRoadRecursive(AiRoadFinder *arf, TileIndex tile, DiagDirection dir)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2983
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2984
	const byte *p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2985
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  2986
	tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2987
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2988
	// Reached destination?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2989
	if (tile == arf->final_tile) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  2990
		if (ReverseDiagDir(arf->final_dir) == dir) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2991
			arf->recursive_mode = 2;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2992
			arf->cur_best_depth = arf->depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2993
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2994
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2995
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2996
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2997
	// Depth too deep?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2998
	if (arf->depth >= 4) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  2999
		uint dist = DistanceMaxPlusManhattan(tile, arf->final_tile);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3000
		if (dist < arf->cur_best_dist) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3001
			// Store the tile that is closest to the final position.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3002
			arf->cur_best_dist = dist;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3003
			arf->cur_best_tile = tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3004
			arf->cur_best_dir = dir;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3005
			arf->cur_best_depth = arf->depth;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3006
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3007
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3008
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3009
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3010
	// Increase recursion depth
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3011
	arf->depth++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3012
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3013
	// Grab pointer to list of stuff that is possible to build
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3014
	p = _ai_table_15[dir];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3015
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3016
	// Try to build a single rail in all directions.
3088
eb49840fcc1d (svn r3677) Remove the FindLandscapeHeightByTile()s from the default AI.
tron
parents: 3071
diff changeset
  3017
	if (GetTileZ(tile) == 0) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3018
		p += 6;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3019
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3020
		do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3021
			// Make sure that a road can be built here.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3022
			if (AiBuildRoadHelper(tile, DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, p[0])) {
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  3023
				AiBuildRoadRecursive(arf, tile, (DiagDirection)p[1]);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3024
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3025
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3026
			// At the bottom depth?
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3027
			if (arf->depth == 1) AiCheckRoadPathBetter(arf, p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3028
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3029
			p += 2;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3030
		} while (!(p[0] & 0x80));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3031
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3032
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3033
	AiCheckBuildRoadBridgeHere(arf, tile, p);
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3034
	AiCheckBuildRoadTunnelHere(arf, tile, p + 1);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3035
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3036
	arf->depth--;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3037
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3038
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3039
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3040
static void AiBuildRoadConstruct(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3041
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3042
	AiRoadFinder arf;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3043
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3044
	TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3045
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3046
	// Reached destination?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3047
	if (AiCheckRoadFinished(p)) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3048
		_players_ai[p->index].state_mode = 255;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3049
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3050
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3051
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3052
	// Setup recursive finder and call it.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3053
	arf.player = p;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3054
	arf.final_tile = _players_ai[p->index].cur_tile_b;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3055
	arf.final_dir = _players_ai[p->index].cur_dir_b;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3056
	arf.depth = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3057
	arf.recursive_mode = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3058
	arf.best_ptr = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3059
	arf.cur_best_dist = (uint)-1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3060
	arf.cur_best_depth = 0xff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3061
	arf.best_dist = (uint)-1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3062
	arf.best_depth =  0xff;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3063
	arf.cur_best_tile = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3064
	arf.best_tile = 0;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3065
	AiBuildRoadRecursive(&arf, _players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3066
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3067
	// Reached destination?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3068
	if (arf.recursive_mode == 2 && arf.cur_best_depth == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3069
		_players_ai[p->index].state_mode = 255;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3070
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3071
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3072
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3073
	// Didn't find anything to build?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3074
	if (arf.best_ptr == NULL) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3075
		// Terraform some
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3076
do_some_terraform:
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3077
		for (i = 0; i != 5; i++)
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3078
			AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3079
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3080
		if (++_players_ai[p->index].state_counter == 21) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3081
			_players_ai[p->index].state_mode = 1;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3082
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3083
			_players_ai[p->index].cur_tile_a = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a));
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3084
			_players_ai[p->index].cur_dir_a = ReverseDiagDir(_players_ai[p->index].cur_dir_a);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3085
			_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3086
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3087
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3088
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3089
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3090
	tile = TILE_MASK(_players_ai[p->index].cur_tile_a + TileOffsByDiagDir(_players_ai[p->index].cur_dir_a));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3091
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3092
	if (arf.best_ptr[0] & 0x80) {
8617
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3093
		TileIndex t1 = tile;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3094
		TileIndex t2 = arf.bridge_end_tile;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3095
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3096
		int32 bridge_len = GetTunnelBridgeLength(t1, t2);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3097
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3098
		Axis axis = (TileX(t1) == TileX(t2) ? AXIS_Y : AXIS_X);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3099
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3100
		/* try to build a long road instead of bridge - CMD_BUILD_LONG_ROAD has to fail if it couldn't build at least one piece! */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3101
 		CommandCost cost = DoCommand(t2, t1, (t2 < t1 ? 1 : 2) | (axis << 2) | (ROADTYPE_ROAD << 3), DC_AUTO | DC_NO_WATER, CMD_BUILD_LONG_ROAD);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3102
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3103
		if (CmdSucceeded(cost) && cost.GetCost() <= p->player_money) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3104
			DoCommand(t2, t1, (t2 < t1 ? 1 : 2) | (axis << 2) | (ROADTYPE_ROAD << 3), DC_AUTO | DC_EXEC | DC_NO_WATER, CMD_BUILD_LONG_ROAD);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3105
		} else {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3106
			int i;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3107
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3108
			/* Figure out what (road)bridge type to build
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3109
			 * start with best bridge, then go down to worse and worse bridges
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3110
			 * unnecessary to check for worse bridge (i=0), since AI will always build that */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3111
			for (i = MAX_BRIDGES - 1; i != 0; i--) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3112
				if (CheckBridge_Stuff(i, bridge_len)) {
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3113
					CommandCost cost = DoCommand(t1, t2, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE);
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3114
					if (CmdSucceeded(cost) && cost.GetCost() < (p->player_money >> 1) && cost.GetCost() < ((p->player_money + _economy.max_loan - p->current_loan) >> 5)) break;
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3115
				}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3116
			}
8617
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3117
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3118
			/* Build it */
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3119
			DoCommand(t1, t2, i + ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO | DC_EXEC, CMD_BUILD_BRIDGE);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3120
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3121
8617
338141724037 (svn r12200) -Fix: force AI to build rail or road instead of bridges if possible, so it doesn't build bridges everywhere
smatz
parents: 8616
diff changeset
  3122
		_players_ai[p->index].cur_tile_a = t2;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3123
		_players_ai[p->index].state_counter = 0;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3124
	} else if (arf.best_ptr[0] & 0x40) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3125
		// tunnel
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3126
		DoCommand(tile, 0x200, 0, DC_AUTO | DC_EXEC, CMD_BUILD_TUNNEL);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3127
		_players_ai[p->index].cur_tile_a = _build_tunnel_endtile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3128
		_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3129
	} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3130
		// road
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3131
		if (!AiBuildRoadHelper(tile, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, arf.best_ptr[0]))
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3132
			goto do_some_terraform;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3133
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3134
		_players_ai[p->index].cur_dir_a = (DiagDirection)(arf.best_ptr[1] & 3);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3135
		_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3136
		_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3137
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3138
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3139
	if (arf.best_tile != 0) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3140
		for (i = 0; i != 2; i++)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3141
			AiDoTerraformLand(arf.best_tile, arf.best_dir, 3, 0);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3142
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3143
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3144
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3145
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3146
static void AiBuildRoad(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3147
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3148
	if (_players_ai[p->index].state_mode < 1) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3149
		// Construct mode, build new road.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3150
		AiBuildRoadConstruct(p);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3151
	} else if (_players_ai[p->index].state_mode == 1) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3152
		// Destruct mode, not implemented for roads.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3153
		_players_ai[p->index].state_mode = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3154
		_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3155
	} else if (_players_ai[p->index].state_mode == 2) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3156
		uint i;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3157
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3158
		// Terraform some and then try building again.
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3159
		for (i = 0; i != 4; i++) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3160
			AiDoTerraformLand(_players_ai[p->index].cur_tile_a, _players_ai[p->index].cur_dir_a, 3, 0);
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3161
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3162
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3163
		if (++_players_ai[p->index].state_counter == 4) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3164
			_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3165
			_players_ai[p->index].state_mode = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3166
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3167
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3168
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3169
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  3170
static TileIndex AiGetRoadBlockEdge(byte rule, TileIndex tile, DiagDirection *dir)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3171
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3172
	const AiDefaultBlockData *p = _road_default_block_data[rule]->data;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3173
	while (p->mode != 1) p++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3174
	*dir = p->attr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3175
	return TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3176
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3177
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3178
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3179
static void AiStateBuildRoad(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3180
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3181
	int num;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3182
	AiBuildRec *aib;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3183
	byte cmd;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3184
	TileIndex tile;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 6990
diff changeset
  3185
	DiagDirection dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3186
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3187
	// time out?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3188
	if (++_players_ai[p->index].timeout_counter == 1388) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3189
		_players_ai[p->index].state = AIS_DELETE_ROAD_BLOCKS;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3190
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3191
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3192
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3193
	// Currently building a road between two points?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3194
	if (_players_ai[p->index].state_mode != 255) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3195
		AiBuildRoad(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3196
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3197
		// Alternate between edges
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3198
		Swap(_players_ai[p->index].start_tile_a, _players_ai[p->index].start_tile_b);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3199
		Swap(_players_ai[p->index].cur_tile_a,   _players_ai[p->index].cur_tile_b);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3200
		Swap(_players_ai[p->index].start_dir_a,  _players_ai[p->index].start_dir_b);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3201
		Swap(_players_ai[p->index].cur_dir_a,    _players_ai[p->index].cur_dir_b);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3202
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3203
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3204
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3205
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3206
	// Now, find two new points to build between
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3207
	num = _players_ai[p->index].num_build_rec;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3208
	aib = &_players_ai[p->index].src;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3209
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2819
diff changeset
  3210
	for (;;) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3211
		cmd = aib->buildcmd_a;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3212
		aib->buildcmd_a = 255;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3213
		if (cmd != 255) break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3214
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3215
		aib++;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3216
		if (--num == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3217
			_players_ai[p->index].state = AIS_BUILD_ROAD_VEHICLES;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3218
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3219
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3220
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3221
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3222
	// Find first edge to build from.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3223
	tile = AiGetRoadBlockEdge(aib->cur_building_rule, aib->use_tile, &dir);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3224
	_players_ai[p->index].start_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3225
	_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3226
	_players_ai[p->index].start_dir_a = dir;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3227
	_players_ai[p->index].cur_dir_a = dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3228
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3229
	// Find second edge to build to
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3230
	aib = (&_players_ai[p->index].src) + (cmd & 0xF);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3231
	tile = AiGetRoadBlockEdge(aib->cur_building_rule, aib->use_tile, &dir);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3232
	_players_ai[p->index].start_tile_b = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3233
	_players_ai[p->index].cur_tile_b = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3234
	_players_ai[p->index].start_dir_b = dir;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3235
	_players_ai[p->index].cur_dir_b = dir;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3236
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3237
	// And setup state.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3238
	_players_ai[p->index].state_mode = 2;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3239
	_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3240
	_players_ai[p->index].banned_tile_count = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3241
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3242
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
  3243
static StationID AiGetStationIdFromRoadBlock(TileIndex tile, int id)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3244
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3245
	const AiDefaultBlockData *p = _road_default_block_data[id]->data;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3246
	while (p->mode != 1) p++;
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
  3247
	return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3248
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3249
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3250
static void AiStateBuildRoadVehicles(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3251
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3252
	const AiDefaultBlockData *ptr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3253
	TileIndex tile;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3254
	VehicleID loco_id;
2551
00e02ecf5835 (svn r3080) byte -> PlayerID, int -> EngineID, -1 -> INVALID_ENGINE
tron
parents: 2544
diff changeset
  3255
	EngineID veh;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3256
	uint i;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3257
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3258
	ptr = _road_default_block_data[_players_ai[p->index].src.cur_building_rule]->data;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3259
	for (; ptr->mode != 0; ptr++) {}
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3260
	tile = TILE_ADD(_players_ai[p->index].src.use_tile, ToTileIndexDiff(ptr->tileoffs));
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3261
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3262
	veh = AiChooseRoadVehToBuild(_players_ai[p->index].cargo_type, p->player_money, tile);
2551
00e02ecf5835 (svn r3080) byte -> PlayerID, int -> EngineID, -1 -> INVALID_ENGINE
tron
parents: 2544
diff changeset
  3263
	if (veh == INVALID_ENGINE) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3264
		_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3265
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3266
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3267
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3268
	if (CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH))) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3269
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3933
diff changeset
  3270
	loco_id = _new_vehicle_id;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3271
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3272
	if (GetVehicle(loco_id)->cargo_type != _players_ai[p->index].cargo_type) {
5031
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3273
		/* Cargo type doesn't match, so refit it */
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3274
		if (CmdFailed(DoCommand(tile, loco_id, _players_ai[p->index].cargo_type, DC_EXEC, CMD_REFIT_ROAD_VEH))) {
5031
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3275
			/* Refit failed... sell the vehicle */
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3276
			DoCommand(tile, loco_id, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3277
			return;
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3278
		}
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3279
	}
93e873e3ab03 (svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
peter1138
parents: 5029
diff changeset
  3280
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3281
	for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3282
		const AiBuildRec* aib = &_players_ai[p->index].src + _players_ai[p->index].order_list_blocks[i];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  3283
		bool is_pass = (
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3284
			_players_ai[p->index].cargo_type == CT_PASSENGERS ||
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3285
			_players_ai[p->index].cargo_type == CT_MAIL ||
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3286
			(_opt.landscape == LT_TEMPERATE && _players_ai[p->index].cargo_type == CT_VALUABLES)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
  3287
		);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3288
		Order order;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3289
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3290
		order.MakeGoToStation(AiGetStationIdFromRoadBlock(aib->use_tile, aib->cur_building_rule));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3291
8855
6d841d5d4789 (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents: 8843
diff changeset
  3292
		if (!is_pass && i == 1) order.SetUnloadType(OUFB_UNLOAD);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3293
		if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0))
8855
6d841d5d4789 (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents: 8843
diff changeset
  3294
			order.SetLoadType(OLFB_FULL_LOAD);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3295
8839
6337281b393b (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents: 8836
diff changeset
  3296
		DoCommand(0, loco_id + (i << 16), order.Pack(), DC_EXEC, CMD_INSERT_ORDER);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3297
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3298
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3299
	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3300
	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3301
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3302
	if (_players_ai[p->index].num_want_fullload != 0) _players_ai[p->index].num_want_fullload--;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3303
	if (--_players_ai[p->index].num_loco_to_build == 0) _players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3304
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3305
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3306
static void AiStateDeleteRoadBlocks(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3307
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3308
	const AiBuildRec* aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3309
	uint num = _players_ai[p->index].num_build_rec;
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3310
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3311
	do {
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3312
		const AiDefaultBlockData* b;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3313
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3314
		if (aib->cur_building_rule == 255) continue;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3315
		for (b = _road_default_block_data[aib->cur_building_rule]->data; b->mode != 4; b++) {
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3316
			if (b->mode > 1) continue;
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3317
			DoCommand(TILE_ADD(aib->use_tile, ToTileIndexDiff(b->tileoffs)), 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3318
		}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3319
	} while (++aib, --num);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3320
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3321
	_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3322
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3323
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3324
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3325
static void AiStateAirportStuff(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3326
{
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3327
	const Station* st;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3328
	int i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3329
	AiBuildRec *aib;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3330
	byte rule;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3331
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3332
	// Here we look for an airport we could use instead of building a new
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3333
	// one. If we find such an aiport for any waypoint,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3334
	// AiStateBuildDefaultAirportBlocks() will kindly skip that one when
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3335
	// building the waypoints.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3336
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3337
	i = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3338
	do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3339
		// We do this all twice - once for the source (town in the case
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3340
		// of oilrig route) and then for the destination (oilrig in the
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3341
		// case of oilrig route).
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3342
		aib = &_players_ai[p->index].src + i;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3343
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3344
		FOR_ALL_STATIONS(st) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3345
			// Is this an airport?
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3346
			if (!(st->facilities & FACIL_AIRPORT)) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3347
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3348
			// Do we own the airport? (Oilrigs aren't owned, though.)
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3349
			if (st->owner != OWNER_NONE && st->owner != _current_player) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3350
6032
fe6a454ac1ba (svn r8755) -Fix
tron
parents: 6027
diff changeset
  3351
			AirportFTAClass::Flags flags = st->Airport()->flags;
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 5971
diff changeset
  3352
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3353
			if (!(flags & (_players_ai[p->index].build_kind == 1 && i == 0 ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES))) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3354
				continue;
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 5971
diff changeset
  3355
			}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3356
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3357
			// Dismiss airports too far away.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3358
			if (DistanceMax(st->airport_tile, aib->spec_tile) > aib->rand_rng)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3359
				continue;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3360
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3361
			// It's ideal airport, let's take it!
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3362
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3363
			/* XXX: This part is utterly broken - rule should
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3364
			 * contain number of the rule appropriate for the
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3365
			 * airport type (country, town, ...), see
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3366
			 * _airport_default_block_data (rule is just an index
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3367
			 * in this array). But the only difference between the
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3368
			 * currently existing two rules (rule 0 - town and rule
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3369
			 * 1 - country) is the attr field which is used only
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3370
			 * when building new airports - and that's irrelevant
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3371
			 * for us. So using just about any rule will suffice
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3372
			 * here for now (some of the new airport types would be
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3373
			 * broken because they will probably need different
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3374
			 * tileoff values etc), no matter that
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3336
diff changeset
  3375
			 * IsHangarTile() makes no sense. --pasky */
6027
ff15b8c7c087 (svn r8750) -Fix (r8747): PLANES defined in wingdi.h caused compilation error under Win32. Changed to AIRPLANES
KUDr
parents: 6024
diff changeset
  3376
			if (!(flags & AirportFTAClass::AIRPLANES)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3377
				/* Heliports should have maybe own rulesets but
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3378
				 * OTOH we don't want AI to pick them up when
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3379
				 * looking for a suitable airport type to build.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3380
				 * So any of rules 0 or 1 would do for now. The
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3381
				 * original rule number was 2 but that's a bug
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3382
				 * because we have no such rule. */
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3383
				rule = 1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3384
			} else {
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3336
diff changeset
  3385
				rule = IsHangarTile(st->airport_tile);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3386
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3387
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3388
			aib->cur_building_rule = rule;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3389
			aib->use_tile = st->airport_tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3390
			break;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3391
		}
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3392
	} while (++i != _players_ai[p->index].num_build_rec);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3393
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3394
	_players_ai[p->index].state = AIS_BUILD_DEFAULT_AIRPORT_BLOCKS;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3395
	_players_ai[p->index].state_mode = 255;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3396
	_players_ai[p->index].state_counter = 0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3397
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3398
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  3399
static CommandCost AiDoBuildDefaultAirportBlock(TileIndex tile, const AiDefaultBlockData *p, byte flag)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3400
{
5971
b21fda7c7f1e (svn r8660) -Fix
tron
parents: 5868
diff changeset
  3401
	uint32 avail_airports = GetValidAirports();
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8229
diff changeset
  3402
	CommandCost ret,total_cost(EXPENSES_CONSTRUCTION);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3403
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3404
	for (; p->mode == 0; p++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7653
diff changeset
  3405
		if (!HasBit(avail_airports, p->attr)) return CMD_ERROR;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3406
		ret = DoCommand(TILE_MASK(tile + ToTileIndexDiff(p->tileoffs)), p->attr, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_AIRPORT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3407
		if (CmdFailed(ret)) return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  3408
		total_cost.AddCost(ret);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3409
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3410
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3411
	return total_cost;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3412
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3413
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3414
static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3415
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3416
	uint values[NUM_CARGO];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3417
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3418
	for (; p->mode == 0; p++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3419
		TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3871
diff changeset
  3420
		const AirportFTAClass* airport = GetAirport(p->attr);
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3871
diff changeset
  3421
		uint w = airport->size_x;
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3871
diff changeset
  3422
		uint h = airport->size_y;
8574
7a10054a7d2a (svn r12155) -Fix (r12154): some warnings (always compile before commit)
glx
parents: 8573
diff changeset
  3423
		uint rad = _patches.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3424
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3425
		if (cargo & 0x80) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3426
			GetProductionAroundTiles(values, tile2, w, h, rad);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3427
			return values[cargo & 0x7F] != 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3428
		} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3429
			GetAcceptanceAroundTiles(values, tile2, w, h, rad);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3430
			return values[cargo] >= 8;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3431
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3432
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3433
	return true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3434
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3435
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  3436
static int AiFindBestDefaultAirportBlock(TileIndex tile, byte cargo, byte heli, CommandCost *cost)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3437
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3438
	const AiDefaultBlockData *p;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3439
	uint i;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3440
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3441
	for (i = 0; (p = _airport_default_block_data[i]) != NULL; i++) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3442
		// If we are doing a helicopter service, avoid building
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3443
		// airports where they can't land.
6024
37e72f8f6a99 (svn r8747) -Fix
tron
parents: 5971
diff changeset
  3444
		if (heli && !(GetAirport(p->attr)->flags & AirportFTAClass::HELICOPTERS)) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3445
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3446
		*cost = AiDoBuildDefaultAirportBlock(tile, p, 0);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  3447
		if (CmdSucceeded(*cost) && AiCheckAirportResources(tile, p, cargo))
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3448
			return i;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3449
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3450
	return -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3451
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3452
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3453
static void AiStateBuildDefaultAirportBlocks(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3454
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3455
	int i, j;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3456
	AiBuildRec *aib;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3457
	int rule;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  3458
	CommandCost cost;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3459
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3460
	// time out?
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3461
	if (++_players_ai[p->index].timeout_counter == 1388) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3462
		_players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3463
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3464
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3465
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3466
	// do the following 8 times
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3467
	i = 8;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3468
	do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3469
		// check if we can build the default
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3470
		aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3471
		j = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3472
		do {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3473
			// this item has already been built?
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3474
			if (aib->cur_building_rule != 255) continue;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3475
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3476
			// adjust the coordinate randomly,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3477
			// to make sure that we find a position.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3478
			aib->use_tile = AdjustTileCoordRandomly(aib->spec_tile, aib->rand_rng);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3479
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3480
			// check if the aircraft stuff can be built there.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3481
			rule = AiFindBestDefaultAirportBlock(aib->use_tile, aib->cargo, _players_ai[p->index].build_kind, &cost);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3482
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3483
//			SetRedErrorSquare(aib->use_tile);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3484
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3485
			if (rule == -1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3486
				// cannot build, terraform after a while
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3487
				if (_players_ai[p->index].state_counter >= 600) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3488
					AiDoTerraformLand(aib->use_tile, (DiagDirection)(Random() & 3), 3, (int8)_players_ai[p->index].state_mode);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3489
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3490
				// also try the other terraform direction
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3491
				if (++_players_ai[p->index].state_counter >= 1000) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3492
					_players_ai[p->index].state_counter = 0;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3493
					_players_ai[p->index].state_mode = -_players_ai[p->index].state_mode;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3494
				}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3495
			} else if (CheckPlayerHasMoney(cost) && AiCheckBlockDistances(p, aib->use_tile)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3496
				// player has money, build it.
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6866
diff changeset
  3497
				CommandCost r;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3498
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3499
				aib->cur_building_rule = rule;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3500
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3501
				r = AiDoBuildDefaultAirportBlock(
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3502
					aib->use_tile,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3503
					_airport_default_block_data[rule],
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3504
					DC_EXEC | DC_NO_TOWN_RATING
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3505
				);
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  3506
				assert(CmdSucceeded(r));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3507
			}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3508
		} while (++aib, --j);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3509
	} while (--i);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3510
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3511
	// check if we're done with all of them
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3512
	aib = &_players_ai[p->index].src;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3513
	j = _players_ai[p->index].num_build_rec;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3514
	do {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3515
		if (aib->cur_building_rule == 255) return;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3516
	} while (++aib, --j);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3517
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3518
	// yep, all are done. switch state.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3519
	_players_ai[p->index].state = AIS_BUILD_AIRCRAFT_VEHICLES;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3520
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3521
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
  3522
static StationID AiGetStationIdFromAircraftBlock(TileIndex tile, int id)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3523
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3524
	const AiDefaultBlockData *p = _airport_default_block_data[id];
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3525
	while (p->mode != 1) p++;
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3269
diff changeset
  3526
	return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3527
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3528
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3529
static void AiStateBuildAircraftVehicles(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3530
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3531
	const AiDefaultBlockData *ptr;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3532
	TileIndex tile;
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
  3533
	EngineID veh;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3534
	int i;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3535
	VehicleID loco_id;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3536
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3537
	ptr = _airport_default_block_data[_players_ai[p->index].src.cur_building_rule];
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3538
	for (; ptr->mode != 0; ptr++) {}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3539
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3540
	tile = TILE_ADD(_players_ai[p->index].src.use_tile, ToTileIndexDiff(ptr->tileoffs));
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3541
8402
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3542
	/* determine forbidden aircraft bits */
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3543
	byte forbidden = 0;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3544
	for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) {
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3545
		const AiBuildRec *aib = (&_players_ai[p->index].src) + _players_ai[p->index].order_list_blocks[i];
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3546
		const Station *st = GetStationByTile(aib->use_tile);
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3547
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3548
		if (st == NULL || !(st->facilities & FACIL_AIRPORT)) continue;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3549
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3550
		AirportFTAClass::Flags flags = st->Airport()->flags;
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3551
		if (!(flags & AirportFTAClass::AIRPLANES)) forbidden |= AIR_CTOL | AIR_FAST; // no planes for heliports / oil rigs
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3552
		if (flags & AirportFTAClass::SHORT_STRIP) forbidden |= AIR_FAST; // no fast planes for small airports
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3553
	}
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3554
bd167712432a (svn r11972) -Fix: old AI shouldn't build fast planes with a small airport in orders
smatz
parents: 8398
diff changeset
  3555
	veh = AiChooseAircraftToBuild(p->player_money, forbidden);
2544
2c6a25db1bd0 (svn r3073) int/byte -> EngineID/PlayerID/VehicleID
tron
parents: 2529
diff changeset
  3556
	if (veh == INVALID_ENGINE) return;
2423
4266590b549d (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2381
diff changeset
  3557
4266590b549d (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2381
diff changeset
  3558
	/* XXX - Have the AI pick the hangar terminal in an airport. Eg get airport-type
4266590b549d (svn r2949) The AI no longer needs to 'cheat' to build aircraft; eg it builds them now from a hangar. Also, to query the price of a new aircraft tile information is not needed
Darkvater
parents: 2381
diff changeset
  3559
	 * and offset to the FIRST depot because the AI picks the st->xy tile */
6032
fe6a454ac1ba (svn r8755) -Fix
tron
parents: 6027
diff changeset
  3560
	tile += ToTileIndexDiff(GetStationByTile(tile)->Airport()->airport_depots[0]);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3561
	if (CmdFailed(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) return;
3948
a09379beffd5 (svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents: 3933
diff changeset
  3562
	loco_id = _new_vehicle_id;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3563
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3564
	for (i = 0; _players_ai[p->index].order_list_blocks[i] != 0xFF; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3565
		AiBuildRec *aib = (&_players_ai[p->index].src) + _players_ai[p->index].order_list_blocks[i];
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3566
		bool is_pass = (_players_ai[p->index].cargo_type == CT_PASSENGERS || _players_ai[p->index].cargo_type == CT_MAIL);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3567
		Order order;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3568
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3569
		order.MakeGoToStation(AiGetStationIdFromAircraftBlock(aib->use_tile, aib->cur_building_rule));
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3570
8855
6d841d5d4789 (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents: 8843
diff changeset
  3571
		if (!is_pass && i == 1) order.SetUnloadType(OUFB_UNLOAD);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3572
		if (_players_ai[p->index].num_want_fullload != 0 && (is_pass || i == 0))
8855
6d841d5d4789 (svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents: 8843
diff changeset
  3573
			order.SetLoadType(OLFB_FULL_LOAD);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3574
8839
6337281b393b (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium
parents: 8836
diff changeset
  3575
		DoCommand(0, loco_id + (i << 16), order.Pack(), DC_EXEC, CMD_INSERT_ORDER);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3576
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3577
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3578
	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_AIRCRAFT);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3579
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3580
	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3581
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3582
	if (_players_ai[p->index].num_want_fullload != 0) _players_ai[p->index].num_want_fullload--;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3583
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3584
	if (--_players_ai[p->index].num_loco_to_build == 0) _players_ai[p->index].state = AIS_0;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3585
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3586
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3587
static void AiStateCheckShipStuff(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3588
{
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
  3589
	/* Ships are not implemented in this (broken) AI */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3590
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3591
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3592
static void AiStateBuildDefaultShipBlocks(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3593
{
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
  3594
	/* Ships are not implemented in this (broken) AI */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3595
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3596
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3597
static void AiStateDoShipStuff(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3598
{
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
  3599
	/* Ships are not implemented in this (broken) AI */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3600
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3601
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3602
static void AiStateSellVeh(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3603
{
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3604
	Vehicle *v = _players_ai[p->index].cur_veh;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3605
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3606
	if (v->owner == _current_player) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  3607
		if (v->type == VEH_TRAIN) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3608
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3609
			if (!IsTileDepotType(v->tile, TRANSPORT_RAIL) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) {
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3610
				if (!v->current_order.IsType(OT_GOTO_DEPOT))
4495
b6381e4bcb61 (svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents: 4434
diff changeset
  3611
					DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_TRAIN_TO_DEPOT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3612
				goto going_to_depot;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3613
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3614
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3615
			// Sell whole train
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3616
			DoCommand(v->tile, v->index, 1, DC_EXEC, CMD_SELL_RAIL_WAGON);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3617
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  3618
		} else if (v->type == VEH_ROAD) {
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7455
diff changeset
  3619
			if (!v->IsStoppedInDepot()) {
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3620
				if (!v->current_order.IsType(OT_GOTO_DEPOT))
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3621
					DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_ROADVEH_TO_DEPOT);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3622
				goto going_to_depot;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3623
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3624
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3625
			DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  3626
		} else if (v->type == VEH_AIRCRAFT) {
7490
bb27d92565d3 (svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents: 7455
diff changeset
  3627
			if (!v->IsStoppedInDepot()) {
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3628
				if (!v->current_order.IsType(OT_GOTO_DEPOT))
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3629
					DoCommand(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3630
				goto going_to_depot;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3631
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3632
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3633
			DoCommand(0, v->index, 0, DC_EXEC, CMD_SELL_AIRCRAFT);
7455
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
  3634
		} else if (v->type == VEH_SHIP) {
5552aed07bc5 (svn r10942) -Fix [FS#1133]: make the AI not crash when it has ships as the AI does not support them.
rubidium
parents: 7390
diff changeset
  3635
			/* Ships are not implemented in this (broken) AI */
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3636
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3637
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3638
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3639
	goto return_to_loop;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3640
going_to_depot:;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3641
	if (++_players_ai[p->index].state_counter <= 832) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3642
8836
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3643
	if (v->current_order.IsType(OT_GOTO_DEPOT)) {
f6f1ea3d7e93 (svn r12584) -Codechange: do not access the order type directly.
rubidium
parents: 8800
diff changeset
  3644
		v->current_order.MakeDummy();
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3645
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3646
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3647
return_to_loop:;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3648
	_players_ai[p->index].state = AIS_VEH_LOOP;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3649
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3650
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3651
static void AiStateRemoveStation(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3652
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3653
	// Remove stations that aren't in use by any vehicle
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3654
	const Order *ord;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3655
	const Station *st;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3656
	TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3657
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3658
	// Go to this state when we're done.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3659
	_players_ai[p->index].state = AIS_1;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3660
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3661
	// Get a list of all stations that are in use by a vehicle
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5602
diff changeset
  3662
	byte *in_use = MallocT<byte>(GetMaxStationIndex() + 1);
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5031
diff changeset
  3663
	memset(in_use, 0, GetMaxStationIndex() + 1);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3664
	FOR_ALL_ORDERS(ord) {
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8839
diff changeset
  3665
		if (ord->IsType(OT_GOTO_STATION)) in_use[ord->GetDestination()] = 1;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3666
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3667
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3668
	// Go through all stations and delete those that aren't in use
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3669
	FOR_ALL_STATIONS(st) {
5004
2d11c27a8492 (svn r7020) -Fix r6047: AI tries to delete stations that are 'in use' because FOR_ALL_STATIONS skips invalid stations
glx
parents: 4845
diff changeset
  3670
		if (st->owner == _current_player && !in_use[st->index] &&
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3671
				( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != 0) ||
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3672
					(st->truck_stops != NULL && (tile = st->truck_stops->xy)) != 0 ||
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3673
					(tile = st->train_tile) != 0 ||
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3674
					(tile = st->dock_tile) != 0 ||
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3675
					(tile = st->airport_tile) != 0)) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3676
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3677
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3678
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3679
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3680
	free(in_use);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3681
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3682
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3683
static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3684
{
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3685
	TrackBits rails;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3686
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3687
	if (IsTileType(tile, MP_RAILWAY)) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3688
		if (!IsTileOwner(tile, _current_player)) return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3689
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3690
		if (IsPlainRailTile(tile)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3691
is_rail_crossing:;
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3692
			rails = GetRailTrackStatus(tile);
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3693
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3694
			if (rails == TRACK_BIT_HORZ || rails == TRACK_BIT_VERT) return;
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3695
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3696
			if (rails & TRACK_BIT_3WAY_NE) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3697
pos_0:
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3698
				if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & TRACK_BIT_3WAY_SW) == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3699
					_players_ai[p->index].cur_dir_a = DIAGDIR_NE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3700
					_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3701
					_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3702
					return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3703
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3704
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3705
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3706
			if (rails & TRACK_BIT_3WAY_SE) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3707
pos_1:
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3708
				if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & TRACK_BIT_3WAY_NW) == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3709
					_players_ai[p->index].cur_dir_a = DIAGDIR_SE;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3710
					_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3711
					_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3712
					return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3713
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3714
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3715
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3716
			if (rails & TRACK_BIT_3WAY_SW) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3717
pos_2:
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3718
				if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & TRACK_BIT_3WAY_NE) == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3719
					_players_ai[p->index].cur_dir_a = DIAGDIR_SW;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3720
					_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3721
					_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3722
					return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3723
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3724
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3725
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3726
			if (rails & TRACK_BIT_3WAY_NW) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3727
pos_3:
3269
62fb247bf94b (svn r3981) More work for the rail accessing functions and enums
tron
parents: 3234
diff changeset
  3728
				if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & TRACK_BIT_3WAY_SE) == 0) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3729
					_players_ai[p->index].cur_dir_a = DIAGDIR_NW;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3730
					_players_ai[p->index].cur_tile_a = tile;
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3731
					_players_ai[p->index].state = AIS_REMOVE_SINGLE_RAIL_TILE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3732
					return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3733
				}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3734
			}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3735
		} else {
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3736
			static const byte _depot_bits[] = {0x19, 0x16, 0x25, 0x2A};
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3737
3185
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3184
diff changeset
  3738
			DiagDirection dir = GetRailDepotDirection(tile);
a9d0cdff7b84 (svn r3831) Add and use GetRailDepotDirection()
tron
parents: 3184
diff changeset
  3739
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  3740
			if (GetRailTrackStatus(tile + TileOffsByDiagDir(dir)) & _depot_bits[dir])
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3741
				return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3742
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3743
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3744
		}
7370
41adc721b1fa (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7317
diff changeset
  3745
	} else if (IsTileType(tile, MP_ROAD)) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3746
		if (!IsTileOwner(tile, _current_player)) return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3747
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3748
		if (IsLevelCrossing(tile)) goto is_rail_crossing;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3749
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8556
diff changeset
  3750
		if (IsRoadDepot(tile)) {
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  3751
			DiagDirection dir;
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3752
			TileIndex t;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3753
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3754
			// Check if there are any stations around.
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3755
			t = tile + TileDiffXY(-1, 0);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3756
			if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3757
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3758
			t = tile + TileDiffXY(1, 0);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3759
			if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3760
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3761
			t = tile + TileDiffXY(0, -1);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3762
			if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return;
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3763
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3764
			t = tile + TileDiffXY(0, 1);
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
  3765
			if (IsTileType(t, MP_STATION) && IsTileOwner(t, _current_player)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3766
3179
8ef3e8028af5 (svn r3816) Use existing accessors
tron
parents: 3153
diff changeset
  3767
			dir = GetRoadDepotDirection(tile);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3768
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3769
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3770
			DoCommand(
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4527
diff changeset
  3771
				TILE_MASK(tile + TileOffsByDiagDir(dir)),
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
  3772
				DiagDirToRoadBits(ReverseDiagDir(dir)),
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3773
				0,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3774
				DC_EXEC,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3775
				CMD_REMOVE_ROAD);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3776
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3777
	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3214
diff changeset
  3778
		if (!IsTileOwner(tile, _current_player) ||
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3214
diff changeset
  3779
				!IsBridge(tile) ||
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8006
diff changeset
  3780
				GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3781
			return;
3234
a2791a480b71 (svn r3907) Replace many bridge related direct map accesses with calls to shiny new functions and mark some strange constructs with XXX
tron
parents: 3214
diff changeset
  3782
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3783
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3784
		rails = TRACK_BIT_NONE;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3785
8083
ad22eade501f (svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents: 8006
diff changeset
  3786
		switch (GetTunnelBridgeDirection(tile)) {
3196
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
  3787
			default:
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
  3788
			case DIAGDIR_NE: goto pos_2;
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
  3789
			case DIAGDIR_SE: goto pos_3;
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
  3790
			case DIAGDIR_SW: goto pos_0;
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
  3791
			case DIAGDIR_NW: goto pos_1;
5cec26c5ab75 (svn r3857) Add and use GetBridgeRampDirection()
tron
parents: 3185
diff changeset
  3792
		}
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3793
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3794
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3795
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3796
static void AiStateRemoveTrack(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3797
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3798
	/* Was 1000 for standard 8x8 maps. */
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3799
	int num = MapSizeX() * 4;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3800
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3801
	do {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3802
		TileIndex tile = ++_players_ai[p->index].state_counter;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3803
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3804
		// Iterated all tiles?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3805
		if (tile >= MapSize()) {
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3806
			_players_ai[p->index].state = AIS_REMOVE_STATION;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3807
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3808
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3809
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3810
		// Remove player stuff in that tile
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3811
		AiRemovePlayerRailOrRoad(p, tile);
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3812
		if (_players_ai[p->index].state != AIS_REMOVE_TRACK) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3813
	} while (--num);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3814
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3815
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3816
static void AiStateRemoveSingleRailTile(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3817
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3818
	// Remove until we can't remove more.
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3819
	if (!AiRemoveTileAndGoForward(p)) _players_ai[p->index].state = AIS_REMOVE_TRACK;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3820
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3821
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3822
static AiStateAction * const _ai_actions[] = {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3823
	AiCase0,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3824
	AiCase1,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3825
	AiStateVehLoop,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3826
	AiStateCheckReplaceVehicle,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3827
	AiStateDoReplaceVehicle,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3828
	AiStateWantNewRoute,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3829
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3830
	AiStateBuildDefaultRailBlocks,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3831
	AiStateBuildRail,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3832
	AiStateBuildRailVeh,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3833
	AiStateDeleteRailBlocks,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3834
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3835
	AiStateBuildDefaultRoadBlocks,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3836
	AiStateBuildRoad,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3837
	AiStateBuildRoadVehicles,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3838
	AiStateDeleteRoadBlocks,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3839
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3840
	AiStateAirportStuff,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3841
	AiStateBuildDefaultAirportBlocks,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3842
	AiStateBuildAircraftVehicles,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3843
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3844
	AiStateCheckShipStuff,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3845
	AiStateBuildDefaultShipBlocks,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3846
	AiStateDoShipStuff,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3847
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3848
	AiStateSellVeh,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3849
	AiStateRemoveStation,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3850
	AiStateRemoveTrack,
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3851
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3852
	AiStateRemoveSingleRailTile
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3853
};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3854
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3855
extern void ShowBuyCompanyDialog(uint player);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3856
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3857
static void AiHandleTakeover(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3858
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3859
	if (p->bankrupt_timeout != 0) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3860
		p->bankrupt_timeout -= 8;
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3861
		if (p->bankrupt_timeout > 0) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3862
		p->bankrupt_timeout = 0;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3863
		DeleteWindowById(WC_BUY_COMPANY, _current_player);
2425
e755ee29133a (svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents: 2423
diff changeset
  3864
		if (IsLocalPlayer()) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3865
			AskExitToGameMenu();
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3866
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3867
		}
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4560
diff changeset
  3868
		if (IsHumanPlayer(_current_player)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3869
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3870
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3022
diff changeset
  3871
	if (p->bankrupt_asked == 255) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3872
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3873
	{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3874
		uint asked = p->bankrupt_asked;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3875
		Player *pp, *best_pl = NULL;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3876
		int32 best_val = -1;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3877
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3878
		// Ask the guy with the highest performance hist.
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3879
		FOR_ALL_PLAYERS(pp) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3880
			if (pp->is_active &&
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3881
					!(asked & 1) &&
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3882
					pp->bankrupt_asked == 0 &&
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3883
					best_val < pp->old_economy[1].performance_history) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3884
				best_val = pp->old_economy[1].performance_history;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3885
				best_pl = pp;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3886
			}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3887
			asked >>= 1;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3888
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3889
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3890
		// Asked all players?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3891
		if (best_val == -1) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3892
			p->bankrupt_asked = 255;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3893
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3894
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3895
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
  3896
		SetBit(p->bankrupt_asked, best_pl->index);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3897
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3898
		if (best_pl->index == _local_player) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3899
			p->bankrupt_timeout = 4440;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3900
			ShowBuyCompanyDialog(_current_player);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3901
			return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3902
		}
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4560
diff changeset
  3903
		if (IsHumanPlayer(best_pl->index)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3904
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3905
		// Too little money for computer to buy it?
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3906
		if (best_pl->player_money >> 1 >= p->bankrupt_value) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3907
			// Computer wants to buy it.
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3908
			PlayerID old_p = _current_player;
6404
e74c41bdba64 (svn r9540) -Fix (r1): Bankrupt AIs no longer buy themselves (usage of wrong variable)
celestar
parents: 6400
diff changeset
  3909
			_current_player = best_pl->index;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3910
			DoCommand(0, old_p, 0, DC_EXEC, CMD_BUY_COMPANY);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3911
			_current_player = old_p;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3912
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3913
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3914
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3915
4011
59533bcf68ec (svn r5222) Misc. smaller changes, mostly const, variable scope and replacing some magic numbers by enums
tron
parents: 4000
diff changeset
  3916
static void AiAdjustLoan(const Player* p)
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3917
{
6990
136a08baf0ed (svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents: 6950
diff changeset
  3918
	Money base = AiGetBasePrice(p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3919
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3920
	if (p->player_money > base * 1400) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3921
		// Decrease loan
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3922
		if (p->current_loan != 0) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3923
			DoCommand(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3924
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3925
	} else if (p->player_money < base * 500) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3926
		// Increase loan
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3927
		if (p->current_loan < _economy.max_loan &&
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3928
				p->num_valid_stat_ent >= 2 &&
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3929
				-(p->old_economy[0].expenses + p->old_economy[1].expenses) < base * 60) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3930
			DoCommand(0, 0, 0, DC_EXEC, CMD_INCREASE_LOAN);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3931
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3932
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3933
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3934
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3935
static void AiBuildCompanyHQ(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3936
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3937
	TileIndex tile;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3938
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3939
	if (p->location_of_house == 0 &&
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3940
			p->last_build_coordinate != 0) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3941
		tile = AdjustTileCoordRandomly(p->last_build_coordinate, 8);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3473
diff changeset
  3942
		DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3943
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3944
}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3945
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3946
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3947
void AiDoGameLoop(Player *p)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3948
{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3949
	if (p->bankrupt_asked != 0) {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3950
		AiHandleTakeover(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3951
		return;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3952
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3953
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3954
	// Ugly hack to make sure the service interval of the AI is good, not looking
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3955
	//  to the patch-setting
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3956
	// Also, it takes into account the setting if the service-interval is in days
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3957
	//  or in %
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3958
	_ai_service_interval = _patches.servint_ispercent ? 80 : 180;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3959
4845
72bbb6e2694e (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4560
diff changeset
  3960
	if (IsHumanPlayer(_current_player)) return;
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3961
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3962
	AiAdjustLoan(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3963
	AiBuildCompanyHQ(p);
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3964
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3965
#if 0
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3966
	{
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3967
		static byte old_state = 99;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3968
		static bool hasdots = false;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
  3969
		char *_ai_state_names[] = {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3970
			"AiCase0",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3971
			"AiCase1",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3972
			"AiStateVehLoop",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3973
			"AiStateCheckReplaceVehicle",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3974
			"AiStateDoReplaceVehicle",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3975
			"AiStateWantNewRoute",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3976
			"AiStateBuildDefaultRailBlocks",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3977
			"AiStateBuildRail",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3978
			"AiStateBuildRailVeh",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3979
			"AiStateDeleteRailBlocks",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3980
			"AiStateBuildDefaultRoadBlocks",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3981
			"AiStateBuildRoad",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3982
			"AiStateBuildRoadVehicles",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3983
			"AiStateDeleteRoadBlocks",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3984
			"AiStateAirportStuff",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3985
			"AiStateBuildDefaultAirportBlocks",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3986
			"AiStateBuildAircraftVehicles",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3987
			"AiStateCheckShipStuff",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3988
			"AiStateBuildDefaultShipBlocks",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3989
			"AiStateDoShipStuff",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3990
			"AiStateSellVeh",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3991
			"AiStateRemoveStation",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3992
			"AiStateRemoveTrack",
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3993
			"AiStateRemoveSingleRailTile"
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3994
		};
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3995
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  3996
		if (_players_ai[p->index].state != old_state) {
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3997
			if (hasdots)
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3998
				printf("\n");
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  3999
			hasdots=false;
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4000
			printf("AiState: %s\n", _ai_state_names[old_state=_players_ai[p->index].state]);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4001
		} else {
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4002
			printf(".");
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4003
			hasdots=true;
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4004
		}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4005
	}
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4006
#endif
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4007
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4008
	_ai_actions[_players_ai[p->index].state](p);
2381
9a5ed6c0a2e6 (svn r2907) -Codechange: splitted the AIs to their own directory. AINew becomes 'trolly', AIOld becomes 'default', both in their own dir in the 'ai' dir. More AIs to come.
truelight
parents:
diff changeset
  4009
}
8229
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4010
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4011
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4012
static const SaveLoad _player_ai_desc[] = {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4013
	    SLE_VAR(PlayerAI, state,             SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4014
	    SLE_VAR(PlayerAI, tick,              SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4015
	SLE_CONDVAR(PlayerAI, state_counter,     SLE_FILE_U16 | SLE_VAR_U32,  0, 12),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4016
	SLE_CONDVAR(PlayerAI, state_counter,     SLE_UINT32,                 13, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4017
	    SLE_VAR(PlayerAI, timeout_counter,   SLE_UINT16),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4018
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4019
	    SLE_VAR(PlayerAI, state_mode,        SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4020
	    SLE_VAR(PlayerAI, banned_tile_count, SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4021
	    SLE_VAR(PlayerAI, railtype_to_use,   SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4022
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4023
	    SLE_VAR(PlayerAI, cargo_type,        SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4024
	    SLE_VAR(PlayerAI, num_wagons,        SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4025
	    SLE_VAR(PlayerAI, build_kind,        SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4026
	    SLE_VAR(PlayerAI, num_build_rec,     SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4027
	    SLE_VAR(PlayerAI, num_loco_to_build, SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4028
	    SLE_VAR(PlayerAI, num_want_fullload, SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4029
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4030
	    SLE_VAR(PlayerAI, route_type_mask,   SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4031
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4032
	SLE_CONDVAR(PlayerAI, start_tile_a,      SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4033
	SLE_CONDVAR(PlayerAI, start_tile_a,      SLE_UINT32,                  6, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4034
	SLE_CONDVAR(PlayerAI, cur_tile_a,        SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4035
	SLE_CONDVAR(PlayerAI, cur_tile_a,        SLE_UINT32,                  6, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4036
	    SLE_VAR(PlayerAI, start_dir_a,       SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4037
	    SLE_VAR(PlayerAI, cur_dir_a,         SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4038
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4039
	SLE_CONDVAR(PlayerAI, start_tile_b,      SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4040
	SLE_CONDVAR(PlayerAI, start_tile_b,      SLE_UINT32,                  6, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4041
	SLE_CONDVAR(PlayerAI, cur_tile_b,        SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4042
	SLE_CONDVAR(PlayerAI, cur_tile_b,        SLE_UINT32,                  6, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4043
	    SLE_VAR(PlayerAI, start_dir_b,       SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4044
	    SLE_VAR(PlayerAI, cur_dir_b,         SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4045
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4046
	    SLE_REF(PlayerAI, cur_veh,           REF_VEHICLE),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4047
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4048
	    SLE_ARR(PlayerAI, wagon_list,        SLE_UINT16, 9),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4049
	    SLE_ARR(PlayerAI, order_list_blocks, SLE_UINT8, 20),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4050
	    SLE_ARR(PlayerAI, banned_tiles,      SLE_UINT16, 16),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4051
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4052
	SLE_CONDNULL(64, 2, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4053
	SLE_END()
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4054
};
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4055
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4056
static const SaveLoad _player_ai_build_rec_desc[] = {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4057
	SLE_CONDVAR(AiBuildRec, spec_tile,         SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4058
	SLE_CONDVAR(AiBuildRec, spec_tile,         SLE_UINT32,                 6, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4059
	SLE_CONDVAR(AiBuildRec, use_tile,          SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4060
	SLE_CONDVAR(AiBuildRec, use_tile,          SLE_UINT32,                 6, SL_MAX_VERSION),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4061
	    SLE_VAR(AiBuildRec, rand_rng,          SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4062
	    SLE_VAR(AiBuildRec, cur_building_rule, SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4063
	    SLE_VAR(AiBuildRec, unk6,              SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4064
	    SLE_VAR(AiBuildRec, unk7,              SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4065
	    SLE_VAR(AiBuildRec, buildcmd_a,        SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4066
	    SLE_VAR(AiBuildRec, buildcmd_b,        SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4067
	    SLE_VAR(AiBuildRec, direction,         SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4068
	    SLE_VAR(AiBuildRec, cargo,             SLE_UINT8),
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4069
	SLE_END()
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4070
};
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4071
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4072
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4073
void SaveLoad_AI(PlayerID id)
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4074
{
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4075
	PlayerAI *pai = &_players_ai[id];
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4076
	SlObject(pai, _player_ai_desc);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4077
	for (int i = 0; i != pai->num_build_rec; i++) {
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4078
		SlObject(&pai->src + i, _player_ai_build_rec_desc);
00e7467ceeee (svn r11792) -Codechange: move some (virtually) globally included AI related structs to a place where they are only included a few times.
rubidium
parents: 8144
diff changeset
  4079
	}
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
  4080
}