vehicle.c
author tron
Thu, 27 Jan 2005 12:52:20 +0000
changeset 1192 cd9b8a18a183
parent 1187 4ee23281d3a5
child 1209 a1ac96655b79
permissions -rw-r--r--
(svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
While touching the code make a bit more clear how GetBridgeHeight() works.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 445
diff changeset
     3
#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
     4
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "engine.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 260
diff changeset
    13
#include "sound.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#define INVALID_COORD (-0x8000)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    18
enum {
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    19
	VEHICLES_MIN_FREE_FOR_AI = 90
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    20
};
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
    21
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: 577
diff changeset
    22
void VehicleServiceInDepot(Vehicle *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: 577
diff changeset
    23
{
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: 577
diff changeset
    24
	v->date_of_last_service = _date;
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: 577
diff changeset
    25
	v->breakdowns_since_last_service = 0;
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: 577
diff changeset
    26
	v->reliability = _engines[v->engine_type].reliability;
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: 577
diff changeset
    27
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
593
e303a764de50 (svn r1015) MFM r789
tron
parents: 588
diff changeset
    29
bool VehicleNeedsService(const Vehicle *v)
e303a764de50 (svn r1015) MFM r789
tron
parents: 588
diff changeset
    30
{
1037
60bb8079eeea (svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents: 1035
diff changeset
    31
	if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0)
60bb8079eeea (svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents: 1035
diff changeset
    32
		return false;
60bb8079eeea (svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents: 1035
diff changeset
    33
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
    34
	return _patches.servint_ispercent ?
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
    35
		(v->reliability < _engines[v->engine_type].reliability * (100 - v->service_interval) / 100) :
593
e303a764de50 (svn r1015) MFM r789
tron
parents: 588
diff changeset
    36
		(v->date_of_last_service + v->service_interval < _date);
e303a764de50 (svn r1015) MFM r789
tron
parents: 588
diff changeset
    37
}
e303a764de50 (svn r1015) MFM r789
tron
parents: 588
diff changeset
    38
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
void VehicleInTheWayErrMsg(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	StringID id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	(id = STR_8803_TRAIN_IN_THE_WAY,v->type == VEH_Train) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	(id = STR_9000_ROAD_VEHICLE_IN_THE_WAY,v->type == VEH_Road) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	(id = STR_A015_AIRCRAFT_IN_THE_WAY,v->type == VEH_Aircraft) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
		(id = STR_980E_SHIP_IN_THE_WAY, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	_error_message = id;
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 void *EnsureNoVehicleProc(Vehicle *v, void *data)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
{
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    53
	if (v->tile != *(const TileIndex*)data || v->type == VEH_Disaster)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
		return NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
    55
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
    56
	VehicleInTheWayErrMsg(v);
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    57
	return v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
    58
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
bool EnsureNoVehicle(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
{
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    62
	return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
}
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
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
{
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    67
	const TileInfo *ti = data;
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    68
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    69
	if (v->tile != ti->tile || v->z_pos != ti->z || v->type == VEH_Disaster)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	VehicleInTheWayErrMsg(v);
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    73
	return v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
1082
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    76
static inline uint Correct_Z(uint tileh)
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    77
{
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    78
	// needs z correction for slope-type graphics that have the NORTHERN tile lowered
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    79
	// 1, 2, 3, 4, 5, 6 and 7
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    80
	return (CORRECT_Z(tileh)) ? 8 : 0;
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    81
}
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    82
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    83
uint GetCorrectTileHeight(TileIndex tile)
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    84
{
1192
cd9b8a18a183 (svn r1696) Use GetTileSlope() instead of FindLandscapeHeightByTile() where it is sufficient. FindLandscapeHeightByTile() uses GetTileSlope() internally and adds some more info, which is discarded in these cases.
tron
parents: 1187
diff changeset
    85
	return Correct_Z(GetTileSlope(tile, NULL));
1082
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    86
}
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    87
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
bool EnsureNoVehicleZ(TileIndex tile, byte z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
	TileInfo ti;
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    91
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	FindLandscapeHeightByTile(&ti, tile);
1082
56a4c048c5c3 (svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents: 1068
diff changeset
    93
	ti.z = z + Correct_Z(ti.tileh);
537
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    94
88d71dbdcd13 (svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents: 534
diff changeset
    95
	return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
{
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: 924
diff changeset
   100
	int x1 = TileX(from);
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: 924
diff changeset
   101
	int y1 = TileY(from);
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: 924
diff changeset
   102
	int x2 = TileX(to);
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: 924
diff changeset
   103
	int y2 = TileY(to);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	Vehicle *veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	/* Make sure x1 < x2 or y1 < y2 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	if (x1 > x2 || y1 > y2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		intswap(x1,x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		intswap(y1,y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   111
	FOR_ALL_VEHICLES(veh) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
		if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
			if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
					(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
				return veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
			}
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
void VehiclePositionChanged(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	int img = v->cur_image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	const SpriteDimension *sd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	sd = GetSpriteDimension(img);
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
	pt.x += sd->xoffs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	pt.y += sd->yoffs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	UpdateVehiclePosHash(v, pt.x, pt.y);
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
	v->left_coord = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	v->top_coord = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	v->right_coord = pt.x + sd->xsize + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	v->bottom_coord = pt.y + sd->ysize + 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   141
void UpdateWaypointSign(Waypoint *cp)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
{
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: 924
diff changeset
   143
	Point pt = RemapCoords2(TileX(cp->xy) * 16, TileY(cp->xy) * 16);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   144
	SetDParam(0, cp - _waypoints);
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   145
	UpdateViewportSignPos(&cp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   148
void RedrawWaypointSign(Waypoint *cp)
0
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
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
		cp->sign.left - 6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
		cp->sign.top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		cp->sign.left + (cp->sign.width_1 << 2) + 12,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
		cp->sign.top + 48);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
// Called after load to update coordinates
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   158
void AfterLoadVehicles(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	Vehicle *v;
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   161
	Waypoint *cp;
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
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
		if (v->type != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
			v->left_coord = INVALID_COORD;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
			if (v->type == VEH_Train) {
1067
a083a6dd1419 (svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents: 1063
diff changeset
   169
				if (v->subtype == TS_Front_Engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
					UpdateTrainAcceleration(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   175
	// update waypoint signs
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   176
	for(cp=_waypoints; cp != endof(_waypoints); cp++) if (cp->xy) UpdateWaypointSign(cp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
static Vehicle *InitializeVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	VehicleID index = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	memset(v, 0, sizeof(Vehicle));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	v->index = index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
   186
	assert(v->orders == NULL);
0
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->left_coord = INVALID_COORD;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	v->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	v->next_hash = 0xffff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	v->string_id = 0;
1111
2184bf930d25 (svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents: 1109
diff changeset
   192
	v->next_shared = NULL;
2184bf930d25 (svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents: 1109
diff changeset
   193
	v->prev_shared = NULL;
1139
c63f257aa7fb (svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents: 1128
diff changeset
   194
	v->set_for_replacement = false;
548
bd14538d4a66 (svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents: 547
diff changeset
   195
	/* random_bits is used to pick out a random sprite for vehicles
bd14538d4a66 (svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents: 547
diff changeset
   196
	    which are technical the same (newgrf stuff).
bd14538d4a66 (svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents: 547
diff changeset
   197
	   Because RandomRange() results in desyncs, and because it does
826
0e2b569b737b (svn r1297) Language fixes in the source.. (ln-)
miham
parents: 817
diff changeset
   198
	    not really matter that one client has other visual vehicles than
548
bd14538d4a66 (svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents: 547
diff changeset
   199
	    the other, it can be InteractiveRandomRange() without any problem
bd14538d4a66 (svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents: 547
diff changeset
   200
	*/
547
a20b5b3cf4f4 (svn r947) -Fix: [Network] Desync problem
truelight
parents: 543
diff changeset
   201
	v->random_bits = InteractiveRandomRange(256);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   205
Vehicle *ForceAllocateSpecialVehicle(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	Vehicle *v;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   208
	FOR_ALL_VEHICLES_FROM(v, NUM_NORMAL_VEHICLES) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		if (v->type == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
			return InitializeVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   216
Vehicle *ForceAllocateVehicle(void)
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
	Vehicle *v;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   219
	FOR_ALL_VEHICLES(v) {
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   220
		if (v->index >= NUM_NORMAL_VEHICLES)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   221
			return NULL;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   222
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
		if (v->type == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
			return InitializeVehicle(v);
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
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   229
Vehicle *AllocateVehicle(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	if (IS_HUMAN_PLAYER(_current_player)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
		num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   237
		FOR_ALL_VEHICLES(v) {
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   238
			if (v->index >= NUM_NORMAL_VEHICLES)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   239
				break;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   240
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
			if (v->type == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   245
		if (num <= VEHICLES_MIN_FREE_FOR_AI)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
			return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	return ForceAllocateVehicle();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	int x,y,x2,y2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	VehicleID veh;
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: 924
diff changeset
   256
	Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	x2 = ((pt.x + 104) & 0x1F80) >> 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	x  = ((pt.x - 174) & 0x1F80) >> 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	y2 = ((pt.y + 56) & 0xFC0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	y  = ((pt.y - 294) & 0xFC0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
		int xb = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
		for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
			veh = _vehicle_position_hash[ (x+y)&0xFFFF ];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
			while (veh != INVALID_VEHICLE) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   269
				Vehicle *v = GetVehicle(veh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
				void *a;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   271
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
				if ((a = proc(v, data)) != NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
					return a;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
				veh = v->next_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
			if (x == x2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
				break;
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
			x = (x + 1) & 0x3F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		x = xb;
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
		if (y == y2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
		y = (y + 0x40) & ((0x3F) << 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
void UpdateVehiclePosHash(Vehicle *v, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	VehicleID *old_hash, *new_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	int old_x = v->left_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	int old_y = v->top_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(old_x, old_y)];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   303
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	if (old_hash == new_hash)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	/* remove from hash table? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	if (old_hash != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
		Vehicle *last = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
		int idx = *old_hash;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   311
		while ((u = GetVehicle(idx)) != v) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
			idx = u->next_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
			assert(idx != INVALID_VEHICLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
			last = u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		if (last == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
			*old_hash = v->next_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
		else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
			last->next_hash = v->next_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	/* insert into hash table? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	if (new_hash != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
		v->next_hash = *new_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
		*new_hash = v->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   330
void InitializeVehicles(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	// clear it...
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   336
	memset(&_vehicles, 0, sizeof(_vehicles[0]) * _vehicles_size);
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   337
	memset(&_waypoints, 0, sizeof(_waypoints));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	memset(&_depots, 0, sizeof(_depots));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   339
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	// setup indexes..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	i = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	FOR_ALL_VEHICLES(v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
		v->index = i++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	memset(_vehicle_position_hash, -1, sizeof(_vehicle_position_hash));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
Vehicle *GetLastVehicleInChain(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	while (v->next != NULL) v = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
Vehicle *GetPrevVehicleInChain(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	Vehicle *org = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   358
	FOR_ALL_VEHICLES(v) {
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   359
		if (v->type == VEH_Train && org == v->next)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   360
			return v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   363
	return NULL;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
Vehicle *GetFirstVehicleInChain(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
{
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   368
	Vehicle *u;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   369
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   370
	while (true) {
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   371
		u = v;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   372
		v = GetPrevVehicleInChain(v);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   373
		/* If there is no such vehicle,
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   374
		    'v' == NULL and so 'u' is the first vehicle in chain */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   375
		if (v == NULL)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   376
			return u;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   377
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
int CountVehiclesInChain(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	int count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	do count++; while ( (v=v->next) != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
	return count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   388
Depot *AllocateDepot(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	Depot *dep, *free_dep = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
	int num_free = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
	for(dep = _depots; dep != endof(_depots); dep++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
		if (dep->xy == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
			num_free++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
			if (free_dep==NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
				free_dep = dep;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   401
	if (free_dep == NULL ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
			(num_free < 30 && IS_HUMAN_PLAYER(_current_player))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
		_error_message = STR_1009_TOO_MANY_DEPOTS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   407
	return free_dep;
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
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   410
Waypoint *AllocateWaypoint(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
{
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   412
	Waypoint *cp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   414
	for(cp = _waypoints; cp != endof(_waypoints); cp++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
		if (cp->xy == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
			return cp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	}
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
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   422
uint GetWaypointByTile(uint tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
{
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   424
	Waypoint *cp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	int i=0;
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
   426
	for(cp=_waypoints; cp->xy != (TileIndex)tile; cp++) { i++; }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
void DoDeleteDepot(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
{
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 548
diff changeset
   432
	Order order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	byte dep_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	Depot *d;
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
	// Clear it
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	DoClearSquare(tile);
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
	// Nullify the depot struct
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
	for(d=_depots,dep_index=0; d->xy != (TileIndex)tile; d++) {dep_index++;}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	d->xy = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 548
diff changeset
   443
	order.type = OT_GOTO_DEPOT;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 548
diff changeset
   444
	order.station = dep_index;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
   445
	DeleteDestinationFromVehicleOrder(order);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	// Delete the depot
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	DeleteWindowById(WC_VEHICLE_DEPOT, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
void DeleteVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	DeleteName(v->string_id);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
	v->type = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	UpdateVehiclePosHash(v, INVALID_COORD, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	v->next_hash = 0xffff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
   458
	if (v->orders != NULL)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
   459
		DeleteVehicleOrders(v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
void DeleteVehicleChain(Vehicle *v)
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
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
		Vehicle *u = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		v = v->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		DeleteVehicle(u);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	} while (v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
void Aircraft_Tick(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
void RoadVeh_Tick(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
void Ship_Tick(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
void Train_Tick(Vehicle *v);
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   476
static void EffectVehicle_Tick(Vehicle *v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
void DisasterVehicle_Tick(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
VehicleTickProc *_vehicle_tick_procs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	Train_Tick,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	RoadVeh_Tick,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	Ship_Tick,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	Aircraft_Tick,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	EffectVehicle_Tick,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	DisasterVehicle_Tick,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
   488
void CallVehicleTicks(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	Vehicle *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
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		if (v->type != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
			_vehicle_tick_procs[v->type - 0x10](v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
static bool CanFillVehicle_FullLoadAny(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	uint32 full = 0, not_full = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   501
924
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   502
	//special handling of aircraft
941
4a695e126035 (svn r1429) Change: bumped savegame to revision 5.
truelight
parents: 939
diff changeset
   503
924
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   504
	//if the aircraft carries passengers and is NOT full, then
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   505
	//continue loading, no matter how much mail is in
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   506
	if ((v->type == VEH_Aircraft) && (v->cargo_type == CT_PASSENGERS) && (v->cargo_cap != v->cargo_count)) {
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   507
		return true;
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   508
	}
433faaf547c1 (svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents: 922
diff changeset
   509
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
		//Should never happen, but just in case future additions change this
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
		assert(v->cargo_type<32);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
		if (v->cargo_cap != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
			uint32 mask = 1 << v->cargo_type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
			if (v->cargo_cap == v->cargo_count) full |= mask; else not_full |= mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	} while ( (v=v->next) != NULL);
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
	// continue loading if there is a non full cargo type and no cargo type that is full
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	return not_full && (full & ~not_full) == 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
bool CanFillVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
{
1058
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   527
	TileIndex tile = v->tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
1058
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   529
	if (IsTileType(tile, MP_STATION) ||
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   530
			(v->type == VEH_Ship && (
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   531
				IsTileType(TILE_ADDXY(tile,  1,  0), MP_STATION) ||
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   532
				IsTileType(TILE_ADDXY(tile, -1,  0), MP_STATION) ||
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   533
				IsTileType(TILE_ADDXY(tile,  0,  1), MP_STATION) ||
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   534
				IsTileType(TILE_ADDXY(tile,  0, -1), MP_STATION) ||
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   535
				IsTileType(TILE_ADDXY(tile, -2,  0), MP_STATION)
0a1a77da0a03 (svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents: 1037
diff changeset
   536
			))) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
		// If patch is active, use alternative CanFillVehicle-function
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
		if (_patches.full_load_any)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
			return CanFillVehicle_FullLoadAny(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
			if (v->cargo_count != v->cargo_cap)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
		} while ( (v=v->next) != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
static void DoDrawVehicle(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	uint32 image = v->cur_image;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   553
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	if (v->vehstatus & VS_DISASTER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
		image |= 0x3224000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	} else if (v->vehstatus & VS_DEFPAL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
		image |= (v->vehstatus & VS_CRASHED) ? 0x3248000 : SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   558
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   560
	AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
		v->sprite_width, v->sprite_height, v->z_height, v->z_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
void ViewportAddVehicles(DrawPixelInfo *dpi)
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
	int x,xb, y, x2, y2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
	VehicleID veh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	Vehicle *v;
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
	x  = ((dpi->left - 70) & 0x1F80) >> 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	x2 = ((dpi->left + dpi->width) & 0x1F80) >> 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
	y  = ((dpi->top - 70) & 0xFC0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	y2 = ((dpi->top + dpi->height) & 0xFC0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		xb = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
		for(;;) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
			veh = _vehicle_position_hash[ (x+y)&0xFFFF ];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
			while (veh != INVALID_VEHICLE) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   581
				v = GetVehicle(veh);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   582
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   583
				if (!(v->vehstatus & VS_HIDDEN) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
						dpi->left <= v->right_coord &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
						dpi->top <= v->bottom_coord &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
						dpi->left + dpi->width >= v->left_coord &&
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   587
						dpi->top + dpi->height >= v->top_coord) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
					DoDrawVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
				veh = v->next_hash;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
			}
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 (x == x2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
			x = (x + 1) & 0x3F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		x = xb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
		if (y == y2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
		y = (y + 0x40) & ((0x3F) << 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
static void EffectInit_0(Vehicle *v)
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
	uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	v->cur_image = (uint16)((r & 7) + 3701);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	v->progress = (byte)((r >> 16)&7);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
static void EffectTick_0(Vehicle *v)
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
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	uint img;
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
	if (--v->progress & 0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		BeginVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   619
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
		tile = TILE_FROM_XY(v->x_pos, v->y_pos);
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
   621
		if (!IsTileType(tile, MP_INDUSTRY)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
		img = v->cur_image + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
		if (img > 3708) img = 3701;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
		v->cur_image = img;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
		v->progress = 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
		EndVehicleMove(v);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
static void EffectInit_1(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	v->cur_image = 3079;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	v->progress = 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
static void EffectTick_1(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	bool moved;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   645
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	BeginVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   647
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	moved = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   649
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	if ((++v->progress & 7) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
		v->z_pos++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
		moved = true;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	if ((v->progress & 0xF)==4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
		if (++v->cur_image > 3083) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	if (moved) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
static void EffectInit_2(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	v->cur_image = 3073;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
static void EffectTick_2(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	if ((++v->progress & 3) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
		v->z_pos++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	} else if ((v->progress & 7) == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
		if (++v->cur_image > 3078) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
static void EffectInit_3(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	v->cur_image = 3084;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	v->progress = 1;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
static void EffectTick_3(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	if (++v->progress > 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
		v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
		if (++v->cur_image > 3089) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
static void EffectInit_4(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
	v->cur_image = 2040;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	v->progress = 12;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
static void EffectTick_4(Vehicle *v)
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
	bool moved;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   725
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	BeginVehicleMove(v);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   727
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	moved = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
   729
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	if ((++v->progress & 3) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
		v->z_pos++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
	if ((v->progress & 0xF)==4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
		if (++v->cur_image > 2044) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
		moved = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
	if (moved) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
static void EffectInit_5(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	v->cur_image = 3709;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
static void EffectTick_5(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	if (!(++v->progress & 3)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
		if (++v->cur_image > 3724) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
static void EffectInit_6(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	v->cur_image = 3737;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
static void EffectTick_6(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	if (!(++v->progress & 7)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
		if (++v->cur_image > 3740) v->cur_image = 3737;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	}
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
	if (!--v->u.special.unk0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
		DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
static void EffectInit_7(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	v->cur_image = 3725;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
static void EffectTick_7(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	if (!(++v->progress & 3)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
		if (++v->cur_image > 3736) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
			DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
static void EffectInit_8(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
	v->cur_image = 1416;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	v->u.special.unk0 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	v->u.special.unk2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
#define MK(imag,dir,dur) (imag<<6)+(dir<<4)+dur
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
static const byte _effecttick8_data[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	MK(0,0,4),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	MK(3,3,4),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	MK(2,2,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	MK(0,2,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
	MK(1,1,3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	MK(2,2,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
	MK(0,2,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
	MK(1,1,3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	MK(2,2,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	MK(0,2,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	MK(3,3,6),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	MK(2,2,6),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
	MK(1,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
	MK(3,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	MK(0,0,3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
	MK(1,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
	MK(3,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
	MK(0,0,3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	MK(1,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
	MK(3,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	255
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
#undef MK
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
static const int8 _xy_inc_by_dir[5] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
	-1, 0, 1, 0, -1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
};
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
#define GET_X_INC_BY_DIR(d) _xy_inc_by_dir[d]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
#define GET_Y_INC_BY_DIR(d) _xy_inc_by_dir[(d)+1]
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
static void EffectTick_8(Vehicle *v)
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
	byte b;
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
	if (!(++v->progress & 7)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		v->u.special.unk2++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
		b = _effecttick8_data[v->u.special.unk0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
		v->cur_image = 0x588 + (b>>6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
		v->x_pos += GET_X_INC_BY_DIR((b>>4)&3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
		v->y_pos += GET_X_INC_BY_DIR((b>>4)&3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
		if (v->u.special.unk2 < (b & 7)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
			v->u.special.unk2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
			v->u.special.unk0++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
			if (_effecttick8_data[v->u.special.unk0] == 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
				EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
				DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
static void EffectInit_9(Vehicle *v)
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
	v->cur_image = 4751;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	v->spritenum = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	v->progress = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
#define MK(x,y,z,i) (x+4)+(y+4)*16,(z+4)+i*16
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
/* -1,0,1,2 = 2*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
/* -1,0,1   = 2*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
/* */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
static const byte _effecttick9_data1[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	MK(1,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	MK(1,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	0x81,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
static const byte _effecttick9_data2[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	MK(-1,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	MK(-1,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	0x81,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
};
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
static const byte _effecttick9_data3[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
	MK(0,1,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	MK(0,1,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
	0x81,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
static const byte _effecttick9_data4[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	MK(0,-1,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	MK(0,-1,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	0x81,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
static const byte _effecttick9_data5[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	MK(0,0,1,7),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	MK(0,0,1,8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	MK(0,0,1,9),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	0x80,
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
static const byte _effecttick9_data6[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	MK(0,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	MK(0,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	MK(2,1,3,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	MK(1,1,3,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	MK(2,1,3,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	MK(1,1,3,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
	MK(2,1,3,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
	MK(1,1,3,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	MK(2,1,3,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	MK(1,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
	MK(1,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	MK(1,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	MK(1,0,1,1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	MK(0,0,1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
	MK(1,0,1,2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	0x82,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	MK(0,0,0,0xA),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	MK(0,0,0,0xB),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	MK(0,0,0,0xC),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	MK(0,0,0,0xD),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
	MK(0,0,0,0xE),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	0x80
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
#undef MK
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
static const byte * const _effecttick9_data[6] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	_effecttick9_data1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
	_effecttick9_data2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
	_effecttick9_data3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
	_effecttick9_data4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	_effecttick9_data5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
	_effecttick9_data6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
static void EffectTick_9(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
{
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1035
	/*
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1036
	 * Warning: those effects can NOT use Random(), and have to use
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1037
	 *  InteractiveRandom(), because somehow someone forgot to save
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1038
	 *  spritenum to the savegame, and so it will cause desyncs in
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1039
	 *  multiplayer!! (that is: in ToyLand)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1040
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
	int et;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	const byte *b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
	if (((++v->progress)&3) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
	et = v->engine_type + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
	if (v->spritenum == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
		if (++v->cur_image < 4754) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
			VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
			EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
		if (v->u.special.unk2 != 0) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1058
			v->spritenum = (byte)((InteractiveRandom()&3)+1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
			v->spritenum = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
		et = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
again:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	v->engine_type = et;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	b = &_effecttick9_data[v->spritenum - 1][et*2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	if (*b == 0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
		DeleteVehicle(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1073
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1074
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
	if (*b == 0x81) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1076
		if (v->z_pos > 180 || CHANCE16I(1,96, InteractiveRandom())) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
			v->spritenum = 5;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 537
diff changeset
  1078
			SndPlayVehicleFx(SND_2F_POP, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
		et = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
		goto again;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1082
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1083
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	if (*b == 0x82) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
		uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
		et++;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 537
diff changeset
  1088
		SndPlayVehicleFx(SND_31_EXTRACT, v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
		tile = TILE_FROM_XY(v->x_pos, v->y_pos);
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
  1091
		if (IsTileType(tile, MP_INDUSTRY) &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
				_map5[tile]==0xA2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
			AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
		goto again;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
	v->x_pos += (b[0]&0xF) - 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	v->y_pos += (b[0]>>4)  - 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	v->z_pos += (b[1]&0xF) - 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
	v->cur_image = 4748 + (b[1] >> 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
	EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
typedef void EffectInitProc(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
typedef void EffectTickProc(Vehicle *v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
static EffectInitProc * const _effect_init_procs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	EffectInit_0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
	EffectInit_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	EffectInit_2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	EffectInit_3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
	EffectInit_4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	EffectInit_5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	EffectInit_6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
	EffectInit_7,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	EffectInit_8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
	EffectInit_9,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
static EffectTickProc * const _effect_tick_procs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
	EffectTick_0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
	EffectTick_1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	EffectTick_2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	EffectTick_3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
	EffectTick_4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
	EffectTick_5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	EffectTick_6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
	EffectTick_7,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	EffectTick_8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
	EffectTick_9,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
Vehicle *CreateEffectVehicle(int x, int y, int z, int type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	Vehicle *v;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1141
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	v = ForceAllocateSpecialVehicle();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
	if (v != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
		v->type = VEH_Special;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
		v->subtype = type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
		v->x_pos = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
		v->y_pos = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
		v->z_pos = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
		v->z_height = v->sprite_width = v->sprite_height = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
		v->x_offs = v->y_offs = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
		v->tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
		v->vehstatus = VS_UNCLICKABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
		_effect_init_procs[type](v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
		VehiclePositionChanged(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
		BeginVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
		EndVehicleMove(v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	return v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, int type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	return CreateEffectVehicle(x, y, GetSlopeZ(x, y) + z, type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
Vehicle *CreateEffectVehicleRel(Vehicle *v, int x, int y, int z, int type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
	return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1173
static void EffectVehicle_Tick(Vehicle *v)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	_effect_tick_procs[v->subtype](v);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
Vehicle *CheckClickOnVehicle(ViewPort *vp, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
	Vehicle *found = NULL, *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	uint dist, best_dist = (uint)-1;
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
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
			 (uint)(y -= vp->top) >= (uint)vp->height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
				return NULL;
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
	x = (x << vp->zoom) + vp->virtual_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	y = (y << vp->zoom) + vp->virtual_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
	FOR_ALL_VEHICLES(v) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1191
		if (v->type != 0 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
				x >= v->left_coord && x <= v->right_coord &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
				y >= v->top_coord && y <= v->bottom_coord) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1194
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
			dist = max(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
				myabs( ((v->left_coord + v->right_coord)>>1) - x ),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
				myabs( ((v->top_coord + v->bottom_coord)>>1) - y )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
			);
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
			if (dist < best_dist) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
				found = v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
				best_dist = dist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
			}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	return found;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
void DecreaseVehicleValue(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	v->value -= v->value >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
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
static const byte _breakdown_chance[64] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	3, 3, 3, 3, 3, 3, 3, 3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	4, 4, 5, 5, 6, 6, 7, 7,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	8, 8, 9, 9, 10, 10, 11, 11,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	12, 13, 13, 13, 13, 14, 15, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
	17, 19, 21, 25, 28, 31, 34, 37,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	40, 44, 48, 52, 56, 60, 64, 68,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
	72, 80, 90, 100, 110, 120, 130, 140,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	150, 170, 190, 210, 230, 250, 250, 250,
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
void CheckVehicleBreakdown(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	int rel, rel_old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	int chance;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	/* decrease reliability */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	if ((rel_old >> 8) != (rel >> 8))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
	if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) != 0 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
			v->cur_speed < 5 || _game_mode == GM_MENU)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
				return;
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
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
	/* increase chance of failure */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
	chance = v->breakdown_chance + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	if (CHANCE16I(1,25,r)) chance += 25;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	v->breakdown_chance = min(255, chance);
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
	/* calculate reliability value to use in comparison */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	rel = v->reliability;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	if (v->type == VEH_Ship) rel += 0x6666;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1253
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
	/* disabled breakdowns? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	if (_opt.diff.vehicle_breakdowns < 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
	/* reduced breakdowns? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
	/* check if to break down */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
		v->breakdown_ctr = (byte)(((r >> 16) & 0x3F) + 0x3F);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
		v->breakdown_delay = (byte)(((r >> 24) & 0x7F) | 0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		v->breakdown_chance = 0;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
static const StringID _vehicle_type_names[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	STR_019F_TRAIN,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	STR_019C_ROAD_VEHICLE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	STR_019E_SHIP,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
	STR_019D_AIRCRAFT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
static void ShowVehicleGettingOld(Vehicle *v, StringID msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
	if (v->owner != _local_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
		return;
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1280
26
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1281
	// Do not show getting-old message if autorenew is active
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1282
	if (_patches.autorenew)
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1283
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1285
	SetDParam(0, _vehicle_type_names[v->type - 0x10]);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1286
	SetDParam(1, v->unitnumber);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
void AgeVehicle(Vehicle *v)
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
	int age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
	if (v->age < 65535)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
		v->age++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	age = v->age - v->max_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	if (age == 366*0 || age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1299
		v->reliability_spd_dec <<= 1;
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1300
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	if (age == -366) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
		ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	} else if (age == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
		ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
	} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
		ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1312
extern int32 EstimateTrainCost(const RailVehicleInfo *rvi);
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1313
extern int32 EstimateRoadVehCost(byte engine_type);
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1314
extern int32 EstimateShipCost(uint16 engine_type);
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1315
extern int32 EstimateAircraftCost(uint16 engine_type);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1316
extern int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1317
extern int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1318
extern int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2);
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1319
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1320
/* Replaces a vehicle (used to be called autorenew)
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1321
    p1 - Index of vehicle
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1322
    p2 - Type of new engine */
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1323
int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
{
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1325
	/* makesvariables to inform about how much money the player wants to have left after replacing
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1326
	 and which engine to replace with out of p2.
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1327
	 the first 16 bit is the money. The last 5 digits (all 0) were removed when sent, so we add them again.
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1328
	 This way the max is 6553 millions and it is more than the 32 bit that is stored in _patches
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1329
	 This is a nice way to send 32 bit and only use 16 bit
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1330
	 the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1331
	uint16 new_engine_type = (uint16)(p2 & 0xFFFF);
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1332
	uint32 autorefit_money = (p2  >> 16) * 100000;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  1333
	Vehicle *v = GetVehicle(p1);
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1334
	int cost, build_cost, rear_engine_cost = 0;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1335
	Vehicle *u = v;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1336
	byte old_engine_type = v->engine_type;
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 842
diff changeset
  1337
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 842
diff changeset
  1338
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1339
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1340
890
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1341
	// first we make sure that it's a valid type the user requested
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1342
	// check that it's an engine that is in the engine array
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1343
	if (new_engine_type >= TOTAL_NUM_ENGINES ) return CMD_ERROR;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1344
890
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1345
	// check that the new vehicle type is the same as the original one
907
60cb7cfb0580 (svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents: 892
diff changeset
  1346
	if (v->type != DEREF_ENGINE(new_engine_type)->type) return CMD_ERROR;
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1347
890
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1348
	// check that it's the vehicle's owner that requested the replace
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1349
	if (!CheckOwnership(v->owner)) return CMD_ERROR;
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1350
1185
08d48bad089c (svn r1687) - Feature: [autoreplace] server now checks for plane<->helicopter replacement and reject replacement if needed
bjarni
parents: 1174
diff changeset
  1351
	// makes sure that we do not replace a plane with a helicopter or vise versa
1187
4ee23281d3a5 (svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents: 1185
diff changeset
  1352
	if (v->type == VEH_Aircraft) {
4ee23281d3a5 (svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents: 1185
diff changeset
  1353
		if (HASBIT(AircraftVehInfo(old_engine_type)->subtype, 0) != HASBIT(AircraftVehInfo(new_engine_type)->subtype, 0)) return CMD_ERROR;
4ee23281d3a5 (svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents: 1185
diff changeset
  1354
	}
1185
08d48bad089c (svn r1687) - Feature: [autoreplace] server now checks for plane<->helicopter replacement and reject replacement if needed
bjarni
parents: 1174
diff changeset
  1355
1187
4ee23281d3a5 (svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents: 1185
diff changeset
  1356
	// makes sure that the player can actually buy the new engine. Renewing is still allowed to outdated engines
4ee23281d3a5 (svn r1690) - Fix: [autoreplace] Cheaters can no longer exploit autoreplace to get vehicles, that's not invented yet
bjarni
parents: 1185
diff changeset
  1357
	if (!HASBIT(DEREF_ENGINE(new_engine_type)->player_avail, v->owner) && old_engine_type != new_engine_type) return CMD_ERROR;
890
a39ee70d9886 (svn r1376) fixed an issue where a modified client could try to replace a vehicle to an invalid engine ID and crash the server. Now the server just rejects the request. Also added a check for vehicle ownership, so you should not be able to replace other player's vehicles
bjarni
parents: 889
diff changeset
  1358
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1359
	switch (v->type) {
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1360
		case VEH_Train:    build_cost = EstimateTrainCost(RailVehInfo(new_engine_type)); break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1361
		case VEH_Road:     build_cost = EstimateRoadVehCost(new_engine_type);            break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1362
		case VEH_Ship:     build_cost = EstimateShipCost(new_engine_type);               break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1363
		case VEH_Aircraft: build_cost = EstimateAircraftCost(new_engine_type);           break;
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1364
		default: return CMD_ERROR;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1365
	}
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1366
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1367
	/* In a rare situation, when 2 clients are connected to 1 company and have the same
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1368
	    settings, a vehicle can be replaced twice.. check if this is the situation here */
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1369
	if (old_engine_type == new_engine_type && v->age == 0)
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1370
		return CMD_ERROR;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1371
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1372
	if ( v->type == VEH_Train ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1373
		u = GetLastVehicleInChain(v);
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1374
		if ( RailVehInfo(new_engine_type)->flags & RVI_MULTIHEAD )
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1375
			build_cost = build_cost >> 1;   //multiheaded engines have EstimateTrainCost() for both engines
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1376
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1377
		if ( old_engine_type != new_engine_type ) {
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1378
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1379
			// prevent that the rear engine can get replaced to something else than the front engine
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1380
			if ( v->u.rail.first_engine != 0xffff && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD && RailVehInfo(old_engine_type)->flags ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1381
				Vehicle *first = GetFirstVehicleInChain(v);
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1382
				if ( first->engine_type != new_engine_type ) return CMD_ERROR;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1383
			}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1384
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1385
			// checks if the engine is the first one
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1386
			if ( v->u.rail.first_engine == 0xffff ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1387
				if ( RailVehInfo(new_engine_type)->flags & RVI_MULTIHEAD ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1388
					if ( u->engine_type == old_engine_type && v->next != NULL) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1389
						rear_engine_cost = build_cost - u->value;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1390
					} else {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1391
						rear_engine_cost = build_cost;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1392
					}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1393
				} else {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1394
					if ( u->engine_type == old_engine_type && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD) {
1068
2a9f53e0a5e6 (svn r1569) -Fix: signed/unsigned mismatch
darkvater
parents: 1067
diff changeset
  1395
						if (v->next != NULL) rear_engine_cost = -(int32)u->value;
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1396
					}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1397
				}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1398
			 }
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1399
		}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1400
	}
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1401
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1402
	/* Check if there is money for the upgrade.. if not, give a nice news-item
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1403
	    (that is needed, because this CMD is called automaticly) */
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1404
	if ( DEREF_PLAYER(v->owner)->money64 < (int32)(autorefit_money + build_cost + rear_engine_cost - v->value)) {
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1405
		if (( _local_player == v->owner ) && ( v->unitnumber != 0 )) {  //v->unitnumber = 0 for train cars
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1406
			int message;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1407
			SetDParam(0, v->unitnumber);
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1408
			switch (v->type) {
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1409
				case VEH_Train:    message = STR_TRAIN_AUTORENEW_FAILED;       break;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1410
				case VEH_Road:     message = STR_ROADVEHICLE_AUTORENEW_FAILED; break;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1411
				case VEH_Ship:     message = STR_SHIP_AUTORENEW_FAILED;        break;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1412
				case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED;    break;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1413
				// This should never happen
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1414
				default: message = 0; break;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1415
			}
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1416
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1417
			AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1418
		}
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1419
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1420
		return CMD_ERROR;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1421
	}
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1422
	cost = build_cost - v->value + rear_engine_cost;
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1423
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1424
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1425
	if (flags & DC_EXEC) {
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1426
		/* We do not really buy a new vehicle, we upgrade the old one */
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1427
		Engine *e;
907
60cb7cfb0580 (svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents: 892
diff changeset
  1428
		e = DEREF_ENGINE(new_engine_type);
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1429
1139
c63f257aa7fb (svn r1640) fix: now helicopters will use a hangar in schedule to be replaced in, even if they are only set to service there. Since helicopters are serviced at helipads, they will only go there if they needs to be replaced or renewed.
bjarni
parents: 1128
diff changeset
  1430
		v->set_for_replacement = false;
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1431
		v->reliability = e->reliability;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1432
		v->reliability_spd_dec = e->reliability_spd_dec;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1433
		v->age = 0;
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1434
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1435
		v->date_of_last_service = _date;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1436
		v->build_year = _cur_year;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1437
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1438
		v->value = build_cost;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1439
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1440
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1441
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1442
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1443
		if (v->engine_type != new_engine_type) {
933
90817bb28f1d (svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
bjarni
parents: 931
diff changeset
  1444
			byte sprite = v->spritenum;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1445
			byte cargo_type = v->cargo_type;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1446
			v->engine_type = new_engine_type;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1447
			v->max_age = e->lifelength * 366;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1448
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1449
			/* Update limits of the vehicle (for when upgraded) */
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1450
			switch (v->type) {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1451
			case VEH_Train:
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1452
				{
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1453
				const RailVehicleInfo *rvi = RailVehInfo(new_engine_type);
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1454
				const RailVehicleInfo *rvi2 = RailVehInfo(old_engine_type);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1455
				byte capacity = rvi->capacity;
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1456
				Vehicle *first = GetFirstVehicleInChain(v);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1457
1128
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1458
				//if (v->owner == _local_player) InvalidateWindowClasses(WC_TRAINS_LIST);
933
90817bb28f1d (svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
bjarni
parents: 931
diff changeset
  1459
				/* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way
90817bb28f1d (svn r1421) improved autoreplace multiheaded trains. It now remembers the current heading for an engine instead of turning all of them like the first one and the last the other way
bjarni
parents: 931
diff changeset
  1460
				if it is a multiheaded engine (rear engine)
939
68f8d6560c23 (svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents: 938
diff changeset
  1461
				(rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) is true if the engine is heading the other way, otherwise 0*/
68f8d6560c23 (svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents: 938
diff changeset
  1462
				v->spritenum = rvi->image_index + (( rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) ? 1 : 0);
941
4a695e126035 (svn r1429) Change: bumped savegame to revision 5.
truelight
parents: 939
diff changeset
  1463
939
68f8d6560c23 (svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents: 938
diff changeset
  1464
				// turn the last engine in a multiheaded train if needed
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1465
				if ( v->next == NULL && v->u.rail.first_engine != 0xffff && rvi->flags & RVI_MULTIHEAD && v->spritenum == rvi->image_index )
939
68f8d6560c23 (svn r1427) fixed issue where the wrong sprite could be used if autoreplacing between single and multiheaded trains
bjarni
parents: 938
diff changeset
  1466
					v->spritenum++;
956
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1467
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1468
				v->cargo_type = rvi->cargo_type;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1469
				v->cargo_cap = rvi->capacity;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1470
				v->max_speed = rvi->max_speed;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1471
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1472
				v->u.rail.railtype = e->railtype;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1473
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1474
				// 0x0100 means that we skip the check for being stopped inside the depot
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1475
				// since we do not stop it for autorefitting
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1476
				if (v->cargo_type != cargo_type && capacity) {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1477
					// BUG: somehow v->index is not transfered properly
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1478
					//CmdRefitRailVehicle(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1479
					v->cargo_type = cargo_type; // workaround, but it do not check the refit table
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1480
				} else {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1481
					v->cargo_type = rvi->cargo_type;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1482
				}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1483
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1484
				if ( rvi2->flags & RVI_MULTIHEAD && !(rvi->flags & RVI_MULTIHEAD) &&  v->index == first->index) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1485
					if (old_engine_type == u->engine_type ) {
1063
03fed43e58fc (svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents: 1062
diff changeset
  1486
						Vehicle *w;
03fed43e58fc (svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents: 1062
diff changeset
  1487
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1488
						u = GetLastVehicleInChain(v);
1063
03fed43e58fc (svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents: 1062
diff changeset
  1489
						w = GetPrevVehicleInChain(u);
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1490
						w->next = NULL;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1491
						DeleteVehicle(u);
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1492
					}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1493
				}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1494
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1495
				if ( rvi->flags & RVI_MULTIHEAD && rvi2->flags & RVI_MULTIHEAD &&  v->index == first->index ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1496
					CmdReplaceVehicle(x, y, flags, u->index, p2);
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1497
				}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1498
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1499
				if ( rvi->flags & RVI_MULTIHEAD && !(rvi2->flags & RVI_MULTIHEAD) &&  v->index == first->index ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1500
					if ( old_engine_type != u->engine_type ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1501
						Vehicle *w;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1502
						if ( (w=AllocateVehicle()) != NULL ) {
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1503
							AddRearEngineToMultiheadedTrain(v,w, false);
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1504
							u->next = w;
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1505
						}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1506
					}
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1507
				}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1093
diff changeset
  1508
1062
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1509
				// updates the id of the front engine in the other units, since the front engine just got a new engine_id
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1510
				// this is needed for wagon override
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1511
				if ( v->u.rail.first_engine == 0xffff && v->next != NULL ) {
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1512
					Vehicle *veh = v->next;
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1513
					do {
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1514
						veh->u.rail.first_engine = new_engine_type;
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1515
					} while ( (veh=veh->next) != NULL );
4131a8dfde94 (svn r1563) fix: autoreplaced trains now sets wagon override properly
bjarni
parents: 1060
diff changeset
  1516
				}
1128
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1517
				InvalidateWindowClasses(WC_TRAINS_LIST);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1518
				break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1519
				}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1520
			case VEH_Road:
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1521
				{
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1522
				const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1523
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1524
				v->spritenum = rvi->image_index;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1525
				v->cargo_type = rvi->cargo_type;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1526
				v->cargo_cap = rvi->capacity;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1527
				v->max_speed = rvi->max_speed;
1128
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1528
				InvalidateWindowClasses(WC_ROADVEH_LIST);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1529
				break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1530
				}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1531
			case VEH_Ship:
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1532
				{
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1533
				const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1534
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1535
				v->spritenum = svi->image_index;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1536
				v->cargo_type = svi->cargo_type;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1537
				v->cargo_cap = svi->capacity;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1538
				v->max_speed = svi->max_speed;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1539
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1540
				// 0x0100 means that we skip the check for being stopped inside the depot
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1541
				// since we do not stop it for autorefitting
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1542
				if (v->cargo_type != cargo_type)
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1543
					CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
1128
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1544
				InvalidateWindowClasses(WC_SHIPS_LIST);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1545
				break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1546
				}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1547
			case VEH_Aircraft:
1060
e8c44e426175 (svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents: 1058
diff changeset
  1548
				{
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1549
				const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1550
				Vehicle *u;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1551
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1552
				v->max_speed = avi->max_speed;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1553
				v->acceleration = avi->acceleration;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1554
				v->spritenum = avi->image_index;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1555
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1556
					if ( cargo_type == CT_PASSENGERS ) {
922
fc040662bd43 (svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents: 919
diff changeset
  1557
						v->cargo_cap = avi->passenger_capacity;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1558
						u = v->next;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1559
						u->cargo_cap = avi->mail_capacity;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1560
					} else {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1561
						// 0x0100 means that we skip the check for being stopped inside the hangar
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1562
						// since we do not stop it for autorefitting
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1563
						CmdRefitAircraft(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1564
					}
1128
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1565
				InvalidateWindowClasses(WC_AIRCRAFT_LIST);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1566
				break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1567
				}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1568
			default: return CMD_ERROR;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1569
			}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1570
			// makes sure that the cargo is still valid compared to new capacity
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1571
			if (v->cargo_count != 0) {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1572
				if ( v->cargo_type != cargo_type )
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1573
					v->cargo_count = 0;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1574
				else if ( v->cargo_count > v->cargo_cap )
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1575
					v->cargo_count = v->cargo_cap;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1576
			}
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1577
		}
1128
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1578
		InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
d3ffc98b92ad (svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents: 1111
diff changeset
  1579
		ResortVehicleLists();
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1580
	}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1581
	//needs to be down here because refitting will change SET_EXPENSES_TYPE if called
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1582
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1583
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1584
	return cost;
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1585
}
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1586
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1587
void MaybeReplaceVehicle(Vehicle *v)
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1588
{
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1589
	uint32 new_engine_and_autoreplace_money;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1590
812
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1591
	if (v->owner != _local_player)
79c99885ad00 (svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents: 755
diff changeset
  1592
		return;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1593
	// uncomment next line if you want to see what engine type just entered a depot
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1594
	//printf("engine type: %d\n", v->engine_type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
26
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1596
	// A vehicle is autorenewed when it it gets the amount of months
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1597
	//  give by _patches.autorenew_months away for his max age.
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1598
	//  Standard is -6, meaning 6 months before his max age
4c08274a29dc (svn r27) -Fix: [1006715] Autorenew issues
truelight
parents: 22
diff changeset
  1599
	//  It can be any value between -12 and 12.
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1600
	//  Here it also checks if the vehicles is listed for replacement
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1601
	if (!_patches.autorenew || v->age - v->max_age < (_patches.autorenew_months * 30)) {  //replace if engine is too old
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1602
		if (_autoreplace_array[v->engine_type] == v->engine_type && v->type != VEH_Train) //updates to a new model
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1603
			return;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1604
	}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1605
	/* Now replace the vehicle */
829
b71111ccf2cc (svn r1300) -Fix: The cost for an autorenew was not always send to the right player ;)
truelight
parents: 826
diff changeset
  1606
	_current_player = v->owner;
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1607
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1608
	/* makes the variable to inform about how much money the player wants to have left after replacing
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1609
	 and which engine to replace with
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1610
	 the first 16 bit is the money. Since we know the last 5 digits is 0, they are thrown away.
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1611
	 This way the max is 6553 millions and it is more than the 32 bit that is stored in _patches
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1612
	 This is a nice way to send 32 bit and only use 16 bit
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1613
	 the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */
892
3e5dd4c4d5b3 (svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents: 890
diff changeset
  1614
	new_engine_and_autoreplace_money = ((_patches.autorenew_money / 100000) << 16) + _autoreplace_array[v->engine_type];
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1615
907
60cb7cfb0580 (svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents: 892
diff changeset
  1616
	assert(v->type == DEREF_ENGINE(_autoreplace_array[v->engine_type])->type);
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 907
diff changeset
  1617
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1618
	if ( v->type != VEH_Train ) {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1619
		DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1620
	} else {
892
3e5dd4c4d5b3 (svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents: 890
diff changeset
  1621
	// checks if any of the engines in the train are either old or listed for replacement
3e5dd4c4d5b3 (svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents: 890
diff changeset
  1622
		do {
907
60cb7cfb0580 (svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
bjarni
parents: 892
diff changeset
  1623
			if ( v->engine_type != _autoreplace_array[v->engine_type] || (_patches.autorenew && (v->age - v->max_age) > (_patches.autorenew_months * 30))) {
892
3e5dd4c4d5b3 (svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents: 890
diff changeset
  1624
				new_engine_and_autoreplace_money = (new_engine_and_autoreplace_money & 0xFFFF0000) + _autoreplace_array[v->engine_type]; // sets the new engine replacement type
3e5dd4c4d5b3 (svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents: 890
diff changeset
  1625
				DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1626
			}
892
3e5dd4c4d5b3 (svn r1378) Fix: train engines are now only replaced if the engine is really set to be replaced and they are replaced to the type that engine type is set to be replaced to (instead of whtat the first engine in the train is set to)
bjarni
parents: 890
diff changeset
  1627
		} while ((v=v->next) != NULL);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1628
	}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 829
diff changeset
  1629
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
int32 CmdNameVehicle(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
  1634
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  1638
	v = GetVehicle(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	if (!CheckOwnership(v->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1643
	str = AllocateNameUnique((byte*)_decode_parameters, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	if (str == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
		return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1646
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
		StringID old_str = v->string_id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
		v->string_id = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
		DeleteName(old_str);
588
1b60458bdc29 (svn r1009) -Feature: per-station vehicle lists
tron
parents: 585
diff changeset
  1651
		ResortVehicleLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
		DeleteName(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
static Rect _old_vehicle_coords;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
void BeginVehicleMove(Vehicle *v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
	_old_vehicle_coords.left = v->left_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
	_old_vehicle_coords.top = v->top_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
	_old_vehicle_coords.right = v->right_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
	_old_vehicle_coords.bottom = v->bottom_coord;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
void EndVehicleMove(Vehicle *v)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
		min(_old_vehicle_coords.left,v->left_coord),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
		min(_old_vehicle_coords.top,v->top_coord),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
		max(_old_vehicle_coords.right,v->right_coord)+1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
		max(_old_vehicle_coords.bottom,v->bottom_coord)+1
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
/* returns true if staying in the same tile */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
	static const int8 _delta_coord[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
		-1,-1,-1, 0, 1, 1, 1, 0, /* x */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
		-1, 0, 1, 1, 1, 0,-1,-1, /* y */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
	int x = v->x_pos + _delta_coord[v->direction];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
	int y = v->y_pos + _delta_coord[v->direction + 8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
	gp->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
	gp->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
	gp->old_tile = v->tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
	gp->new_tile = TILE_FROM_XY(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
	return gp->old_tile == gp->new_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
static const byte _new_direction_table[9] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
	0, 7, 6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
	1, 3, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
	2, 3, 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
byte GetDirectionTowards(Vehicle *v, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
	byte dirdiff, dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
	int i = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
	if (y >= v->y_pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
		if (y != v->y_pos) i+=3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
		i+=3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
	if (x >= v->x_pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
		if (x != v->x_pos) i++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
		i++;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
	dir = v->direction;
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
	dirdiff = _new_direction_table[i] - dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
	if (dirdiff == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
		return dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
	return (dir+((dirdiff&7)<5?1:-1)) & 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1728
/* Return value has bit 0x2 set, when the vehicle enters a station. Then,
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1729
 * result << 8 contains the id of the station entered. If the return value has
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1730
 * bit 0x8 set, the vehicle could not and did not enter the tile. Are there
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1731
 * other bits that can be set? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
uint32 VehicleEnterTile(Vehicle *v, uint tile, int x, int y)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1733
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
	uint old_tile = v->tile;
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
  1735
	uint32 result = _tile_type_procs[TileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1736
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1737
	/* When vehicle_enter_tile_proc returns 8, that apparently means that
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1738
	 * we cannot enter the tile at all. In that case, don't call
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  1739
	 * leave_tile. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
	if (!(result & 8) && old_tile != tile) {
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
  1741
		VehicleLeaveTileProc *proc = _tile_type_procs[TileType(old_tile)]->vehicle_leave_tile_proc;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
		if (proc != NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
			proc(v, old_tile, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
	return result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
uint GetFreeUnitNumber(byte type)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
	uint unit_num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	Vehicle *u;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
restart:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
	unit_num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	FOR_ALL_VEHICLES(u) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1756
		if (u->type == type && u->owner == _current_player &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
		    unit_num == u->unitnumber)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
					goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
	return unit_num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
// Save and load of vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
const byte _common_veh_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
	SLE_VAR(Vehicle,subtype,					SLE_UINT8),
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1767
938
4f84a0530758 (svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents: 933
diff changeset
  1768
	SLE_REF(Vehicle,next,							REF_VEHICLE_OLD),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
	SLE_VAR(Vehicle,string_id,				SLE_STRINGID),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
	SLE_VAR(Vehicle,unitnumber,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
	SLE_VAR(Vehicle,owner,						SLE_UINT8),
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1772
	SLE_CONDVAR(Vehicle,tile,					SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1773
	SLE_CONDVAR(Vehicle,tile,					SLE_UINT32, 6, 255),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1774
	SLE_CONDVAR(Vehicle,dest_tile,		SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1775
	SLE_CONDVAR(Vehicle,dest_tile,		SLE_UINT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1777
	SLE_CONDVAR(Vehicle,x_pos,				SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1778
	SLE_CONDVAR(Vehicle,x_pos,				SLE_UINT32, 6, 255),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1779
	SLE_CONDVAR(Vehicle,y_pos,				SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1780
	SLE_CONDVAR(Vehicle,y_pos,				SLE_UINT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
	SLE_VAR(Vehicle,z_pos,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
	SLE_VAR(Vehicle,direction,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
	SLE_VAR(Vehicle,cur_image,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
	SLE_VAR(Vehicle,spritenum,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
	SLE_VAR(Vehicle,sprite_width,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
	SLE_VAR(Vehicle,sprite_height,		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
	SLE_VAR(Vehicle,z_height,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
	SLE_VAR(Vehicle,x_offs,						SLE_INT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
	SLE_VAR(Vehicle,y_offs,						SLE_INT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
	SLE_VAR(Vehicle,engine_type,			SLE_UINT16),
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: 410
diff changeset
  1792
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
	SLE_VAR(Vehicle,max_speed,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
	SLE_VAR(Vehicle,cur_speed,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
	SLE_VAR(Vehicle,subspeed,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
	SLE_VAR(Vehicle,acceleration,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
	SLE_VAR(Vehicle,progress,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
	SLE_VAR(Vehicle,vehstatus,				SLE_UINT8),
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  1800
	SLE_CONDVAR(Vehicle,last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  1801
	SLE_CONDVAR(Vehicle,last_station_visited, SLE_UINT16, 5, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
	SLE_VAR(Vehicle,cargo_type,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
	SLE_VAR(Vehicle,cargo_days,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
	SLE_VAR(Vehicle,cargo_source,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
	SLE_VAR(Vehicle,cargo_cap,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
	SLE_VAR(Vehicle,cargo_count,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
	SLE_VAR(Vehicle,day_counter,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
	SLE_VAR(Vehicle,tick_counter,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1812
	SLE_VAR(Vehicle,cur_order_index,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
	SLE_VAR(Vehicle,num_orders,				SLE_UINT8),
956
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1814
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1815
	/* This next line is for version 4 and prior compatibility.. it temporarily reads
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1816
	    type and flags (which were both 4 bits) into type. Later on this is
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1817
	    converted correctly */
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1818
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type),    SLE_UINT8,  0, 4),
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1819
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1820
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1821
	/* Orders for version 5 and on */
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1822
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type),    SLE_UINT8,  5, 255),
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1823
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags),   SLE_UINT8,  5, 255),
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1824
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255),
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1825
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  1826
	SLE_REF(Vehicle,orders,						REF_ORDER),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
	SLE_VAR(Vehicle,age,							SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
	SLE_VAR(Vehicle,max_age,					SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
	SLE_VAR(Vehicle,date_of_last_service,SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
	SLE_VAR(Vehicle,service_interval,	SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
	SLE_VAR(Vehicle,reliability,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
	SLE_VAR(Vehicle,reliability_spd_dec,SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
	SLE_VAR(Vehicle,breakdown_ctr,		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
	SLE_VAR(Vehicle,breakdown_delay,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
	SLE_VAR(Vehicle,breakdowns_since_last_service,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
	SLE_VAR(Vehicle,breakdown_chance,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
	SLE_VAR(Vehicle,build_year,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
	SLE_VAR(Vehicle,load_unload_time_rem,	SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
	SLE_VAR(Vehicle,profit_this_year,	SLE_INT32),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1843
	SLE_VAR(Vehicle,profit_last_year,	SLE_INT32),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
	SLE_VAR(Vehicle,value,						SLE_UINT32),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
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: 410
diff changeset
  1846
	SLE_VAR(Vehicle,random_bits,       SLE_UINT8),
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: 410
diff changeset
  1847
	SLE_VAR(Vehicle,waiting_triggers,  SLE_UINT8),
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: 410
diff changeset
  1848
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  1849
	SLE_REF(Vehicle,next_shared,				REF_VEHICLE),
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  1850
	SLE_REF(Vehicle,prev_shared,				REF_VEHICLE),
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  1851
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  1852
	// reserve extra space in savegame here. (currently 10 bytes)
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: 410
diff changeset
  1853
	SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 2, 2, 255), /* 2 */
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: 410
diff changeset
  1854
	SLE_CONDARR(NullStruct,null,SLE_FILE_U32 | SLE_VAR_NULL, 2, 2, 255), /* 8 */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1855
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1856
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1857
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
static const byte _train_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
	SLE_WRITEBYTE(Vehicle,type,VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,crash_anim_pos), SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,force_proceed), SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,railtype), SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,track), SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
	SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,flags), SLE_UINT8, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
	SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,days_since_order_progr), SLE_UINT16, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
	// reserve extra space in savegame here. (currently 13 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
	SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 13, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
static const byte _roadveh_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
	SLE_WRITEBYTE(Vehicle,type,VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,state),					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,frame),					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,unk2),					SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking),		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking_ctr),SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,crashed_ctr),		SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,reverse_ctr),			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
	// reserve extra space in savegame here. (currently 16 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
	SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
static const byte _ship_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
	SLE_WRITEBYTE(Vehicle,type,VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1896
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleShip,state),				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
	// reserve extra space in savegame here. (currently 16 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
	SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
static const byte _aircraft_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	SLE_WRITEBYTE(Vehicle,type,VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
	SLE_INCLUDEX(0, INC_VEHICLE_COMMON),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter),	SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,pos),							SLE_UINT8),
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  1910
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  1911
	SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport),		SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  1912
	SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport),		SLE_UINT16, 5, 255),
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  1913
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,state),						SLE_UINT8),
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1915
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
	SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos),			SLE_UINT8, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
	// reserve extra space in savegame here. (currently 15 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
	SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 15, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
static const byte _special_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	SLE_VAR(Vehicle,subtype,					SLE_UINT8),
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 164
diff changeset
  1928
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1929
	SLE_CONDVAR(Vehicle,tile,					SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1930
	SLE_CONDVAR(Vehicle,tile,					SLE_UINT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1932
	SLE_CONDVAR(Vehicle,x_pos,				SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1933
	SLE_CONDVAR(Vehicle,x_pos,				SLE_INT32, 6, 255),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1934
	SLE_CONDVAR(Vehicle,y_pos,				SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1935
	SLE_CONDVAR(Vehicle,y_pos,				SLE_INT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
	SLE_VAR(Vehicle,z_pos,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
	SLE_VAR(Vehicle,cur_image,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	SLE_VAR(Vehicle,sprite_width,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
	SLE_VAR(Vehicle,sprite_height,		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
	SLE_VAR(Vehicle,z_height,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
	SLE_VAR(Vehicle,x_offs,						SLE_INT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
	SLE_VAR(Vehicle,y_offs,						SLE_INT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
	SLE_VAR(Vehicle,progress,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
	SLE_VAR(Vehicle,vehstatus,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk0),	SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk2),	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
	// reserve extra space in savegame here. (currently 16 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
	SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1956
static const byte _disaster_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
	SLE_WRITEBYTE(Vehicle,type,VEH_Disaster, 5),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
938
4f84a0530758 (svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents: 933
diff changeset
  1959
	SLE_REF(Vehicle,next,							REF_VEHICLE_OLD),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
	SLE_VAR(Vehicle,subtype,					SLE_UINT8),
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1962
	SLE_CONDVAR(Vehicle,tile,					SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1963
	SLE_CONDVAR(Vehicle,tile,					SLE_UINT32, 6, 255),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1964
	SLE_CONDVAR(Vehicle,dest_tile,		SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1965
	SLE_CONDVAR(Vehicle,dest_tile,		SLE_UINT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1967
	SLE_CONDVAR(Vehicle,x_pos,				SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1968
	SLE_CONDVAR(Vehicle,x_pos,				SLE_INT32, 6, 255),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1969
	SLE_CONDVAR(Vehicle,y_pos,				SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  1970
	SLE_CONDVAR(Vehicle,y_pos,				SLE_INT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
	SLE_VAR(Vehicle,z_pos,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
	SLE_VAR(Vehicle,direction,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
	SLE_VAR(Vehicle,x_offs,						SLE_INT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
	SLE_VAR(Vehicle,y_offs,						SLE_INT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
	SLE_VAR(Vehicle,sprite_width,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
	SLE_VAR(Vehicle,sprite_height,		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
	SLE_VAR(Vehicle,z_height,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
	SLE_VAR(Vehicle,owner,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
	SLE_VAR(Vehicle,vehstatus,				SLE_UINT8),
956
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1981
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  1982
	SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
	SLE_VAR(Vehicle,cur_image,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
	SLE_VAR(Vehicle,age,							SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1986
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1987
	SLE_VAR(Vehicle,tick_counter,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1989
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,image_override),	SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
	SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,unk2),						SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
	// reserve extra space in savegame here. (currently 16 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
	SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1996
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1997
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
static const void *_veh_descs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
	_train_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
	_roadveh_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
	_ship_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
	_aircraft_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
	_special_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
	_disaster_desc,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
// Will be called when the vehicles need to be saved.
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
  2009
static void Save_VEHS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
	// Write the vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2013
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
		if (v->type != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
			SlSetArrayIndex(v->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
			SlObject(v, _veh_descs[v->type - 0x10]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
// Will be called when vehicles need to be loaded.
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
  2022
static void Load_VEHS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2023
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2025
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2026
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2027
	while ((index = SlIterateArray()) != -1) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2028
		Vehicle *v = GetVehicle(index);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2029
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
		SlObject(v, _veh_descs[SlReadByte()]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
		if (v->type == VEH_Train)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2032
			v->u.rail.first_engine = 0xffff;
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  2033
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  2034
		/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  2035
		if (_sl.version < 5 && v->last_station_visited == 0xFF)
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 812
diff changeset
  2036
			v->last_station_visited = 0xFFFF;
956
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2037
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2038
		if (_sl.version < 5) {
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2039
			/* Convert the current_order.type (which is a mix of type and flags, because
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2040
			    in those versions, they both were 4 bits big) to type and flags */
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2041
			v->current_order.flags = (v->current_order.type & 0xF0) >> 4;
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2042
			v->current_order.type  =  v->current_order.type & 0x0F;
d72a565cc672 (svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents: 941
diff changeset
  2043
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
	// Iterate through trains and set first_engine appropriately.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
	FOR_ALL_VEHICLES(v) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
		Vehicle *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
1067
a083a6dd1419 (svn r1568) made an enum of train subtypes to make the code more readable
bjarni
parents: 1063
diff changeset
  2050
		if (v->type != VEH_Train || v->subtype != TS_Front_Engine)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
			continue;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
		for (w = v->next; w; w = w->next)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
			w->u.rail.first_engine = v->engine_type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2055
	}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2056
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2057
	/* Check for shared order-lists (we now use pointers for that) */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2058
	if (_sl.full_version < 0x502) {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2059
		FOR_ALL_VEHICLES(v) {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2060
			Vehicle *u;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2061
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2062
			if (v->type == 0)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2063
				continue;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2064
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2065
			FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2066
				if (u->type == 0)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2067
					continue;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2068
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2069
				/* If a vehicle has the same orders, add the link to eachother
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2070
				    in both vehicles */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2071
				if (v->orders == u->orders) {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2072
					v->next_shared = u;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2073
					u->prev_shared = v;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2074
					break;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2075
				}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2076
			}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2077
		}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2078
	}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
  2079
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2080
	/* This is to ensure all pointers are within the limits of
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2081
	    _vehicles_size */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2082
	if (_vehicle_id_ctr_day >= _vehicles_size)
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
  2083
		_vehicle_id_ctr_day = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
static const byte _depot_desc[] = {
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  2087
	SLE_CONDVAR(Depot, xy,			SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  2088
	SLE_CONDVAR(Depot, xy,			SLE_UINT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	SLE_VAR(Depot,town_index,		SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
  2093
static void Save_DEPT(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
	Depot *d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2096
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
	for(i=0,d=_depots; i!=lengthof(_depots); i++,d++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
		if (d->xy != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
			SlSetArrayIndex(i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
			SlObject(d, _depot_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2102
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
  2105
static void Load_DEPT(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
	while ((index = SlIterateArray()) != -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
		SlObject(&_depots[index], _depot_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2113
static const byte _waypoint_desc[] = {
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  2114
	SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1139
diff changeset
  2115
	SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, 255),
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2116
	SLE_VAR(Waypoint,town_or_string,		SLE_UINT16),
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2117
	SLE_VAR(Waypoint,deleted,						SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2119
	SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, 255),
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2120
	SLE_CONDVAR(Waypoint, stat_id, SLE_UINT8, 3, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2124
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
  2125
static void Save_CHKP(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
{
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2127
	Waypoint *cp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
	int i;
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2129
	for(i=0,cp=_waypoints; i!=lengthof(_waypoints); i++,cp++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
		if (cp->xy != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
			SlSetArrayIndex(i);
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2132
			SlObject(cp, _waypoint_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1082
diff changeset
  2137
static void Load_CHKP(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
	while ((index = SlIterateArray()) != -1) {
395
4c990f33dab7 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 337
diff changeset
  2141
		SlObject(&_waypoints[index], _waypoint_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2142
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
const ChunkHandler _veh_chunk_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
	{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
	{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
	{ 'CHKP', Save_CHKP, Load_CHKP, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2149
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2151