roadveh_cmd.c
author tron
Sun, 18 Dec 2005 12:10:46 +0000
changeset 2767 3282c77ffc27
parent 2760 29be62b09f09
child 2804 b932fe148d36
permissions -rw-r--r--
(svn r3313) Remove GPMI related changes from trunk
Revisions in detail: 2542, 3226 (partial), 3229, 3231, 3232, 3238, 3242-3245, 3251, 3253, 3260, 3263, 3265, 3266, 3269, 3277, 3278, 3279, 3283 (partial), 3304, 3305, 3306
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1793
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1295
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2150
diff changeset
     6
#include "functions.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 493
diff changeset
     7
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 593
diff changeset
     8
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1206
diff changeset
     9
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "pathfind.h"
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
    16
#include "npf.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "player.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 241
diff changeset
    18
#include "sound.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    19
#include "depot.h"
1752
cdbfb2f23e72 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1745
diff changeset
    20
#include "vehicle_gui.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
void ShowRoadVehViewWindow(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
static const uint16 _roadveh_images[63] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
static const uint16 _roadveh_full_adder[63] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
    0,  88,   0,   0,   0,   0,  48,  48,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
   48,  48,   0,   0,  64,  64,   0,  16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
   16,   0,  88,   0,   0,   0,   0,  48,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
   48,  48,  48,   0,   0,  64,  64,   0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
   16,  16,   0,  88,   0,   0,   0,   0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
   48,  48,  48,  48,   0,   0,  64,  64,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
    0,  16,  16,   0,   8,   8,   8,   8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
    0,   0,   0,   8,   8,   8,   8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
static const uint16 _road_veh_fp_ax_or[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	0x100,0x200,1,2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
static const uint16 _road_veh_fp_ax_and[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	0x1009, 0x16, 0x520, 0x2A00
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
static const byte _road_reverse_table[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	6, 7, 14, 15
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
static const uint16 _road_pf_table_3[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	0x910, 0x1600, 0x2005, 0x2A
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
    63
int GetRoadVehImage(const Vehicle *v, byte direction)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	int img = v->spritenum;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	int image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	if (is_custom_sprite(img)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
		image = GetCustomVehicleSprite(v, direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
		if (image) return image;
2464
3dee59d241c0 (svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents: 2260
diff changeset
    71
		img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
    73
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	image = direction + _roadveh_images[img];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	if (v->cargo_count >= (v->cargo_cap >> 1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
		image += _roadveh_full_adder[img];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	return image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2464
diff changeset
    80
void DrawRoadVehEngine(int x, int y, EngineID engine, uint32 image_ormod)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
{
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
    82
	int spritenum = RoadVehInfo(engine)->image_index;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    83
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    84
	if (is_custom_sprite(spritenum)) {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    85
		int sprite = GetCustomVehicleIcon(engine, 6);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    86
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    87
		if (sprite) {
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    88
			DrawSprite(sprite | image_ormod, x, y);
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    89
			return;
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    90
		}
2464
3dee59d241c0 (svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents: 2260
diff changeset
    91
		spritenum = orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index;
378
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    92
	}
9f170b63d48e (svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents: 374
diff changeset
    93
	DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
    96
int32 EstimateRoadVehCost(EngineID engine_type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
{
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
    98
	return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   101
/** Build a road vehicle.
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   102
 * @param x,y tile coordinates of depot where road vehicle is built
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   103
 * @param p1 bus/truck type being built (engine)
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   104
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   105
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	Vehicle *v;
1282
e7a73ee62d2f (svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents: 1266
diff changeset
   110
	UnitID unit_num;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   111
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
	Engine *e;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   113
1197
4322cf8d6ae7 (svn r1701) Style police ^^
tron
parents: 1196
diff changeset
   114
	if (!IsEngineBuildable(p1, VEH_Road)) return CMD_ERROR;
1196
115f46e3807d (svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents: 1151
diff changeset
   115
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	cost = EstimateRoadVehCost(p1);
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   119
	if (flags & DC_QUERY_COST) return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
1442
3e0ac5f13ee2 (svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents: 1401
diff changeset
   121
	/* The ai_new queries the vehicle cost before building the route,
3e0ac5f13ee2 (svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents: 1401
diff changeset
   122
	 * so we must check against cheaters no sooner than now. --pasky */
3e0ac5f13ee2 (svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents: 1401
diff changeset
   123
	if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR;
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   124
	if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
1442
3e0ac5f13ee2 (svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents: 1401
diff changeset
   125
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	v = AllocateVehicle();
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   127
	if (v == NULL || IsOrderPoolFull())
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	/* find the first free roadveh id */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	unit_num = GetFreeUnitNumber(VEH_Road);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	if (unit_num > _patches.max_roadveh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	if (flags & DC_EXEC) {
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   136
		const RoadVehicleInfo *rvi = RoadVehInfo(p1);
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   137
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
		v->unitnumber = unit_num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
		v->direction = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
		v->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		v->tile = tile;
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   143
		x = TileX(tile) * 16 + 8;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   144
		y = TileY(tile) * 16 + 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
		v->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
		v->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
		v->z_pos = GetSlopeZ(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		v->z_height = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
		v->u.road.state = 254;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
		v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   153
		v->spritenum = rvi->image_index;
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   154
		v->cargo_type = rvi->cargo_type;
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   155
		v->cargo_cap = rvi->capacity;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
//		v->cargo_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		v->value = cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
//		v->day_counter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
//		v->next_order_param = v->next_order = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
//		v->load_unload_time_rem = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
//		v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
//	v->u.road.unk2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
//	v->u.road.overtaking = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   166
		v->u.road.slot = NULL;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   167
		v->u.road.slotindex = 0;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   168
		v->u.road.slot_age = 0;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   169
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1247
diff changeset
   170
		v->last_station_visited = INVALID_STATION;
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
   171
		v->max_speed = rvi->max_speed;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		v->engine_type = (byte)p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1901
diff changeset
   174
		e = GetEngine(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
		v->reliability = e->reliability;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
		v->reliability_spd_dec = e->reliability_spd_dec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
		v->max_age = e->lifelength * 366;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
		_new_roadveh_id = v->index;
2564
371e0fa97e1e (svn r3101) -Codechange: added _new_vehicle_id
bjarni
parents: 2552
diff changeset
   179
		_new_vehicle_id = v->index;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   180
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
		v->string_id = STR_SV_ROADVEH_NAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
		v->service_interval = _patches.servint_roadveh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
		v->date_of_last_service = _date;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
		v->build_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
		v->type = VEH_Road;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		v->cur_image = 0xC15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   194
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
		InvalidateWindow(WC_COMPANY, v->owner);
2618
7546b838230b (svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents: 2574
diff changeset
   196
		if (IsLocalPlayer())
7546b838230b (svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents: 2574
diff changeset
   197
			InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   203
/** Start/Stop a road vehicle.
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   204
 * @param x,y unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   205
 * @param p1 road vehicle ID to start/stop
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   206
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   207
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
int32 CmdStartStopRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   212
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   213
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 904
diff changeset
   214
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   216
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		v->vehstatus ^= VS_STOPPED;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
   220
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
1680
0ca4f679c154 (svn r2184) - CodeChange: remove the copy of ClearSlot(), which is now also called for CmdSkipOrder(). This also fixes the involuntary crash introduced 2 revisions ago
Darkvater
parents: 1665
diff changeset
   227
void ClearSlot(Vehicle *v, RoadStop *rs)
1664
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   228
{
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   229
	DEBUG(ms, 3) ("Multistop: Clearing slot %d at 0x%x", v->u.road.slotindex, rs->xy);
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   230
	v->u.road.slot = NULL;
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   231
	v->u.road.slot_age = 0;
1680
0ca4f679c154 (svn r2184) - CodeChange: remove the copy of ClearSlot(), which is now also called for CmdSkipOrder(). This also fixes the involuntary crash introduced 2 revisions ago
Darkvater
parents: 1665
diff changeset
   232
	if (rs != NULL) {
0ca4f679c154 (svn r2184) - CodeChange: remove the copy of ClearSlot(), which is now also called for CmdSkipOrder(). This also fixes the involuntary crash introduced 2 revisions ago
Darkvater
parents: 1665
diff changeset
   233
		// check that the slot is indeed assigned to the same vehicle
0ca4f679c154 (svn r2184) - CodeChange: remove the copy of ClearSlot(), which is now also called for CmdSkipOrder(). This also fixes the involuntary crash introduced 2 revisions ago
Darkvater
parents: 1665
diff changeset
   234
		assert(rs->slot[v->u.road.slotindex] == v->index);
1664
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   235
		rs->slot[v->u.road.slotindex] = INVALID_SLOT;
1680
0ca4f679c154 (svn r2184) - CodeChange: remove the copy of ClearSlot(), which is now also called for CmdSkipOrder(). This also fixes the involuntary crash introduced 2 revisions ago
Darkvater
parents: 1665
diff changeset
   236
 }
1664
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   237
}
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   238
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   239
/** Sell a road vehicle.
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   240
 * @param x,y unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   241
 * @param p1 vehicle ID to be sold
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   242
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   243
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   248
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   249
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 904
diff changeset
   250
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   252
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   254
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   255
1330
8a67d04016ce (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1313
diff changeset
   256
	if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
		return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   258
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		// Invalidate depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   262
		RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		InvalidateWindow(WC_COMPANY, v->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
		DeleteWindowById(WC_VEHICLE_VIEW, v->index);
1664
000099fbae6e (svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents: 1530
diff changeset
   265
		ClearSlot(v, v->u.road.slot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
		DeleteVehicle(v);
2618
7546b838230b (svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents: 2574
diff changeset
   267
		if (IsLocalPlayer())
7546b838230b (svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents: 2574
diff changeset
   268
			InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   270
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	return -(int32)v->value;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
typedef struct RoadFindDepotData {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	uint best_length;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   276
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	byte owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
} RoadFindDepotData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
static const byte _road_pf_directions[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	0, 1, 0, 1, 2, 1, 255, 255,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	2, 3, 3, 2, 3, 0, 255, 255,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   285
static bool EnumRoadSignalFindDepot(TileIndex tile, RoadFindDepotData *rfdd, int track, uint length, byte *state)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
{
904
bff808a1c7f0 (svn r1390) Use TileOffsByDir() instead of home brewed table
tron
parents: 900
diff changeset
   287
	tile += TileOffsByDir(_road_pf_directions[track]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
   289
	if (IsTileType(tile, MP_STREET) &&
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2484
diff changeset
   290
			GB(_m[tile].m5, 4, 4) == 2 &&
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   291
			IsTileOwner(tile, rfdd->owner)) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   292
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		if (length < rfdd->best_length) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
			rfdd->best_length = length;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
			rfdd->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   301
static Depot *FindClosestRoadDepot(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   303
	TileIndex tile = v->tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	int i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   305
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2493
diff changeset
   306
	if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   308
	if (_patches.new_pathfinding_all) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   309
		NPFFoundTargetData ftd;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   310
		/* See where we are now */
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1935
diff changeset
   311
		Trackdir trackdir = GetVehicleTrackdir(v);
1745
2dcc0a66d91d (svn r2249) - Fix: [ 1187703 ] [NPF] Road vehicles cannot find a depot when in a roadstop
matthijs
parents: 1709
diff changeset
   312
2006
324916f22a8a (svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents: 1998
diff changeset
   313
		ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE);
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   314
		if (ftd.best_bird_dist == 0)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   315
			return GetDepotByTile(ftd.node.tile); /* Target found */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   316
		else
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   317
			return NULL; /* Target not found */
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   318
		/* We do not search in two directions here, why should we? We can't reverse right now can we? */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   319
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   320
		RoadFindDepotData rfdd;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   321
		rfdd.owner = v->owner;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   322
		rfdd.best_length = (uint)-1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   324
		/* search in all directions */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   325
		for(i=0; i!=4; i++)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   326
			FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   328
		if (rfdd.best_length == (uint)-1)
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   329
			return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   331
		return GetDepotByTile(rfdd.tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   332
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   335
/** Send a road vehicle to the depot.
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   336
 * @param x,y unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   337
 * @param p1 vehicle ID to send to the depot
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   338
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   339
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
{
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   342
	Vehicle *v;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   343
	const Depot *dep;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   345
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   346
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   347
	v = GetVehicle(p1);
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   348
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   349
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   351
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
1757
b179d50241dc (svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents: 1752
diff changeset
   352
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   353
	/* If the current orders are already goto-depot */
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   354
	if (v->current_order.type == OT_GOTO_DEPOT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
		if (flags & DC_EXEC) {
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   356
			/* If the orders to 'goto depot' are in the orders list (forced servicing),
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   357
			 * then skip to the next order; effectively cancelling this forced service */
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
   358
			if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
				v->cur_order_index++;
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
   360
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   361
			v->current_order.type = OT_DUMMY;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   362
			v->current_order.flags = 0;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
   363
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   368
	dep = FindClosestRoadDepot(v);
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   369
	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	if (flags & DC_EXEC) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   372
		v->current_order.type = OT_GOTO_DEPOT;
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
   373
		v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   374
		v->current_order.station = dep->index;
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   375
		v->dest_tile = dep->xy;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
   376
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   378
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   382
/** Turn a roadvehicle around.
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   383
 * @param x,y unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   384
 * @param p1 vehicle ID to turn
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   385
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   386
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   391
	if (!IsVehicleIndex(p1)) return CMD_ERROR;
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   392
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 904
diff changeset
   393
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1790
diff changeset
   395
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	if (v->vehstatus & (VS_HIDDEN|VS_STOPPED) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			v->u.road.crashed_ctr != 0 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
			v->breakdown_ctr != 0 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
			v->u.road.overtaking != 0 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
			v->cur_speed < 5) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   404
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
		v->u.road.reverse_ctr = 180;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   407
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   412
/** Change the service interval for road vehicles.
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   413
 * @param x,y unused
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   414
 * @param p1 vehicle ID that is being service-interval-changed
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   415
 * @param p2 new service interval
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   416
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	Vehicle *v;
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   420
	uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   422
	if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR;
1237
0a1ce05c3d45 (svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents: 1232
diff changeset
   423
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 904
diff changeset
   424
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   426
	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	if (flags & DC_EXEC) {
1790
4afb4b4e4278 (svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents: 1769
diff changeset
   429
		v->service_interval = serv_int;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
		InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
static void MarkRoadVehDirty(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	v->cur_image = GetRoadVehImage(v, v->direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
	MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
static void UpdateRoadVehDeltaXY(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	static const uint32 _delta_xy_table[8] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
		MKIT(3, 3, -1, -1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
		MKIT(3, 7, -1, -3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
		MKIT(3, 3, -1, -1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
		MKIT(7, 3, -3, -1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
		MKIT(3, 3, -1, -1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
		MKIT(3, 7, -1, -3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		MKIT(3, 3, -1, -1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		MKIT(7, 3, -3, -1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
#undef MKIT
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
	uint32 x = _delta_xy_table[v->direction];
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2107
diff changeset
   458
	v->x_offs        = GB(x,  0, 8);
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2107
diff changeset
   459
	v->y_offs        = GB(x,  8, 8);
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2107
diff changeset
   460
	v->sprite_width  = GB(x, 16, 8);
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2107
diff changeset
   461
	v->sprite_height = GB(x, 24, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
static void ClearCrashedStation(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
{
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2662
diff changeset
   466
	RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	// mark station as not busy
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2662
diff changeset
   469
	CLRBIT(rs->status, 7);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   470
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	// free parking bay
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2662
diff changeset
   472
	SETBIT(rs->status, HASBIT(v->u.road.state, 1) ? 1 : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
static void RoadVehDelete(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   479
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 578
diff changeset
   480
	RebuildVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	InvalidateWindow(WC_COMPANY, v->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
   483
	if (IsTileType(v->tile, MP_STATION))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
		ClearCrashedStation(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   485
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	EndVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   488
1665
502e6aa3e60b (svn r2169) -Fix: Doing the slot clearing also for crashed road vehicles (c.f. previous commit)
celestar
parents: 1664
diff changeset
   489
	ClearSlot(v, v->u.road.slot);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
static byte SetRoadVehPosition(Vehicle *v, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	byte new_z, old_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
	// need this hint so it returns the right z coordinate on bridges.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	_get_z_hint = v->z_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
	new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	_get_z_hint = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
	old_z = v->z_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	v->z_pos = new_z;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   504
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
	VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
	EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	return old_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
static void RoadVehSetRandomDirection(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	static const int8 _turn_prob[4] = { -1, 0, 0, 1 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	v->direction = (v->direction+_turn_prob[r&3])&7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	v->cur_image = GetRoadVehImage(v, v->direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
	SetRoadVehPosition(v, v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
static void RoadVehIsCrashed(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	v->u.road.crashed_ctr++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
	if (v->u.road.crashed_ctr == 2) {
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1330
diff changeset
   525
		CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	} else if (v->u.road.crashed_ctr <= 45) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
		if ((v->tick_counter&7)==0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
			RoadVehSetRandomDirection(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	} else if (v->u.road.crashed_ctr >= 2220) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		RoadVehDelete(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
	if (v->type != VEH_Train ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
			myabs(v->z_pos - u->z_pos) > 6 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
			myabs(v->x_pos - u->x_pos) > 4 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
			myabs(v->y_pos - u->y_pos) > 4)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
				return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
static void RoadVehCrash(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	uint16 pass;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
	v->u.road.crashed_ctr++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	v->vehstatus |= VS_CRASHED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
   551
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	pass = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	if (v->cargo_type == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
		pass += v->cargo_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	v->cargo_count = 0;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   557
	SetDParam(0, pass);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
2260
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2214
diff changeset
   559
	AddNewsItem(
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2214
diff changeset
   560
		(pass == 1) ?
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2214
diff changeset
   561
			STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
		v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
		0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
	ModifyStationRatingAround(v->tile, v->owner, -160, 22);
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 538
diff changeset
   567
	SndPlayVehicleFx(SND_12_EXPLOSION, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
static void RoadVehCheckTrainCrash(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   572
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	if (v->u.road.state == 255)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
	tile = v->tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
	// Make sure it's a road/rail crossing
1927
4126e0e3e884 (svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents: 1926
diff changeset
   580
	if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile))
4126e0e3e884 (svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents: 1926
diff changeset
   581
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
		RoadVehCrash(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
static void HandleBrokenRoadVeh(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	if (v->breakdown_ctr != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
		v->breakdown_ctr = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
		v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
		if (v->breakdowns_since_last_service != 255)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
			v->breakdowns_since_last_service++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   595
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   598
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 538
diff changeset
   599
		SndPlayVehicleFx((_opt.landscape != LT_CANDY) ?
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 538
diff changeset
   600
			SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
		if (!(v->vehstatus & VS_HIDDEN)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
			if (u)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
				u->u.special.unk0 = v->breakdown_delay * 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	if (!(v->tick_counter & 1)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
		if (!--v->breakdown_delay) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
			v->breakdown_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			InvalidateWindow(WC_VEHICLE_VIEW, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
static void ProcessRoadVehOrder(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
{
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   619
	const Order *order;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   620
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   622
	if (v->current_order.type >= OT_GOTO_DEPOT && v->current_order.type <= OT_LEAVESTATION) {
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   623
		// Let a depot order in the orderlist interrupt.
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   624
		if (v->current_order.type != OT_GOTO_DEPOT ||
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   625
				!(v->current_order.flags & OF_UNLOAD))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   629
	if (v->current_order.type == OT_GOTO_DEPOT &&
2214
75d037f8dcc4 (svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents: 2186
diff changeset
   630
			(v->current_order.flags & (OF_PART_OF_ORDERS | OF_SERVICE_IF_NEEDED)) == (OF_PART_OF_ORDERS | OF_SERVICE_IF_NEEDED) &&
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1467
diff changeset
   631
			!VehicleNeedsService(v)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
		v->cur_order_index++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	if (v->cur_order_index >= v->num_orders)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
		v->cur_order_index = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   638
	order = GetVehicleOrder(v, v->cur_order_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   640
	if (order == NULL) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   641
		v->current_order.type = OT_NOTHING;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   642
		v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
		v->dest_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   647
	if (order->type    == v->current_order.type &&
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   648
			order->flags   == v->current_order.flags &&
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   649
			order->station == v->current_order.station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   652
	v->current_order = *order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	v->dest_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   656
	if (order->type == OT_GOTO_STATION) {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   657
		if (order->station == v->last_station_visited)
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1247
diff changeset
   658
			v->last_station_visited = INVALID_STATION;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   659
		st = GetStation(order->station);
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   660
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   661
		{
1709
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
   662
			uint mindist = 0xFFFFFFFF;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   663
			RoadStopType type;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   664
			RoadStop *rs;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   665
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   666
			type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   667
			rs = GetPrimaryRoadStop(st, type);
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   668
1231
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   669
			if (rs == NULL) {
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   670
				//There is no stop left at the station, so don't even TRY to go there
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   671
				v->cur_order_index++;
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   672
				InvalidateVehicleOrder(v);
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   673
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   674
				return;
64cc1f5c1c82 (svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents: 1224
diff changeset
   675
			}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   676
1709
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
   677
			for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) {
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
   678
				if (DistanceManhattan(v->tile, rs->xy) < mindist) {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   679
					v->dest_tile = rs->xy;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   680
				}
1709
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
   681
			}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   682
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
   683
		}
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   684
	} else if (order->type == OT_GOTO_DEPOT) {
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   685
		v->dest_tile = GetDepot(order->station)->xy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   688
	InvalidateVehicleOrder(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
static void HandleRoadVehLoading(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
{
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   693
	if (v->current_order.type == OT_NOTHING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   695
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   696
	if (v->current_order.type != OT_DUMMY) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   697
		if (v->current_order.type != OT_LOADING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
		if (--v->load_unload_time_rem)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   703
		if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
			SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
			if (LoadUnloadVehicle(v)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
				InvalidateWindow(WC_ROADVEH_LIST, v->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
				MarkRoadVehDirty(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   711
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
		{
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   713
			Order b = v->current_order;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   714
			v->current_order.type = OT_LEAVESTATION;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   715
			v->current_order.flags = 0;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
   716
			if (!(b.flags & OF_NON_STOP))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
	v->cur_order_index++;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
   722
	InvalidateVehicleOrder(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
static void StartRoadVehSound(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
{
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 538
diff changeset
   727
	SoundFx s = RoadVehInfo(v->engine_type)->sfx;
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 538
diff changeset
   728
	if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0)
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 538
diff changeset
   729
		s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	SndPlayVehicleFx(s, v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
typedef struct RoadVehFindData {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
	Vehicle *veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	byte dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
} RoadVehFindData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   739
static void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   741
	static const short _dists[] = {
63
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   742
		-4, -8, -4, -1, 4, 8, 4, 1,
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   743
		-4, -1, 4, 8, 4, 1, -4, -8,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
	};
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   745
63
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   746
	short x_diff = v->x_pos - rvf->x;
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   747
	short y_diff = v->y_pos - rvf->y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   749
	if (rvf->veh == v ||
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   750
			v->type != VEH_Road ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
			v->u.road.state == 254 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
			myabs(v->z_pos - rvf->veh->z_pos) > 6 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
			v->direction != rvf->dir ||
63
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   754
			(_dists[v->direction] < 0 && (x_diff <= _dists[v->direction] || x_diff > 0)) ||
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   755
			(_dists[v->direction] > 0 && (x_diff >= _dists[v->direction] || x_diff < 0)) ||
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   756
			(_dists[v->direction+8] < 0 && (y_diff <= _dists[v->direction+8] || y_diff > 0)) ||
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   757
			(_dists[v->direction+8] > 0 && (y_diff >= _dists[v->direction+8] || y_diff < 0)))
1151
614cbcb5b9fe (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1128
diff changeset
   758
				return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
	RoadVehFindData rvf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
	if (v->u.road.reverse_ctr != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
		return NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   770
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	rvf.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	rvf.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	rvf.dir = dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	rvf.veh = v;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
   775
	u = VehicleFromPos(TileVirtXY(x, y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   776
63
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   777
	// This code protects a roadvehicle from being blocked for ever
826
0e2b569b737b (svn r1297) Language fixes in the source.. (ln-)
miham
parents: 817
diff changeset
   778
	//  If more than 1480 / 74 days a road vehicle is blocked, it will
63
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   779
	//  drive just through it. The ultimate backup-code of TTD.
53cc59601b3c (svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents: 19
diff changeset
   780
	// It can be disabled.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	if (u == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
		v->u.road.unk2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
	if (++v->u.road.unk2 > 1480)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
		return NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   788
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	return u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2618
diff changeset
   792
static void RoadVehArrivesAt(const Vehicle* v, Station* st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
{
2550
5e405f5b2836 (svn r3079) Determine the type of the "first arrival" message for road vehicles using the cargo type and not a magic engine number
tron
parents: 2549
diff changeset
   794
	if (v->cargo_type == CT_PASSENGERS) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
		/* Check if station was ever visited before */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
		if (!(st->had_vehicle_of_type & HVOT_BUS)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
			uint32 flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
			st->had_vehicle_of_type |= HVOT_BUS;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   800
			SetDParam(0, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
			flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
			AddNewsItem(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
				STR_902F_CITIZENS_CELEBRATE_FIRST,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
				flags,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
				v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
				0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		/* Check if station was ever visited before */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
		if (!(st->had_vehicle_of_type & HVOT_TRUCK)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
			uint32 flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
			st->had_vehicle_of_type |= HVOT_TRUCK;
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   814
			SetDParam(0, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
			flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
			AddNewsItem(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
				STR_9030_CITIZENS_CELEBRATE_FIRST,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
				flags,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
				v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
				0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
static bool RoadVehAccelerate(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
	byte t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   829
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	// Clamp
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	spd = min(spd, v->max_speed);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	//updates statusbar only if speed have changed to save CPU time
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
	if (spd != v->cur_speed) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   835
		v->cur_speed = spd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
		if (_patches.vehicle_speed)
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
   837
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	// Decrease somewhat when turning
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
	if (!(v->direction&1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		spd = spd * 3 >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	if (spd == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
	if ((byte)++spd == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
	v->progress = (t = v->progress) - (byte)spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
	return (t < v->progress);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
static byte RoadVehGetNewDirection(Vehicle *v, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	static const byte _roadveh_new_dir[11] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		0, 7, 6, 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		1, 0, 5, 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
		2, 3, 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	};
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   862
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	x = x - v->x_pos + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	y = y - v->y_pos + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	if ((uint)x > 2 || (uint)y > 2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
		return v->direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
	return _roadveh_new_dir[y*4+x];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
static byte RoadVehGetSlidingDirection(Vehicle *v, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	byte b = RoadVehGetNewDirection(v,x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	byte d = v->direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
	if (b == d) return d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	d = (d+1)&7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	if (b==d) return d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	d = (d-2)&7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	if (b==d) return d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	if (b==((d-1)&7)) return d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	if (b==((d-2)&7)) return d;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   882
	return (d+2)&7;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
typedef struct OvertakeData {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	Vehicle *u, *v;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   887
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	byte tilebits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
} OvertakeData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   891
static void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
{
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1980
diff changeset
   893
	if (v->tile != od->tile || v->type != VEH_Road || v == od->u || v == od->v)
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1980
diff changeset
   894
		return NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   895
	return v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
static bool FindRoadVehToOvertake(OvertakeData *od)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	uint32 bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 156
diff changeset
   902
	bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	return VehicleFromPos(od->tile, od, (VehicleFromPosProc*)EnumFindVehToOvertake) != NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	OvertakeData od;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	byte tt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	od.v = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	od.u = u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
	if (u->max_speed >= v->max_speed &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
			!(u->vehstatus&VS_STOPPED) &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
			u->cur_speed != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	if (v->direction != u->direction || !(v->direction&1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
	if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2107
diff changeset
   928
	tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	if ((tt & 3) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	if ((tt & 0x3C) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	if (tt == 3) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
		tt = (v->direction&2)?2:1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	od.tilebits = tt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	od.tile = v->tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	if (FindRoadVehToOvertake(&od))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
900
feed1801fd35 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 842
diff changeset
   943
	od.tile = v->tile + TileOffsByDir(v->direction >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	if (FindRoadVehToOvertake(&od))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
		v->u.road.overtaking_ctr = 0x11;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		v->u.road.overtaking = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
//		if (FindRoadVehToOvertake(&od))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
//			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
		v->u.road.overtaking_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
		v->u.road.overtaking = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	if (old_z == v->z_pos)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	if (old_z < v->z_pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
		v->cur_speed = v->cur_speed * 232 >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
		uint16 spd = v->cur_speed + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
		if (spd <= v->max_speed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
			v->cur_speed = spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
static int PickRandomBit(uint bits)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
	uint num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	uint b = bits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		if (b & 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
			num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
	} while (b >>= 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
2637
8807e6a63f89 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2630
diff changeset
   983
	num = RandomRange(num);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
	for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	TileIndex dest;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	uint maxtracklen;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	uint mindist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
} FindRoadToChooseData;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   995
static bool EnumRoadTrackFindDist(TileIndex tile, FindRoadToChooseData *frd, int track, uint length, byte *state)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
{
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1239
diff changeset
   997
	uint dist = DistanceManhattan(tile, frd->dest);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	if (dist <= frd->mindist) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
		if (dist != frd->mindist || length < frd->maxtracklen) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
			frd->maxtracklen = length;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
		frd->mindist = dist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
// Returns direction to choose
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
// or -1 if the direction is currently blocked
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1009
static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
#define return_track(x) {best_track = x; goto found_best_track; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
	uint16 signal;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	uint bitmask;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1015
	TileIndex desttile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	FindRoadToChooseData frd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	int best_track;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	uint best_dist, best_maxlen;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
		uint32 r;
241
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1024
		r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
  1025
		signal  = GB(r, 16, 16);
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2477
diff changeset
  1026
		bitmask = GB(r,  0, 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
  1029
	if (IsTileType(tile, MP_STREET)) {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2493
diff changeset
  1030
		if (GB(_m[tile].m5, 4, 4) == 2 && IsTileOwner(tile, v->owner)) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2493
diff changeset
  1031
			/* Road depot */
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2493
diff changeset
  1032
			bitmask |= _road_veh_fp_ax_or[GB(_m[tile].m5, 0, 2)];
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2493
diff changeset
  1033
		}
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
  1034
	} else if (IsTileType(tile, MP_STATION)) {
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1035
		if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) {
241
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1036
			/* Our station */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2493
diff changeset
  1037
			const Station* st = GetStation(_m[tile].m2);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1038
			byte val = _m[tile].m5;
241
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1039
			if (v->cargo_type != CT_PASSENGERS) {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1040
				if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3))
241
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1041
					bitmask |= _road_veh_fp_ax_or[(val-0x43)&3];
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1042
			} else {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1043
				if (IS_BYTE_INSIDE(val, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stops->status&3))
241
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1044
					bitmask |= _road_veh_fp_ax_or[(val-0x47)&3];
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1045
			}
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1046
		}
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1047
	}
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1048
	/* The above lookups should be moved to GetTileTrackStatus in the
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1049
	 * future, but that requires more changes to the pathfinder and other
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1050
	 * stuff, probably even more arguments to GTTS.
e6e62a5e7f52 (svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents: 193
diff changeset
  1051
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 156
diff changeset
  1053
	/* remove unreachable tracks */
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1054
	bitmask &= _road_veh_fp_ax_and[enterdir];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	if (bitmask == 0) {
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1056
		/* No reachable tracks, so we'll reverse */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1057
		return_track(_road_reverse_table[enterdir]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	if (v->u.road.reverse_ctr != 0) {
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1061
		/* What happens here?? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
		v->u.road.reverse_ctr = 0;
1986
5dd3db2b86d7 (svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents: 1980
diff changeset
  1063
		if (v->tile != tile) {
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1064
			return_track(_road_reverse_table[enterdir]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	desttile = v->dest_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	if (desttile == 0) {
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1070
		// Pick a random track
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
		return_track(PickRandomBit(bitmask));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1074
	// Only one track to choose between?
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1075
	if (!(KillFirstBit2x64(bitmask))) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
		return_track(FindFirstBit2x64(bitmask));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1079
	if (_patches.new_pathfinding_all) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1080
		NPFFindStationOrTileData fstd;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1081
		NPFFoundTargetData ftd;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1082
		byte trackdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1083
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1084
		NPFFillWithOrderData(&fstd, v);
1942
634961366cdc (svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents: 1935
diff changeset
  1085
		trackdir = DiagdirToDiagTrackdir(enterdir);
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1086
		//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1087
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
  1088
		ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE, PBS_MODE_NONE);
1698
bf364c664a60 (svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents: 1680
diff changeset
  1089
		if (ftd.best_trackdir == 0xff) {
bf364c664a60 (svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents: 1680
diff changeset
  1090
			/* We are already at our target. Just do something */
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1091
			//TODO: maybe display error?
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1092
			//TODO: go straight ahead if possible?
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1093
			return_track(FindFirstBit2x64(bitmask));
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1094
		} else {
1698
bf364c664a60 (svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents: 1680
diff changeset
  1095
			/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains
bf364c664a60 (svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents: 1680
diff changeset
  1096
			the direction we need to take to get there, if ftd.best_bird_dist is not 0,
bf364c664a60 (svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents: 1680
diff changeset
  1097
			we did not find our target, but ftd.best_trackdir contains the direction leading
bf364c664a60 (svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents: 1680
diff changeset
  1098
			to the tile closest to our target. */
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1099
			return_track(ftd.best_trackdir);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1100
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1101
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1102
		if (IsTileType(desttile, MP_STREET)) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1103
			m5 = _m[desttile].m5;
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1104
			if ((m5&0xF0) == 0x20)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1105
				/* We are heading for a Depot */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1106
				goto do_it;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1107
		} else if (IsTileType(desttile, MP_STATION)) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1108
			m5 = _m[desttile].m5;
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1109
			if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1110
				/* We are heading for a station */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1111
				m5 -= 0x43;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
do_it:;
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1113
				/* When we are heading for a depot or station, we just
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1114
				 * pretend we are heading for the tile in front, we'll
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1115
				 * see from there */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1116
				desttile += TileOffsByDir(m5 & 3);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1117
				if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1118
					/* If we are already in front of the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1119
					 * station/depot and we can get in from here,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1120
					 * we enter */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1121
					return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3]));
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1122
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1124
		}
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1125
		// do pathfind
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1126
		frd.dest = desttile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1128
		best_track = -1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1129
		best_dist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1130
		best_maxlen = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1131
		i = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1132
		do {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1133
			if (bitmask & 1) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1134
				if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1135
				frd.maxtracklen = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1136
				frd.mindist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1137
				FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1139
				if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1140
					best_dist = frd.mindist;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1141
					best_maxlen = frd.maxtracklen;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1142
					best_track = i;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1143
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
			}
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1145
		} while (++i,(bitmask>>=1) != 0);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1146
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
found_best_track:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	if (HASBIT(signal, best_track))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
		return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1153
	return best_track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
2107
607a900aefa3 (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2094
diff changeset
  1156
#if 0
1709
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
  1157
static uint RoadFindPathToStation(const Vehicle *v, TileIndex tile)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1158
{
1709
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
  1159
  NPFFindStationOrTileData fstd;
1752
cdbfb2f23e72 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1745
diff changeset
  1160
  byte trackdir = GetVehicleTrackdir(v);
cdbfb2f23e72 (svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents: 1745
diff changeset
  1161
	assert(trackdir != 0xFF);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1162
1709
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
  1163
  fstd.dest_coords = tile;
80b108681ff1 (svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents: 1698
diff changeset
  1164
  fstd.station_index = -1;	// indicates that the destination is a tile, not a station
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1165
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 2006
diff changeset
  1166
  return NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE, PBS_MODE_NONE).best_path_dist;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1167
}
2107
607a900aefa3 (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2094
diff changeset
  1168
#endif
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1169
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
typedef struct RoadDriveEntry {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	byte x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
} RoadDriveEntry;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
#include "table/roadveh.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
static const byte _road_veh_data_1[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	20, 20, 16, 16, 0, 0, 0, 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
	19, 19, 15, 15, 0, 0, 0, 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	16, 16, 12, 12, 0, 0, 0, 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
	15, 15, 11, 11
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
static const byte _roadveh_data_2[4] = { 0,1,8,9 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
1401
56d372a75b74 (svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents: 1359
diff changeset
  1185
static void RoadVehController(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
	GetNewVehiclePosResult gp;
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1188
	byte new_dir, old_dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
	RoadDriveEntry rd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	// decrease counters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	v->tick_counter++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
	if (v->u.road.reverse_ctr != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
		v->u.road.reverse_ctr--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
	// handle crashed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	if (v->u.road.crashed_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
		RoadVehIsCrashed(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	RoadVehCheckTrainCrash(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	// road vehicle has broken down?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	if (v->breakdown_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
		if (v->breakdown_ctr <= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
			HandleBrokenRoadVeh(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
		v->breakdown_ctr--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	// exit if vehicle is stopped
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	if (v->vehstatus & VS_STOPPED)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	ProcessRoadVehOrder(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
	HandleRoadVehLoading(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1224
	if (v->current_order.type == OT_LOADING)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
	if (v->u.road.state == 254) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
		int dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
		const RoadDriveEntry*rdp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
		byte rd2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
		v->cur_speed = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1233
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2484
diff changeset
  1234
		dir = GB(_m[v->tile].m5, 0, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
		v->direction = dir*2+1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
		rd2 = _roadveh_data_2[dir];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
		rdp = _road_drive_data[(_opt.road_side<<4) + rd2];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1239
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1240
		x = TileX(v->tile) * 16 + (rdp[6].x & 0xF);
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1241
		y = TileY(v->tile) * 16 + (rdp[6].y & 0xF);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
		if (RoadVehFindCloseTo(v,x,y,v->direction))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
578
86e352980acd (svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents: 555
diff changeset
  1246
		VehicleServiceInDepot(v);
86e352980acd (svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents: 555
diff changeset
  1247
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
		StartRoadVehSound(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
		v->vehstatus &= ~VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
		v->u.road.state = rd2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
		v->u.road.frame = 6;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		v->cur_image = GetRoadVehImage(v, v->direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
		UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
		SetRoadVehPosition(v,x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
	if (!RoadVehAccelerate(v))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
	if (v->u.road.overtaking != 0)  {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
		if (++v->u.road.overtaking_ctr >= 35)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
			v->u.road.overtaking = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	if (v->u.road.state == 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
		GetNewVehiclePos(v, &gp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
		if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
  1282
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) &&
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2484
diff changeset
  1283
				GB(_m[gp.new_tile].m5, 4, 4) == 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
				(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&4)) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1285
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
			//new_dir = RoadGetNewDirection(v, gp.x, gp.y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
			v->cur_image = GetRoadVehImage(v, v->direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
			UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
			SetRoadVehPosition(v,gp.x,gp.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
		v->x_pos = gp.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
		v->y_pos = gp.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
	rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
// switch to another tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
	if (rd.x & 0x80) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1303
		TileIndex tile = v->tile + TileOffsByDir(rd.x & 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
		int dir = RoadFindPathToDest(v, tile, rd.x&3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
		int tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
		uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
		byte newdir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
		const RoadDriveEntry *rdp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
		if (dir == -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
again:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
		if ((dir & 7) >= 6) {
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
  1317
			/* Turning around */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
			tile = v->tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
		tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
		rdp = _road_drive_data[tmp];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
		tmp &= ~0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1326
		x = TileX(tile) * 16 + rdp[0].x;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1327
		y = TileY(tile) * 16 + rdp[0].y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
		if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
		r = VehicleEnterTile(v, tile, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
		if (r & 8) {
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
  1334
			if (!IsTileType(tile, MP_TUNNELBRIDGE)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
				v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
			dir = _road_reverse_table[rd.x&3];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
			goto again;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1024
diff changeset
  1342
		if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
			if ((tmp&7) >= 6) { v->cur_speed = 0; return; }
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1344
			if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1345
				RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1346
				byte *b = &rs->status;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1348
				//we have reached a loading bay, mark it as used
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1349
				//and clear the usage bit (0x80) of the stop
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1350
				*b = (*b | ((v->u.road.state&2)?2:1)) & ~0x80;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
		if (!(r & 4)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
			v->tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
			v->u.road.state = (byte)tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
			v->u.road.frame = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
		if (newdir != v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
			v->direction = newdir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
			v->cur_speed -= v->cur_speed >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
		v->cur_image = GetRoadVehImage(v, newdir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
		UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
		RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
	if (rd.x & 0x40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		int dir = RoadFindPathToDest(v, v->tile,	rd.x&3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
		uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
		int tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
		byte newdir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
		const RoadDriveEntry *rdp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
		if (dir == -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
		tmp = (_opt.road_side<<4) + dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
		rdp = _road_drive_data[tmp];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1385
		x = TileX(v->tile) * 16 + rdp[1].x;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1386
		y = TileY(v->tile) * 16 + rdp[1].y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
		if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
		r = VehicleEnterTile(v, v->tile, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		if (r & 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
			v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
		v->u.road.state = tmp & ~16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
		v->u.road.frame = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		if (newdir != v->direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
			v->direction = newdir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
			v->cur_speed -= v->cur_speed >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
		v->cur_image = GetRoadVehImage(v, newdir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
		UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
		RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	x = (v->x_pos&~15)+(rd.x&15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	y = (v->y_pos&~15)+(rd.y&15);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1413
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
	new_dir = RoadVehGetSlidingDirection(v, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
	if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
		if (v->u.road.overtaking == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
			RoadVehCheckOvertake(v, u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
	old_dir = v->direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	if (new_dir != old_dir) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
		v->direction = new_dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
		v->cur_speed -= (v->cur_speed >> 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
		if (old_dir != v->u.road.state) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
			v->cur_image = GetRoadVehImage(v, new_dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
			UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
			SetRoadVehPosition(v, v->x_pos, v->y_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
	if (v->u.road.state >= 0x20 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
			_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1436
		RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1437
		byte *b = &rs->status;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1439
		st = GetStation(_m[v->tile].m2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1441
		if (v->current_order.type != OT_LEAVESTATION &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1442
				v->current_order.type != OT_GOTO_DEPOT) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1443
			Order old_order;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1444
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
			*b &= ~0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  1447
			v->last_station_visited = _m[v->tile].m2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
			RoadVehArrivesAt(v, st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1451
			old_order = v->current_order;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1452
			v->current_order.type = OT_LOADING;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1453
			v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1455
			if (old_order.type == OT_GOTO_STATION &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1456
					v->current_order.station == v->last_station_visited) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1457
				v->current_order.flags =
1935
f43f062c9498 (svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents: 1927
diff changeset
  1458
					(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
			SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
			if (LoadUnloadVehicle(v)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
				InvalidateWindow(WC_ROADVEH_LIST, v->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
				MarkRoadVehDirty(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
			}
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
  1466
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1470
		if (v->current_order.type != OT_GOTO_DEPOT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
			if (*b&0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
				v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
			}
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1475
			v->current_order.type = OT_NOTHING;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1476
			v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
		*b |= 0x80;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1480
		if (rs == v->u.road.slot) {
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1481
			//we have arrived at the correct station
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1482
			ClearSlot(v, rs);
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1483
		} else if (v->u.road.slot != NULL) {
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1484
			//we have arrived at the wrong station
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1485
			//XXX The question is .. what to do? Actually we shouldn't be here
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1486
			//but I guess we need to clear the slot
1295
5dc810674581 (svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents: 1282
diff changeset
  1487
 			DEBUG(ms, 1) ("Multistop: Wrong station, force a slot clearing. Vehicle %d at 0x%x, should go to 0x%x of station %d (%x), destination 0x%x", v->unitnumber, v->tile, v->u.road.slot->xy, st->index, st->xy, v->dest_tile);
1239
6e61c510580e (svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents: 1237
diff changeset
  1488
			ClearSlot(v, v->u.road.slot);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1489
		}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1490
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
		StartRoadVehSound(v);
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
  1492
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
	r = VehicleEnterTile(v, v->tile, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
	if (r & 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
		v->cur_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
	if ((r & 4) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
		v->u.road.frame++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	v->cur_image = GetRoadVehImage(v, v->direction);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
	UpdateRoadVehDeltaXY(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
	RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
void RoadVehEnterDepot(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	v->u.road.state = 254;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
	v->vehstatus |= VS_HIDDEN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
578
86e352980acd (svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents: 555
diff changeset
  1517
	VehicleServiceInDepot(v);
86e352980acd (svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents: 555
diff changeset
  1518
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 378
diff changeset
  1519
	TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1520
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1521
	if (v->current_order.type == OT_GOTO_DEPOT) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1522
		Order t;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1523
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1525
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1526
		t = v->current_order;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1527
		v->current_order.type = OT_DUMMY;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1528
		v->current_order.flags = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
  1530
		// Part of the orderlist?
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
  1531
		if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1532
			v->cur_order_index++;
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
  1533
		} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
			v->vehstatus |= VS_STOPPED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
			if (v->owner == _local_player) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1536
				SetDParam(0, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
				AddNewsItem(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
					STR_9016_ROAD_VEHICLE_IS_WAITING,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
					NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
					v->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
					0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
	InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
1151
614cbcb5b9fe (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1128
diff changeset
  1547
	InvalidateWindowClasses(WC_ROADVEH_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
static void AgeRoadVehCargo(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	if (_age_cargo_skip_counter != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	if (v->cargo_days != 255)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
		v->cargo_days++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
void RoadVeh_Tick(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
	AgeRoadVehCargo(v);
1401
56d372a75b74 (svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents: 1359
diff changeset
  1561
	RoadVehController(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
static void CheckIfRoadVehNeedsService(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
{
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
  1566
	Depot *depot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1467
diff changeset
  1568
	if (_patches.servint_roadveh == 0)
11
836bc4b37b5b (svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents: 0
diff changeset
  1569
		return;
836bc4b37b5b (svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents: 0
diff changeset
  1570
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1467
diff changeset
  1571
	if (!VehicleNeedsService(v))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
	if (v->vehstatus & VS_STOPPED)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 926
diff changeset
  1577
	if (_patches.gotodepot && VehicleHasDepotOrders(v))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1579
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
	// Don't interfere with a depot visit scheduled by the user, or a
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
	// depot visit by the order list.
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1582
	if (v->current_order.type == OT_GOTO_DEPOT &&
1530
caa16c506a22 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1520
diff changeset
  1583
			(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1586
	//If we already got a slot at a stop, use that FIRST, and go to a depot later
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1587
	if (v->u.road.slot != NULL)
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1588
		return;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1589
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
  1590
	depot = FindClosestRoadDepot(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
  1592
	if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
1520
c85dc79795e0 (svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents: 1467
diff changeset
  1593
		if (v->current_order.type == OT_GOTO_DEPOT) {
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1594
			v->current_order.type = OT_DUMMY;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1595
			v->current_order.flags = 0;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
  1596
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1601
	if (v->current_order.type == OT_GOTO_DEPOT &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1602
			v->current_order.flags & OF_NON_STOP &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1603
			!CHANCE16(1,20))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1606
	v->current_order.type = OT_GOTO_DEPOT;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 541
diff changeset
  1607
	v->current_order.flags = OF_NON_STOP;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
  1608
	v->current_order.station = depot->index;
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
  1609
	v->dest_tile = depot->xy;
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 679
diff changeset
  1610
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1613
int dist_compare(const void *a, const void *b)
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1614
{
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1615
	return ( *(const uint32 *)a) - ( *(const uint32 *) b);
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1616
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1617
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
void OnNewDay_RoadVeh(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
	if ((++v->day_counter & 7) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
		DecreaseVehicleValue(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
	if (v->u.road.unk2 == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
		CheckVehicleBreakdown(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
	AgeVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
	CheckIfRoadVehNeedsService(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
1053
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1035
diff changeset
  1632
	CheckOrders(v->index, OC_INIT);
19
6080d2b6a959 (svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents: 11
diff changeset
  1633
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	/* update destination */
1769
0a51d1534f06 (svn r2273) -Fix: Road vehicles no longer try to obtain a slot when they have crashed. (peter1138)
celestar
parents: 1758
diff changeset
  1635
	if (v->current_order.type == OT_GOTO_STATION && !(v->vehstatus & VS_CRASHED)) {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1636
		RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1637
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 904
diff changeset
  1638
		st = GetStation(v->current_order.station);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1639
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1640
		//Current slot has expired
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1641
		if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL))
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1642
			ClearSlot(v, v->u.road.slot);
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1643
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1644
		//We do not have a slot, so make one
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1645
		if (v->u.road.slot == NULL) {
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1646
			RoadStop *rs = GetPrimaryRoadStop(st, type);
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1647
			RoadStop *first_stop = rs;
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1648
			RoadStop *best_stop = NULL;
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1649
			uint32 mindist = 12, dist; // 12 is threshold distance.
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1650
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1651
		//first we need to find out how far our stations are away.
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1652
			DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy);
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1653
			for(; rs != NULL; rs = rs->next) {
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1654
				// Only consider those with at least a free slot.
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1655
				if (!(rs->slot[0] == INVALID_SLOT || rs->slot[1] == INVALID_SLOT))
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1656
					continue;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1657
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1658
				// Previously the NPF pathfinder was used here even if NPF is OFF.. WTF?
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1659
				assert(NUM_SLOTS == 2);
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1660
				dist = DistanceManhattan(v->tile, rs->xy);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1661
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1662
				// Check if the station is located BEHIND the vehicle..
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1663
				// In that case, add penalty.
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1664
				switch(v->direction) {
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1665
				case 1: // going north east,x position decreasing
2107
607a900aefa3 (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2094
diff changeset
  1666
					if (v->x_pos <= (int32)TileX(rs->xy) * 16 + 15)
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1667
						dist += 6;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1668
					break;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1669
				case 3: // Going south east, y position increasing
2107
607a900aefa3 (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2094
diff changeset
  1670
					if (v->y_pos >= (int32)TileY(rs->xy) * 16)
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1671
						dist += 6;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1672
					break;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1673
				case 5: // Going south west, x position increasing
2107
607a900aefa3 (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2094
diff changeset
  1674
					if (v->x_pos >= (int32)TileX(rs->xy) * 16)
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1675
						dist += 6;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1676
					break;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1677
				case 7: // Going north west, y position decrasing.
2107
607a900aefa3 (svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents: 2094
diff changeset
  1678
					if (v->y_pos <= (int32)TileY(rs->xy) * 16 + 15)
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1679
						dist += 6;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1680
					break;
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1681
				}
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1682
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1683
				// Remember the one with the shortest distance
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1684
				if (dist < mindist) {
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1685
					mindist = dist;
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1686
					best_stop = rs;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1687
				}
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1688
				DEBUG(ms, 3) ("Multistop: Distance to stop at 0x%x is %d", rs->xy, dist);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1689
			}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1690
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1691
			// best_stop now contains the best stop we found.
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1692
			if (best_stop) {
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1693
				int slot;
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1694
				// Find a free slot in this stop. We know that at least one is free.
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1695
				assert(best_stop->slot[0] == INVALID_SLOT || best_stop->slot[1] == INVALID_SLOT);
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1696
				slot = (best_stop->slot[0] == INVALID_SLOT) ? 0 : 1;
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1697
				best_stop->slot[slot] = v->index;
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1698
				v->u.road.slot = best_stop;
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1699
				v->dest_tile = best_stop->xy;
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1700
				v->u.road.slot_age = -5;
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1701
				v->u.road.slotindex = slot;
2093
357b05db938f (svn r2603) Fix [multistop] Fix problem with multistop handling, the range in my fix was way too high. Also only lock a slot for 5 days instead of 30.
ludde
parents: 2089
diff changeset
  1702
				DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d (0x%x)", slot, best_stop->xy, v->unitnumber, v->tile);
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1703
			} else if (first_stop) {
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1704
				//now we couldn't assign a slot for one reason or another.
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1705
				//so we just go towards the first station
1295
5dc810674581 (svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents: 1282
diff changeset
  1706
				DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber);
2089
36f1c7177730 (svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents: 2049
diff changeset
  1707
				v->dest_tile = first_stop->xy;
1295
5dc810674581 (svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents: 1282
diff changeset
  1708
			}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1209
diff changeset
  1709
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
	if (v->vehstatus & VS_STOPPED)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
538
5dd99f3b7eca (svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents: 534
diff changeset
  1715
	cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
	v->profit_this_year -= cost >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
	SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
	SubtractMoneyFromPlayerFract(v->owner, cost);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
1151
614cbcb5b9fe (svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents: 1128
diff changeset
  1723
	InvalidateWindowClasses(WC_ROADVEH_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1053
diff changeset
  1727
void RoadVehiclesYearlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
		if (v->type == VEH_Road) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
			v->profit_last_year = v->profit_this_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
			v->profit_this_year = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
}