author | bjarni |
Thu, 29 Jun 2006 09:05:30 +0000 | |
changeset 4096 | 3ee959ce63c9 |
parent 4077 | d4d440dd8925 |
child 4121 | 85057433d1ea |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
3957
25f4a4f22e05
(svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents:
3953
diff
changeset
|
5 |
#include "road_map.h" |
3959 | 6 |
#include "roadveh.h" |
3961
9868b766fda7
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
7 |
#include "ship.h" |
1349
15979a2e9001
(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
|
8 |
#include "spritecache.h" |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
9 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
10 |
#include "table/strings.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
11 |
#include "functions.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
12 |
#include "map.h" |
1209
2e00193652b2
(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
|
13 |
#include "tile.h" |
0 | 14 |
#include "vehicle.h" |
15 |
#include "gfx.h" |
|
16 |
#include "viewport.h" |
|
17 |
#include "news.h" |
|
18 |
#include "command.h" |
|
19 |
#include "saveload.h" |
|
20 |
#include "player.h" |
|
21 |
#include "engine.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
260
diff
changeset
|
22 |
#include "sound.h" |
1601
83fbe3bfb847
(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
|
23 |
#include "debug.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
24 |
#include "vehicle_gui.h" |
1758
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
25 |
#include "depot.h" |
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
26 |
#include "station.h" |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
27 |
#include "rail.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
28 |
#include "train.h" |
3428
146dc5f172fc
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
29 |
#include "industry_map.h" |
3404
eb8ebfe5df67
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
30 |
#include "station_map.h" |
3957
25f4a4f22e05
(svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents:
3953
diff
changeset
|
31 |
#include "water_map.h" |
0 | 32 |
|
33 |
#define INVALID_COORD (-0x8000) |
|
34 |
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0))) |
|
35 |
||
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
36 |
/* |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
37 |
* These command macros are used to call vehicle type specific commands with non type specific commands |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
38 |
* it should be used like: DoCommandP(x, y, p1, p2, flags, CMD_STARTSTOP_VEH(v->type)) |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
39 |
* that line will start/stop a vehicle nomatter what type it is |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
40 |
* VEH_Train is used as an offset because the vehicle type values doesn't start with 0 |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
41 |
*/ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
42 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
43 |
#define CMD_BUILD_VEH(x) _veh_build_proc_table[ x - VEH_Train] |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
44 |
#define CMD_SELL_VEH(x) _veh_sell_proc_table[ x - VEH_Train] |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
45 |
#define CMD_REFIT_VEH(x) _veh_refit_proc_table[ x - VEH_Train] |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
46 |
|
2630 | 47 |
static const uint32 _veh_build_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
48 |
CMD_BUILD_RAIL_VEHICLE, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
49 |
CMD_BUILD_ROAD_VEH, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
50 |
CMD_BUILD_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
51 |
CMD_BUILD_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
52 |
}; |
2630 | 53 |
static const uint32 _veh_sell_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
54 |
CMD_SELL_RAIL_WAGON, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
55 |
CMD_SELL_ROAD_VEH, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
56 |
CMD_SELL_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
57 |
CMD_SELL_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
58 |
}; |
2753 | 59 |
|
2630 | 60 |
static const uint32 _veh_refit_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
61 |
CMD_REFIT_RAIL_VEHICLE, |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
62 |
CMD_REFIT_ROAD_VEH, |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
63 |
CMD_REFIT_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
64 |
CMD_REFIT_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
65 |
}; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
66 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
67 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
68 |
enum { |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
69 |
/* Max vehicles: 64000 (512 * 125) */ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
70 |
VEHICLES_POOL_BLOCK_SIZE_BITS = 9, /* In bits, so (1 << 9) == 512 */ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
71 |
VEHICLES_POOL_MAX_BLOCKS = 125, |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
72 |
|
3173
f56ca618721b
(svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents:
3161
diff
changeset
|
73 |
BLOCKS_FOR_SPECIAL_VEHICLES = 2, ///< Blocks needed for special vehicles |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
74 |
}; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
75 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
76 |
/** |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
77 |
* Called if a new block is added to the vehicle-pool |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
78 |
*/ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
79 |
static void VehiclePoolNewBlock(uint start_item) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
80 |
{ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
81 |
Vehicle *v; |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
82 |
|
2639 | 83 |
FOR_ALL_VEHICLES_FROM(v, start_item) v->index = start_item++; |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
84 |
} |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
85 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
86 |
/* Initialize the vehicle-pool */ |
3585
43461f26b729
(svn r4471) - Pools: Add a facility for calling a custom function during pool block clean up.
peter1138
parents:
3491
diff
changeset
|
87 |
MemoryPool _vehicle_pool = { "Vehicle", VEHICLES_POOL_MAX_BLOCKS, VEHICLES_POOL_BLOCK_SIZE_BITS, sizeof(Vehicle), &VehiclePoolNewBlock, NULL, 0, 0, NULL }; |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
88 |
|
578
1e66514eb621
(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
|
89 |
void VehicleServiceInDepot(Vehicle *v) |
1e66514eb621
(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
|
90 |
{ |
1e66514eb621
(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
|
91 |
v->date_of_last_service = _date; |
1e66514eb621
(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
|
92 |
v->breakdowns_since_last_service = 0; |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
93 |
v->reliability = GetEngine(v->engine_type)->reliability; |
578
1e66514eb621
(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
|
94 |
} |
0 | 95 |
|
593 | 96 |
bool VehicleNeedsService(const Vehicle *v) |
97 |
{ |
|
1037
4fbbb01cf87b
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
98 |
if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) |
4fbbb01cf87b
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
99 |
return false; |
4fbbb01cf87b
(svn r1538) -Feature: [988816] Disable servicing when breakdowns set to none (jaguar7)
darkvater
parents:
1035
diff
changeset
|
100 |
|
1757
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
101 |
if (v->vehstatus & VS_CRASHED) |
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
102 |
return false; /* Crashed vehicles don't need service anymore */ |
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
103 |
|
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
104 |
return _patches.servint_ispercent ? |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
105 |
(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : |
593 | 106 |
(v->date_of_last_service + v->service_interval < _date); |
107 |
} |
|
108 |
||
3881 | 109 |
StringID VehicleInTheWayErrMsg(const Vehicle* v) |
0 | 110 |
{ |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
111 |
switch (v->type) { |
3881 | 112 |
case VEH_Train: return STR_8803_TRAIN_IN_THE_WAY; |
113 |
case VEH_Road: return STR_9000_ROAD_VEHICLE_IN_THE_WAY; |
|
114 |
case VEH_Aircraft: return STR_A015_AIRCRAFT_IN_THE_WAY; |
|
115 |
default: return STR_980E_SHIP_IN_THE_WAY; |
|
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
116 |
} |
0 | 117 |
} |
118 |
||
119 |
static void *EnsureNoVehicleProc(Vehicle *v, void *data) |
|
120 |
{ |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
121 |
if (v->tile != *(const TileIndex*)data || v->type == VEH_Disaster) |
0 | 122 |
return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
123 |
|
3881 | 124 |
_error_message = VehicleInTheWayErrMsg(v); |
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
125 |
return v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
126 |
} |
0 | 127 |
|
128 |
bool EnsureNoVehicle(TileIndex tile) |
|
129 |
{ |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
130 |
return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL; |
0 | 131 |
} |
132 |
||
133 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
134 |
{ |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
135 |
const TileInfo *ti = data; |
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
136 |
|
2871
1ac651552db5
(svn r3419) - Fix: [FS#40] (Possible) game crash on removing track/road under bridge. This was caused by a wrong tile-occupancy testing where it was assumed that a vehicle's height is only a multitude of 8 (a single height-difference). This is incorrect as a vehicle on a slope will assume all height levels between the lower-and upper-bounds. The crash is still possible as seen in the Flyspray bugreport but this has a different cause.
Darkvater
parents:
2855
diff
changeset
|
137 |
if (v->tile != ti->tile || v->type == VEH_Disaster) return NULL; |
3794
f72053a38797
(svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents:
3679
diff
changeset
|
138 |
if (v->z_pos > ti->z) return NULL; |
0 | 139 |
|
3881 | 140 |
_error_message = VehicleInTheWayErrMsg(v); |
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
141 |
return v; |
0 | 142 |
} |
143 |
||
1082
a83d7ac6fecb
(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
|
144 |
|
3794
f72053a38797
(svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents:
3679
diff
changeset
|
145 |
bool EnsureNoVehicleOnGround(TileIndex tile) |
0 | 146 |
{ |
147 |
TileInfo ti; |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
148 |
|
2871
1ac651552db5
(svn r3419) - Fix: [FS#40] (Possible) game crash on removing track/road under bridge. This was caused by a wrong tile-occupancy testing where it was assumed that a vehicle's height is only a multitude of 8 (a single height-difference). This is incorrect as a vehicle on a slope will assume all height levels between the lower-and upper-bounds. The crash is still possible as seen in the Flyspray bugreport but this has a different cause.
Darkvater
parents:
2855
diff
changeset
|
149 |
ti.tile = tile; |
3794
f72053a38797
(svn r4790) Remove slope magic from EnsureNoVehicleZ() and rename it to EnsureNoVehicleOnGround() to make more clear what it does
tron
parents:
3679
diff
changeset
|
150 |
ti.z = GetTileMaxZ(tile); |
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
151 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL; |
0 | 152 |
} |
153 |
||
1605
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
154 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
155 |
{ |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
156 |
TileInfo ti; |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
157 |
|
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
158 |
ti.tile = tile; |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
159 |
ti.z = z; |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
160 |
|
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
161 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ); |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
162 |
} |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
163 |
|
0 | 164 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z) |
165 |
{ |
|
926
a6d140a6a4de
(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
|
166 |
int x1 = TileX(from); |
a6d140a6a4de
(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
|
167 |
int y1 = TileY(from); |
a6d140a6a4de
(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
|
168 |
int x2 = TileX(to); |
a6d140a6a4de
(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
|
169 |
int y2 = TileY(to); |
0 | 170 |
Vehicle *veh; |
171 |
||
172 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
173 |
if (x1 > x2 || y1 > y2) { |
|
174 |
intswap(x1,x2); |
|
175 |
intswap(y1,y2); |
|
176 |
} |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
177 |
FOR_ALL_VEHICLES(veh) { |
0 | 178 |
if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) { |
179 |
if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 && |
|
180 |
(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) { |
|
181 |
return veh; |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
return NULL; |
|
186 |
} |
|
187 |
||
2817 | 188 |
|
189 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y); |
|
190 |
||
0 | 191 |
void VehiclePositionChanged(Vehicle *v) |
192 |
{ |
|
193 |
int img = v->cur_image; |
|
194 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
195 |
const Sprite* spr = GetSprite(img); |
0 | 196 |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
197 |
pt.x += spr->x_offs; |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
198 |
pt.y += spr->y_offs; |
0 | 199 |
|
200 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
201 |
||
202 |
v->left_coord = pt.x; |
|
203 |
v->top_coord = pt.y; |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
204 |
v->right_coord = pt.x + spr->width + 2; |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
205 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 206 |
} |
207 |
||
208 |
// Called after load to update coordinates |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
209 |
void AfterLoadVehicles(void) |
0 | 210 |
{ |
211 |
Vehicle *v; |
|
212 |
||
213 |
FOR_ALL_VEHICLES(v) { |
|
1601
83fbe3bfb847
(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
|
214 |
v->first = NULL; |
3355
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
215 |
if (v->type == VEH_Train) v->u.rail.first_engine = INVALID_ENGINE; |
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
216 |
} |
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
217 |
|
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
218 |
FOR_ALL_VEHICLES(v) { |
2994
38c63961334e
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
219 |
if (v->type == VEH_Train && (IsFrontEngine(v) || IsFreeWagon(v))) |
38c63961334e
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
220 |
TrainConsistChanged(v); |
38c63961334e
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
221 |
} |
38c63961334e
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
222 |
|
38c63961334e
(svn r3571) - When loading a game, call TrainConsistChanged() for each train head separately before updating images, as v->first is used extensively in GetTrainImage() for custom graphics. This gives a significant speed improvement on loading a game.
peter1138
parents:
2970
diff
changeset
|
223 |
FOR_ALL_VEHICLES(v) { |
0 | 224 |
if (v->type != 0) { |
2465
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
225 |
switch (v->type) { |
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
226 |
case VEH_Train: v->cur_image = GetTrainImage(v, v->direction); break; |
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
227 |
case VEH_Road: v->cur_image = GetRoadVehImage(v, v->direction); break; |
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
228 |
case VEH_Ship: v->cur_image = GetShipImage(v, v->direction); break; |
2467
43884d655281
(svn r2993) Fix: Reset aircraft images differently. Fixes assertion introduced in r2991.
peter1138
parents:
2465
diff
changeset
|
229 |
case VEH_Aircraft: |
43884d655281
(svn r2993) Fix: Reset aircraft images differently. Fixes assertion introduced in r2991.
peter1138
parents:
2465
diff
changeset
|
230 |
if (v->subtype == 0 || v->subtype == 2) { |
43884d655281
(svn r2993) Fix: Reset aircraft images differently. Fixes assertion introduced in r2991.
peter1138
parents:
2465
diff
changeset
|
231 |
v->cur_image = GetAircraftImage(v, v->direction); |
2639 | 232 |
if (v->next != NULL) v->next->cur_image = v->cur_image; |
2467
43884d655281
(svn r2993) Fix: Reset aircraft images differently. Fixes assertion introduced in r2991.
peter1138
parents:
2465
diff
changeset
|
233 |
} |
43884d655281
(svn r2993) Fix: Reset aircraft images differently. Fixes assertion introduced in r2991.
peter1138
parents:
2465
diff
changeset
|
234 |
break; |
2465
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
235 |
default: break; |
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
236 |
} |
76412332557e
(svn r2991) Reset vehicle images on game load. Allows savegames with NewGRFs saved prior to r2868 to load.
peter1138
parents:
2436
diff
changeset
|
237 |
|
0 | 238 |
v->left_coord = INVALID_COORD; |
239 |
VehiclePositionChanged(v); |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
static Vehicle *InitializeVehicle(Vehicle *v) |
|
245 |
{ |
|
246 |
VehicleID index = v->index; |
|
247 |
memset(v, 0, sizeof(Vehicle)); |
|
248 |
v->index = index; |
|
249 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
250 |
assert(v->orders == NULL); |
0 | 251 |
|
252 |
v->left_coord = INVALID_COORD; |
|
1601
83fbe3bfb847
(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
|
253 |
v->first = NULL; |
0 | 254 |
v->next = NULL; |
1765
155dfdbbbc8d
(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
|
255 |
v->next_hash = INVALID_VEHICLE; |
0 | 256 |
v->string_id = 0; |
1111
6f4d8544e70b
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
257 |
v->next_shared = NULL; |
6f4d8544e70b
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
258 |
v->prev_shared = NULL; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
259 |
v->depot_list = NULL; |
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
260 |
v->random_bits = 0; |
0 | 261 |
return v; |
262 |
} |
|
263 |
||
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
264 |
/** |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
265 |
* Get a value for a vehicle's random_bits. |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
266 |
* @return A random value from 0 to 255. |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
267 |
*/ |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
268 |
byte VehicleRandomBits(void) |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
269 |
{ |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
270 |
return GB(Random(), 0, 8); |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
271 |
} |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
272 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
273 |
Vehicle *ForceAllocateSpecialVehicle(void) |
0 | 274 |
{ |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
275 |
/* This stays a strange story.. there should always be room for special |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
276 |
* vehicles (special effects all over the map), but with 65k of vehicles |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
277 |
* is this realistic to double-check for that? For now we just reserve |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
278 |
* BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
279 |
* be used for special vehicles.. should work nicely :) */ |
0 | 280 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
281 |
Vehicle *v; |
0 | 282 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
283 |
FOR_ALL_VEHICLES(v) { |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
284 |
/* No more room for the special vehicles, return NULL */ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
285 |
if (v->index >= (1 << _vehicle_pool.block_size_bits) * BLOCKS_FOR_SPECIAL_VEHICLES) |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
286 |
return NULL; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
287 |
|
0 | 288 |
if (v->type == 0) |
289 |
return InitializeVehicle(v); |
|
290 |
} |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
291 |
|
0 | 292 |
return NULL; |
293 |
} |
|
294 |
||
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
295 |
/* |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
296 |
* finds a free vehicle in the memory or allocates a new one |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
297 |
* returns a pointer to the first free vehicle or NULL if all vehicles are in use |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
298 |
* *skip_vehicles is an offset to where in the array we should begin looking |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
299 |
* this is to avoid looping though the same vehicles more than once after we learned that they are not free |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
300 |
* this feature is used by AllocateVehicles() since it need to allocate more than one and when |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
301 |
* another block is added to _vehicle_pool, since we only do that when we know it's already full |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
302 |
*/ |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
303 |
static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles) |
0 | 304 |
{ |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
305 |
/* See note by ForceAllocateSpecialVehicle() why we skip the |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
306 |
* first blocks */ |
0 | 307 |
Vehicle *v; |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
308 |
const int offset = (1 << VEHICLES_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES; |
0 | 309 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
310 |
if (*skip_vehicles < (_vehicle_pool.total_items - offset)) { // make sure the offset in the array is not larger than the array itself |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
311 |
FOR_ALL_VEHICLES_FROM(v, offset + *skip_vehicles) { |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
312 |
(*skip_vehicles)++; |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
313 |
if (v->type == 0) |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
314 |
return InitializeVehicle(v); |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
315 |
} |
0 | 316 |
} |
317 |
||
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
318 |
/* Check if we can add a block to the pool */ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
319 |
if (AddBlockToPool(&_vehicle_pool)) |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
320 |
return AllocateSingleVehicle(skip_vehicles); |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
321 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
322 |
return NULL; |
0 | 323 |
} |
324 |
||
2639 | 325 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
326 |
Vehicle *AllocateVehicle(void) |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
327 |
{ |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
328 |
VehicleID counter = 0; |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
329 |
return AllocateSingleVehicle(&counter); |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
330 |
} |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
331 |
|
2639 | 332 |
|
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
333 |
/** Allocates a lot of vehicles and frees them again |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
334 |
* @param vl pointer to an array of vehicles to get allocated. Can be NULL if the vehicles aren't needed (makes it test only) |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
335 |
* @param num number of vehicles to allocate room for |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
336 |
* returns true if there is room to allocate all the vehicles |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
337 |
*/ |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
338 |
bool AllocateVehicles(Vehicle **vl, int num) |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
339 |
{ |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
340 |
int i; |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
341 |
Vehicle *v; |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
342 |
VehicleID counter = 0; |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
343 |
|
2952 | 344 |
for (i = 0; i != num; i++) { |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
345 |
v = AllocateSingleVehicle(&counter); |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
346 |
if (v == NULL) { |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
347 |
return false; |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
348 |
} |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
349 |
if (vl != NULL) { |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
350 |
vl[i] = v; |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
351 |
} |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
352 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
353 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
354 |
return true; |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
355 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
356 |
|
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
357 |
|
2651 | 358 |
static VehicleID _vehicle_position_hash[0x1000]; |
359 |
||
0 | 360 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
361 |
{ |
|
362 |
int x,y,x2,y2; |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3413
diff
changeset
|
363 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, 0); |
0 | 364 |
|
365 |
x2 = ((pt.x + 104) & 0x1F80) >> 7; |
|
366 |
x = ((pt.x - 174) & 0x1F80) >> 7; |
|
367 |
||
368 |
y2 = ((pt.y + 56) & 0xFC0); |
|
369 |
y = ((pt.y - 294) & 0xFC0); |
|
370 |
||
2639 | 371 |
for (;;) { |
0 | 372 |
int xb = x; |
2639 | 373 |
for (;;) { |
374 |
VehicleID veh = _vehicle_position_hash[(x + y) & 0xFFFF]; |
|
0 | 375 |
while (veh != INVALID_VEHICLE) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
376 |
Vehicle *v = GetVehicle(veh); |
0 | 377 |
void *a; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
378 |
|
2639 | 379 |
a = proc(v, data); |
380 |
if (a != NULL) return a; |
|
0 | 381 |
veh = v->next_hash; |
382 |
} |
|
383 |
||
384 |
if (x == x2) |
|
385 |
break; |
|
386 |
||
387 |
x = (x + 1) & 0x3F; |
|
388 |
} |
|
389 |
x = xb; |
|
390 |
||
391 |
if (y == y2) |
|
392 |
break; |
|
393 |
||
394 |
y = (y + 0x40) & ((0x3F) << 6); |
|
395 |
} |
|
396 |
return NULL; |
|
397 |
} |
|
398 |
||
399 |
||
2817 | 400 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y) |
0 | 401 |
{ |
402 |
VehicleID *old_hash, *new_hash; |
|
403 |
int old_x = v->left_coord; |
|
404 |
int old_y = v->top_coord; |
|
405 |
Vehicle *u; |
|
406 |
||
407 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)]; |
|
408 |
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
|
409 |
|
2639 | 410 |
if (old_hash == new_hash) return; |
0 | 411 |
|
412 |
/* remove from hash table? */ |
|
413 |
if (old_hash != NULL) { |
|
414 |
Vehicle *last = NULL; |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2469
diff
changeset
|
415 |
VehicleID idx = *old_hash; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
416 |
while ((u = GetVehicle(idx)) != v) { |
0 | 417 |
idx = u->next_hash; |
418 |
assert(idx != INVALID_VEHICLE); |
|
419 |
last = u; |
|
420 |
} |
|
421 |
||
2639 | 422 |
if (last == NULL) { |
0 | 423 |
*old_hash = v->next_hash; |
2639 | 424 |
} else { |
0 | 425 |
last->next_hash = v->next_hash; |
2639 | 426 |
} |
0 | 427 |
} |
428 |
||
429 |
/* insert into hash table? */ |
|
430 |
if (new_hash != NULL) { |
|
431 |
v->next_hash = *new_hash; |
|
432 |
*new_hash = v->index; |
|
433 |
} |
|
434 |
} |
|
435 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
436 |
void InitializeVehicles(void) |
0 | 437 |
{ |
438 |
int i; |
|
439 |
||
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
440 |
/* Clean the vehicle pool, and reserve enough blocks |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
441 |
* for the special vehicles, plus one for all the other |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
442 |
* vehicles (which is increased on-the-fly) */ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
443 |
CleanPool(&_vehicle_pool); |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
444 |
AddBlockToPool(&_vehicle_pool); |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
445 |
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
446 |
AddBlockToPool(&_vehicle_pool); |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
447 |
|
0 | 448 |
// clear it... |
449 |
memset(_vehicle_position_hash, -1, sizeof(_vehicle_position_hash)); |
|
450 |
} |
|
451 |
||
452 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
453 |
{ |
|
454 |
while (v->next != NULL) v = v->next; |
|
455 |
return v; |
|
456 |
} |
|
457 |
||
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
458 |
/** Finds the previous vehicle in a chain, by a brute force search. |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
459 |
* This old function is REALLY slow because it searches through all vehicles to |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
460 |
* find the previous vehicle, but if v->first has not been set, then this function |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
461 |
* will need to be used to find the previous one. This function should never be |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
462 |
* called by anything but GetFirstVehicleInChain |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
463 |
*/ |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
464 |
static Vehicle *GetPrevVehicleInChain_bruteforce(const Vehicle *v) |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
465 |
{ |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
466 |
Vehicle *u; |
2006
9d5d7fd428c2
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
467 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
468 |
FOR_ALL_VEHICLES(u) if (u->type == VEH_Train && u->next == v) return u; |
2006
9d5d7fd428c2
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
469 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
470 |
return NULL; |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
471 |
} |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
472 |
|
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
473 |
/** Find the previous vehicle in a chain, by using the v->first cache. |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
474 |
* While this function is fast, it cannot be used in the GetFirstVehicleInChain |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
475 |
* function, otherwise you'll end up in an infinite loop call |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
476 |
*/ |
1475 | 477 |
Vehicle *GetPrevVehicleInChain(const Vehicle *v) |
0 | 478 |
{ |
1600
d2f718ee5111
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
479 |
Vehicle *u; |
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
480 |
assert(v != NULL); |
0 | 481 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
482 |
u = GetFirstVehicleInChain(v); |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
483 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
484 |
// Check to see if this is the first |
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
485 |
if (v == u) return NULL; |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
486 |
|
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
487 |
do { |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
488 |
if (u->next == v) return u; |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
489 |
} while ( ( u = u->next) != NULL); |
0 | 490 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
491 |
return NULL; |
0 | 492 |
} |
493 |
||
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
494 |
/** Finds the first vehicle in a chain. |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
495 |
* This function reads out the v->first cache. Should the cache be dirty, |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
496 |
* it determines the first vehicle in a chain, and updates the cache. |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
497 |
*/ |
1475 | 498 |
Vehicle *GetFirstVehicleInChain(const Vehicle *v) |
0 | 499 |
{ |
1601
83fbe3bfb847
(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
|
500 |
Vehicle* u; |
83fbe3bfb847
(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
|
501 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
502 |
assert(v != NULL); |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
503 |
|
1601
83fbe3bfb847
(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
|
504 |
if (v->first != NULL) { |
2998
48b021e47f06
(svn r3576) - Allow unused wagons have their ->first set. This fixes the faulty cache warning message, and noticably speeds up depot operations in large games.
peter1138
parents:
2996
diff
changeset
|
505 |
if (IsFrontEngine(v->first) || IsFreeWagon(v->first)) return v->first; |
1765
155dfdbbbc8d
(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
|
506 |
|
155dfdbbbc8d
(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
|
507 |
DEBUG(misc, 0) ("v->first cache faulty. We shouldn't be here, rebuilding cache!"); |
1601
83fbe3bfb847
(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
|
508 |
} |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
509 |
|
1765
155dfdbbbc8d
(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
|
510 |
/* It is the fact (currently) that newly built vehicles do not have |
155dfdbbbc8d
(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
|
511 |
* their ->first pointer set. When this is the case, go up to the |
155dfdbbbc8d
(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
|
512 |
* first engine and set the pointers correctly. Also the first pointer |
155dfdbbbc8d
(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
|
513 |
* is not saved in a savegame, so this has to be fixed up after loading */ |
155dfdbbbc8d
(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
|
514 |
|
155dfdbbbc8d
(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
|
515 |
/* Find the 'locomotive' or the first wagon in a chain */ |
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
516 |
while ((u = GetPrevVehicleInChain_bruteforce(v)) != NULL) v = u; |
1600
d2f718ee5111
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
517 |
|
1765
155dfdbbbc8d
(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
|
518 |
/* Set the first pointer of all vehicles in that chain to the first wagon */ |
2998
48b021e47f06
(svn r3576) - Allow unused wagons have their ->first set. This fixes the faulty cache warning message, and noticably speeds up depot operations in large games.
peter1138
parents:
2996
diff
changeset
|
519 |
if (IsFrontEngine(v) || IsFreeWagon(v)) |
1601
83fbe3bfb847
(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
|
520 |
for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v; |
83fbe3bfb847
(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
|
521 |
|
1600
d2f718ee5111
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
522 |
return (Vehicle*)v; |
0 | 523 |
} |
524 |
||
2630 | 525 |
uint CountVehiclesInChain(const Vehicle* v) |
0 | 526 |
{ |
2639 | 527 |
uint count = 0; |
528 |
do count++; while ((v = v->next) != NULL); |
|
0 | 529 |
return count; |
530 |
} |
|
531 |
||
532 |
void DeleteVehicle(Vehicle *v) |
|
533 |
{ |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
534 |
Vehicle *u; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
535 |
bool has_artic_part = false; |
0 | 536 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3132
diff
changeset
|
537 |
DeleteVehicleNews(v->index, INVALID_STRING_ID); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3132
diff
changeset
|
538 |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
539 |
do { |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
540 |
u = v->next; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
541 |
has_artic_part = EngineHasArticPart(v); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
542 |
DeleteName(v->string_id); |
3490
d53bc3e794bd
(svn r4341) -Fix (FS#101) When a player got bankrupt, slots were not cleared, because vehicles got deleted directly by DeleteVehicle
celestar
parents:
3431
diff
changeset
|
543 |
if (v->type == VEH_Road) ClearSlot(v); |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
544 |
v->type = 0; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
545 |
UpdateVehiclePosHash(v, INVALID_COORD, 0); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
546 |
v->next_hash = INVALID_VEHICLE; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
547 |
|
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
548 |
if (v->orders != NULL) |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
549 |
DeleteVehicleOrders(v); |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
550 |
v = u; |
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
551 |
} while (v != NULL && has_artic_part); |
0 | 552 |
} |
553 |
||
554 |
void DeleteVehicleChain(Vehicle *v) |
|
555 |
{ |
|
556 |
do { |
|
557 |
Vehicle *u = v; |
|
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
558 |
v = GetNextVehicle(v); |
0 | 559 |
DeleteVehicle(u); |
1765
155dfdbbbc8d
(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
|
560 |
} while (v != NULL); |
0 | 561 |
} |
562 |
||
563 |
||
564 |
void Aircraft_Tick(Vehicle *v); |
|
565 |
void RoadVeh_Tick(Vehicle *v); |
|
566 |
void Ship_Tick(Vehicle *v); |
|
567 |
void Train_Tick(Vehicle *v); |
|
410 | 568 |
static void EffectVehicle_Tick(Vehicle *v); |
0 | 569 |
void DisasterVehicle_Tick(Vehicle *v); |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
570 |
static void MaybeReplaceVehicle(Vehicle *v); |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
571 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
572 |
// head of the linked list to tell what vehicles that visited a depot in a tick |
2630 | 573 |
static Vehicle* _first_veh_in_depot_list; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
574 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
575 |
/** Adds a vehicle to the list of vehicles, that visited a depot this tick |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
576 |
* @param *v vehicle to add |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
577 |
*/ |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
578 |
void VehicleEnteredDepotThisTick(Vehicle *v) |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
579 |
{ |
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
580 |
// we need to set v->leave_depot_instantly as we have no control of it's contents at this time |
2600
3266a93d1444
(svn r3137) -Fix: [autoreplace] fixed assert that was triggerable when a vehicle entered a depot even though the goto depot was canceled
bjarni
parents:
2599
diff
changeset
|
581 |
if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT) && !HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS) && v->current_order.type == OT_GOTO_DEPOT) { |
2590
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
582 |
// we keep the vehicle in the depot since the user ordered it to stay |
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
583 |
v->leave_depot_instantly = false; |
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
584 |
} else { |
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
585 |
// the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
586 |
// out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
587 |
// we store that we stopped the vehicle, so autoreplace can start it again |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
588 |
v->vehstatus |= VS_STOPPED; |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
589 |
v->leave_depot_instantly = true; |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
590 |
} |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
591 |
|
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
592 |
if (_first_veh_in_depot_list == NULL) { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
593 |
_first_veh_in_depot_list = v; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
594 |
} else { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
595 |
Vehicle *w = _first_veh_in_depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
596 |
while (w->depot_list != NULL) w = w->depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
597 |
w->depot_list = v; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
598 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
599 |
} |
0 | 600 |
|
2752 | 601 |
static VehicleTickProc* _vehicle_tick_procs[] = { |
0 | 602 |
Train_Tick, |
603 |
RoadVeh_Tick, |
|
604 |
Ship_Tick, |
|
605 |
Aircraft_Tick, |
|
606 |
EffectVehicle_Tick, |
|
607 |
DisasterVehicle_Tick, |
|
608 |
}; |
|
609 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
610 |
void CallVehicleTicks(void) |
0 | 611 |
{ |
612 |
Vehicle *v; |
|
613 |
||
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
614 |
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
615 |
|
0 | 616 |
FOR_ALL_VEHICLES(v) { |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
617 |
if (v->type != 0) { |
0 | 618 |
_vehicle_tick_procs[v->type - 0x10](v); |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
619 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
620 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
621 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
622 |
// now we handle all the vehicles that entered a depot this tick |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
623 |
v = _first_veh_in_depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
624 |
while (v != NULL) { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
625 |
Vehicle *w = v->depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
626 |
v->depot_list = NULL; // it should always be NULL at the end of each tick |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
627 |
MaybeReplaceVehicle(v); |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
628 |
v = w; |
0 | 629 |
} |
630 |
} |
|
631 |
||
632 |
static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
633 |
{ |
|
634 |
uint32 full = 0, not_full = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
635 |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
636 |
//special handling of aircraft |
941
d271102b3010
(svn r1429) Change: bumped savegame to revision 5.
truelight
parents:
939
diff
changeset
|
637 |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
638 |
//if the aircraft carries passengers and is NOT full, then |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
639 |
//continue loading, no matter how much mail is in |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
640 |
if (v->type == VEH_Aircraft && |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
641 |
v->cargo_type == CT_PASSENGERS && |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
642 |
v->cargo_cap != v->cargo_count) { |
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
643 |
return true; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
644 |
} |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
645 |
|
0 | 646 |
// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. |
647 |
do { |
|
648 |
//Should never happen, but just in case future additions change this |
|
649 |
assert(v->cargo_type<32); |
|
650 |
||
651 |
if (v->cargo_cap != 0) { |
|
652 |
uint32 mask = 1 << v->cargo_type; |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
653 |
|
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
654 |
if (v->cargo_cap == v->cargo_count) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
655 |
full |= mask; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
656 |
} else { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
657 |
not_full |= mask; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
658 |
} |
0 | 659 |
} |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
660 |
} while ((v = v->next) != NULL); |
0 | 661 |
|
662 |
// continue loading if there is a non full cargo type and no cargo type that is full |
|
663 |
return not_full && (full & ~not_full) == 0; |
|
664 |
} |
|
665 |
||
666 |
bool CanFillVehicle(Vehicle *v) |
|
667 |
{ |
|
1058
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
668 |
TileIndex tile = v->tile; |
0 | 669 |
|
1058
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
670 |
if (IsTileType(tile, MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
671 |
(v->type == VEH_Ship && ( |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
672 |
IsTileType(TILE_ADDXY(tile, 1, 0), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
673 |
IsTileType(TILE_ADDXY(tile, -1, 0), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
674 |
IsTileType(TILE_ADDXY(tile, 0, 1), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
675 |
IsTileType(TILE_ADDXY(tile, 0, -1), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
676 |
IsTileType(TILE_ADDXY(tile, -2, 0), MP_STATION) |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
677 |
))) { |
0 | 678 |
|
679 |
// If patch is active, use alternative CanFillVehicle-function |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
680 |
if (_patches.full_load_any) return CanFillVehicle_FullLoadAny(v); |
0 | 681 |
|
682 |
do { |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
683 |
if (v->cargo_count != v->cargo_cap) return true; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
684 |
} while ((v = v->next) != NULL); |
0 | 685 |
} |
686 |
return false; |
|
687 |
} |
|
688 |
||
2704
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
689 |
/** Check if a given engine type can be refitted to a given cargo |
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
690 |
* @param engine_type Engine type to check |
1802
da61740cc1e7
(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
|
691 |
* @param cid_to check refit to this cargo-type |
da61740cc1e7
(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
|
692 |
* @return true if it is possible, false otherwise |
da61740cc1e7
(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
|
693 |
*/ |
2704
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
694 |
bool CanRefitTo(EngineID engine_type, CargoID cid_to) |
1802
da61740cc1e7
(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
|
695 |
{ |
da61740cc1e7
(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
|
696 |
CargoID cid = _global_cargo_id[_opt_ptr->landscape][cid_to]; |
3393
c40975f04842
(svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents:
3364
diff
changeset
|
697 |
return HASBIT(EngInfo(engine_type)->refit_mask, cid); |
1802
da61740cc1e7
(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
|
698 |
} |
da61740cc1e7
(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
|
699 |
|
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
700 |
/** Find the first cargo type that an engine can be refitted to. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
701 |
* @param engine Which engine to find cargo for. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
702 |
* @return A climate dependent cargo type. CT_INVALID is returned if not refittable. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
703 |
*/ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
704 |
CargoID FindFirstRefittableCargo(EngineID engine_type) |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
705 |
{ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
706 |
CargoID cid; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
707 |
uint32 refit_mask = EngInfo(engine_type)->refit_mask; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
708 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
709 |
if (refit_mask != 0) { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
710 |
for (cid = CT_PASSENGERS; cid < NUM_CARGO; cid++) { |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
711 |
if (HASBIT(refit_mask, _global_cargo_id[_opt_ptr->landscape][cid])) return cid; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
712 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
713 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
714 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
715 |
return CT_INVALID; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
716 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
717 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
718 |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
719 |
static void DoDrawVehicle(const Vehicle *v) |
0 | 720 |
{ |
721 |
uint32 image = v->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
722 |
|
0 | 723 |
if (v->vehstatus & VS_DISASTER) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
724 |
MAKE_TRANSPARENT(image); |
0 | 725 |
} else if (v->vehstatus & VS_DEFPAL) { |
3040
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
726 |
image |= (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
727 |
} |
0 | 728 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
729 |
AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
0 | 730 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos); |
731 |
} |
|
732 |
||
733 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
734 |
{ |
|
735 |
int x,xb, y, x2, y2; |
|
736 |
VehicleID veh; |
|
737 |
Vehicle *v; |
|
738 |
||
739 |
x = ((dpi->left - 70) & 0x1F80) >> 7; |
|
740 |
x2 = ((dpi->left + dpi->width) & 0x1F80) >> 7; |
|
741 |
||
742 |
y = ((dpi->top - 70) & 0xFC0); |
|
743 |
y2 = ((dpi->top + dpi->height) & 0xFC0); |
|
744 |
||
2952 | 745 |
for (;;) { |
0 | 746 |
xb = x; |
2952 | 747 |
for (;;) { |
2639 | 748 |
veh = _vehicle_position_hash[(x + y) & 0xFFFF]; |
0 | 749 |
while (veh != INVALID_VEHICLE) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
750 |
v = GetVehicle(veh); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
751 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
752 |
if (!(v->vehstatus & VS_HIDDEN) && |
0 | 753 |
dpi->left <= v->right_coord && |
754 |
dpi->top <= v->bottom_coord && |
|
755 |
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
|
756 |
dpi->top + dpi->height >= v->top_coord) { |
0 | 757 |
DoDrawVehicle(v); |
758 |
} |
|
759 |
veh = v->next_hash; |
|
760 |
} |
|
761 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
762 |
if (x == x2) break; |
0 | 763 |
x = (x + 1) & 0x3F; |
764 |
} |
|
765 |
x = xb; |
|
766 |
||
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
767 |
if (y == y2) break; |
0 | 768 |
y = (y + 0x40) & ((0x3F) << 6); |
769 |
} |
|
770 |
} |
|
771 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
772 |
static void ChimneySmokeInit(Vehicle *v) |
0 | 773 |
{ |
774 |
uint32 r = Random(); |
|
2140
a04d0142ad65
(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
|
775 |
v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3); |
a04d0142ad65
(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
|
776 |
v->progress = GB(r, 16, 3); |
0 | 777 |
} |
778 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
779 |
static void ChimneySmokeTick(Vehicle *v) |
0 | 780 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
781 |
if (v->progress > 0) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
782 |
v->progress--; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
783 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
784 |
TileIndex tile; |
0 | 785 |
|
786 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
787 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
788 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
1035
812f837ee03f
(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
|
789 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
0 | 790 |
EndVehicleMove(v); |
791 |
DeleteVehicle(v); |
|
792 |
return; |
|
793 |
} |
|
794 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
795 |
if (v->cur_image != SPR_CHIMNEY_SMOKE_7) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
796 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
797 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
798 |
v->cur_image = SPR_CHIMNEY_SMOKE_0; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
799 |
} |
0 | 800 |
v->progress = 7; |
801 |
VehiclePositionChanged(v); |
|
802 |
EndVehicleMove(v); |
|
803 |
} |
|
804 |
} |
|
805 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
806 |
static void SteamSmokeInit(Vehicle *v) |
0 | 807 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
808 |
v->cur_image = SPR_STEAM_SMOKE_0; |
0 | 809 |
v->progress = 12; |
810 |
} |
|
811 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
812 |
static void SteamSmokeTick(Vehicle *v) |
0 | 813 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
814 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
815 |
|
0 | 816 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
817 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
818 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
819 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
820 |
if ((v->progress & 7) == 0) { |
0 | 821 |
v->z_pos++; |
822 |
moved = true; |
|
823 |
} |
|
824 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
825 |
if ((v->progress & 0xF) == 4) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
826 |
if (v->cur_image != SPR_STEAM_SMOKE_4) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
827 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
828 |
} else { |
0 | 829 |
EndVehicleMove(v); |
830 |
DeleteVehicle(v); |
|
831 |
return; |
|
832 |
} |
|
833 |
moved = true; |
|
834 |
} |
|
835 |
||
836 |
if (moved) { |
|
837 |
VehiclePositionChanged(v); |
|
838 |
EndVehicleMove(v); |
|
839 |
} |
|
840 |
} |
|
841 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
842 |
static void DieselSmokeInit(Vehicle *v) |
0 | 843 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
844 |
v->cur_image = SPR_DIESEL_SMOKE_0; |
0 | 845 |
v->progress = 0; |
846 |
} |
|
847 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
848 |
static void DieselSmokeTick(Vehicle *v) |
0 | 849 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
850 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
851 |
|
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
852 |
if ((v->progress & 3) == 0) { |
0 | 853 |
BeginVehicleMove(v); |
854 |
v->z_pos++; |
|
855 |
VehiclePositionChanged(v); |
|
856 |
EndVehicleMove(v); |
|
857 |
} else if ((v->progress & 7) == 1) { |
|
858 |
BeginVehicleMove(v); |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
859 |
if (v->cur_image != SPR_DIESEL_SMOKE_5) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
860 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
861 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
862 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
863 |
} else { |
0 | 864 |
EndVehicleMove(v); |
865 |
DeleteVehicle(v); |
|
866 |
} |
|
867 |
} |
|
868 |
} |
|
869 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
870 |
static void ElectricSparkInit(Vehicle *v) |
0 | 871 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
872 |
v->cur_image = SPR_ELECTRIC_SPARK_0; |
0 | 873 |
v->progress = 1; |
874 |
} |
|
875 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
876 |
static void ElectricSparkTick(Vehicle *v) |
0 | 877 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
878 |
if (v->progress < 2) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
879 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
880 |
} else { |
0 | 881 |
v->progress = 0; |
882 |
BeginVehicleMove(v); |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
883 |
if (v->cur_image != SPR_ELECTRIC_SPARK_5) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
884 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
885 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
886 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
887 |
} else { |
0 | 888 |
EndVehicleMove(v); |
889 |
DeleteVehicle(v); |
|
890 |
} |
|
891 |
} |
|
892 |
} |
|
893 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
894 |
static void SmokeInit(Vehicle *v) |
0 | 895 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
896 |
v->cur_image = SPR_SMOKE_0; |
0 | 897 |
v->progress = 12; |
898 |
} |
|
899 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
900 |
static void SmokeTick(Vehicle *v) |
0 | 901 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
902 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
903 |
|
0 | 904 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
905 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
906 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
907 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
908 |
if ((v->progress & 3) == 0) { |
0 | 909 |
v->z_pos++; |
910 |
moved = true; |
|
911 |
} |
|
912 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
913 |
if ((v->progress & 0xF) == 4) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
914 |
if (v->cur_image != SPR_SMOKE_4) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
915 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
916 |
} else { |
0 | 917 |
EndVehicleMove(v); |
918 |
DeleteVehicle(v); |
|
919 |
return; |
|
920 |
} |
|
921 |
moved = true; |
|
922 |
} |
|
923 |
||
924 |
if (moved) { |
|
925 |
VehiclePositionChanged(v); |
|
926 |
EndVehicleMove(v); |
|
927 |
} |
|
928 |
} |
|
929 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
930 |
static void ExplosionLargeInit(Vehicle *v) |
0 | 931 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
932 |
v->cur_image = SPR_EXPLOSION_LARGE_0; |
0 | 933 |
v->progress = 0; |
934 |
} |
|
935 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
936 |
static void ExplosionLargeTick(Vehicle *v) |
0 | 937 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
938 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
939 |
if ((v->progress & 3) == 0) { |
0 | 940 |
BeginVehicleMove(v); |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
941 |
if (v->cur_image != SPR_EXPLOSION_LARGE_F) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
942 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
943 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
944 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
945 |
} else { |
0 | 946 |
EndVehicleMove(v); |
947 |
DeleteVehicle(v); |
|
948 |
} |
|
949 |
} |
|
950 |
} |
|
951 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
952 |
static void BreakdownSmokeInit(Vehicle *v) |
0 | 953 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
954 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
0 | 955 |
v->progress = 0; |
956 |
} |
|
957 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
958 |
static void BreakdownSmokeTick(Vehicle *v) |
0 | 959 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
960 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
961 |
if ((v->progress & 7) == 0) { |
0 | 962 |
BeginVehicleMove(v); |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
963 |
if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
964 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
965 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
966 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
967 |
} |
0 | 968 |
VehiclePositionChanged(v); |
969 |
EndVehicleMove(v); |
|
970 |
} |
|
971 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
972 |
v->u.special.unk0--; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
973 |
if (v->u.special.unk0 == 0) { |
0 | 974 |
BeginVehicleMove(v); |
975 |
EndVehicleMove(v); |
|
976 |
DeleteVehicle(v); |
|
977 |
} |
|
978 |
} |
|
979 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
980 |
static void ExplosionSmallInit(Vehicle *v) |
0 | 981 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
982 |
v->cur_image = SPR_EXPLOSION_SMALL_0; |
0 | 983 |
v->progress = 0; |
984 |
} |
|
985 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
986 |
static void ExplosionSmallTick(Vehicle *v) |
0 | 987 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
988 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
989 |
if ((v->progress & 3) == 0) { |
0 | 990 |
BeginVehicleMove(v); |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
991 |
if (v->cur_image != SPR_EXPLOSION_SMALL_B) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
992 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
993 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
994 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
995 |
} else { |
0 | 996 |
EndVehicleMove(v); |
997 |
DeleteVehicle(v); |
|
998 |
} |
|
999 |
} |
|
1000 |
} |
|
1001 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1002 |
static void BulldozerInit(Vehicle *v) |
0 | 1003 |
{ |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1004 |
v->cur_image = SPR_BULLDOZER_NE; |
0 | 1005 |
v->progress = 0; |
1006 |
v->u.special.unk0 = 0; |
|
1007 |
v->u.special.unk2 = 0; |
|
1008 |
} |
|
1009 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1010 |
typedef struct BulldozerMovement { |
1365
3ec3ff0adc01
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1011 |
byte direction:2; |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1012 |
byte image:2; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1013 |
byte duration:3; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1014 |
} BulldozerMovement; |
0 | 1015 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1016 |
static const BulldozerMovement _bulldozer_movement[] = { |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1017 |
{ 0, 0, 4 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1018 |
{ 3, 3, 4 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1019 |
{ 2, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1020 |
{ 0, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1021 |
{ 1, 1, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1022 |
{ 2, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1023 |
{ 0, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1024 |
{ 1, 1, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1025 |
{ 2, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1026 |
{ 0, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1027 |
{ 3, 3, 6 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1028 |
{ 2, 2, 6 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1029 |
{ 1, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1030 |
{ 3, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1031 |
{ 0, 0, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1032 |
{ 1, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1033 |
{ 3, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1034 |
{ 0, 0, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1035 |
{ 1, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1036 |
{ 3, 1, 7 } |
0 | 1037 |
}; |
1038 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1039 |
static const struct { |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1040 |
int8 x; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1041 |
int8 y; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1042 |
} _inc_by_dir[] = { |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1043 |
{ -1, 0 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1044 |
{ 0, 1 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1045 |
{ 1, 0 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1046 |
{ 0, -1 } |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1047 |
}; |
0 | 1048 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1049 |
static void BulldozerTick(Vehicle *v) |
0 | 1050 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1051 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1052 |
if ((v->progress & 7) == 0) { |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1053 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.unk0]; |
0 | 1054 |
|
1055 |
BeginVehicleMove(v); |
|
1056 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1057 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
0 | 1058 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1059 |
v->x_pos += _inc_by_dir[b->direction].x; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1060 |
v->y_pos += _inc_by_dir[b->direction].y; |
0 | 1061 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1062 |
v->u.special.unk2++; |
1365
3ec3ff0adc01
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1063 |
if (v->u.special.unk2 >= b->duration) { |
0 | 1064 |
v->u.special.unk2 = 0; |
1065 |
v->u.special.unk0++; |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1066 |
if (v->u.special.unk0 == lengthof(_bulldozer_movement)) { |
0 | 1067 |
EndVehicleMove(v); |
1068 |
DeleteVehicle(v); |
|
1069 |
return; |
|
1070 |
} |
|
1071 |
} |
|
1072 |
VehiclePositionChanged(v); |
|
1073 |
EndVehicleMove(v); |
|
1074 |
} |
|
1075 |
} |
|
1076 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1077 |
static void BubbleInit(Vehicle *v) |
0 | 1078 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1079 |
v->cur_image = SPR_BUBBLE_GENERATE_0; |
0 | 1080 |
v->spritenum = 0; |
1081 |
v->progress = 0; |
|
1082 |
} |
|
1083 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1084 |
typedef struct BubbleMovement { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1085 |
int8 x:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1086 |
int8 y:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1087 |
int8 z:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1088 |
byte image:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1089 |
} BubbleMovement; |
0 | 1090 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1091 |
#define MK(x, y, z, i) { x, y, z, i } |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1092 |
#define ME(i) { i, 4, 0, 0 } |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1093 |
|
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1094 |
static const BubbleMovement _bubble_float_sw[] = { |
0 | 1095 |
MK(0,0,1,0), |
1096 |
MK(1,0,1,1), |
|
1097 |
MK(0,0,1,0), |
|
1098 |
MK(1,0,1,2), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1099 |
ME(1) |
0 | 1100 |
}; |
1101 |
||
1102 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1103 |
static const BubbleMovement _bubble_float_ne[] = { |
0 | 1104 |
MK(0,0,1,0), |
1105 |
MK(-1,0,1,1), |
|
1106 |
MK(0,0,1,0), |
|
1107 |
MK(-1,0,1,2), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1108 |
ME(1) |
0 | 1109 |
}; |
1110 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1111 |
static const BubbleMovement _bubble_float_se[] = { |
0 | 1112 |
MK(0,0,1,0), |
1113 |
MK(0,1,1,1), |
|
1114 |
MK(0,0,1,0), |
|
1115 |
MK(0,1,1,2), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1116 |
ME(1) |
0 | 1117 |
}; |
1118 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1119 |
static const BubbleMovement _bubble_float_nw[] = { |
0 | 1120 |
MK(0,0,1,0), |
1121 |
MK(0,-1,1,1), |
|
1122 |
MK(0,0,1,0), |
|
1123 |
MK(0,-1,1,2), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1124 |
ME(1) |
0 | 1125 |
}; |
1126 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1127 |
static const BubbleMovement _bubble_burst[] = { |
0 | 1128 |
MK(0,0,1,2), |
1129 |
MK(0,0,1,7), |
|
1130 |
MK(0,0,1,8), |
|
1131 |
MK(0,0,1,9), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1132 |
ME(0) |
0 | 1133 |
}; |
1134 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1135 |
static const BubbleMovement _bubble_absorb[] = { |
0 | 1136 |
MK(0,0,1,0), |
1137 |
MK(0,0,1,1), |
|
1138 |
MK(0,0,1,0), |
|
1139 |
MK(0,0,1,2), |
|
1140 |
MK(0,0,1,0), |
|
1141 |
MK(0,0,1,1), |
|
1142 |
MK(0,0,1,0), |
|
1143 |
MK(0,0,1,2), |
|
1144 |
MK(0,0,1,0), |
|
1145 |
MK(0,0,1,1), |
|
1146 |
MK(0,0,1,0), |
|
1147 |
MK(0,0,1,2), |
|
1148 |
MK(0,0,1,0), |
|
1149 |
MK(0,0,1,1), |
|
1150 |
MK(0,0,1,0), |
|
1151 |
MK(0,0,1,2), |
|
1152 |
MK(0,0,1,0), |
|
1153 |
MK(0,0,1,1), |
|
1154 |
MK(0,0,1,0), |
|
1155 |
MK(0,0,1,2), |
|
1156 |
MK(0,0,1,0), |
|
1157 |
MK(0,0,1,1), |
|
1158 |
MK(0,0,1,0), |
|
1159 |
MK(0,0,1,2), |
|
1160 |
MK(0,0,1,0), |
|
1161 |
MK(0,0,1,1), |
|
1162 |
MK(0,0,1,0), |
|
1163 |
MK(0,0,1,2), |
|
1164 |
MK(0,0,1,0), |
|
1165 |
MK(0,0,1,1), |
|
1166 |
MK(0,0,1,0), |
|
1167 |
MK(0,0,1,2), |
|
1168 |
MK(0,0,1,0), |
|
1169 |
MK(0,0,1,1), |
|
1170 |
MK(0,0,1,0), |
|
1171 |
MK(0,0,1,2), |
|
1172 |
MK(0,0,1,0), |
|
1173 |
MK(0,0,1,1), |
|
1174 |
MK(0,0,1,0), |
|
1175 |
MK(0,0,1,2), |
|
1176 |
MK(0,0,1,0), |
|
1177 |
MK(0,0,1,1), |
|
1178 |
MK(0,0,1,0), |
|
1179 |
MK(0,0,1,2), |
|
1180 |
MK(0,0,1,0), |
|
1181 |
MK(0,0,1,1), |
|
1182 |
MK(0,0,1,0), |
|
1183 |
MK(0,0,1,2), |
|
1184 |
MK(0,0,1,0), |
|
1185 |
MK(0,0,1,1), |
|
1186 |
MK(0,0,1,0), |
|
1187 |
MK(0,0,1,2), |
|
1188 |
MK(0,0,1,0), |
|
1189 |
MK(0,0,1,1), |
|
1190 |
MK(0,0,1,0), |
|
1191 |
MK(0,0,1,2), |
|
1192 |
MK(0,0,1,0), |
|
1193 |
MK(0,0,1,1), |
|
1194 |
MK(0,0,1,0), |
|
1195 |
MK(0,0,1,2), |
|
1196 |
MK(0,0,1,0), |
|
1197 |
MK(0,0,1,1), |
|
1198 |
MK(2,1,3,0), |
|
1199 |
MK(1,1,3,1), |
|
1200 |
MK(2,1,3,0), |
|
1201 |
MK(1,1,3,2), |
|
1202 |
MK(2,1,3,0), |
|
1203 |
MK(1,1,3,1), |
|
1204 |
MK(2,1,3,0), |
|
1205 |
MK(1,0,1,2), |
|
1206 |
MK(0,0,1,0), |
|
1207 |
MK(1,0,1,1), |
|
1208 |
MK(0,0,1,0), |
|
1209 |
MK(1,0,1,2), |
|
1210 |
MK(0,0,1,0), |
|
1211 |
MK(1,0,1,1), |
|
1212 |
MK(0,0,1,0), |
|
1213 |
MK(1,0,1,2), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1214 |
ME(2), |
0 | 1215 |
MK(0,0,0,0xA), |
1216 |
MK(0,0,0,0xB), |
|
1217 |
MK(0,0,0,0xC), |
|
1218 |
MK(0,0,0,0xD), |
|
1219 |
MK(0,0,0,0xE), |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1220 |
ME(0) |
0 | 1221 |
}; |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1222 |
#undef ME |
0 | 1223 |
#undef MK |
1224 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1225 |
static const BubbleMovement * const _bubble_movement[] = { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1226 |
_bubble_float_sw, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1227 |
_bubble_float_ne, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1228 |
_bubble_float_se, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1229 |
_bubble_float_nw, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1230 |
_bubble_burst, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1231 |
_bubble_absorb, |
0 | 1232 |
}; |
1233 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1234 |
static void BubbleTick(Vehicle *v) |
0 | 1235 |
{ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1236 |
/* |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1237 |
* Warning: those effects can NOT use Random(), and have to use |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1238 |
* InteractiveRandom(), because somehow someone forgot to save |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1239 |
* spritenum to the savegame, and so it will cause desyncs in |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1240 |
* multiplayer!! (that is: in ToyLand) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1241 |
*/ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1242 |
uint et; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1243 |
const BubbleMovement *b; |
0 | 1244 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1245 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1246 |
if ((v->progress & 3) != 0) |
0 | 1247 |
return; |
1248 |
||
1249 |
BeginVehicleMove(v); |
|
1250 |
||
1251 |
if (v->spritenum == 0) { |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1252 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1253 |
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { |
0 | 1254 |
VehiclePositionChanged(v); |
1255 |
EndVehicleMove(v); |
|
1256 |
return; |
|
1257 |
} |
|
1258 |
if (v->u.special.unk2 != 0) { |
|
2635 | 1259 |
v->spritenum = GB(InteractiveRandom(), 0, 2) + 1; |
0 | 1260 |
} else { |
1261 |
v->spritenum = 6; |
|
1262 |
} |
|
1263 |
et = 0; |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1264 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1265 |
et = v->engine_type + 1; |
0 | 1266 |
} |
1267 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1268 |
b = &_bubble_movement[v->spritenum - 1][et]; |
0 | 1269 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1270 |
if (b->y == 4 && b->x == 0) { |
0 | 1271 |
EndVehicleMove(v); |
1272 |
DeleteVehicle(v); |
|
1273 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1274 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1275 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1276 |
if (b->y == 4 && b->x == 1) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1277 |
if (v->z_pos > 180 || CHANCE16I(1, 96, InteractiveRandom())) { |
0 | 1278 |
v->spritenum = 5; |
541 | 1279 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1280 |
} |
1281 |
et = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1282 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1283 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1284 |
if (b->y == 4 && b->x == 2) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1285 |
TileIndex tile; |
0 | 1286 |
|
1287 |
et++; |
|
541 | 1288 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1289 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1290 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
3428
146dc5f172fc
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
1291 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == 0xA2) AddAnimatedTile(tile); |
0 | 1292 |
} |
1293 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1294 |
v->engine_type = et; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1295 |
b = &_bubble_movement[v->spritenum - 1][et]; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1296 |
|
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1297 |
v->x_pos += b->x; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1298 |
v->y_pos += b->y; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1299 |
v->z_pos += b->z; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1300 |
v->cur_image = SPR_BUBBLE_0 + b->image; |
0 | 1301 |
|
1302 |
VehiclePositionChanged(v); |
|
1303 |
EndVehicleMove(v); |
|
1304 |
} |
|
1305 |
||
1306 |
||
1307 |
typedef void EffectInitProc(Vehicle *v); |
|
1308 |
typedef void EffectTickProc(Vehicle *v); |
|
1309 |
||
1310 |
static EffectInitProc * const _effect_init_procs[] = { |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1311 |
ChimneySmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1312 |
SteamSmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1313 |
DieselSmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1314 |
ElectricSparkInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1315 |
SmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1316 |
ExplosionLargeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1317 |
BreakdownSmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1318 |
ExplosionSmallInit, |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1319 |
BulldozerInit, |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1320 |
BubbleInit, |
0 | 1321 |
}; |
1322 |
||
1323 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1324 |
ChimneySmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1325 |
SteamSmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1326 |
DieselSmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1327 |
ElectricSparkTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1328 |
SmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1329 |
ExplosionLargeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1330 |
BreakdownSmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1331 |
ExplosionSmallTick, |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1332 |
BulldozerTick, |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1333 |
BubbleTick, |
0 | 1334 |
}; |
1335 |
||
1336 |
||
1359
52782e5cf7c9
(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
|
1337 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) |
0 | 1338 |
{ |
1339 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1340 |
|
0 | 1341 |
v = ForceAllocateSpecialVehicle(); |
1342 |
if (v != NULL) { |
|
1343 |
v->type = VEH_Special; |
|
1344 |
v->subtype = type; |
|
1345 |
v->x_pos = x; |
|
1346 |
v->y_pos = y; |
|
1347 |
v->z_pos = z; |
|
1348 |
v->z_height = v->sprite_width = v->sprite_height = 1; |
|
1349 |
v->x_offs = v->y_offs = 0; |
|
1350 |
v->tile = 0; |
|
1351 |
v->vehstatus = VS_UNCLICKABLE; |
|
1352 |
||
1353 |
_effect_init_procs[type](v); |
|
1354 |
||
1355 |
VehiclePositionChanged(v); |
|
1356 |
BeginVehicleMove(v); |
|
1357 |
EndVehicleMove(v); |
|
1358 |
} |
|
1359 |
return v; |
|
1360 |
} |
|
1361 |
||
1359
52782e5cf7c9
(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
|
1362 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type) |
0 | 1363 |
{ |
1364 |
return CreateEffectVehicle(x, y, GetSlopeZ(x, y) + z, type); |
|
1365 |
} |
|
1366 |
||
1359
52782e5cf7c9
(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
|
1367 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type) |
0 | 1368 |
{ |
1369 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1370 |
} |
|
1371 |
||
410 | 1372 |
static void EffectVehicle_Tick(Vehicle *v) |
0 | 1373 |
{ |
1374 |
_effect_tick_procs[v->subtype](v); |
|
1375 |
} |
|
1376 |
||
2116 | 1377 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 1378 |
{ |
1379 |
Vehicle *found = NULL, *v; |
|
1380 |
uint dist, best_dist = (uint)-1; |
|
1381 |
||
1382 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1383 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1384 |
return NULL; |
|
1385 |
||
1386 |
x = (x << vp->zoom) + vp->virtual_left; |
|
1387 |
y = (y << vp->zoom) + vp->virtual_top; |
|
1388 |
||
1389 |
FOR_ALL_VEHICLES(v) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1390 |
if (v->type != 0 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1391 |
x >= v->left_coord && x <= v->right_coord && |
1392 |
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
|
1393 |
|
0 | 1394 |
dist = max( |
1395 |
myabs( ((v->left_coord + v->right_coord)>>1) - x ), |
|
1396 |
myabs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
|
1397 |
); |
|
1398 |
||
1399 |
if (dist < best_dist) { |
|
1400 |
found = v; |
|
1401 |
best_dist = dist; |
|
1402 |
} |
|
1403 |
} |
|
1404 |
} |
|
1405 |
||
1406 |
return found; |
|
1407 |
} |
|
1408 |
||
1409 |
||
1410 |
void DecreaseVehicleValue(Vehicle *v) |
|
1411 |
{ |
|
1412 |
v->value -= v->value >> 8; |
|
1413 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1414 |
} |
|
1415 |
||
1416 |
static const byte _breakdown_chance[64] = { |
|
1417 |
3, 3, 3, 3, 3, 3, 3, 3, |
|
1418 |
4, 4, 5, 5, 6, 6, 7, 7, |
|
1419 |
8, 8, 9, 9, 10, 10, 11, 11, |
|
1420 |
12, 13, 13, 13, 13, 14, 15, 16, |
|
1421 |
17, 19, 21, 25, 28, 31, 34, 37, |
|
1422 |
40, 44, 48, 52, 56, 60, 64, 68, |
|
1423 |
72, 80, 90, 100, 110, 120, 130, 140, |
|
1424 |
150, 170, 190, 210, 230, 250, 250, 250, |
|
1425 |
}; |
|
1426 |
||
1427 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1428 |
{ |
|
1429 |
int rel, rel_old; |
|
1430 |
uint32 r; |
|
1431 |
int chance; |
|
1432 |
||
1433 |
/* decrease reliability */ |
|
1434 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1435 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1436 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1437 |
||
2639 | 1438 |
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED || |
1439 |
v->cur_speed < 5 || _game_mode == GM_MENU) { |
|
1440 |
return; |
|
1441 |
} |
|
0 | 1442 |
|
1443 |
r = Random(); |
|
1444 |
||
1445 |
/* increase chance of failure */ |
|
1446 |
chance = v->breakdown_chance + 1; |
|
1447 |
if (CHANCE16I(1,25,r)) chance += 25; |
|
1448 |
v->breakdown_chance = min(255, chance); |
|
1449 |
||
1450 |
/* calculate reliability value to use in comparison */ |
|
1451 |
rel = v->reliability; |
|
1452 |
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
|
1453 |
|
0 | 1454 |
/* disabled breakdowns? */ |
2639 | 1455 |
if (_opt.diff.vehicle_breakdowns < 1) return; |
0 | 1456 |
|
1457 |
/* reduced breakdowns? */ |
|
1458 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1459 |
||
1460 |
/* check if to break down */ |
|
1461 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
2140
a04d0142ad65
(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
|
1462 |
v->breakdown_ctr = GB(r, 16, 6) + 0x3F; |
a04d0142ad65
(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
|
1463 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 1464 |
v->breakdown_chance = 0; |
1465 |
} |
|
1466 |
} |
|
1467 |
||
1468 |
static const StringID _vehicle_type_names[4] = { |
|
1469 |
STR_019F_TRAIN, |
|
1470 |
STR_019C_ROAD_VEHICLE, |
|
1471 |
STR_019E_SHIP, |
|
1472 |
STR_019D_AIRCRAFT, |
|
1473 |
}; |
|
1474 |
||
1475 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1476 |
{ |
|
2639 | 1477 |
if (v->owner != _local_player) return; |
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1478 |
|
26 | 1479 |
// Do not show getting-old message if autorenew is active |
2639 | 1480 |
if (GetPlayer(v->owner)->engine_renew) return; |
0 | 1481 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1482 |
SetDParam(0, _vehicle_type_names[v->type - 0x10]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1483 |
SetDParam(1, v->unitnumber); |
0 | 1484 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1485 |
} |
|
1486 |
||
1487 |
void AgeVehicle(Vehicle *v) |
|
1488 |
{ |
|
1489 |
int age; |
|
1490 |
||
1491 |
if (v->age < 65535) |
|
1492 |
v->age++; |
|
1493 |
||
1494 |
age = v->age - v->max_age; |
|
1495 |
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
|
1496 |
v->reliability_spd_dec <<= 1; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1497 |
|
0 | 1498 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1499 |
||
1500 |
if (age == -366) { |
|
1501 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1502 |
} else if (age == 0) { |
|
1503 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
1504 |
} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) { |
|
1505 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
|
1506 |
} |
|
1507 |
} |
|
1508 |
||
2244 | 1509 |
/** Clone a vehicle. If it is a train, it will clone all the cars too |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1510 |
* @param tile tile of the depot where the cloned vehicle is build |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1511 |
* @param p1 the original vehicle's index |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1512 |
* @param p2 1 = shared orders, else copied orders |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1513 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1514 |
int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2244 | 1515 |
{ |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1516 |
Vehicle *v_front, *v; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1517 |
Vehicle *w_front, *w, *w_rear; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1518 |
int cost, total_cost = 0; |
3816
28ee8b8c2522
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3815
diff
changeset
|
1519 |
uint32 build_argument = 2; |
2244 | 1520 |
|
2639 | 1521 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
2244 | 1522 |
v = GetVehicle(p1); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1523 |
v_front = v; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1524 |
w = NULL; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1525 |
w_front = NULL; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1526 |
w_rear = NULL; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1527 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1528 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1529 |
/* |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1530 |
* v_front is the front engine in the original vehicle |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1531 |
* v is the car/vehicle of the original vehicle, that is currently being copied |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1532 |
* w_front is the front engine of the cloned vehicle |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1533 |
* w is the car/vehicle currently being cloned |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1534 |
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1535 |
*/ |
2244 | 1536 |
|
2639 | 1537 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1538 |
|
2813
504f3e6d14ff
(svn r3361) - Clone Vehicle: Disallow cloning of crashed rail vehicles after starting removal process.
peter1138
parents:
2805
diff
changeset
|
1539 |
if (v->type == VEH_Train && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR; |
2244 | 1540 |
|
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1541 |
// check that we can allocate enough vehicles |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1542 |
if (!(flags & DC_EXEC)) { |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1543 |
int veh_counter = 0; |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1544 |
do { |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1545 |
veh_counter++; |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1546 |
} while ((v = v->next) != NULL); |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1547 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1548 |
if (!AllocateVehicles(NULL, veh_counter)) { |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1549 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1550 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1551 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1552 |
|
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1553 |
v = v_front; |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1554 |
|
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1555 |
do { |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1556 |
|
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1557 |
if (IsMultiheaded(v) && !IsTrainEngine(v)) { |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1558 |
/* we build the rear ends of multiheaded trains with the front ones */ |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1559 |
continue; |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1560 |
} |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1561 |
|
3815
b91a1d73a857
(svn r4825) - Fix [clone FS#159]: Game crashes when cloning reaches train-limit.
bjarni
parents:
3794
diff
changeset
|
1562 |
cost = DoCommand(tile, v->engine_type, build_argument, flags, CMD_BUILD_VEH(v->type)); |
3819
64c55c77567a
(svn r4829) -Codechage: [clone vehilces] only check for a free unitnumber for the first engine in the test run as well as execute run (to improve speed. The result should be unchanged)
bjarni
parents:
3816
diff
changeset
|
1563 |
build_argument = 3; // ensure that we only assign a number to the first engine |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1564 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1565 |
if (CmdFailed(cost)) return cost; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1566 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1567 |
total_cost += cost; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1568 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1569 |
if (flags & DC_EXEC) { |
2639 | 1570 |
w = GetVehicle(_new_vehicle_id); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1571 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1572 |
if (v->type != VEH_Road) { // road vehicles can't be refitted |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1573 |
if (v->cargo_type != w->cargo_type) { |
3364
6aea3b4cc44e
(svn r4159) added missing comments about refitting in CmdCloneVehicle
bjarni
parents:
3363
diff
changeset
|
1574 |
// we can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build |
6aea3b4cc44e
(svn r4159) added missing comments about refitting in CmdCloneVehicle
bjarni
parents:
3363
diff
changeset
|
1575 |
// if we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1576 |
DoCommand(0, w->index, v->cargo_type, flags, CMD_REFIT_VEH(v->type)); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1577 |
} |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1578 |
} |
3896
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1579 |
if (v->type == VEH_Train && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { |
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1580 |
SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION); |
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1581 |
} |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1582 |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1583 |
if (v->type == VEH_Train && !IsFrontEngine(v)) { |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1584 |
// this s a train car |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1585 |
// add this unit to the end of the train |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1586 |
DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1587 |
} else { |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1588 |
// this is a front engine or not a train. It need orders |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1589 |
w_front = w; |
3679
252b4ab2aad4
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1590 |
w->service_interval = v->service_interval; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1591 |
DoCommand(0, (v->index << 16) | w->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1592 |
} |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1593 |
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1594 |
} |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
1595 |
} while (v->type == VEH_Train && (v = GetNextVehicle(v)) != NULL); |
2244 | 1596 |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1597 |
if (flags & DC_EXEC && v_front->type == VEH_Train) { |
3948
a09379beffd5
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3896
diff
changeset
|
1598 |
// for trains this needs to be the front engine due to the callback function |
a09379beffd5
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3896
diff
changeset
|
1599 |
_new_vehicle_id = w_front->index; |
2244 | 1600 |
} |
1601 |
return total_cost; |
|
1602 |
} |
|
1603 |
||
2599
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1604 |
/* |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1605 |
* move the cargo from one engine to another if possible |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1606 |
*/ |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1607 |
static void MoveVehicleCargo(Vehicle *dest, Vehicle *source) |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1608 |
{ |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1609 |
Vehicle *v = dest; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1610 |
int units_moved; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1611 |
|
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1612 |
do { |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1613 |
do { |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1614 |
if (source->cargo_type != dest->cargo_type) |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1615 |
continue; // cargo not compatible |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1616 |
|
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1617 |
if (dest->cargo_count == dest->cargo_cap) |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1618 |
continue; // the destination vehicle is already full |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1619 |
|
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1620 |
units_moved = min(source->cargo_count, dest->cargo_cap - dest->cargo_count); |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1621 |
source->cargo_count -= units_moved; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1622 |
dest->cargo_count += units_moved; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1623 |
dest->cargo_source = source->cargo_source; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1624 |
|
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1625 |
// copy the age of the cargo |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1626 |
dest->cargo_days = source->cargo_days; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1627 |
dest->day_counter = source->day_counter; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1628 |
dest->tick_counter = source->tick_counter; |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1629 |
|
2678
71ca8ee16593
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1630 |
} while (source->cargo_count > 0 && (dest = dest->next) != NULL); |
2599
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1631 |
dest = v; |
2678
71ca8ee16593
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1632 |
} while ((source = source->next) != NULL); |
2599
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1633 |
} |
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1634 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1635 |
/* Replaces a vehicle (used to be called autorenew) |
2639 | 1636 |
* This function is only called from MaybeReplaceVehicle() |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1637 |
* Must be called with _current_player set to the owner of the vehicle |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1638 |
* @param w Vehicle to replace |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1639 |
* @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts |
2639 | 1640 |
* @return value is cost of the replacement or CMD_ERROR |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1641 |
*/ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1642 |
static int32 ReplaceVehicle(Vehicle **w, byte flags) |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1643 |
{ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1644 |
int32 cost; |
2599
ad75080afea4
(svn r3136) -Fix: [autoreplace] all cargo in engines that consists of more than one vehicle will try to move cargo from all vehicles
bjarni
parents:
2592
diff
changeset
|
1645 |
Vehicle *old_v = *w; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1646 |
const Player *p = GetPlayer(old_v->owner); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1647 |
EngineID new_engine_type; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1648 |
const UnitID cached_unitnumber = old_v->unitnumber; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1649 |
bool new_front = false; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1650 |
Vehicle *new_v = NULL; |
2716
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1651 |
char vehicle_name[32]; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1652 |
|
2848 | 1653 |
new_engine_type = EngineReplacementForPlayer(p, old_v->engine_type); |
2697
97fc22baf3da
(svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents:
2685
diff
changeset
|
1654 |
if (new_engine_type == INVALID_ENGINE) new_engine_type = old_v->engine_type; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1655 |
|
3816
28ee8b8c2522
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3815
diff
changeset
|
1656 |
cost = DoCommand(old_v->tile, new_engine_type, 3, flags, CMD_BUILD_VEH(old_v->type)); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1657 |
if (CmdFailed(cost)) return cost; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1658 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1659 |
if (flags & DC_EXEC) { |
2564 | 1660 |
new_v = GetVehicle(_new_vehicle_id); |
1661 |
*w = new_v; //we changed the vehicle, so MaybeReplaceVehicle needs to work on the new one. Now we tell it what the new one is |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1662 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1663 |
/* refit if needed */ |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
1664 |
if (old_v->cargo_type != new_v->cargo_type && old_v->cargo_cap != 0 && new_v->cargo_cap != 0) {// some train engines do not have cargo capacity |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
1665 |
// we add the refit cost to cost, so it's added to the cost animation |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
1666 |
// it's not in the calculation of having enough money to actually do the replace since it's rather hard to do by design, but since |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
1667 |
// we pay for it, it's nice to make the cost animation include it |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
1668 |
int32 temp_cost = DoCommand(0, new_v->index, old_v->cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type)); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
1669 |
if (!CmdFailed(temp_cost)) cost += temp_cost; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1670 |
} |
3896
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1671 |
if (new_v->type == VEH_Train && HASBIT(old_v->u.rail.flags, VRF_REVERSE_DIRECTION) && !IsMultiheaded(new_v) && !(new_v->next != NULL && IsArticulatedPart(new_v->next))) { |
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1672 |
// we are autorenewing to a single engine, so we will turn it as the old one was turned as well |
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1673 |
SETBIT(new_v->u.rail.flags, VRF_REVERSE_DIRECTION); |
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1674 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1675 |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1676 |
if (old_v->type == VEH_Train && !IsFrontEngine(old_v)) { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1677 |
/* this is a railcar. We need to move the car into the train |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1678 |
* We add the new engine after the old one instead of replacing it. It will give the same result anyway when we |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1679 |
* sell the old engine in a moment |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1680 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1681 |
DoCommand(0, (GetPrevVehicleInChain(old_v)->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2678
71ca8ee16593
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1682 |
/* Now we move the old one out of the train */ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1683 |
DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1684 |
} else { |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1685 |
// copy/clone the orders |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1686 |
DoCommand(0, (old_v->index << 16) | new_v->index, IsOrderListShared(old_v) ? CO_SHARE : CO_COPY, DC_EXEC, CMD_CLONE_ORDER); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1687 |
new_v->cur_order_index = old_v->cur_order_index; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1688 |
ChangeVehicleViewWindow(old_v, new_v); |
2575
7a3e28317661
(svn r3112) -Feature: [autoreplace] profit counters are now remembered too (request by Darkvater)
bjarni
parents:
2574
diff
changeset
|
1689 |
new_v->profit_this_year = old_v->profit_this_year; |
7a3e28317661
(svn r3112) -Feature: [autoreplace] profit counters are now remembered too (request by Darkvater)
bjarni
parents:
2574
diff
changeset
|
1690 |
new_v->profit_last_year = old_v->profit_last_year; |
3679
252b4ab2aad4
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1691 |
new_v->service_interval = old_v->service_interval; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1692 |
new_front = true; |
3816
28ee8b8c2522
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3815
diff
changeset
|
1693 |
new_v->unitnumber = old_v->unitnumber; // use the same unit number |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1694 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1695 |
new_v->current_order = old_v->current_order; |
2842
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1696 |
if (old_v->type == VEH_Train && GetNextVehicle(old_v) != NULL){ |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1697 |
Vehicle *temp_v = GetNextVehicle(old_v); |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1698 |
|
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1699 |
// move the entire train to the new engine, excluding the old engine |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1700 |
if (IsMultiheaded(old_v) && temp_v == old_v->u.rail.other_multiheaded_part) { |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1701 |
// we got front and rear of a multiheaded engine right after each other. We should work with the next in line instead |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1702 |
temp_v = GetNextVehicle(temp_v); |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1703 |
} |
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1704 |
|
954112262878
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
1705 |
if (temp_v != NULL) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1706 |
DoCommand(0, (new_v->index << 16) | temp_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2681
d7376b436f9c
(svn r3223) -Fix: [autoreplace] fixed crash when replacing a train engine without any cars (introduced in r3220)
bjarni
parents:
2678
diff
changeset
|
1707 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1708 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1709 |
} |
2678
71ca8ee16593
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1710 |
/* We are done setting up the new vehicle. Now we move the cargo from the old one to the new one */ |
71ca8ee16593
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1711 |
MoveVehicleCargo(new_v->type == VEH_Train ? GetFirstVehicleInChain(new_v) : new_v, old_v); |
2716
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1712 |
|
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1713 |
// Get the name of the old vehicle if it has a custom name. |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1714 |
if ((old_v->string_id & 0xF800) != 0x7800) { |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1715 |
vehicle_name[0] = '\0'; |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1716 |
} else { |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1717 |
GetName(old_v->string_id & 0x7FF, vehicle_name); |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1718 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1719 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1720 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1721 |
// sell the engine/ find out how much you get for the old engine |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1722 |
cost += DoCommand(0, old_v->index, 0, flags, CMD_SELL_VEH(old_v->type)); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1723 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1724 |
if (new_front) { |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1725 |
// now we assign the old unitnumber to the new vehicle |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1726 |
new_v->unitnumber = cached_unitnumber; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1727 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1728 |
|
2716
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1729 |
// Transfer the name of the old vehicle. |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1730 |
if ((flags & DC_EXEC) && vehicle_name[0] != '\0') { |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1731 |
_cmd_text = vehicle_name; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1732 |
DoCommand(0, new_v->index, 0, DC_EXEC, CMD_NAME_VEHICLE); |
2716
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1733 |
} |
2eb2687665e7
(svn r3261) - Autoreplace: If a replaced vehicle had a custom name, transfer it to the new vehicle. Fixes "[ 1370039 ] Autoreplaced vehicles lose their names"
peter1138
parents:
2704
diff
changeset
|
1734 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1735 |
return cost; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1736 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1737 |
|
2639 | 1738 |
/** replaces a vehicle if it's set for autoreplace or is too old |
1739 |
* (used to be called autorenew) |
|
1740 |
* @param v The vehicle to replace |
|
1741 |
* if the vehicle is a train, v needs to be the front engine |
|
1742 |
* return value is a pointer to the new vehicle, which is the same as the argument if nothing happened |
|
1743 |
*/ |
|
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
1744 |
static void MaybeReplaceVehicle(Vehicle *v) |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1745 |
{ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1746 |
Vehicle *w; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1747 |
const Player *p = GetPlayer(v->owner); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1748 |
byte flags = 0; |
2591
00e40545fc9c
(svn r3128) -Fix: [autoreplace] fixed bug that made the player pay twice for autoreplacing and could end up with negative money
bjarni
parents:
2590
diff
changeset
|
1749 |
int32 cost, temp_cost = 0; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
1750 |
bool stopped = false; |
2805
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2804
diff
changeset
|
1751 |
|
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2804
diff
changeset
|
1752 |
/* Remember the length in case we need to trim train later on |
3175
30c8cb7cc416
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
1753 |
* If it's not a train, the value is unused |
30c8cb7cc416
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
1754 |
* round up to the length of the tiles used for the train instead of the train length instead |
30c8cb7cc416
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
1755 |
* Useful when newGRF uses custom length */ |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3421
diff
changeset
|
1756 |
uint16 old_total_length = (v->type == VEH_Train ? |
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3421
diff
changeset
|
1757 |
(v->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE * TILE_SIZE : |
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3421
diff
changeset
|
1758 |
-1 |
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3421
diff
changeset
|
1759 |
); |
3175
30c8cb7cc416
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
1760 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1761 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1762 |
_current_player = v->owner; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1763 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1764 |
assert(v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship || v->type == VEH_Aircraft); |
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
1765 |
|
2590
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
1766 |
assert(v->vehstatus & VS_STOPPED); // the vehicle should have been stopped in VehicleEnteredDepotThisTick() if needed |
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
1767 |
|
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
1768 |
if (v->leave_depot_instantly) { |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
1769 |
// we stopped the vehicle to do this, so we have to remember to start it again when we are done |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
1770 |
// we need to store this info as the engine might be replaced and lose this info |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
1771 |
stopped = true; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
1772 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1773 |
|
2639 | 1774 |
for (;;) { |
2591
00e40545fc9c
(svn r3128) -Fix: [autoreplace] fixed bug that made the player pay twice for autoreplacing and could end up with negative money
bjarni
parents:
2590
diff
changeset
|
1775 |
cost = 0; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1776 |
w = v; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1777 |
do { |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1778 |
if (w->type == VEH_Train && IsMultiheaded(w) && !IsTrainEngine(w)) { |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1779 |
/* we build the rear ends of multiheaded trains with the front ones */ |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1780 |
continue; |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1781 |
} |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1782 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1783 |
// check if the vehicle should be replaced |
2639 | 1784 |
if (!p->engine_renew || |
1785 |
w->age - w->max_age < (p->engine_renew_months * 30) || // replace if engine is too old |
|
1786 |
w->max_age == 0) { // rail cars got a max age of 0 |
|
2848 | 1787 |
if (!EngineHasReplacementForPlayer(p, w->engine_type)) // updates to a new model |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1788 |
continue; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1789 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1790 |
|
3412
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1791 |
if (w->type == VEH_Train && IsTrainWagon(w)) { |
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1792 |
EngineID e = EngineReplacementForPlayer(p, w->engine_type); |
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1793 |
|
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1794 |
if (w->cargo_type != RailVehInfo(e)->cargo_type && !CanRefitTo(e, w->cargo_type)) { |
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1795 |
// we can't replace this wagon since the cargo type is incorrent, and we can't refit it |
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1796 |
continue; |
f1dc9f094c2a
(svn r4227) - Fix: Wagon replace nows checks if the cargo types are the same before seeing if it can refit.
peter1138
parents:
3404
diff
changeset
|
1797 |
} |
2970
3b9380f10074
(svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents:
2952
diff
changeset
|
1798 |
} |
3b9380f10074
(svn r3535) -Feature: [autoreplace] allow autoreplacing of train wagons
bjarni
parents:
2952
diff
changeset
|
1799 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1800 |
/* Now replace the vehicle */ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1801 |
temp_cost = ReplaceVehicle(&w, flags); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1802 |
|
2639 | 1803 |
if (flags & DC_EXEC && |
2999
1d613b0e6884
(svn r3579) v->u.rail.first_engine holds an engine type, not a vehicle index, so use INVALID_ENGINE.
peter1138
parents:
2998
diff
changeset
|
1804 |
(w->type != VEH_Train || w->u.rail.first_engine == INVALID_ENGINE)) { |
2639 | 1805 |
/* now we bought a new engine and sold the old one. We need to fix the |
1806 |
* pointers in order to avoid pointing to the old one for trains: these |
|
1807 |
* pointers should point to the front engine and not the cars |
|
1808 |
*/ |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1809 |
v = w; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1810 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1811 |
|
3413
bebbb9d71cc8
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
1812 |
if (!CmdFailed(temp_cost)) { |
bebbb9d71cc8
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
1813 |
cost += temp_cost; |
bebbb9d71cc8
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
1814 |
} |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
1815 |
} while (w->type == VEH_Train && (w = GetNextVehicle(w)) != NULL); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1816 |
|
3413
bebbb9d71cc8
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
1817 |
if (p->money64 < (int32)(cost + p->engine_renew_money) || cost == 0) { |
2558
64d44eaf39ee
(svn r3093) -Fix: [autoreplace] fixed issue where the money limit message showed up in some cases when no replace was needed
bjarni
parents:
2552
diff
changeset
|
1818 |
if (p->money64 < (int32)(cost + p->engine_renew_money) && ( _local_player == v->owner ) && cost != 0) { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1819 |
StringID message; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1820 |
SetDParam(0, v->unitnumber); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1821 |
switch (v->type) { |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1822 |
case VEH_Train: message = STR_TRAIN_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1823 |
case VEH_Road: message = STR_ROADVEHICLE_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1824 |
case VEH_Ship: message = STR_SHIP_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1825 |
case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1826 |
// This should never happen |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1827 |
default: NOT_REACHED(); message = 0; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1828 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1829 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1830 |
AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1831 |
} |
2639 | 1832 |
if (stopped) v->vehstatus &= ~VS_STOPPED; |
2592
1b5741daf07a
(svn r3129) -Fix: [autoreplace] fixed bug that made the player pay twice for autoreplacing and could end up with negative money
bjarni
parents:
2591
diff
changeset
|
1833 |
_current_player = OWNER_NONE; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
1834 |
return; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1835 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1836 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1837 |
if (flags & DC_EXEC) { |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1838 |
break; // we are done replacing since the loop ran once with DC_EXEC |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1839 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1840 |
// now we redo the loop, but this time we actually do stuff since we know that we can do it |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1841 |
flags |= DC_EXEC; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1842 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1843 |
|
2805
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2804
diff
changeset
|
1844 |
/* If setting is on to try not to exceed the old length of the train with the replacement */ |
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2804
diff
changeset
|
1845 |
if (v->type == VEH_Train && p->renew_keep_length) { |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1846 |
Vehicle *temp; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1847 |
w = v; |
2805
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2804
diff
changeset
|
1848 |
|
29e2b43a1e20
(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length
tron
parents:
2804
diff
changeset
|
1849 |
while (v->u.rail.cached_total_length > old_total_length) { |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1850 |
// the train is too long. We will remove cars one by one from the start of the train until it's short enough |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1851 |
while (w != NULL && !(RailVehInfo(w->engine_type)->flags&RVI_WAGON) ) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1852 |
w = GetNextVehicle(w); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1853 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1854 |
if (w == NULL) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1855 |
// we failed to make the train short enough |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1856 |
SetDParam(0, v->unitnumber); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1857 |
AddNewsItem(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1858 |
break; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1859 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1860 |
temp = w; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1861 |
w = GetNextVehicle(w); |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1862 |
DoCommand(0, (INVALID_VEHICLE << 16) | temp->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2678
71ca8ee16593
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1863 |
MoveVehicleCargo(v, temp); |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1864 |
cost += DoCommand(0, temp->index, 0, flags, CMD_SELL_VEH(temp->type)); |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1865 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1866 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
1867 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1868 |
if (IsLocalPlayer()) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1869 |
|
2639 | 1870 |
if (stopped) v->vehstatus &= ~VS_STOPPED; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1871 |
_current_player = OWNER_NONE; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1872 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1873 |
|
2244 | 1874 |
|
1786
7cfd46c3fcc4
(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
|
1875 |
/** Give a custom name to your vehicle |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1876 |
* @param tile unused |
1786
7cfd46c3fcc4
(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
|
1877 |
* @param p1 vehicle ID to name |
7cfd46c3fcc4
(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
|
1878 |
* @param p2 unused |
7cfd46c3fcc4
(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
|
1879 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1880 |
int32 CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1881 |
{ |
1882 |
Vehicle *v; |
|
1883 |
StringID str; |
|
1884 |
||
1840
ce40137a6ab4
(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
|
1885 |
if (!IsVehicleIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1886 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1887 |
v = GetVehicle(p1); |
0 | 1888 |
|
1786
7cfd46c3fcc4
(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
|
1889 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1890 |
|
1820
d03c56850dc2
(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
|
1891 |
str = AllocateNameUnique(_cmd_text, 2); |
1786
7cfd46c3fcc4
(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
|
1892 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1893 |
|
0 | 1894 |
if (flags & DC_EXEC) { |
1895 |
StringID old_str = v->string_id; |
|
1896 |
v->string_id = str; |
|
1897 |
DeleteName(old_str); |
|
588 | 1898 |
ResortVehicleLists(); |
0 | 1899 |
MarkWholeScreenDirty(); |
1900 |
} else { |
|
1901 |
DeleteName(str); |
|
1902 |
} |
|
1903 |
||
1904 |
return 0; |
|
1905 |
} |
|
1906 |
||
1907 |
||
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1908 |
/** Change the service interval of a vehicle |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1909 |
* @param tile unused |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1910 |
* @param p1 vehicle ID that is being service-interval-changed |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1911 |
* @param p2 new service interval |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1912 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1913 |
int32 CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1914 |
{ |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1915 |
Vehicle* v; |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1916 |
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */ |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1917 |
|
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1918 |
if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR; |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1919 |
|
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1920 |
v = GetVehicle(p1); |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1921 |
|
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1922 |
if (v->type == 0 || !CheckOwnership(v->owner)) return CMD_ERROR; |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1923 |
|
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1924 |
if (flags & DC_EXEC) { |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1925 |
v->service_interval = serv_int; |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1926 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1927 |
} |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1928 |
|
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1929 |
return 0; |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1930 |
} |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1931 |
|
0 | 1932 |
|
1933 |
static Rect _old_vehicle_coords; |
|
1934 |
||
1935 |
void BeginVehicleMove(Vehicle *v) { |
|
1936 |
_old_vehicle_coords.left = v->left_coord; |
|
1937 |
_old_vehicle_coords.top = v->top_coord; |
|
1938 |
_old_vehicle_coords.right = v->right_coord; |
|
1939 |
_old_vehicle_coords.bottom = v->bottom_coord; |
|
1940 |
} |
|
1941 |
||
1942 |
void EndVehicleMove(Vehicle *v) |
|
1943 |
{ |
|
1944 |
MarkAllViewportsDirty( |
|
1945 |
min(_old_vehicle_coords.left,v->left_coord), |
|
1946 |
min(_old_vehicle_coords.top,v->top_coord), |
|
1947 |
max(_old_vehicle_coords.right,v->right_coord)+1, |
|
1948 |
max(_old_vehicle_coords.bottom,v->bottom_coord)+1 |
|
1949 |
); |
|
1950 |
} |
|
1951 |
||
1952 |
/* returns true if staying in the same tile */ |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
1953 |
bool GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp) |
0 | 1954 |
{ |
1955 |
static const int8 _delta_coord[16] = { |
|
1956 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
1957 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
1958 |
}; |
|
1959 |
||
1960 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
1961 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
1962 |
||
1963 |
gp->x = x; |
|
1964 |
gp->y = y; |
|
1965 |
gp->old_tile = v->tile; |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1966 |
gp->new_tile = TileVirtXY(x, y); |
0 | 1967 |
return gp->old_tile == gp->new_tile; |
1968 |
} |
|
1969 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1970 |
static const Direction _new_direction_table[] = { |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1971 |
DIR_N , DIR_NW, DIR_W , |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1972 |
DIR_NE, DIR_SE, DIR_SW, |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1973 |
DIR_E , DIR_SE, DIR_S |
0 | 1974 |
}; |
1975 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1976 |
Direction GetDirectionTowards(const Vehicle* v, int x, int y) |
0 | 1977 |
{ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1978 |
Direction dir; |
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1979 |
DirDiff dirdiff; |
0 | 1980 |
int i = 0; |
1981 |
||
1982 |
if (y >= v->y_pos) { |
|
1983 |
if (y != v->y_pos) i+=3; |
|
1984 |
i+=3; |
|
1985 |
} |
|
1986 |
||
1987 |
if (x >= v->x_pos) { |
|
1988 |
if (x != v->x_pos) i++; |
|
1989 |
i++; |
|
1990 |
} |
|
1991 |
||
1992 |
dir = v->direction; |
|
1993 |
||
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1994 |
dirdiff = DirDifference(_new_direction_table[i], dir); |
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1995 |
if (dirdiff == DIRDIFF_SAME) return dir; |
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1996 |
return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 1997 |
} |
1998 |
||
1944
dd9cba5fab2a
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
1999 |
Trackdir GetVehicleTrackdir(const Vehicle* v) |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2000 |
{ |
1765
155dfdbbbc8d
(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
|
2001 |
if (v->vehstatus & VS_CRASHED) return 0xFF; |
1758
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
2002 |
|
2952 | 2003 |
switch (v->type) { |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2004 |
case VEH_Train: |
1765
155dfdbbbc8d
(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
|
2005 |
if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */ |
3185 | 2006 |
return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); /* Train in depot */ |
1765
155dfdbbbc8d
(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
|
2007 |
|
155dfdbbbc8d
(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
|
2008 |
if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */ |
3161 | 2009 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1765
155dfdbbbc8d
(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
|
2010 |
|
1944
dd9cba5fab2a
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
2011 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.rail.track),v->direction); |
1959 | 2012 |
|
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2013 |
case VEH_Ship: |
3961
9868b766fda7
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
2014 |
if (IsShipInDepot(v)) |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
2015 |
/* We'll assume the ship is facing outwards */ |
3953
e64bbd8598e2
(svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents:
3948
diff
changeset
|
2016 |
return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile)); |
1765
155dfdbbbc8d
(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
|
2017 |
|
1944
dd9cba5fab2a
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
2018 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction); |
1959 | 2019 |
|
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2020 |
case VEH_Road: |
3959 | 2021 |
if (IsRoadVehInDepot(v)) /* We'll assume the road vehicle is facing outwards */ |
3179 | 2022 |
return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile)); |
1765
155dfdbbbc8d
(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
|
2023 |
|
3404
eb8ebfe5df67
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
2024 |
if (IsRoadStopTile(v->tile)) /* We'll assume the road vehicle is facing outwards */ |
eb8ebfe5df67
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
2025 |
return DiagdirToDiagTrackdir(GetRoadStopDir(v->tile)); /* Road vehicle in a station */ |
1765
155dfdbbbc8d
(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
|
2026 |
|
3161 | 2027 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1959 | 2028 |
|
1765
155dfdbbbc8d
(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
|
2029 |
/* case VEH_Aircraft: case VEH_Special: case VEH_Disaster: */ |
155dfdbbbc8d
(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
|
2030 |
default: return 0xFF; |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2031 |
} |
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2032 |
} |
22 | 2033 |
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, |
2034 |
* result << 8 contains the id of the station entered. If the return value has |
|
2035 |
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there |
|
2036 |
* other bits that can be set? */ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2037 |
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
|
2038 |
{ |
3657 | 2039 |
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
0 | 2040 |
} |
2041 |
||
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
2042 |
UnitID GetFreeUnitNumber(byte type) |
0 | 2043 |
{ |
3018
22ede527b855
(svn r3598) -Fix: suppress invalid warning by assigning value to variable
truelight
parents:
3009
diff
changeset
|
2044 |
UnitID unit, max = 0; |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2045 |
const Vehicle *u; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2046 |
static bool *cache = NULL; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2047 |
static UnitID gmax = 0; |
0 | 2048 |
|
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2049 |
switch (type) { |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2050 |
case VEH_Train: max = _patches.max_trains; break; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2051 |
case VEH_Road: max = _patches.max_roadveh; break; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2052 |
case VEH_Ship: max = _patches.max_ships; break; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2053 |
case VEH_Aircraft: max = _patches.max_aircraft; break; |
2996
9d77b3aec341
(svn r3573) - Replace assert(0) with NOT_REACHED(). This commit sponsored by "giving Darkvater credit for the last three".
peter1138
parents:
2995
diff
changeset
|
2054 |
default: NOT_REACHED(); |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2055 |
} |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2056 |
|
4096
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2057 |
if (max == 0) { |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2058 |
/* we can't build any of this kind of vehicle, so we just return 1 instead of looking for a free number |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2059 |
* a max of 0 will cause the following code to write to a NULL pointer |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2060 |
* We know that 1 is bigger than the max allowed vehicle number, so it's the same as returning something, that is too big |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2061 |
*/ |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2062 |
return 1; |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2063 |
} |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
2064 |
|
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2065 |
if (max > gmax) { |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2066 |
gmax = max; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2067 |
free(cache); |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2068 |
cache = malloc((max + 1) * sizeof(*cache)); |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2069 |
} |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2070 |
|
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2071 |
// Clear the cache |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2072 |
memset(cache, 0, (max + 1) * sizeof(*cache)); |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2073 |
|
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2074 |
// Fill the cache |
0 | 2075 |
FOR_ALL_VEHICLES(u) { |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2076 |
if (u->type == type && u->owner == _current_player && u->unitnumber != 0 && u->unitnumber <= max) |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2077 |
cache[u->unitnumber] = true; |
0 | 2078 |
} |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2079 |
|
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2080 |
// Find the first unused unit number |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2081 |
for (unit = 1; unit <= max; unit++) { |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2082 |
if (!cache[unit]) break; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2083 |
} |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2084 |
|
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
2085 |
return unit; |
0 | 2086 |
} |
2087 |
||
3113
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2088 |
static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID player) |
3040
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2089 |
{ |
3113
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2090 |
SpriteID map; |
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2091 |
byte colour = _player_colors[player]; |
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2092 |
|
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2093 |
/* XXX Magic 0x307 is the first company colour remap sprite */ |
3393
c40975f04842
(svn r4201) - Codechange: Do for _engine_info[] what we do for _*_vehicle_info[]; create and use a function to retrieve data, and ensure constness.
peter1138
parents:
3364
diff
changeset
|
2094 |
map = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC) ? |
3326
00cf690a7fe1
(svn r4092) CodeChange : Named sprites instead of magic numbers plus create/use helper macro/enum for recoloring scheme
belugas
parents:
3222
diff
changeset
|
2095 |
(SPR_2CCMAP_BASE + colour + colour * 16) : (PALETTE_RECOLOR_START + colour); |
3113
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2096 |
|
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2097 |
return SPRITE_PALETTE(map << PALETTE_SPRITE_START); |
3040
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2098 |
} |
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2099 |
|
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2100 |
PalSpriteID GetEnginePalette(EngineID engine_type, PlayerID player) |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2101 |
{ |
3113
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2102 |
return GetEngineColourMap(engine_type, player); |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2103 |
} |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2104 |
|
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2105 |
PalSpriteID GetVehiclePalette(const Vehicle *v) |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2106 |
{ |
3113
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
2107 |
return GetEngineColourMap(v->engine_type, v->owner); |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2108 |
} |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2109 |
|
0 | 2110 |
// Save and load of vehicles |
1881
435d39bd6ee0
(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
|
2111 |
const SaveLoad _common_veh_desc[] = { |
0 | 2112 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2113 |
|
938
23cc832ac8a2
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
933
diff
changeset
|
2114 |
SLE_REF(Vehicle,next, REF_VEHICLE_OLD), |
0 | 2115 |
SLE_VAR(Vehicle,string_id, SLE_STRINGID), |
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
2116 |
SLE_CONDVAR(Vehicle,unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2117 |
SLE_CONDVAR(Vehicle,unitnumber, SLE_UINT16, 8, SL_MAX_VERSION), |
0 | 2118 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
1174
6a5e747f3ba6
(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
|
2119 |
SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2120 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, SL_MAX_VERSION), |
1174
6a5e747f3ba6
(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,dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2122 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
0 | 2123 |
|
1174
6a5e747f3ba6
(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
|
2124 |
SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2125 |
SLE_CONDVAR(Vehicle,x_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
1174
6a5e747f3ba6
(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
|
2126 |
SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2127 |
SLE_CONDVAR(Vehicle,y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
0 | 2128 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
2129 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
2130 |
||
2131 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
2132 |
SLE_VAR(Vehicle,spritenum, SLE_UINT8), |
|
2133 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
2134 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
2135 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
2136 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
2137 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
2138 |
SLE_VAR(Vehicle,engine_type, SLE_UINT16), |
|
445
beafc0fb8f12
(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
|
2139 |
|
0 | 2140 |
SLE_VAR(Vehicle,max_speed, SLE_UINT16), |
2141 |
SLE_VAR(Vehicle,cur_speed, SLE_UINT16), |
|
2142 |
SLE_VAR(Vehicle,subspeed, SLE_UINT8), |
|
2143 |
SLE_VAR(Vehicle,acceleration, SLE_UINT8), |
|
2144 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
2145 |
||
2146 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2147 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2148 |
SLE_CONDVAR(Vehicle,last_station_visited, SLE_UINT16, 5, SL_MAX_VERSION), |
0 | 2149 |
|
2150 |
SLE_VAR(Vehicle,cargo_type, SLE_UINT8), |
|
2151 |
SLE_VAR(Vehicle,cargo_days, SLE_UINT8), |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1237
diff
changeset
|
2152 |
SLE_CONDVAR(Vehicle,cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2153 |
SLE_CONDVAR(Vehicle,cargo_source, SLE_UINT16, 7, SL_MAX_VERSION), |
0 | 2154 |
SLE_VAR(Vehicle,cargo_cap, SLE_UINT16), |
2155 |
SLE_VAR(Vehicle,cargo_count, SLE_UINT16), |
|
2156 |
||
2157 |
SLE_VAR(Vehicle,day_counter, SLE_UINT8), |
|
2158 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
2159 |
||
2160 |
SLE_VAR(Vehicle,cur_order_index, SLE_UINT8), |
|
2161 |
SLE_VAR(Vehicle,num_orders, SLE_UINT8), |
|
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2162 |
|
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2163 |
/* This next line is for version 4 and prior compatibility.. it temporarily reads |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2164 |
type and flags (which were both 4 bits) into type. Later on this is |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2165 |
converted correctly */ |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2166 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 0, 4), |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2167 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2168 |
|
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2169 |
/* Orders for version 5 and on */ |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2170 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2171 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2172 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, SL_MAX_VERSION), |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2173 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2174 |
SLE_REF(Vehicle,orders, REF_ORDER), |
0 | 2175 |
|
2176 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
2177 |
SLE_VAR(Vehicle,max_age, SLE_UINT16), |
|
2178 |
SLE_VAR(Vehicle,date_of_last_service,SLE_UINT16), |
|
2179 |
SLE_VAR(Vehicle,service_interval, SLE_UINT16), |
|
2180 |
SLE_VAR(Vehicle,reliability, SLE_UINT16), |
|
2181 |
SLE_VAR(Vehicle,reliability_spd_dec,SLE_UINT16), |
|
2182 |
SLE_VAR(Vehicle,breakdown_ctr, SLE_UINT8), |
|
2183 |
SLE_VAR(Vehicle,breakdown_delay, SLE_UINT8), |
|
2184 |
SLE_VAR(Vehicle,breakdowns_since_last_service, SLE_UINT8), |
|
2185 |
SLE_VAR(Vehicle,breakdown_chance, SLE_UINT8), |
|
2186 |
SLE_VAR(Vehicle,build_year, SLE_UINT8), |
|
2187 |
||
2188 |
SLE_VAR(Vehicle,load_unload_time_rem, SLE_UINT16), |
|
2189 |
||
2190 |
SLE_VAR(Vehicle,profit_this_year, SLE_INT32), |
|
2191 |
SLE_VAR(Vehicle,profit_last_year, SLE_INT32), |
|
2192 |
SLE_VAR(Vehicle,value, SLE_UINT32), |
|
2193 |
||
445
beafc0fb8f12
(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
|
2194 |
SLE_VAR(Vehicle,random_bits, SLE_UINT8), |
beafc0fb8f12
(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
|
2195 |
SLE_VAR(Vehicle,waiting_triggers, SLE_UINT8), |
beafc0fb8f12
(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
|
2196 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2197 |
SLE_REF(Vehicle,next_shared, REF_VEHICLE), |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2198 |
SLE_REF(Vehicle,prev_shared, REF_VEHICLE), |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2199 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2200 |
// reserve extra space in savegame here. (currently 10 bytes) |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2201 |
SLE_CONDNULL(10, 2, SL_MAX_VERSION), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2202 |
|
0 | 2203 |
SLE_END() |
2204 |
}; |
|
2205 |
||
2206 |
||
1881
435d39bd6ee0
(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
|
2207 |
static const SaveLoad _train_desc[] = { |
0 | 2208 |
SLE_WRITEBYTE(Vehicle,type,VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file. |
2209 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2210 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,crash_anim_pos), SLE_UINT16), |
|
2211 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,force_proceed), SLE_UINT8), |
|
2212 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,railtype), SLE_UINT8), |
|
2213 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRail,track), SLE_UINT8), |
|
2214 |
||
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2215 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,flags), SLE_UINT8, 2, SL_MAX_VERSION), |
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2216 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,days_since_order_progr), SLE_UINT16, 2, SL_MAX_VERSION), |
0 | 2217 |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2218 |
SLE_CONDNULL(2, 2, 19), |
2926
acbd46ed22a8
(svn r3482) - Fix: since multiheaded links are not saved anymore do NOT save them anymore at all, return the extra space. Since Bjarni's fix for this was abominable, the weird situation arises of 2 NULL structs of free space, of which the first isn't usable.
Darkvater
parents:
2916
diff
changeset
|
2219 |
// reserve extra space in savegame here. (currently 11 bytes) |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2220 |
SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
0 | 2221 |
|
2222 |
SLE_END() |
|
2223 |
}; |
|
2224 |
||
1881
435d39bd6ee0
(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
|
2225 |
static const SaveLoad _roadveh_desc[] = { |
0 | 2226 |
SLE_WRITEBYTE(Vehicle,type,VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file. |
2227 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2228 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,state), SLE_UINT8), |
|
2229 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,frame), SLE_UINT8), |
|
3009
c75f1a8d5ff9
(svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents:
2999
diff
changeset
|
2230 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,blocked_ctr), SLE_UINT16), |
0 | 2231 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking), SLE_UINT8), |
2232 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,overtaking_ctr),SLE_UINT8), |
|
2233 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,crashed_ctr), SLE_UINT16), |
|
2234 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,reverse_ctr), SLE_UINT8), |
|
2235 |
||
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2236 |
SLE_CONDREFX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
3431 | 2237 |
SLE_CONDNULL(1, 6, SL_MAX_VERSION), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2238 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRoad,slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
0 | 2239 |
// reserve extra space in savegame here. (currently 16 bytes) |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2240 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2241 |
|
2242 |
SLE_END() |
|
2243 |
}; |
|
2244 |
||
1881
435d39bd6ee0
(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
|
2245 |
static const SaveLoad _ship_desc[] = { |
0 | 2246 |
SLE_WRITEBYTE(Vehicle,type,VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file. |
2247 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2248 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleShip,state), SLE_UINT8), |
|
2249 |
||
2250 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2251 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2252 |
|
2253 |
SLE_END() |
|
2254 |
}; |
|
2255 |
||
1881
435d39bd6ee0
(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
|
2256 |
static const SaveLoad _aircraft_desc[] = { |
0 | 2257 |
SLE_WRITEBYTE(Vehicle,type,VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file. |
2258 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
|
2259 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,crashed_counter), SLE_UINT16), |
|
2260 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleAir,pos), SLE_UINT8), |
|
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2261 |
|
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2262 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2263 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
2264 |
|
0 | 2265 |
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
|
2266 |
|
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2267 |
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleAir,previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2268 |
|
2269 |
// reserve extra space in savegame here. (currently 15 bytes) |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2270 |
SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
0 | 2271 |
|
2272 |
SLE_END() |
|
2273 |
}; |
|
2274 |
||
1881
435d39bd6ee0
(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
|
2275 |
static const SaveLoad _special_desc[] = { |
0 | 2276 |
SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4), |
2277 |
||
2278 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2279 |
|
1174
6a5e747f3ba6
(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
|
2280 |
SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2281 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, SL_MAX_VERSION), |
0 | 2282 |
|
1174
6a5e747f3ba6
(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
|
2283 |
SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2284 |
SLE_CONDVAR(Vehicle,x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
1174
6a5e747f3ba6
(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
|
2285 |
SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2286 |
SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
0 | 2287 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
2288 |
||
2289 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
2290 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
2291 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
2292 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
2293 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
2294 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
2295 |
SLE_VAR(Vehicle,progress, SLE_UINT8), |
|
2296 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
2297 |
||
2298 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk0), SLE_UINT16), |
|
2299 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleSpecial,unk2), SLE_UINT8), |
|
2300 |
||
2301 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2302 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2303 |
|
2304 |
SLE_END() |
|
2305 |
}; |
|
2306 |
||
1881
435d39bd6ee0
(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
|
2307 |
static const SaveLoad _disaster_desc[] = { |
0 | 2308 |
SLE_WRITEBYTE(Vehicle,type,VEH_Disaster, 5), |
2309 |
||
938
23cc832ac8a2
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
933
diff
changeset
|
2310 |
SLE_REF(Vehicle,next, REF_VEHICLE_OLD), |
0 | 2311 |
|
2312 |
SLE_VAR(Vehicle,subtype, SLE_UINT8), |
|
1174
6a5e747f3ba6
(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
|
2313 |
SLE_CONDVAR(Vehicle,tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2314 |
SLE_CONDVAR(Vehicle,tile, SLE_UINT32, 6, SL_MAX_VERSION), |
1174
6a5e747f3ba6
(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
|
2315 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2316 |
SLE_CONDVAR(Vehicle,dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
0 | 2317 |
|
1174
6a5e747f3ba6
(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
|
2318 |
SLE_CONDVAR(Vehicle,x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2319 |
SLE_CONDVAR(Vehicle,x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
1174
6a5e747f3ba6
(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
|
2320 |
SLE_CONDVAR(Vehicle,y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2321 |
SLE_CONDVAR(Vehicle,y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
0 | 2322 |
SLE_VAR(Vehicle,z_pos, SLE_UINT8), |
2323 |
SLE_VAR(Vehicle,direction, SLE_UINT8), |
|
2324 |
||
2325 |
SLE_VAR(Vehicle,x_offs, SLE_INT8), |
|
2326 |
SLE_VAR(Vehicle,y_offs, SLE_INT8), |
|
2327 |
SLE_VAR(Vehicle,sprite_width, SLE_UINT8), |
|
2328 |
SLE_VAR(Vehicle,sprite_height, SLE_UINT8), |
|
2329 |
SLE_VAR(Vehicle,z_height, SLE_UINT8), |
|
2330 |
SLE_VAR(Vehicle,owner, SLE_UINT8), |
|
2331 |
SLE_VAR(Vehicle,vehstatus, SLE_UINT8), |
|
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2332 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
3047
2880aef0ee9d
(svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents:
3040
diff
changeset
|
2333 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, station), SLE_UINT16, 5, SL_MAX_VERSION), |
0 | 2334 |
|
2335 |
SLE_VAR(Vehicle,cur_image, SLE_UINT16), |
|
2336 |
SLE_VAR(Vehicle,age, SLE_UINT16), |
|
2337 |
||
2338 |
SLE_VAR(Vehicle,tick_counter, SLE_UINT8), |
|
2339 |
||
2340 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,image_override), SLE_UINT16), |
|
2341 |
SLE_VARX(offsetof(Vehicle,u)+offsetof(VehicleDisaster,unk2), SLE_UINT16), |
|
2342 |
||
2343 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2344 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2345 |
|
2346 |
SLE_END() |
|
2347 |
}; |
|
2348 |
||
2349 |
||
2350 |
static const void *_veh_descs[] = { |
|
2351 |
_train_desc, |
|
2352 |
_roadveh_desc, |
|
2353 |
_ship_desc, |
|
2354 |
_aircraft_desc, |
|
2355 |
_special_desc, |
|
2356 |
_disaster_desc, |
|
2357 |
}; |
|
2358 |
||
2359 |
// Will be called when the vehicles need to be saved. |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
2360 |
static void Save_VEHS(void) |
0 | 2361 |
{ |
2362 |
Vehicle *v; |
|
2363 |
// Write the vehicles |
|
2364 |
FOR_ALL_VEHICLES(v) { |
|
2365 |
if (v->type != 0) { |
|
2366 |
SlSetArrayIndex(v->index); |
|
2367 |
SlObject(v, _veh_descs[v->type - 0x10]); |
|
2368 |
} |
|
2369 |
} |
|
2370 |
} |
|
2371 |
||
2372 |
// Will be called when vehicles need to be loaded. |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
2373 |
static void Load_VEHS(void) |
0 | 2374 |
{ |
2375 |
int index; |
|
2376 |
Vehicle *v; |
|
2377 |
||
2378 |
while ((index = SlIterateArray()) != -1) { |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2379 |
Vehicle *v; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2380 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2381 |
if (!AddBlockIfNeeded(&_vehicle_pool, index)) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2382 |
error("Vehicles: failed loading savegame: too many vehicles"); |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2383 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2384 |
v = GetVehicle(index); |
0 | 2385 |
SlObject(v, _veh_descs[SlReadByte()]); |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2386 |
|
2549 | 2387 |
/* Old savegames used 'last_station_visited = 0xFF' */ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2388 |
if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF) |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2467
diff
changeset
|
2389 |
v->last_station_visited = INVALID_STATION; |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2390 |
|
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2391 |
if (CheckSavegameVersion(5)) { |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2392 |
/* Convert the current_order.type (which is a mix of type and flags, because |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2393 |
in those versions, they both were 4 bits big) to type and flags */ |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2394 |
v->current_order.flags = (v->current_order.type & 0xF0) >> 4; |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2395 |
v->current_order.type = v->current_order.type & 0x0F; |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2396 |
} |
0 | 2397 |
} |
2398 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2399 |
/* Check for shared order-lists (we now use pointers for that) */ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2400 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2401 |
FOR_ALL_VEHICLES(v) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2402 |
Vehicle *u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2403 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2404 |
if (v->type == 0) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2405 |
continue; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2406 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2407 |
FOR_ALL_VEHICLES_FROM(u, v->index + 1) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2408 |
if (u->type == 0) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2409 |
continue; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2410 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2411 |
/* If a vehicle has the same orders, add the link to eachother |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2412 |
in both vehicles */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2413 |
if (v->orders == u->orders) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2414 |
v->next_shared = u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2415 |
u->prev_shared = v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2416 |
break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2417 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2418 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2419 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2420 |
} |
0 | 2421 |
} |
2422 |
||
2423 |
const ChunkHandler _veh_chunk_handlers[] = { |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1541
diff
changeset
|
2424 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 2425 |
}; |