author | miham |
Wed, 17 Aug 2005 12:30:07 +0000 | |
changeset 2349 | df02d0ffb588 |
parent 2319 | 9902d3ffa309 |
child 2386 | c5cc666c869d |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1328
diff
changeset
|
5 |
#include "spritecache.h" |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
6 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
7 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
8 |
#include "functions.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
|
9 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1192
diff
changeset
|
10 |
#include "tile.h" |
0 | 11 |
#include "vehicle.h" |
12 |
#include "gfx.h" |
|
13 |
#include "viewport.h" |
|
14 |
#include "news.h" |
|
15 |
#include "command.h" |
|
16 |
#include "saveload.h" |
|
17 |
#include "player.h" |
|
18 |
#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
|
19 |
#include "sound.h" |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
20 |
#include "debug.h" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
21 |
#include "vehicle_gui.h" |
1758
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
22 |
#include "depot.h" |
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
23 |
#include "station.h" |
2244 | 24 |
#include "gui.h" |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
25 |
#include "rail.h" |
0 | 26 |
|
27 |
#define INVALID_COORD (-0x8000) |
|
28 |
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0))) |
|
29 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
30 |
enum { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
31 |
/* Max vehicles: 64000 (512 * 125) */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
32 |
VEHICLES_POOL_BLOCK_SIZE_BITS = 9, /* In bits, so (1 << 9) == 512 */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
33 |
VEHICLES_POOL_MAX_BLOCKS = 125, |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
34 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
35 |
BLOCKS_FOR_SPECIAL_VEHICLES = 2, //! Blocks needed for special vehicles |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
36 |
}; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
37 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
38 |
/** |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
39 |
* Called if a new block is added to the vehicle-pool |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
40 |
*/ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
41 |
static void VehiclePoolNewBlock(uint start_item) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
42 |
{ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
43 |
Vehicle *v; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
44 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
45 |
FOR_ALL_VEHICLES_FROM(v, start_item) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
46 |
v->index = start_item++; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
47 |
} |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
48 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
49 |
/* Initialize the vehicle-pool */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
50 |
MemoryPool _vehicle_pool = { "Vehicle", VEHICLES_POOL_MAX_BLOCKS, VEHICLES_POOL_BLOCK_SIZE_BITS, sizeof(Vehicle), &VehiclePoolNewBlock, 0, 0, NULL }; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
51 |
|
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
|
52 |
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
|
53 |
{ |
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
|
54 |
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
|
55 |
v->breakdowns_since_last_service = 0; |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
56 |
v->reliability = GetEngine(v->engine_type)->reliability; |
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
|
57 |
} |
0 | 58 |
|
593 | 59 |
bool VehicleNeedsService(const Vehicle *v) |
60 |
{ |
|
1037
60bb8079eeea
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
61 |
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
|
62 |
return false; |
60bb8079eeea
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
63 |
|
1757
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
64 |
if (v->vehstatus & VS_CRASHED) |
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
65 |
return false; /* Crashed vehicles don't need service anymore */ |
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
66 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
67 |
return _patches.servint_ispercent ? |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
68 |
(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : |
593 | 69 |
(v->date_of_last_service + v->service_interval < _date); |
70 |
} |
|
71 |
||
0 | 72 |
void VehicleInTheWayErrMsg(Vehicle *v) |
73 |
{ |
|
74 |
StringID id; |
|
75 |
||
76 |
(id = STR_8803_TRAIN_IN_THE_WAY,v->type == VEH_Train) || |
|
77 |
(id = STR_9000_ROAD_VEHICLE_IN_THE_WAY,v->type == VEH_Road) || |
|
78 |
(id = STR_A015_AIRCRAFT_IN_THE_WAY,v->type == VEH_Aircraft) || |
|
79 |
(id = STR_980E_SHIP_IN_THE_WAY, true); |
|
80 |
||
81 |
_error_message = id; |
|
82 |
} |
|
83 |
||
84 |
static void *EnsureNoVehicleProc(Vehicle *v, void *data) |
|
85 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
86 |
if (v->tile != *(const TileIndex*)data || v->type == VEH_Disaster) |
0 | 87 |
return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
88 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
89 |
VehicleInTheWayErrMsg(v); |
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
90 |
return v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
91 |
} |
0 | 92 |
|
93 |
bool EnsureNoVehicle(TileIndex tile) |
|
94 |
{ |
|
537
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, &tile, EnsureNoVehicleProc) == NULL; |
0 | 96 |
} |
97 |
||
98 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
99 |
{ |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
100 |
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
|
101 |
|
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
102 |
if (v->tile != ti->tile || v->z_pos != ti->z || v->type == VEH_Disaster) |
0 | 103 |
return NULL; |
104 |
||
105 |
VehicleInTheWayErrMsg(v); |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
106 |
return v; |
0 | 107 |
} |
108 |
||
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
|
109 |
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
|
110 |
{ |
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
|
111 |
// 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
|
112 |
// 1, 2, 3, 4, 5, 6 and 7 |
1394
449e84bdc04e
(svn r1898) Remove some unused macros from macros.h and move some others to more appropriate headers
tron
parents:
1371
diff
changeset
|
113 |
return CorrectZ(tileh) ? 8 : 0; |
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
|
114 |
} |
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
|
115 |
|
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
|
116 |
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
|
117 |
{ |
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
|
118 |
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
|
119 |
} |
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
|
120 |
|
0 | 121 |
bool EnsureNoVehicleZ(TileIndex tile, byte z) |
122 |
{ |
|
123 |
TileInfo ti; |
|
537
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
124 |
|
0 | 125 |
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
|
126 |
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
|
127 |
|
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
128 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL; |
0 | 129 |
} |
130 |
||
1605
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
131 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
132 |
{ |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
133 |
TileInfo ti; |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
134 |
|
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
135 |
ti.tile = tile; |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
136 |
ti.z = z; |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
137 |
|
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
138 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ); |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
139 |
} |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
140 |
|
0 | 141 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z) |
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 |
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
|
144 |
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
|
145 |
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
|
146 |
int y2 = TileY(to); |
0 | 147 |
Vehicle *veh; |
148 |
||
149 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
150 |
if (x1 > x2 || y1 > y2) { |
|
151 |
intswap(x1,x2); |
|
152 |
intswap(y1,y2); |
|
153 |
} |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
154 |
FOR_ALL_VEHICLES(veh) { |
0 | 155 |
if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) { |
156 |
if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 && |
|
157 |
(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) { |
|
158 |
return veh; |
|
159 |
} |
|
160 |
} |
|
161 |
} |
|
162 |
return NULL; |
|
163 |
} |
|
164 |
||
165 |
void VehiclePositionChanged(Vehicle *v) |
|
166 |
{ |
|
167 |
int img = v->cur_image; |
|
168 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
169 |
const Sprite* spr = GetSprite(img); |
0 | 170 |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
171 |
pt.x += spr->x_offs; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
172 |
pt.y += spr->y_offs; |
0 | 173 |
|
174 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
175 |
||
176 |
v->left_coord = pt.x; |
|
177 |
v->top_coord = pt.y; |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
178 |
v->right_coord = pt.x + spr->width + 2; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
179 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 180 |
} |
181 |
||
182 |
// 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
|
183 |
void AfterLoadVehicles(void) |
0 | 184 |
{ |
185 |
Vehicle *v; |
|
186 |
||
187 |
FOR_ALL_VEHICLES(v) { |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
188 |
v->first = NULL; |
0 | 189 |
if (v->type != 0) { |
190 |
v->left_coord = INVALID_COORD; |
|
191 |
VehiclePositionChanged(v); |
|
192 |
||
1917
74cab7e464d1
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1905
diff
changeset
|
193 |
if (v->type == VEH_Train && (v->subtype == TS_Front_Engine || v->subtype == TS_Free_Car)) |
1905
f43d9e821deb
(svn r2411) - Codechange: Have trains cache stuff like consist power/weight/max speed instead of recalculating it each time.
hackykid
parents:
1891
diff
changeset
|
194 |
TrainConsistChanged(v); |
0 | 195 |
} |
196 |
} |
|
197 |
} |
|
198 |
||
199 |
static Vehicle *InitializeVehicle(Vehicle *v) |
|
200 |
{ |
|
201 |
VehicleID index = v->index; |
|
202 |
memset(v, 0, sizeof(Vehicle)); |
|
203 |
v->index = index; |
|
204 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
205 |
assert(v->orders == NULL); |
0 | 206 |
|
207 |
v->left_coord = INVALID_COORD; |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
208 |
v->first = NULL; |
0 | 209 |
v->next = NULL; |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
210 |
v->next_hash = INVALID_VEHICLE; |
0 | 211 |
v->string_id = 0; |
1111
2184bf930d25
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
212 |
v->next_shared = NULL; |
2184bf930d25
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
213 |
v->prev_shared = NULL; |
548
bd14538d4a66
(svn r948) -Codechange: clearified my last commit a bit more with some comment in the code
truelight
parents:
547
diff
changeset
|
214 |
/* 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
|
215 |
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
|
216 |
Because RandomRange() results in desyncs, and because it does |
826 | 217 |
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
|
218 |
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
|
219 |
*/ |
547 | 220 |
v->random_bits = InteractiveRandomRange(256); |
0 | 221 |
return v; |
222 |
} |
|
223 |
||
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
|
224 |
Vehicle *ForceAllocateSpecialVehicle(void) |
0 | 225 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
226 |
/* This stays a strange story.. there should always be room for special |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
227 |
* vehicles (special effects all over the map), but with 65k of vehicles |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
228 |
* is this realistic to double-check for that? For now we just reserve |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
229 |
* BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
230 |
* be used for special vehicles.. should work nicely :) */ |
0 | 231 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
232 |
Vehicle *v; |
0 | 233 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
234 |
FOR_ALL_VEHICLES(v) { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
235 |
/* No more room for the special vehicles, return NULL */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
236 |
if (v->index >= (1 << _vehicle_pool.block_size_bits) * BLOCKS_FOR_SPECIAL_VEHICLES) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
237 |
return NULL; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
238 |
|
0 | 239 |
if (v->type == 0) |
240 |
return InitializeVehicle(v); |
|
241 |
} |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
242 |
|
0 | 243 |
return NULL; |
244 |
} |
|
245 |
||
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
|
246 |
Vehicle *AllocateVehicle(void) |
0 | 247 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
248 |
/* See note by ForceAllocateSpecialVehicle() why we skip the |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
249 |
* first blocks */ |
0 | 250 |
Vehicle *v; |
251 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
252 |
FOR_ALL_VEHICLES_FROM(v, (1 << _vehicle_pool.block_size_bits) * BLOCKS_FOR_SPECIAL_VEHICLES) { |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
253 |
if (v->type == 0) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
254 |
return InitializeVehicle(v); |
0 | 255 |
} |
256 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
257 |
/* Check if we can add a block to the pool */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
258 |
if (AddBlockToPool(&_vehicle_pool)) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
259 |
return AllocateVehicle(); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
260 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
261 |
return NULL; |
0 | 262 |
} |
263 |
||
264 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
|
265 |
{ |
|
266 |
int x,y,x2,y2; |
|
267 |
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
|
268 |
Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, 0); |
0 | 269 |
|
270 |
x2 = ((pt.x + 104) & 0x1F80) >> 7; |
|
271 |
x = ((pt.x - 174) & 0x1F80) >> 7; |
|
272 |
||
273 |
y2 = ((pt.y + 56) & 0xFC0); |
|
274 |
y = ((pt.y - 294) & 0xFC0); |
|
275 |
||
276 |
for(;;) { |
|
277 |
int xb = x; |
|
278 |
for(;;) { |
|
279 |
veh = _vehicle_position_hash[ (x+y)&0xFFFF ]; |
|
280 |
while (veh != INVALID_VEHICLE) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
281 |
Vehicle *v = GetVehicle(veh); |
0 | 282 |
void *a; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
283 |
|
0 | 284 |
if ((a = proc(v, data)) != NULL) |
285 |
return a; |
|
286 |
veh = v->next_hash; |
|
287 |
} |
|
288 |
||
289 |
if (x == x2) |
|
290 |
break; |
|
291 |
||
292 |
x = (x + 1) & 0x3F; |
|
293 |
} |
|
294 |
x = xb; |
|
295 |
||
296 |
if (y == y2) |
|
297 |
break; |
|
298 |
||
299 |
y = (y + 0x40) & ((0x3F) << 6); |
|
300 |
} |
|
301 |
return NULL; |
|
302 |
} |
|
303 |
||
304 |
||
305 |
||
306 |
void UpdateVehiclePosHash(Vehicle *v, int x, int y) |
|
307 |
{ |
|
308 |
VehicleID *old_hash, *new_hash; |
|
309 |
int old_x = v->left_coord; |
|
310 |
int old_y = v->top_coord; |
|
311 |
Vehicle *u; |
|
312 |
||
313 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)]; |
|
314 |
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
|
315 |
|
0 | 316 |
if (old_hash == new_hash) |
317 |
return; |
|
318 |
||
319 |
/* remove from hash table? */ |
|
320 |
if (old_hash != NULL) { |
|
321 |
Vehicle *last = NULL; |
|
322 |
int idx = *old_hash; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
323 |
while ((u = GetVehicle(idx)) != v) { |
0 | 324 |
idx = u->next_hash; |
325 |
assert(idx != INVALID_VEHICLE); |
|
326 |
last = u; |
|
327 |
} |
|
328 |
||
329 |
if (last == NULL) |
|
330 |
*old_hash = v->next_hash; |
|
331 |
else |
|
332 |
last->next_hash = v->next_hash; |
|
333 |
} |
|
334 |
||
335 |
/* insert into hash table? */ |
|
336 |
if (new_hash != NULL) { |
|
337 |
v->next_hash = *new_hash; |
|
338 |
*new_hash = v->index; |
|
339 |
} |
|
340 |
} |
|
341 |
||
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
|
342 |
void InitializeVehicles(void) |
0 | 343 |
{ |
344 |
int i; |
|
345 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
346 |
/* Clean the vehicle pool, and reserve enough blocks |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
347 |
* for the special vehicles, plus one for all the other |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
348 |
* vehicles (which is increased on-the-fly) */ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
349 |
CleanPool(&_vehicle_pool); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
350 |
AddBlockToPool(&_vehicle_pool); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
351 |
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
352 |
AddBlockToPool(&_vehicle_pool); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
353 |
|
0 | 354 |
// clear it... |
355 |
memset(_vehicle_position_hash, -1, sizeof(_vehicle_position_hash)); |
|
356 |
} |
|
357 |
||
358 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
359 |
{ |
|
360 |
while (v->next != NULL) v = v->next; |
|
361 |
return v; |
|
362 |
} |
|
363 |
||
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
364 |
/** Finds the previous vehicle in a chain, by a brute force search. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
365 |
* This old function is REALLY slow because it searches through all vehicles to |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
366 |
* find the previous vehicle, but if v->first has not been set, then this function |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
367 |
* will need to be used to find the previous one. This function should never be |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
368 |
* called by anything but GetFirstVehicleInChain |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
369 |
*/ |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
370 |
static Vehicle *GetPrevVehicleInChain_bruteforce(const Vehicle *v) |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
371 |
{ |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
372 |
Vehicle *u; |
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
373 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
374 |
FOR_ALL_VEHICLES(u) if (u->type == VEH_Train && u->next == v) return u; |
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
375 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
376 |
return NULL; |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
377 |
} |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
378 |
|
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
379 |
/** Find the previous vehicle in a chain, by using the v->first cache. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
380 |
* While this function is fast, it cannot be used in the GetFirstVehicleInChain |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
381 |
* function, otherwise you'll end up in an infinite loop call |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
382 |
*/ |
1475 | 383 |
Vehicle *GetPrevVehicleInChain(const Vehicle *v) |
0 | 384 |
{ |
1600
b2bd1eaed056
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
385 |
Vehicle *u; |
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
386 |
assert(v != NULL); |
0 | 387 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
388 |
u = GetFirstVehicleInChain(v); |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
389 |
|
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
390 |
// Check to see if this is the first |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
391 |
if (v == u) return NULL; |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
392 |
|
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
393 |
do { |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
394 |
if (u->next == v) return u; |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
395 |
} while ( ( u = u->next) != NULL); |
0 | 396 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
397 |
return NULL; |
0 | 398 |
} |
399 |
||
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
400 |
/** Finds the first vehicle in a chain. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
401 |
* This function reads out the v->first cache. Should the cache be dirty, |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
402 |
* it determines the first vehicle in a chain, and updates the cache. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
403 |
*/ |
1475 | 404 |
Vehicle *GetFirstVehicleInChain(const Vehicle *v) |
0 | 405 |
{ |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
406 |
Vehicle* u; |
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
407 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
408 |
assert(v != NULL); |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
409 |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
410 |
if (v->first != NULL) { |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
411 |
if (v->first->subtype == TS_Front_Engine) return v->first; |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
412 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
413 |
DEBUG(misc, 0) ("v->first cache faulty. We shouldn't be here, rebuilding cache!"); |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
414 |
} |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
415 |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
416 |
/* It is the fact (currently) that newly built vehicles do not have |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
417 |
* their ->first pointer set. When this is the case, go up to the |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
418 |
* first engine and set the pointers correctly. Also the first pointer |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
419 |
* is not saved in a savegame, so this has to be fixed up after loading */ |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
420 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
421 |
/* Find the 'locomotive' or the first wagon in a chain */ |
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
422 |
while ((u = GetPrevVehicleInChain_bruteforce(v)) != NULL) v = u; |
1600
b2bd1eaed056
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
423 |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
424 |
/* Set the first pointer of all vehicles in that chain to the first wagon */ |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
425 |
if (v->subtype == TS_Front_Engine) |
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
426 |
for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v; |
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
427 |
|
1600
b2bd1eaed056
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
428 |
return (Vehicle*)v; |
0 | 429 |
} |
430 |
||
431 |
int CountVehiclesInChain(Vehicle *v) |
|
432 |
{ |
|
433 |
int count = 0; |
|
434 |
do count++; while ( (v=v->next) != NULL); |
|
435 |
return count; |
|
436 |
} |
|
437 |
||
438 |
void DeleteVehicle(Vehicle *v) |
|
439 |
{ |
|
440 |
DeleteName(v->string_id); |
|
441 |
v->type = 0; |
|
442 |
UpdateVehiclePosHash(v, INVALID_COORD, 0); |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
443 |
v->next_hash = INVALID_VEHICLE; |
0 | 444 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
445 |
if (v->orders != NULL) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
446 |
DeleteVehicleOrders(v); |
0 | 447 |
} |
448 |
||
449 |
void DeleteVehicleChain(Vehicle *v) |
|
450 |
{ |
|
451 |
do { |
|
452 |
Vehicle *u = v; |
|
453 |
v = v->next; |
|
454 |
DeleteVehicle(u); |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
455 |
} while (v != NULL); |
0 | 456 |
} |
457 |
||
458 |
||
459 |
void Aircraft_Tick(Vehicle *v); |
|
460 |
void RoadVeh_Tick(Vehicle *v); |
|
461 |
void Ship_Tick(Vehicle *v); |
|
462 |
void Train_Tick(Vehicle *v); |
|
410 | 463 |
static void EffectVehicle_Tick(Vehicle *v); |
0 | 464 |
void DisasterVehicle_Tick(Vehicle *v); |
465 |
||
466 |
VehicleTickProc *_vehicle_tick_procs[] = { |
|
467 |
Train_Tick, |
|
468 |
RoadVeh_Tick, |
|
469 |
Ship_Tick, |
|
470 |
Aircraft_Tick, |
|
471 |
EffectVehicle_Tick, |
|
472 |
DisasterVehicle_Tick, |
|
473 |
}; |
|
474 |
||
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
|
475 |
void CallVehicleTicks(void) |
0 | 476 |
{ |
477 |
Vehicle *v; |
|
478 |
||
479 |
FOR_ALL_VEHICLES(v) { |
|
480 |
if (v->type != 0) |
|
481 |
_vehicle_tick_procs[v->type - 0x10](v); |
|
482 |
} |
|
483 |
} |
|
484 |
||
485 |
static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
486 |
{ |
|
487 |
uint32 full = 0, not_full = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
488 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
489 |
//special handling of aircraft |
941
4a695e126035
(svn r1429) Change: bumped savegame to revision 5.
truelight
parents:
939
diff
changeset
|
490 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
491 |
//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
|
492 |
//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
|
493 |
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
|
494 |
return true; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
495 |
} |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
496 |
|
0 | 497 |
// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. |
498 |
do { |
|
499 |
//Should never happen, but just in case future additions change this |
|
500 |
assert(v->cargo_type<32); |
|
501 |
||
502 |
if (v->cargo_cap != 0) { |
|
503 |
uint32 mask = 1 << v->cargo_type; |
|
504 |
if (v->cargo_cap == v->cargo_count) full |= mask; else not_full |= mask; |
|
505 |
} |
|
506 |
} while ( (v=v->next) != NULL); |
|
507 |
||
508 |
// continue loading if there is a non full cargo type and no cargo type that is full |
|
509 |
return not_full && (full & ~not_full) == 0; |
|
510 |
} |
|
511 |
||
512 |
bool CanFillVehicle(Vehicle *v) |
|
513 |
{ |
|
1058
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
514 |
TileIndex tile = v->tile; |
0 | 515 |
|
1058
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
516 |
if (IsTileType(tile, MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
517 |
(v->type == VEH_Ship && ( |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
518 |
IsTileType(TILE_ADDXY(tile, 1, 0), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
519 |
IsTileType(TILE_ADDXY(tile, -1, 0), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
520 |
IsTileType(TILE_ADDXY(tile, 0, 1), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
521 |
IsTileType(TILE_ADDXY(tile, 0, -1), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
522 |
IsTileType(TILE_ADDXY(tile, -2, 0), MP_STATION) |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
523 |
))) { |
0 | 524 |
|
525 |
// If patch is active, use alternative CanFillVehicle-function |
|
526 |
if (_patches.full_load_any) |
|
527 |
return CanFillVehicle_FullLoadAny(v); |
|
528 |
||
529 |
do { |
|
530 |
if (v->cargo_count != v->cargo_cap) |
|
531 |
return true; |
|
532 |
} while ( (v=v->next) != NULL); |
|
533 |
} |
|
534 |
return false; |
|
535 |
} |
|
536 |
||
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
537 |
/** Check if a given vehicle (type) can be refitted to a given cargo |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
538 |
* @param *v vehicle to check |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
539 |
* @param cid_to check refit to this cargo-type |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
540 |
* @return true if it is possible, false otherwise |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
541 |
*/ |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
542 |
bool CanRefitTo(const Vehicle *v, CargoID cid_to) |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
543 |
{ |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
544 |
CargoID cid = _global_cargo_id[_opt_ptr->landscape][cid_to]; |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
545 |
|
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
546 |
if (cid == GC_INVALID) return false; |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
547 |
|
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
548 |
if (_engine_refit_masks[v->engine_type]) { |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
549 |
if (!HASBIT(_engine_refit_masks[v->engine_type], cid)) return false; |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
550 |
} else { |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
551 |
/* If we are talking about normal vehicles (no newgrf), you can only refit engines */ |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
552 |
if (v->type == VEH_Train && (RailVehInfo(v->engine_type)->flags & RVI_WAGON)) return false; |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
553 |
if (!HASBIT(_default_refitmasks[v->type - VEH_Train], cid)) return false; |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
554 |
} |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
555 |
|
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
556 |
return true; |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
557 |
} |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
558 |
|
0 | 559 |
static void DoDrawVehicle(Vehicle *v) |
560 |
{ |
|
561 |
uint32 image = v->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
562 |
|
0 | 563 |
if (v->vehstatus & VS_DISASTER) { |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
564 |
MAKE_TRANSPARENT(image); |
0 | 565 |
} else if (v->vehstatus & VS_DEFPAL) { |
1922
797081e56d13
(svn r2428) - Feature: [newgrf] Implement shorter train vehicles (Therax), and the callback that goes with it.
hackykid
parents:
1917
diff
changeset
|
566 |
image |= (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : 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
|
567 |
} |
0 | 568 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
569 |
AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
0 | 570 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos); |
571 |
} |
|
572 |
||
573 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
574 |
{ |
|
575 |
int x,xb, y, x2, y2; |
|
576 |
VehicleID veh; |
|
577 |
Vehicle *v; |
|
578 |
||
579 |
x = ((dpi->left - 70) & 0x1F80) >> 7; |
|
580 |
x2 = ((dpi->left + dpi->width) & 0x1F80) >> 7; |
|
581 |
||
582 |
y = ((dpi->top - 70) & 0xFC0); |
|
583 |
y2 = ((dpi->top + dpi->height) & 0xFC0); |
|
584 |
||
585 |
for(;;) { |
|
586 |
xb = x; |
|
587 |
for(;;) { |
|
588 |
veh = _vehicle_position_hash[ (x+y)&0xFFFF ]; |
|
589 |
while (veh != INVALID_VEHICLE) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
590 |
v = GetVehicle(veh); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
591 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
592 |
if (!(v->vehstatus & VS_HIDDEN) && |
0 | 593 |
dpi->left <= v->right_coord && |
594 |
dpi->top <= v->bottom_coord && |
|
595 |
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
|
596 |
dpi->top + dpi->height >= v->top_coord) { |
0 | 597 |
DoDrawVehicle(v); |
598 |
} |
|
599 |
veh = v->next_hash; |
|
600 |
} |
|
601 |
||
602 |
if (x == x2) |
|
603 |
break; |
|
604 |
x = (x + 1) & 0x3F; |
|
605 |
} |
|
606 |
x = xb; |
|
607 |
||
608 |
if (y == y2) |
|
609 |
break; |
|
610 |
y = (y + 0x40) & ((0x3F) << 6); |
|
611 |
} |
|
612 |
} |
|
613 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
614 |
static void ChimneySmokeInit(Vehicle *v) |
0 | 615 |
{ |
616 |
uint32 r = Random(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
617 |
v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
618 |
v->progress = GB(r, 16, 3); |
0 | 619 |
} |
620 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
621 |
static void ChimneySmokeTick(Vehicle *v) |
0 | 622 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
623 |
if (v->progress > 0) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
624 |
v->progress--; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
625 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
626 |
TileIndex tile; |
0 | 627 |
|
628 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
629 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
630 |
tile = TileVirtXY(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
|
631 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
0 | 632 |
EndVehicleMove(v); |
633 |
DeleteVehicle(v); |
|
634 |
return; |
|
635 |
} |
|
636 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
637 |
if (v->cur_image != SPR_CHIMNEY_SMOKE_7) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
638 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
639 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
640 |
v->cur_image = SPR_CHIMNEY_SMOKE_0; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
641 |
} |
0 | 642 |
v->progress = 7; |
643 |
VehiclePositionChanged(v); |
|
644 |
EndVehicleMove(v); |
|
645 |
} |
|
646 |
} |
|
647 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
648 |
static void SteamSmokeInit(Vehicle *v) |
0 | 649 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
650 |
v->cur_image = SPR_STEAM_SMOKE_0; |
0 | 651 |
v->progress = 12; |
652 |
} |
|
653 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
654 |
static void SteamSmokeTick(Vehicle *v) |
0 | 655 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
656 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
657 |
|
0 | 658 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
659 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
660 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
661 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
662 |
if ((v->progress & 7) == 0) { |
0 | 663 |
v->z_pos++; |
664 |
moved = true; |
|
665 |
} |
|
666 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
667 |
if ((v->progress & 0xF) == 4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
668 |
if (v->cur_image != SPR_STEAM_SMOKE_4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
669 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
670 |
} else { |
0 | 671 |
EndVehicleMove(v); |
672 |
DeleteVehicle(v); |
|
673 |
return; |
|
674 |
} |
|
675 |
moved = true; |
|
676 |
} |
|
677 |
||
678 |
if (moved) { |
|
679 |
VehiclePositionChanged(v); |
|
680 |
EndVehicleMove(v); |
|
681 |
} |
|
682 |
} |
|
683 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
684 |
static void DieselSmokeInit(Vehicle *v) |
0 | 685 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
686 |
v->cur_image = SPR_DIESEL_SMOKE_0; |
0 | 687 |
v->progress = 0; |
688 |
} |
|
689 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
690 |
static void DieselSmokeTick(Vehicle *v) |
0 | 691 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
692 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
693 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
694 |
if ((v->progress & 3) == 0) { |
0 | 695 |
BeginVehicleMove(v); |
696 |
v->z_pos++; |
|
697 |
VehiclePositionChanged(v); |
|
698 |
EndVehicleMove(v); |
|
699 |
} else if ((v->progress & 7) == 1) { |
|
700 |
BeginVehicleMove(v); |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
701 |
if (v->cur_image != SPR_DIESEL_SMOKE_5) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
702 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
703 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
704 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
705 |
} else { |
0 | 706 |
EndVehicleMove(v); |
707 |
DeleteVehicle(v); |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
711 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
712 |
static void ElectricSparkInit(Vehicle *v) |
0 | 713 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
714 |
v->cur_image = SPR_ELECTRIC_SPARK_0; |
0 | 715 |
v->progress = 1; |
716 |
} |
|
717 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
718 |
static void ElectricSparkTick(Vehicle *v) |
0 | 719 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
720 |
if (v->progress < 2) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
721 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
722 |
} else { |
0 | 723 |
v->progress = 0; |
724 |
BeginVehicleMove(v); |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
725 |
if (v->cur_image != SPR_ELECTRIC_SPARK_5) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
726 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
727 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
728 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
729 |
} else { |
0 | 730 |
EndVehicleMove(v); |
731 |
DeleteVehicle(v); |
|
732 |
} |
|
733 |
} |
|
734 |
} |
|
735 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
736 |
static void SmokeInit(Vehicle *v) |
0 | 737 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
738 |
v->cur_image = SPR_SMOKE_0; |
0 | 739 |
v->progress = 12; |
740 |
} |
|
741 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
742 |
static void SmokeTick(Vehicle *v) |
0 | 743 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
744 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
745 |
|
0 | 746 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
747 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
748 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
749 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
750 |
if ((v->progress & 3) == 0) { |
0 | 751 |
v->z_pos++; |
752 |
moved = true; |
|
753 |
} |
|
754 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
755 |
if ((v->progress & 0xF) == 4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
756 |
if (v->cur_image != SPR_SMOKE_4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
757 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
758 |
} else { |
0 | 759 |
EndVehicleMove(v); |
760 |
DeleteVehicle(v); |
|
761 |
return; |
|
762 |
} |
|
763 |
moved = true; |
|
764 |
} |
|
765 |
||
766 |
if (moved) { |
|
767 |
VehiclePositionChanged(v); |
|
768 |
EndVehicleMove(v); |
|
769 |
} |
|
770 |
} |
|
771 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
772 |
static void ExplosionLargeInit(Vehicle *v) |
0 | 773 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
774 |
v->cur_image = SPR_EXPLOSION_LARGE_0; |
0 | 775 |
v->progress = 0; |
776 |
} |
|
777 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
778 |
static void ExplosionLargeTick(Vehicle *v) |
0 | 779 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
780 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
781 |
if ((v->progress & 3) == 0) { |
0 | 782 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
783 |
if (v->cur_image != SPR_EXPLOSION_LARGE_F) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
784 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
785 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
786 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
787 |
} else { |
0 | 788 |
EndVehicleMove(v); |
789 |
DeleteVehicle(v); |
|
790 |
} |
|
791 |
} |
|
792 |
} |
|
793 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
794 |
static void BreakdownSmokeInit(Vehicle *v) |
0 | 795 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
796 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
0 | 797 |
v->progress = 0; |
798 |
} |
|
799 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
800 |
static void BreakdownSmokeTick(Vehicle *v) |
0 | 801 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
802 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
803 |
if ((v->progress & 7) == 0) { |
0 | 804 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
805 |
if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
806 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
807 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
808 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
809 |
} |
0 | 810 |
VehiclePositionChanged(v); |
811 |
EndVehicleMove(v); |
|
812 |
} |
|
813 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
814 |
v->u.special.unk0--; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
815 |
if (v->u.special.unk0 == 0) { |
0 | 816 |
BeginVehicleMove(v); |
817 |
EndVehicleMove(v); |
|
818 |
DeleteVehicle(v); |
|
819 |
} |
|
820 |
} |
|
821 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
822 |
static void ExplosionSmallInit(Vehicle *v) |
0 | 823 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
824 |
v->cur_image = SPR_EXPLOSION_SMALL_0; |
0 | 825 |
v->progress = 0; |
826 |
} |
|
827 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
828 |
static void ExplosionSmallTick(Vehicle *v) |
0 | 829 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
830 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
831 |
if ((v->progress & 3) == 0) { |
0 | 832 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
833 |
if (v->cur_image != SPR_EXPLOSION_SMALL_B) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
834 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
835 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
836 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
837 |
} else { |
0 | 838 |
EndVehicleMove(v); |
839 |
DeleteVehicle(v); |
|
840 |
} |
|
841 |
} |
|
842 |
} |
|
843 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
844 |
static void BulldozerInit(Vehicle *v) |
0 | 845 |
{ |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
846 |
v->cur_image = SPR_BULLDOZER_NE; |
0 | 847 |
v->progress = 0; |
848 |
v->u.special.unk0 = 0; |
|
849 |
v->u.special.unk2 = 0; |
|
850 |
} |
|
851 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
852 |
typedef struct BulldozerMovement { |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
853 |
byte direction:2; |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
854 |
byte image:2; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
855 |
byte duration:3; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
856 |
} BulldozerMovement; |
0 | 857 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
858 |
static const BulldozerMovement _bulldozer_movement[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
859 |
{ 0, 0, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
860 |
{ 3, 3, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
861 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
862 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
863 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
864 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
865 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
866 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
867 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
868 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
869 |
{ 3, 3, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
870 |
{ 2, 2, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
871 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
872 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
873 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
874 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
875 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
876 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
877 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
878 |
{ 3, 1, 7 } |
0 | 879 |
}; |
880 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
881 |
static const struct { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
882 |
int8 x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
883 |
int8 y; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
884 |
} _inc_by_dir[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
885 |
{ -1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
886 |
{ 0, 1 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
887 |
{ 1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
888 |
{ 0, -1 } |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
889 |
}; |
0 | 890 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
891 |
static void BulldozerTick(Vehicle *v) |
0 | 892 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
893 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
894 |
if ((v->progress & 7) == 0) { |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
895 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.unk0]; |
0 | 896 |
|
897 |
BeginVehicleMove(v); |
|
898 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
899 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
0 | 900 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
901 |
v->x_pos += _inc_by_dir[b->direction].x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
902 |
v->y_pos += _inc_by_dir[b->direction].y; |
0 | 903 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
904 |
v->u.special.unk2++; |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
905 |
if (v->u.special.unk2 >= b->duration) { |
0 | 906 |
v->u.special.unk2 = 0; |
907 |
v->u.special.unk0++; |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
908 |
if (v->u.special.unk0 == lengthof(_bulldozer_movement)) { |
0 | 909 |
EndVehicleMove(v); |
910 |
DeleteVehicle(v); |
|
911 |
return; |
|
912 |
} |
|
913 |
} |
|
914 |
VehiclePositionChanged(v); |
|
915 |
EndVehicleMove(v); |
|
916 |
} |
|
917 |
} |
|
918 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
919 |
static void BubbleInit(Vehicle *v) |
0 | 920 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
921 |
v->cur_image = SPR_BUBBLE_GENERATE_0; |
0 | 922 |
v->spritenum = 0; |
923 |
v->progress = 0; |
|
924 |
} |
|
925 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
926 |
typedef struct BubbleMovement { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
927 |
int8 x:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
928 |
int8 y:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
929 |
int8 z:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
930 |
byte image:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
931 |
} BubbleMovement; |
0 | 932 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
933 |
#define MK(x, y, z, i) { x, y, z, i } |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
934 |
#define ME(i) { i, 4, 0, 0 } |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
935 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
936 |
static const BubbleMovement _bubble_float_sw[] = { |
0 | 937 |
MK(0,0,1,0), |
938 |
MK(1,0,1,1), |
|
939 |
MK(0,0,1,0), |
|
940 |
MK(1,0,1,2), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
941 |
ME(1) |
0 | 942 |
}; |
943 |
||
944 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
945 |
static const BubbleMovement _bubble_float_ne[] = { |
0 | 946 |
MK(0,0,1,0), |
947 |
MK(-1,0,1,1), |
|
948 |
MK(0,0,1,0), |
|
949 |
MK(-1,0,1,2), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
950 |
ME(1) |
0 | 951 |
}; |
952 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
953 |
static const BubbleMovement _bubble_float_se[] = { |
0 | 954 |
MK(0,0,1,0), |
955 |
MK(0,1,1,1), |
|
956 |
MK(0,0,1,0), |
|
957 |
MK(0,1,1,2), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
958 |
ME(1) |
0 | 959 |
}; |
960 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
961 |
static const BubbleMovement _bubble_float_nw[] = { |
0 | 962 |
MK(0,0,1,0), |
963 |
MK(0,-1,1,1), |
|
964 |
MK(0,0,1,0), |
|
965 |
MK(0,-1,1,2), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
966 |
ME(1) |
0 | 967 |
}; |
968 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
969 |
static const BubbleMovement _bubble_burst[] = { |
0 | 970 |
MK(0,0,1,2), |
971 |
MK(0,0,1,7), |
|
972 |
MK(0,0,1,8), |
|
973 |
MK(0,0,1,9), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
974 |
ME(0) |
0 | 975 |
}; |
976 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
977 |
static const BubbleMovement _bubble_absorb[] = { |
0 | 978 |
MK(0,0,1,0), |
979 |
MK(0,0,1,1), |
|
980 |
MK(0,0,1,0), |
|
981 |
MK(0,0,1,2), |
|
982 |
MK(0,0,1,0), |
|
983 |
MK(0,0,1,1), |
|
984 |
MK(0,0,1,0), |
|
985 |
MK(0,0,1,2), |
|
986 |
MK(0,0,1,0), |
|
987 |
MK(0,0,1,1), |
|
988 |
MK(0,0,1,0), |
|
989 |
MK(0,0,1,2), |
|
990 |
MK(0,0,1,0), |
|
991 |
MK(0,0,1,1), |
|
992 |
MK(0,0,1,0), |
|
993 |
MK(0,0,1,2), |
|
994 |
MK(0,0,1,0), |
|
995 |
MK(0,0,1,1), |
|
996 |
MK(0,0,1,0), |
|
997 |
MK(0,0,1,2), |
|
998 |
MK(0,0,1,0), |
|
999 |
MK(0,0,1,1), |
|
1000 |
MK(0,0,1,0), |
|
1001 |
MK(0,0,1,2), |
|
1002 |
MK(0,0,1,0), |
|
1003 |
MK(0,0,1,1), |
|
1004 |
MK(0,0,1,0), |
|
1005 |
MK(0,0,1,2), |
|
1006 |
MK(0,0,1,0), |
|
1007 |
MK(0,0,1,1), |
|
1008 |
MK(0,0,1,0), |
|
1009 |
MK(0,0,1,2), |
|
1010 |
MK(0,0,1,0), |
|
1011 |
MK(0,0,1,1), |
|
1012 |
MK(0,0,1,0), |
|
1013 |
MK(0,0,1,2), |
|
1014 |
MK(0,0,1,0), |
|
1015 |
MK(0,0,1,1), |
|
1016 |
MK(0,0,1,0), |
|
1017 |
MK(0,0,1,2), |
|
1018 |
MK(0,0,1,0), |
|
1019 |
MK(0,0,1,1), |
|
1020 |
MK(0,0,1,0), |
|
1021 |
MK(0,0,1,2), |
|
1022 |
MK(0,0,1,0), |
|
1023 |
MK(0,0,1,1), |
|
1024 |
MK(0,0,1,0), |
|
1025 |
MK(0,0,1,2), |
|
1026 |
MK(0,0,1,0), |
|
1027 |
MK(0,0,1,1), |
|
1028 |
MK(0,0,1,0), |
|
1029 |
MK(0,0,1,2), |
|
1030 |
MK(0,0,1,0), |
|
1031 |
MK(0,0,1,1), |
|
1032 |
MK(0,0,1,0), |
|
1033 |
MK(0,0,1,2), |
|
1034 |
MK(0,0,1,0), |
|
1035 |
MK(0,0,1,1), |
|
1036 |
MK(0,0,1,0), |
|
1037 |
MK(0,0,1,2), |
|
1038 |
MK(0,0,1,0), |
|
1039 |
MK(0,0,1,1), |
|
1040 |
MK(2,1,3,0), |
|
1041 |
MK(1,1,3,1), |
|
1042 |
MK(2,1,3,0), |
|
1043 |
MK(1,1,3,2), |
|
1044 |
MK(2,1,3,0), |
|
1045 |
MK(1,1,3,1), |
|
1046 |
MK(2,1,3,0), |
|
1047 |
MK(1,0,1,2), |
|
1048 |
MK(0,0,1,0), |
|
1049 |
MK(1,0,1,1), |
|
1050 |
MK(0,0,1,0), |
|
1051 |
MK(1,0,1,2), |
|
1052 |
MK(0,0,1,0), |
|
1053 |
MK(1,0,1,1), |
|
1054 |
MK(0,0,1,0), |
|
1055 |
MK(1,0,1,2), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1056 |
ME(2), |
0 | 1057 |
MK(0,0,0,0xA), |
1058 |
MK(0,0,0,0xB), |
|
1059 |
MK(0,0,0,0xC), |
|
1060 |
MK(0,0,0,0xD), |
|
1061 |
MK(0,0,0,0xE), |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1062 |
ME(0) |
0 | 1063 |
}; |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1064 |
#undef ME |
0 | 1065 |
#undef MK |
1066 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1067 |
static const BubbleMovement * const _bubble_movement[] = { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1068 |
_bubble_float_sw, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1069 |
_bubble_float_ne, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1070 |
_bubble_float_se, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1071 |
_bubble_float_nw, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1072 |
_bubble_burst, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1073 |
_bubble_absorb, |
0 | 1074 |
}; |
1075 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1076 |
static void BubbleTick(Vehicle *v) |
0 | 1077 |
{ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1078 |
/* |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1079 |
* 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
|
1080 |
* InteractiveRandom(), because somehow someone forgot to save |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1081 |
* 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
|
1082 |
* multiplayer!! (that is: in ToyLand) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1083 |
*/ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1084 |
uint et; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1085 |
const BubbleMovement *b; |
0 | 1086 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1087 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1088 |
if ((v->progress & 3) != 0) |
0 | 1089 |
return; |
1090 |
||
1091 |
BeginVehicleMove(v); |
|
1092 |
||
1093 |
if (v->spritenum == 0) { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1094 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1095 |
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { |
0 | 1096 |
VehiclePositionChanged(v); |
1097 |
EndVehicleMove(v); |
|
1098 |
return; |
|
1099 |
} |
|
1100 |
if (v->u.special.unk2 != 0) { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1101 |
v->spritenum = (InteractiveRandom() & 3) + 1; |
0 | 1102 |
} else { |
1103 |
v->spritenum = 6; |
|
1104 |
} |
|
1105 |
et = 0; |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1106 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1107 |
et = v->engine_type + 1; |
0 | 1108 |
} |
1109 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1110 |
b = &_bubble_movement[v->spritenum - 1][et]; |
0 | 1111 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1112 |
if (b->y == 4 && b->x == 0) { |
0 | 1113 |
EndVehicleMove(v); |
1114 |
DeleteVehicle(v); |
|
1115 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1116 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1117 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1118 |
if (b->y == 4 && b->x == 1) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1119 |
if (v->z_pos > 180 || CHANCE16I(1, 96, InteractiveRandom())) { |
0 | 1120 |
v->spritenum = 5; |
541 | 1121 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1122 |
} |
1123 |
et = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1124 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1125 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1126 |
if (b->y == 4 && b->x == 2) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1127 |
TileIndex tile; |
0 | 1128 |
|
1129 |
et++; |
|
541 | 1130 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1131 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1132 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1133 |
if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m5 == 0xA2) AddAnimatedTile(tile); |
0 | 1134 |
} |
1135 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1136 |
v->engine_type = et; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1137 |
b = &_bubble_movement[v->spritenum - 1][et]; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1138 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1139 |
v->x_pos += b->x; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1140 |
v->y_pos += b->y; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1141 |
v->z_pos += b->z; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1142 |
v->cur_image = SPR_BUBBLE_0 + b->image; |
0 | 1143 |
|
1144 |
VehiclePositionChanged(v); |
|
1145 |
EndVehicleMove(v); |
|
1146 |
} |
|
1147 |
||
1148 |
||
1149 |
typedef void EffectInitProc(Vehicle *v); |
|
1150 |
typedef void EffectTickProc(Vehicle *v); |
|
1151 |
||
1152 |
static EffectInitProc * const _effect_init_procs[] = { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1153 |
ChimneySmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1154 |
SteamSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1155 |
DieselSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1156 |
ElectricSparkInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1157 |
SmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1158 |
ExplosionLargeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1159 |
BreakdownSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1160 |
ExplosionSmallInit, |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1161 |
BulldozerInit, |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1162 |
BubbleInit, |
0 | 1163 |
}; |
1164 |
||
1165 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1166 |
ChimneySmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1167 |
SteamSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1168 |
DieselSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1169 |
ElectricSparkTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1170 |
SmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1171 |
ExplosionLargeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1172 |
BreakdownSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1173 |
ExplosionSmallTick, |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1174 |
BulldozerTick, |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1175 |
BubbleTick, |
0 | 1176 |
}; |
1177 |
||
1178 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1179 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) |
0 | 1180 |
{ |
1181 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1182 |
|
0 | 1183 |
v = ForceAllocateSpecialVehicle(); |
1184 |
if (v != NULL) { |
|
1185 |
v->type = VEH_Special; |
|
1186 |
v->subtype = type; |
|
1187 |
v->x_pos = x; |
|
1188 |
v->y_pos = y; |
|
1189 |
v->z_pos = z; |
|
1190 |
v->z_height = v->sprite_width = v->sprite_height = 1; |
|
1191 |
v->x_offs = v->y_offs = 0; |
|
1192 |
v->tile = 0; |
|
1193 |
v->vehstatus = VS_UNCLICKABLE; |
|
1194 |
||
1195 |
_effect_init_procs[type](v); |
|
1196 |
||
1197 |
VehiclePositionChanged(v); |
|
1198 |
BeginVehicleMove(v); |
|
1199 |
EndVehicleMove(v); |
|
1200 |
} |
|
1201 |
return v; |
|
1202 |
} |
|
1203 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1204 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type) |
0 | 1205 |
{ |
1206 |
return CreateEffectVehicle(x, y, GetSlopeZ(x, y) + z, type); |
|
1207 |
} |
|
1208 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1209 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type) |
0 | 1210 |
{ |
1211 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1212 |
} |
|
1213 |
||
410 | 1214 |
static void EffectVehicle_Tick(Vehicle *v) |
0 | 1215 |
{ |
1216 |
_effect_tick_procs[v->subtype](v); |
|
1217 |
} |
|
1218 |
||
2116 | 1219 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 1220 |
{ |
1221 |
Vehicle *found = NULL, *v; |
|
1222 |
uint dist, best_dist = (uint)-1; |
|
1223 |
||
1224 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1225 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1226 |
return NULL; |
|
1227 |
||
1228 |
x = (x << vp->zoom) + vp->virtual_left; |
|
1229 |
y = (y << vp->zoom) + vp->virtual_top; |
|
1230 |
||
1231 |
FOR_ALL_VEHICLES(v) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1232 |
if (v->type != 0 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1233 |
x >= v->left_coord && x <= v->right_coord && |
1234 |
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
|
1235 |
|
0 | 1236 |
dist = max( |
1237 |
myabs( ((v->left_coord + v->right_coord)>>1) - x ), |
|
1238 |
myabs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
|
1239 |
); |
|
1240 |
||
1241 |
if (dist < best_dist) { |
|
1242 |
found = v; |
|
1243 |
best_dist = dist; |
|
1244 |
} |
|
1245 |
} |
|
1246 |
} |
|
1247 |
||
1248 |
return found; |
|
1249 |
} |
|
1250 |
||
1251 |
||
1252 |
void DecreaseVehicleValue(Vehicle *v) |
|
1253 |
{ |
|
1254 |
v->value -= v->value >> 8; |
|
1255 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1256 |
} |
|
1257 |
||
1258 |
static const byte _breakdown_chance[64] = { |
|
1259 |
3, 3, 3, 3, 3, 3, 3, 3, |
|
1260 |
4, 4, 5, 5, 6, 6, 7, 7, |
|
1261 |
8, 8, 9, 9, 10, 10, 11, 11, |
|
1262 |
12, 13, 13, 13, 13, 14, 15, 16, |
|
1263 |
17, 19, 21, 25, 28, 31, 34, 37, |
|
1264 |
40, 44, 48, 52, 56, 60, 64, 68, |
|
1265 |
72, 80, 90, 100, 110, 120, 130, 140, |
|
1266 |
150, 170, 190, 210, 230, 250, 250, 250, |
|
1267 |
}; |
|
1268 |
||
1269 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1270 |
{ |
|
1271 |
int rel, rel_old; |
|
1272 |
uint32 r; |
|
1273 |
int chance; |
|
1274 |
||
1275 |
/* decrease reliability */ |
|
1276 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1277 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1278 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1279 |
||
1280 |
if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) != 0 || |
|
1281 |
v->cur_speed < 5 || _game_mode == GM_MENU) |
|
1282 |
return; |
|
1283 |
||
1284 |
r = Random(); |
|
1285 |
||
1286 |
/* increase chance of failure */ |
|
1287 |
chance = v->breakdown_chance + 1; |
|
1288 |
if (CHANCE16I(1,25,r)) chance += 25; |
|
1289 |
v->breakdown_chance = min(255, chance); |
|
1290 |
||
1291 |
/* calculate reliability value to use in comparison */ |
|
1292 |
rel = v->reliability; |
|
1293 |
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
|
1294 |
|
0 | 1295 |
/* disabled breakdowns? */ |
1296 |
if (_opt.diff.vehicle_breakdowns < 1) |
|
1297 |
return; |
|
1298 |
||
1299 |
/* reduced breakdowns? */ |
|
1300 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1301 |
||
1302 |
/* check if to break down */ |
|
1303 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
1304 |
v->breakdown_ctr = GB(r, 16, 6) + 0x3F; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
1305 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 1306 |
v->breakdown_chance = 0; |
1307 |
} |
|
1308 |
} |
|
1309 |
||
1310 |
static const StringID _vehicle_type_names[4] = { |
|
1311 |
STR_019F_TRAIN, |
|
1312 |
STR_019C_ROAD_VEHICLE, |
|
1313 |
STR_019E_SHIP, |
|
1314 |
STR_019D_AIRCRAFT, |
|
1315 |
}; |
|
1316 |
||
1317 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1318 |
{ |
|
1319 |
if (v->owner != _local_player) |
|
1320 |
return; |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1321 |
|
26 | 1322 |
// Do not show getting-old message if autorenew is active |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1323 |
if (GetPlayer(v->owner)->engine_renew) |
26 | 1324 |
return; |
0 | 1325 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1326 |
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
|
1327 |
SetDParam(1, v->unitnumber); |
0 | 1328 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1329 |
} |
|
1330 |
||
1331 |
void AgeVehicle(Vehicle *v) |
|
1332 |
{ |
|
1333 |
int age; |
|
1334 |
||
1335 |
if (v->age < 65535) |
|
1336 |
v->age++; |
|
1337 |
||
1338 |
age = v->age - v->max_age; |
|
1339 |
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
|
1340 |
v->reliability_spd_dec <<= 1; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1341 |
|
0 | 1342 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1343 |
||
1344 |
if (age == -366) { |
|
1345 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1346 |
} else if (age == 0) { |
|
1347 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
1348 |
} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) { |
|
1349 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
|
1350 |
} |
|
1351 |
} |
|
1352 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1353 |
extern int32 EstimateTrainCost(const RailVehicleInfo *rvi); |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1786
diff
changeset
|
1354 |
extern int32 EstimateRoadVehCost(EngineID engine_type); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1786
diff
changeset
|
1355 |
extern int32 EstimateShipCost(EngineID engine_type); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1786
diff
changeset
|
1356 |
extern int32 EstimateAircraftCost(EngineID engine_type); |
842 | 1357 |
extern int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
1358 |
extern int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1359 |
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
|
1360 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1361 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1362 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1363 |
/** Replaces a vehicle (used to be called autorenew). |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1364 |
* Must be called with _current_player set to the owner of the vehicle |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1365 |
* @param v Vehicle to replace |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1366 |
*/ |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1367 |
int32 ReplaceVehicle(Vehicle *v) |
0 | 1368 |
{ |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1369 |
Player *p = GetPlayer(v->owner); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1370 |
EngineID old_engine_type = v->engine_type; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1371 |
EngineID new_engine_type = p->engine_replacement[old_engine_type]; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1372 |
Vehicle *u, *first; |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1373 |
int cost, build_cost, rear_engine_cost = 0; |
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
|
1374 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1375 |
// If replacing due to age only, use the same type :-) |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1376 |
if (new_engine_type == INVALID_ENGINE) |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1377 |
new_engine_type = old_engine_type; |
915 | 1378 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1379 |
u = v; |
915 | 1380 |
|
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1381 |
/* First we make sure that it's a valid type the user requested |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1382 |
* check that it's an engine that is in the engine array */ |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1383 |
if (!IsEngineIndex(new_engine_type)) return CMD_ERROR; |
915 | 1384 |
|
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
|
1385 |
// check that the new vehicle type is the same as the original one |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
1386 |
if (v->type != GetEngine(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
|
1387 |
|
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
|
1388 |
// 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
|
1389 |
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
|
1390 |
|
1185
08d48bad089c
(svn r1687) - Feature: [autoreplace] server now checks for plane<->helicopter replacement and reject replacement if needed
bjarni
parents:
1174
diff
changeset
|
1391 |
// 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
|
1392 |
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
|
1393 |
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
|
1394 |
} |
1185
08d48bad089c
(svn r1687) - Feature: [autoreplace] server now checks for plane<->helicopter replacement and reject replacement if needed
bjarni
parents:
1174
diff
changeset
|
1395 |
|
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
|
1396 |
// makes sure that the player can actually buy the new engine. Renewing is still allowed to outdated engines |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
1397 |
if (!HASBIT(GetEngine(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
|
1398 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1399 |
switch (v->type) { |
842 | 1400 |
case VEH_Train: build_cost = EstimateTrainCost(RailVehInfo(new_engine_type)); break; |
1401 |
case VEH_Road: build_cost = EstimateRoadVehCost(new_engine_type); break; |
|
1402 |
case VEH_Ship: build_cost = EstimateShipCost(new_engine_type); break; |
|
1403 |
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
|
1404 |
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
|
1405 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1406 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1407 |
/* 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
|
1408 |
settings, a vehicle can be replaced twice.. check if this is the situation here */ |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
1409 |
if (old_engine_type == new_engine_type && v->age == 0) return CMD_ERROR; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1410 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1411 |
if ( v->type == VEH_Train ) { |
1635
6a5b991bdd49
(svn r2139) -fix: "[ 1146215 ] Engine power not updated w/auto replace" autoreplace now forces an update of the cache. It should not affect gameplay as the
bjarni
parents:
1605
diff
changeset
|
1412 |
first = GetFirstVehicleInChain(v); |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1413 |
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
|
1414 |
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
|
1415 |
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
|
1416 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1417 |
if ( old_engine_type != new_engine_type ) { |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1418 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1419 |
// prevent that the rear engine can get replaced to something else than the front engine |
1917
74cab7e464d1
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1905
diff
changeset
|
1420 |
if ( v->u.rail.first_engine != INVALID_VEHICLE && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD && RailVehInfo(old_engine_type)->flags ) { |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1421 |
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
|
1422 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1423 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1424 |
// checks if the engine is the first one |
1917
74cab7e464d1
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1905
diff
changeset
|
1425 |
if ( v->u.rail.first_engine == INVALID_VEHICLE ) { |
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 |
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
|
1427 |
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
|
1428 |
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
|
1429 |
} else { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1430 |
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
|
1431 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1432 |
} else { |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1433 |
if ( u->engine_type == old_engine_type && RailVehInfo(old_engine_type)->flags & RVI_MULTIHEAD) { |
1068 | 1434 |
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
|
1435 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1436 |
} |
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 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1439 |
} |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1440 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1441 |
/* 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
|
1442 |
(that is needed, because this CMD is called automaticly) */ |
2296
6e883aaa77e0
(svn r2820) -Fix: [autoreplace] fixed issue introduced in 2817 where autoreplace failed if new engine is cheaper than the old one (peter1138)
bjarni
parents:
2295
diff
changeset
|
1443 |
if ( p->money64 < (int32)(p->engine_renew_money + build_cost + rear_engine_cost - v->value)) { |
842 | 1444 |
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
|
1445 |
int message; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1446 |
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
|
1447 |
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
|
1448 |
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
|
1449 |
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
|
1450 |
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
|
1451 |
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
|
1452 |
// 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
|
1453 |
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
|
1454 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1455 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1456 |
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
|
1457 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1458 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1459 |
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
|
1460 |
} |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1461 |
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
|
1462 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1463 |
if (old_engine_type != 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
|
1464 |
/* We do not really buy a new vehicle, we upgrade the old one */ |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
1465 |
const Engine* e = GetEngine(new_engine_type); |
915 | 1466 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1467 |
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
|
1468 |
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
|
1469 |
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
|
1470 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1471 |
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
|
1472 |
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
|
1473 |
|
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1474 |
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
|
1475 |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1476 |
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
|
1477 |
byte sprite = v->spritenum; |
842 | 1478 |
byte cargo_type = v->cargo_type; |
1479 |
v->engine_type = new_engine_type; |
|
1480 |
v->max_age = e->lifelength * 366; |
|
915 | 1481 |
|
842 | 1482 |
/* Update limits of the vehicle (for when upgraded) */ |
1483 |
switch (v->type) { |
|
1484 |
case VEH_Train: |
|
1485 |
{ |
|
1486 |
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
|
1487 |
const RailVehicleInfo *rvi2 = RailVehInfo(old_engine_type); |
1663
b086c94fb9a5
(svn r2167) -fix: [autoreplace] trains now get the default cargo type if the engine
bjarni
parents:
1652
diff
changeset
|
1488 |
byte capacity = rvi2->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
|
1489 |
Vehicle *first = GetFirstVehicleInChain(v); |
842 | 1490 |
|
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
|
1491 |
//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
|
1492 |
/* 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
|
1493 |
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
|
1494 |
(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
|
1495 |
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
|
1496 |
|
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
|
1497 |
// turn the last engine in a multiheaded train if needed |
1917
74cab7e464d1
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1905
diff
changeset
|
1498 |
if ( v->next == NULL && v->u.rail.first_engine != INVALID_VEHICLE && 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
|
1499 |
v->spritenum++; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1500 |
|
842 | 1501 |
v->cargo_type = rvi->cargo_type; |
1502 |
v->cargo_cap = rvi->capacity; |
|
1503 |
v->max_speed = rvi->max_speed; |
|
1504 |
||
1505 |
v->u.rail.railtype = e->railtype; |
|
915 | 1506 |
|
842 | 1507 |
// 0x0100 means that we skip the check for being stopped inside the depot |
1508 |
// since we do not stop it for autorefitting |
|
1509 |
if (v->cargo_type != cargo_type && capacity) { |
|
1510 |
// BUG: somehow v->index is not transfered properly |
|
1511 |
//CmdRefitRailVehicle(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1512 |
v->cargo_type = cargo_type; // workaround, but it do not check the refit table |
|
1513 |
} else { |
|
1514 |
v->cargo_type = rvi->cargo_type; |
|
1515 |
} |
|
1735
e38d9d16bc03
(svn r2239) -Fix [autoreplace]: [ 1185653 ] autoreplacing a dualheaded engine into a singleheaded engine is no longer a potiontial crash
bjarni
parents:
1663
diff
changeset
|
1516 |
#if 0 |
e38d9d16bc03
(svn r2239) -Fix [autoreplace]: [ 1185653 ] autoreplacing a dualheaded engine into a singleheaded engine is no longer a potiontial crash
bjarni
parents:
1663
diff
changeset
|
1517 |
// we disable this because they can crash the game. They will be fixed at a later date |
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1518 |
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
|
1519 |
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
|
1520 |
Vehicle *w; |
03fed43e58fc
(svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents:
1062
diff
changeset
|
1521 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1522 |
u = GetLastVehicleInChain(v); |
1063
03fed43e58fc
(svn r1564) ISO C90 forbids mixed declarations and code (bad bjarni, no cookie)
tron
parents:
1062
diff
changeset
|
1523 |
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
|
1524 |
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
|
1525 |
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
|
1526 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1527 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1528 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1529 |
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
|
1530 |
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
|
1531 |
} |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1532 |
|
1060
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1533 |
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
|
1534 |
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
|
1535 |
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
|
1536 |
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
|
1537 |
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
|
1538 |
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
|
1539 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1540 |
} |
e8c44e426175
(svn r1561) Fix: autoreplacing a singleheaded engine into a dualheaded engine now adds the the rear engine
bjarni
parents:
1058
diff
changeset
|
1541 |
} |
1735
e38d9d16bc03
(svn r2239) -Fix [autoreplace]: [ 1185653 ] autoreplacing a dualheaded engine into a singleheaded engine is no longer a potiontial crash
bjarni
parents:
1663
diff
changeset
|
1542 |
#endif |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
1543 |
|
1917
74cab7e464d1
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1905
diff
changeset
|
1544 |
// recalculate changed train values |
74cab7e464d1
(svn r2423) - CodeChange: Include first_engine in the train cache, instead of calculating it all over the place.
hackykid
parents:
1905
diff
changeset
|
1545 |
TrainConsistChanged(first); |
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
|
1546 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
1635
6a5b991bdd49
(svn r2139) -fix: "[ 1146215 ] Engine power not updated w/auto replace" autoreplace now forces an update of the cache. It should not affect gameplay as the
bjarni
parents:
1605
diff
changeset
|
1547 |
UpdateTrainAcceleration(first); |
842 | 1548 |
break; |
1549 |
} |
|
1550 |
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
|
1551 |
{ |
842 | 1552 |
const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type); |
1553 |
||
1554 |
v->spritenum = rvi->image_index; |
|
1555 |
v->cargo_type = rvi->cargo_type; |
|
1556 |
v->cargo_cap = rvi->capacity; |
|
1557 |
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
|
1558 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
842 | 1559 |
break; |
1560 |
} |
|
1561 |
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
|
1562 |
{ |
842 | 1563 |
const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type); |
1564 |
||
1565 |
v->spritenum = svi->image_index; |
|
1566 |
v->cargo_type = svi->cargo_type; |
|
1567 |
v->cargo_cap = svi->capacity; |
|
1568 |
v->max_speed = svi->max_speed; |
|
915 | 1569 |
|
842 | 1570 |
// 0x0100 means that we skip the check for being stopped inside the depot |
1571 |
// since we do not stop it for autorefitting |
|
1572 |
if (v->cargo_type != cargo_type) |
|
1573 |
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
|
1574 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
842 | 1575 |
break; |
1576 |
} |
|
1577 |
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
|
1578 |
{ |
842 | 1579 |
const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type); |
1580 |
Vehicle *u; |
|
1581 |
||
1582 |
v->max_speed = avi->max_speed; |
|
1583 |
v->acceleration = avi->acceleration; |
|
1584 |
v->spritenum = avi->image_index; |
|
1585 |
||
1586 |
if ( cargo_type == CT_PASSENGERS ) { |
|
922
fc040662bd43
(svn r1410) Replaced all occurences of 'passanger' by 'passenger' in the code
celestar
parents:
919
diff
changeset
|
1587 |
v->cargo_cap = avi->passenger_capacity; |
842 | 1588 |
u = v->next; |
1589 |
u->cargo_cap = avi->mail_capacity; |
|
1590 |
} else { |
|
1591 |
// 0x0100 means that we skip the check for being stopped inside the hangar |
|
1592 |
// since we do not stop it for autorefitting |
|
1593 |
CmdRefitAircraft(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 ); |
|
1594 |
} |
|
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
|
1595 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
842 | 1596 |
break; |
1597 |
} |
|
1598 |
default: return CMD_ERROR; |
|
1599 |
} |
|
1600 |
// makes sure that the cargo is still valid compared to new capacity |
|
1601 |
if (v->cargo_count != 0) { |
|
1602 |
if ( v->cargo_type != cargo_type ) |
|
1603 |
v->cargo_count = 0; |
|
1604 |
else if ( v->cargo_count > v->cargo_cap ) |
|
1605 |
v->cargo_count = v->cargo_cap; |
|
1606 |
} |
|
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1607 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1608 |
} |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1609 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1610 |
// A replaced vehicle should be classed as new |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1611 |
v->age = 0; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1612 |
|
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1613 |
InvalidateWindow(WC_REPLACE_VEHICLE, v->type); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1614 |
ResortVehicleLists(); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1615 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1616 |
|
842 | 1617 |
//needs to be down here because refitting will change SET_EXPENSES_TYPE if called |
1618 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1619 |
SubtractMoneyFromPlayer(cost); |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1620 |
if (_current_player == _local_player) |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1621 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1622 |
|
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1623 |
return cost; |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1624 |
} |
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1625 |
|
842 | 1626 |
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
|
1627 |
{ |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1628 |
Player *p = GetPlayer(v->owner); |
842 | 1629 |
// uncomment next line if you want to see what engine type just entered a depot |
1630 |
//printf("engine type: %d\n", v->engine_type); |
|
0 | 1631 |
|
26 | 1632 |
// A vehicle is autorenewed when it it gets the amount of months |
1633 |
// give by _patches.autorenew_months away for his max age. |
|
1634 |
// Standard is -6, meaning 6 months before his max age |
|
1635 |
// It can be any value between -12 and 12. |
|
842 | 1636 |
// Here it also checks if the vehicles is listed for replacement |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1637 |
if (!p->engine_renew || v->age - v->max_age < (p->engine_renew_months * 30)) { //replace if engine is too old |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1638 |
if (p->engine_replacement[v->engine_type] == INVALID_ENGINE && v->type != VEH_Train) // updates to a new model |
842 | 1639 |
return; |
1640 |
} |
|
1641 |
/* 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
|
1642 |
_current_player = v->owner; |
915 | 1643 |
|
842 | 1644 |
if ( v->type != VEH_Train ) { |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1645 |
ReplaceVehicle(v); |
842 | 1646 |
} 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
|
1647 |
// 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
|
1648 |
do { |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1649 |
if (p->engine_replacement[v->engine_type] != INVALID_ENGINE || (p->engine_renew && (v->age - v->max_age) > (p->engine_renew_months * 30))) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2261
diff
changeset
|
1650 |
ReplaceVehicle(v); |
842 | 1651 |
} |
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
|
1652 |
} while ((v=v->next) != NULL); |
842 | 1653 |
} |
1654 |
_current_player = OWNER_NONE; |
|
0 | 1655 |
} |
1656 |
||
2244 | 1657 |
int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 veh1_veh2, uint32 mode); |
1658 |
int32 CmdMoveRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1659 |
int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1660 |
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1661 |
int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1662 |
int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2259
diff
changeset
|
1663 |
|
2244 | 1664 |
|
1665 |
typedef int32 VehBuildProc(int x, int y, uint32 flags, uint32 p1, uint32 p2); |
|
1666 |
||
1667 |
static VehBuildProc * const _veh_build_proc_table[] = { |
|
1668 |
CmdBuildRailVehicle, |
|
1669 |
CmdBuildRoadVeh, |
|
1670 |
CmdBuildShip, |
|
1671 |
CmdBuildAircraft, |
|
1672 |
}; |
|
1673 |
||
1674 |
static VehicleID * _new_vehicle_id_proc_table[] = { |
|
1675 |
&_new_train_id, |
|
1676 |
&_new_roadveh_id, |
|
1677 |
&_new_ship_id, |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2259
diff
changeset
|
1678 |
&_new_aircraft_id, |
2244 | 1679 |
}; |
1680 |
||
1681 |
/** Clone a vehicle. If it is a train, it will clone all the cars too |
|
1682 |
* @param x,y unused |
|
1683 |
* @param p1 the original vehicle's index |
|
1684 |
* @param p2 1 = shared orders, else copied orders |
|
1685 |
*/ |
|
1686 |
int32 CmdCloneVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1687 |
{ |
|
1688 |
Vehicle *vfront, *v; |
|
1689 |
Vehicle *wfront, *w1, *w2; |
|
1690 |
int cost, total_cost; |
|
1691 |
VehBuildProc *proc; |
|
1692 |
VehicleID *new_id; |
|
1693 |
uint refit_command = 0; |
|
1694 |
byte needs_refitting = 255; |
|
1695 |
||
1696 |
if (!IsVehicleIndex(p1)) |
|
1697 |
return CMD_ERROR; |
|
1698 |
v = GetVehicle(p1); |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2259
diff
changeset
|
1699 |
wfront = v; |
2244 | 1700 |
w1 = v; |
1701 |
vfront = v; |
|
1702 |
||
1703 |
if (!CheckOwnership(v->owner)) |
|
1704 |
return CMD_ERROR; |
|
1705 |
||
1706 |
if (v->type == VEH_Train && v->subtype != TS_Front_Engine) return CMD_ERROR; |
|
1707 |
||
1708 |
//no need to check if it is a depot since the build command do that |
|
1709 |
switch (v->type) { |
|
1710 |
case VEH_Train: refit_command = CMD_REFIT_RAIL_VEHICLE; break; |
|
1711 |
case VEH_Road: break; |
|
1712 |
case VEH_Ship: refit_command = CMD_REFIT_SHIP; break; |
|
1713 |
case VEH_Aircraft: refit_command = CMD_REFIT_AIRCRAFT; break; |
|
1714 |
default: return CMD_ERROR; |
|
1715 |
} |
|
1716 |
||
1717 |
proc = _veh_build_proc_table[v->type - VEH_Train]; |
|
1718 |
new_id = _new_vehicle_id_proc_table[v->type - VEH_Train]; |
|
1719 |
total_cost = proc(x, y, flags, v->engine_type, 1); |
|
1720 |
if (total_cost == CMD_ERROR) |
|
1721 |
return CMD_ERROR; |
|
1722 |
||
1723 |
if (flags & DC_EXEC) { |
|
1724 |
wfront = GetVehicle(*new_id); |
|
1725 |
w1 = wfront; |
|
1726 |
CmdCloneOrder(x, y, flags, (v->index << 16) | w1->index, p2 & 1 ? CO_SHARE : CO_COPY); |
|
1727 |
||
1728 |
if (wfront->cargo_type != v->cargo_type) { |
|
1729 |
//a refit is needed |
|
1730 |
needs_refitting = v->cargo_type; |
|
1731 |
} |
|
1732 |
} |
|
1733 |
if (v->type == VEH_Train) { |
|
1734 |
// now we handle the cars |
|
1735 |
v = v->next; |
|
1736 |
while (v != NULL) { |
|
1737 |
cost = proc(x, y, flags, v->engine_type, 1); |
|
1738 |
if (cost == CMD_ERROR) |
|
1739 |
return CMD_ERROR; |
|
1740 |
total_cost += cost; |
|
1741 |
||
1742 |
if (flags & DC_EXEC) { |
|
1743 |
// add this unit to the end of the train |
|
1744 |
w2 = GetVehicle(RailVehInfo(v->engine_type)->flags & RVI_WAGON ? _new_wagon_id : _new_train_id); |
|
1745 |
CmdMoveRailVehicle(x, y, flags, (w1->index << 16) | w2->index, 0); |
|
1746 |
w1 = w2; |
|
1747 |
} |
|
1748 |
v = v->next; |
|
1749 |
} |
|
1750 |
||
1751 |
if (flags & DC_EXEC) { |
|
1752 |
_new_train_id = wfront->index; |
|
1753 |
v = vfront; |
|
1754 |
w1 = wfront; |
|
1755 |
while (w1 != NULL && v != NULL) { |
|
1756 |
w1->spritenum = v->spritenum; // makes sure that multiheaded engines are facing the correct way |
|
1757 |
if (w1->cargo_type != v->cargo_type) // checks if a refit is needed |
|
1758 |
needs_refitting = v->cargo_type; |
|
1759 |
w1 = w1->next; |
|
1760 |
v = v->next; |
|
1761 |
} |
|
2261
3f78323707bb
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2259
diff
changeset
|
1762 |
|
2244 | 1763 |
} |
1764 |
} |
|
2259
55a301ad9021
(svn r2779) -Fix: [clone vehicles] fixed typos, which could lead to crashes when cloning refitted trains (chrishuebsch)
bjarni
parents:
2244
diff
changeset
|
1765 |
if (flags & DC_EXEC && needs_refitting != 255 && vfront->type != VEH_Road) { // right now we do not refit road vehicles |
2244 | 1766 |
if (DoCommandByTile(wfront->tile, wfront->index, needs_refitting, 0, refit_command) != CMD_ERROR) |
1767 |
DoCommandByTile(wfront->tile, wfront->index, needs_refitting, DC_EXEC, refit_command); |
|
1768 |
} |
|
1769 |
return total_cost; |
|
1770 |
} |
|
1771 |
||
1772 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1773 |
/** Give a custom name to your vehicle |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1774 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1775 |
* @param p1 vehicle ID to name |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1776 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1777 |
*/ |
0 | 1778 |
int32 CmdNameVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1779 |
{ |
|
1780 |
Vehicle *v; |
|
1781 |
StringID str; |
|
1782 |
||
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
1783 |
if (!IsVehicleIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1784 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1785 |
v = GetVehicle(p1); |
0 | 1786 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1787 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1788 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
1789 |
str = AllocateNameUnique(_cmd_text, 2); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1790 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1791 |
|
0 | 1792 |
if (flags & DC_EXEC) { |
1793 |
StringID old_str = v->string_id; |
|
1794 |
v->string_id = str; |
|
1795 |
DeleteName(old_str); |
|
588 | 1796 |
ResortVehicleLists(); |
0 | 1797 |
MarkWholeScreenDirty(); |
1798 |
} else { |
|
1799 |
DeleteName(str); |
|
1800 |
} |
|
1801 |
||
1802 |
return 0; |
|
1803 |
} |
|
1804 |
||
1805 |
||
1806 |
||
1807 |
static Rect _old_vehicle_coords; |
|
1808 |
||
1809 |
void BeginVehicleMove(Vehicle *v) { |
|
1810 |
_old_vehicle_coords.left = v->left_coord; |
|
1811 |
_old_vehicle_coords.top = v->top_coord; |
|
1812 |
_old_vehicle_coords.right = v->right_coord; |
|
1813 |
_old_vehicle_coords.bottom = v->bottom_coord; |
|
1814 |
} |
|
1815 |
||
1816 |
void EndVehicleMove(Vehicle *v) |
|
1817 |
{ |
|
1818 |
MarkAllViewportsDirty( |
|
1819 |
min(_old_vehicle_coords.left,v->left_coord), |
|
1820 |
min(_old_vehicle_coords.top,v->top_coord), |
|
1821 |
max(_old_vehicle_coords.right,v->right_coord)+1, |
|
1822 |
max(_old_vehicle_coords.bottom,v->bottom_coord)+1 |
|
1823 |
); |
|
1824 |
} |
|
1825 |
||
1826 |
/* returns true if staying in the same tile */ |
|
1827 |
bool GetNewVehiclePos(Vehicle *v, GetNewVehiclePosResult *gp) |
|
1828 |
{ |
|
1829 |
static const int8 _delta_coord[16] = { |
|
1830 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
1831 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
1832 |
}; |
|
1833 |
||
1834 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
1835 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
1836 |
||
1837 |
gp->x = x; |
|
1838 |
gp->y = y; |
|
1839 |
gp->old_tile = v->tile; |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1840 |
gp->new_tile = TileVirtXY(x, y); |
0 | 1841 |
return gp->old_tile == gp->new_tile; |
1842 |
} |
|
1843 |
||
1844 |
static const byte _new_direction_table[9] = { |
|
1845 |
0, 7, 6, |
|
1846 |
1, 3, 5, |
|
1847 |
2, 3, 4, |
|
1848 |
}; |
|
1849 |
||
1850 |
byte GetDirectionTowards(Vehicle *v, int x, int y) |
|
1851 |
{ |
|
1852 |
byte dirdiff, dir; |
|
1853 |
int i = 0; |
|
1854 |
||
1855 |
if (y >= v->y_pos) { |
|
1856 |
if (y != v->y_pos) i+=3; |
|
1857 |
i+=3; |
|
1858 |
} |
|
1859 |
||
1860 |
if (x >= v->x_pos) { |
|
1861 |
if (x != v->x_pos) i++; |
|
1862 |
i++; |
|
1863 |
} |
|
1864 |
||
1865 |
dir = v->direction; |
|
1866 |
||
1867 |
dirdiff = _new_direction_table[i] - dir; |
|
1868 |
if (dirdiff == 0) |
|
1869 |
return dir; |
|
1870 |
return (dir+((dirdiff&7)<5?1:-1)) & 7; |
|
1871 |
} |
|
1872 |
||
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1873 |
Trackdir GetVehicleTrackdir(const Vehicle* v) |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1874 |
{ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1875 |
if (v->vehstatus & VS_CRASHED) return 0xFF; |
1758
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
1876 |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1877 |
switch(v->type) |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1878 |
{ |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1879 |
case VEH_Train: |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1880 |
if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1881 |
return DiagdirToDiagTrackdir(GetDepotDirection(v->tile, TRANSPORT_RAIL)); /* Train in depot */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1882 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1883 |
if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1884 |
return DiagdirToDiagTrackdir((v->direction >> 1) & 3); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1885 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1886 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.rail.track),v->direction); |
1959 | 1887 |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1888 |
case VEH_Ship: |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
1889 |
if (v->u.ship.state == 0x80) /* Inside a depot? */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
1890 |
/* We'll assume the ship is facing outwards */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1891 |
return DiagdirToDiagTrackdir(GetDepotDirection(v->tile, TRANSPORT_WATER)); /* Ship in depot */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1892 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1893 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction); |
1959 | 1894 |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1895 |
case VEH_Road: |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1896 |
if (v->u.road.state == 254) /* We'll assume the road vehicle is facing outwards */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1897 |
return DiagdirToDiagTrackdir(GetDepotDirection(v->tile, TRANSPORT_ROAD)); /* Road vehicle in depot */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1898 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1899 |
if (IsRoadStationTile(v->tile)) /* We'll assume the road vehicle is facing outwards */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1900 |
return DiagdirToDiagTrackdir(GetRoadStationDir(v->tile)); /* Road vehicle in a station */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1901 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1902 |
return DiagdirToDiagTrackdir((v->direction >> 1) & 3); |
1959 | 1903 |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1904 |
/* case VEH_Aircraft: case VEH_Special: case VEH_Disaster: */ |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1905 |
default: return 0xFF; |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1906 |
} |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1907 |
} |
22 | 1908 |
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, |
1909 |
* result << 8 contains the id of the station entered. If the return value has |
|
1910 |
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there |
|
1911 |
* other bits that can be set? */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1912 |
uint32 VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1913 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1914 |
TileIndex old_tile = v->tile; |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
1915 |
uint32 result = _tile_type_procs[GetTileType(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
|
1916 |
|
22 | 1917 |
/* When vehicle_enter_tile_proc returns 8, that apparently means that |
1918 |
* we cannot enter the tile at all. In that case, don't call |
|
1919 |
* leave_tile. */ |
|
0 | 1920 |
if (!(result & 8) && old_tile != tile) { |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
1921 |
VehicleLeaveTileProc *proc = _tile_type_procs[GetTileType(old_tile)]->vehicle_leave_tile_proc; |
0 | 1922 |
if (proc != NULL) |
1923 |
proc(v, old_tile, x, y); |
|
1924 |
} |
|
1925 |
return result; |
|
1926 |
} |
|
1927 |
||
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1928 |
UnitID GetFreeUnitNumber(byte type) |
0 | 1929 |
{ |
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1930 |
UnitID unit_num = 0; |
0 | 1931 |
Vehicle *u; |
1932 |
||
1933 |
restart: |
|
1934 |
unit_num++; |
|
1935 |
FOR_ALL_VEHICLES(u) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1936 |
if (u->type == type && u->owner == _current_player && |
0 | 1937 |
unit_num == u->unitnumber) |
1938 |
goto restart; |
|
1939 |
} |
|
1940 |
return unit_num; |
|
1941 |
} |
|
1942 |
||
1943 |
||
1944 |
// Save and load of vehicles |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
1945 |
const SaveLoad _common_veh_desc[] = { |
0 | 1946 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1947 |
|
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
933
diff
changeset
|
1948 |
SLE_REF(Vehicle,next, REF_VEHICLE_OLD), |
0 | 1949 |
SLE_VAR(Vehicle,string_id, SLE_STRINGID), |
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1950 |
SLE_CONDVAR(Vehicle,unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
1951 |
SLE_CONDVAR(Vehicle,unitnumber, SLE_UINT16, 8, 255), |
0 | 1952 |
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
|
1953 |
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
|
1954 |
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
|
1955 |
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
|
1956 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, 255), |
0 | 1957 |
|
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
|
1958 |
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
|
1959 |
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
|
1960 |
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
|
1961 |
SLE_CONDVAR(Vehicle,y_pos, SLE_UINT32, 6, 255), |
0 | 1962 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
1963 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
1964 |
||
1965 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
1966 |
SLE_VAR(Vehicle,spritenum, SLE_UINT8), |
|
1967 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
1968 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
1969 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
1970 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
1971 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
1972 |
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
|
1973 |
|
0 | 1974 |
SLE_VAR(Vehicle,max_speed, SLE_UINT16), |
1975 |
SLE_VAR(Vehicle,cur_speed, SLE_UINT16), |
|
1976 |
SLE_VAR(Vehicle,subspeed, SLE_UINT8), |
|
1977 |
SLE_VAR(Vehicle,acceleration, SLE_UINT8), |
|
1978 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
1979 |
||
1980 |
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
|
1981 |
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
|
1982 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_UINT16, 5, 255), |
0 | 1983 |
|
1984 |
SLE_VAR(Vehicle,cargo_type, SLE_UINT8), |
|
1985 |
SLE_VAR(Vehicle,cargo_days, SLE_UINT8), |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
1986 |
SLE_CONDVAR(Vehicle,cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
1987 |
SLE_CONDVAR(Vehicle,cargo_source, SLE_UINT16, 7, 255), |
0 | 1988 |
SLE_VAR(Vehicle,cargo_cap, SLE_UINT16), |
1989 |
SLE_VAR(Vehicle,cargo_count, SLE_UINT16), |
|
1990 |
||
1991 |
SLE_VAR(Vehicle,day_counter, SLE_UINT8), |
|
1992 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
1993 |
||
1994 |
SLE_VAR(Vehicle,cur_order_index, SLE_UINT8), |
|
1995 |
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
|
1996 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1997 |
/* 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
|
1998 |
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
|
1999 |
converted correctly */ |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2000 |
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
|
2001 |
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
|
2002 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2003 |
/* 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
|
2004 |
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
|
2005 |
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
|
2006 |
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
|
2007 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2008 |
SLE_REF(Vehicle,orders, REF_ORDER), |
0 | 2009 |
|
2010 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
2011 |
SLE_VAR(Vehicle,max_age, SLE_UINT16), |
|
2012 |
SLE_VAR(Vehicle,date_of_last_service,SLE_UINT16), |
|
2013 |
SLE_VAR(Vehicle,service_interval, SLE_UINT16), |
|
2014 |
SLE_VAR(Vehicle,reliability, SLE_UINT16), |
|
2015 |
SLE_VAR(Vehicle,reliability_spd_dec,SLE_UINT16), |
|
2016 |
SLE_VAR(Vehicle,breakdown_ctr, SLE_UINT8), |
|
2017 |
SLE_VAR(Vehicle,breakdown_delay, SLE_UINT8), |
|
2018 |
SLE_VAR(Vehicle,breakdowns_since_last_service, SLE_UINT8), |
|
2019 |
SLE_VAR(Vehicle,breakdown_chance, SLE_UINT8), |
|
2020 |
SLE_VAR(Vehicle,build_year, SLE_UINT8), |
|
2021 |
||
2022 |
SLE_VAR(Vehicle,load_unload_time_rem, SLE_UINT16), |
|
2023 |
||
2024 |
SLE_VAR(Vehicle,profit_this_year, SLE_INT32), |
|
2025 |
SLE_VAR(Vehicle,profit_last_year, SLE_INT32), |
|
2026 |
SLE_VAR(Vehicle,value, SLE_UINT32), |
|
2027 |
||
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
|
2028 |
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
|
2029 |
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
|
2030 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2031 |
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
|
2032 |
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
|
2033 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2034 |
// 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
|
2035 |
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
|
2036 |
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
|
2037 |
|
0 | 2038 |
SLE_END() |
2039 |
}; |
|
2040 |
||
2041 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2042 |
static const SaveLoad _train_desc[] = { |
0 | 2043 |
SLE_WRITEBYTE(Vehicle,type,VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file. |
2044 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2045 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,crash_anim_pos), SLE_UINT16), |
|
2046 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,force_proceed), SLE_UINT8), |
|
2047 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,railtype), SLE_UINT8), |
|
2048 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,track), SLE_UINT8), |
|
2049 |
||
2050 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,flags), SLE_UINT8, 2, 255), |
|
2051 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,days_since_order_progr), SLE_UINT16, 2, 255), |
|
2052 |
||
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
2053 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,pbs_status), SLE_UINT8, 2, 255), |
2115
71e12444631c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2090
diff
changeset
|
2054 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,pbs_end_tile), SLE_UINT32, 2, 255), |
71e12444631c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2090
diff
changeset
|
2055 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,pbs_end_trackdir), SLE_UINT8, 2, 255), |
71e12444631c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2090
diff
changeset
|
2056 |
// reserve extra space in savegame here. (currently 7 bytes) |
71e12444631c
(svn r2625) - Fix: [pbs] Store the end of a train's reserved path explicitly. Prevents trains from unreserving eachothers paths in some cases.
hackykid
parents:
2090
diff
changeset
|
2057 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 7, 2, 255), |
0 | 2058 |
|
2059 |
SLE_END() |
|
2060 |
}; |
|
2061 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2062 |
static const SaveLoad _roadveh_desc[] = { |
0 | 2063 |
SLE_WRITEBYTE(Vehicle,type,VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file. |
2064 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2065 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,state), SLE_UINT8), |
|
2066 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,frame), SLE_UINT8), |
|
2067 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,unk2), SLE_UINT16), |
|
2068 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking), SLE_UINT8), |
|
2069 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking_ctr),SLE_UINT8), |
|
2070 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,crashed_ctr), SLE_UINT16), |
|
2071 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,reverse_ctr), SLE_UINT8), |
|
2072 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2073 |
SLE_CONDREFX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slot), REF_ROADSTOPS, 6, 255), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2074 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slotindex), SLE_UINT8, 6, 255), |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1214
diff
changeset
|
2075 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slot_age), SLE_UINT8, 6, 255), |
0 | 2076 |
// reserve extra space in savegame here. (currently 16 bytes) |
2077 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
2078 |
||
2079 |
SLE_END() |
|
2080 |
}; |
|
2081 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2082 |
static const SaveLoad _ship_desc[] = { |
0 | 2083 |
SLE_WRITEBYTE(Vehicle,type,VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file. |
2084 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2085 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleShip,state), SLE_UINT8), |
|
2086 |
||
2087 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
2088 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
2089 |
||
2090 |
SLE_END() |
|
2091 |
}; |
|
2092 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2093 |
static const SaveLoad _aircraft_desc[] = { |
0 | 2094 |
SLE_WRITEBYTE(Vehicle,type,VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file. |
2095 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2096 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter), SLE_UINT16), |
|
2097 |
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
|
2098 |
|
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2099 |
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
|
2100 |
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
|
2101 |
|
0 | 2102 |
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
|
2103 |
|
0 | 2104 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, 255), |
2105 |
||
2106 |
// reserve extra space in savegame here. (currently 15 bytes) |
|
2107 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 15, 2, 255), |
|
2108 |
||
2109 |
SLE_END() |
|
2110 |
}; |
|
2111 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2112 |
static const SaveLoad _special_desc[] = { |
0 | 2113 |
SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4), |
2114 |
||
2115 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2116 |
|
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
|
2117 |
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
|
2118 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, 255), |
0 | 2119 |
|
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
|
2120 |
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
|
2121 |
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
|
2122 |
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
|
2123 |
SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, 255), |
0 | 2124 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
2125 |
||
2126 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
2127 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
2128 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
2129 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
2130 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
2131 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
2132 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
2133 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
2134 |
||
2135 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk0), SLE_UINT16), |
|
2136 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk2), SLE_UINT8), |
|
2137 |
||
2138 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
2139 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
2140 |
||
2141 |
SLE_END() |
|
2142 |
}; |
|
2143 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2144 |
static const SaveLoad _disaster_desc[] = { |
0 | 2145 |
SLE_WRITEBYTE(Vehicle,type,VEH_Disaster, 5), |
2146 |
||
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
933
diff
changeset
|
2147 |
SLE_REF(Vehicle,next, REF_VEHICLE_OLD), |
0 | 2148 |
|
2149 |
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
|
2150 |
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
|
2151 |
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
|
2152 |
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
|
2153 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, 255), |
0 | 2154 |
|
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
|
2155 |
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
|
2156 |
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
|
2157 |
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
|
2158 |
SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, 255), |
0 | 2159 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
2160 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
2161 |
||
2162 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
2163 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
2164 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
2165 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
2166 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
2167 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
|
2168 |
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
|
2169 |
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
|
2170 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, 255), |
0 | 2171 |
|
2172 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
2173 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
2174 |
||
2175 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
2176 |
||
2177 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,image_override), SLE_UINT16), |
|
2178 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,unk2), SLE_UINT16), |
|
2179 |
||
2180 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
2181 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
2182 |
||
2183 |
SLE_END() |
|
2184 |
}; |
|
2185 |
||
2186 |
||
2187 |
static const void *_veh_descs[] = { |
|
2188 |
_train_desc, |
|
2189 |
_roadveh_desc, |
|
2190 |
_ship_desc, |
|
2191 |
_aircraft_desc, |
|
2192 |
_special_desc, |
|
2193 |
_disaster_desc, |
|
2194 |
}; |
|
2195 |
||
2196 |
// 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
|
2197 |
static void Save_VEHS(void) |
0 | 2198 |
{ |
2199 |
Vehicle *v; |
|
2200 |
// Write the vehicles |
|
2201 |
FOR_ALL_VEHICLES(v) { |
|
2202 |
if (v->type != 0) { |
|
2203 |
SlSetArrayIndex(v->index); |
|
2204 |
SlObject(v, _veh_descs[v->type - 0x10]); |
|
2205 |
} |
|
2206 |
} |
|
2207 |
} |
|
2208 |
||
2209 |
// 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
|
2210 |
static void Load_VEHS(void) |
0 | 2211 |
{ |
2212 |
int index; |
|
2213 |
Vehicle *v; |
|
2214 |
||
2215 |
while ((index = SlIterateArray()) != -1) { |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2216 |
Vehicle *v; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2217 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2218 |
if (!AddBlockIfNeeded(&_vehicle_pool, index)) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2219 |
error("Vehicles: failed loading savegame: too many vehicles"); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2220 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2221 |
v = GetVehicle(index); |
0 | 2222 |
SlObject(v, _veh_descs[SlReadByte()]); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2223 |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2224 |
/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */ |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
2225 |
if (_sl_version < 5 && v->last_station_visited == 0xFF) |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2226 |
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
|
2227 |
|
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
2228 |
if (_sl_version < 5) { |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2229 |
/* 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
|
2230 |
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
|
2231 |
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
|
2232 |
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
|
2233 |
} |
0 | 2234 |
} |
2235 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2236 |
/* Check for shared order-lists (we now use pointers for that) */ |
2295
af67e1ea8687
(svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents:
2293
diff
changeset
|
2237 |
if (_sl_full_version < 0x502) { |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2238 |
FOR_ALL_VEHICLES(v) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2239 |
Vehicle *u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2240 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2241 |
if (v->type == 0) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2242 |
continue; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2243 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2244 |
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
|
2245 |
if (u->type == 0) |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2246 |
continue; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2247 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2248 |
/* 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
|
2249 |
in both vehicles */ |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2250 |
if (v->orders == u->orders) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2251 |
v->next_shared = u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2252 |
u->prev_shared = v; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2253 |
break; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2254 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2255 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2256 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2257 |
} |
0 | 2258 |
} |
2259 |
||
2260 |
const ChunkHandler _veh_chunk_handlers[] = { |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1541
diff
changeset
|
2261 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 2262 |
}; |