author | Darkvater |
Tue, 31 Oct 2006 23:04:47 +0000 | |
changeset 5009 | 0ae33f104d4f |
parent 4972 | c7f92c6b74e4 |
child 5062 | 470335730a60 |
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" |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
29 |
#include "aircraft.h" |
3428
146dc5f172fc
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
30 |
#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
|
31 |
#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
|
32 |
#include "water_map.h" |
4130
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
33 |
#include "network.h" |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
34 |
#include "yapf/yapf.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4176
diff
changeset
|
35 |
#include "date.h" |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
36 |
#include "newgrf_engine.h" |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
37 |
#include "newgrf_sound.h" |
0 | 38 |
|
39 |
#define INVALID_COORD (-0x8000) |
|
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
40 |
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
0 | 41 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
42 |
/* |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
43 |
* These command macros are used to call vehicle type specific commands with non type specific commands |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
44 |
* it should be used like: DoCommandP(x, y, p1, p2, flags, CMD_STARTSTOP_VEH(v->type)) |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
45 |
* that line will start/stop a vehicle nomatter what type it is |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
46 |
* VEH_Train is used as an offset because the vehicle type values doesn't start with 0 |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
47 |
*/ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
48 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
49 |
#define CMD_BUILD_VEH(x) _veh_build_proc_table[ x - VEH_Train] |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
50 |
#define CMD_SELL_VEH(x) _veh_sell_proc_table [ x - VEH_Train] |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
51 |
#define CMD_REFIT_VEH(x) _veh_refit_proc_table[ x - VEH_Train] |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
52 |
|
2630 | 53 |
static const uint32 _veh_build_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
54 |
CMD_BUILD_RAIL_VEHICLE, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
55 |
CMD_BUILD_ROAD_VEH, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
56 |
CMD_BUILD_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
57 |
CMD_BUILD_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
58 |
}; |
2630 | 59 |
static const uint32 _veh_sell_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
60 |
CMD_SELL_RAIL_WAGON, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
61 |
CMD_SELL_ROAD_VEH, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
62 |
CMD_SELL_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
63 |
CMD_SELL_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
64 |
}; |
2753 | 65 |
|
2630 | 66 |
static const uint32 _veh_refit_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
67 |
CMD_REFIT_RAIL_VEHICLE, |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
68 |
CMD_REFIT_ROAD_VEH, |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
69 |
CMD_REFIT_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
70 |
CMD_REFIT_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
71 |
}; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
72 |
|
4451
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
73 |
const uint32 _send_to_depot_proc_table[] = { |
4495
b6381e4bcb61
(svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents:
4465
diff
changeset
|
74 |
CMD_SEND_TRAIN_TO_DEPOT, |
4451
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
75 |
CMD_SEND_ROADVEH_TO_DEPOT, |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
76 |
CMD_SEND_SHIP_TO_DEPOT, |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
77 |
CMD_SEND_AIRCRAFT_TO_HANGAR, |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
78 |
}; |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
79 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
80 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
81 |
enum { |
3173
f56ca618721b
(svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents:
3161
diff
changeset
|
82 |
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
|
83 |
}; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
84 |
|
1279
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 |
* 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
|
87 |
*/ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
88 |
static void VehiclePoolNewBlock(uint start_item) |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
89 |
{ |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
90 |
Vehicle *v; |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
91 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
92 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
93 |
* TODO - This is just a temporary stage, this will be removed. */ |
4972 | 94 |
for (v = GetVehicle(start_item); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) v->index = start_item++; |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
95 |
} |
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
96 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
97 |
/* Initialize the vehicle-pool */ |
4972 | 98 |
DEFINE_POOL(Vehicle, Vehicle, VehiclePoolNewBlock, NULL) |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
99 |
|
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
|
100 |
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
|
101 |
{ |
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
|
102 |
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
|
103 |
v->breakdowns_since_last_service = 0; |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
104 |
v->reliability = GetEngine(v->engine_type)->reliability; |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
105 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated |
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
|
106 |
} |
0 | 107 |
|
593 | 108 |
bool VehicleNeedsService(const Vehicle *v) |
109 |
{ |
|
1757
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
|
4262
048f6a144c7c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
113 |
if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) { |
4263
88e03e20d57f
(svn r5891) -Code cleanup: cleaned up the code added in revision 5888
bjarni
parents:
4262
diff
changeset
|
114 |
return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type); /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */ |
4262
048f6a144c7c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
115 |
} |
048f6a144c7c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
116 |
|
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
117 |
return _patches.servint_ispercent ? |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
118 |
(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) : |
593 | 119 |
(v->date_of_last_service + v->service_interval < _date); |
120 |
} |
|
121 |
||
3881 | 122 |
StringID VehicleInTheWayErrMsg(const Vehicle* v) |
0 | 123 |
{ |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
124 |
switch (v->type) { |
3881 | 125 |
case VEH_Train: return STR_8803_TRAIN_IN_THE_WAY; |
126 |
case VEH_Road: return STR_9000_ROAD_VEHICLE_IN_THE_WAY; |
|
127 |
case VEH_Aircraft: return STR_A015_AIRCRAFT_IN_THE_WAY; |
|
128 |
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
|
129 |
} |
0 | 130 |
} |
131 |
||
132 |
static void *EnsureNoVehicleProc(Vehicle *v, void *data) |
|
133 |
{ |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
134 |
if (v->tile != *(const TileIndex*)data || v->type == VEH_Disaster) |
0 | 135 |
return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
136 |
|
3881 | 137 |
_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
|
138 |
return v; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
139 |
} |
0 | 140 |
|
141 |
bool EnsureNoVehicle(TileIndex tile) |
|
142 |
{ |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
143 |
return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL; |
0 | 144 |
} |
145 |
||
146 |
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
|
147 |
{ |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
148 |
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
|
149 |
|
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
|
150 |
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
|
151 |
if (v->z_pos > ti->z) return NULL; |
0 | 152 |
|
3881 | 153 |
_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
|
154 |
return v; |
0 | 155 |
} |
156 |
||
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
|
157 |
|
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
|
158 |
bool EnsureNoVehicleOnGround(TileIndex tile) |
0 | 159 |
{ |
160 |
TileInfo ti; |
|
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
161 |
|
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
|
162 |
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
|
163 |
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
|
164 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ) == NULL; |
0 | 165 |
} |
166 |
||
1605
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
167 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
168 |
{ |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
169 |
TileInfo ti; |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
170 |
|
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
171 |
ti.tile = tile; |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
172 |
ti.z = z; |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
173 |
|
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
174 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ); |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
175 |
} |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
176 |
|
0 | 177 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z) |
178 |
{ |
|
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
int y2 = TileY(to); |
0 | 183 |
Vehicle *veh; |
184 |
||
185 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
186 |
if (x1 > x2 || y1 > y2) { |
|
187 |
intswap(x1,x2); |
|
188 |
intswap(y1,y2); |
|
189 |
} |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
190 |
FOR_ALL_VEHICLES(veh) { |
0 | 191 |
if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) { |
192 |
if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 && |
|
193 |
(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) { |
|
194 |
return veh; |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
return NULL; |
|
199 |
} |
|
200 |
||
2817 | 201 |
|
202 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y); |
|
203 |
||
0 | 204 |
void VehiclePositionChanged(Vehicle *v) |
205 |
{ |
|
206 |
int img = v->cur_image; |
|
207 |
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
|
208 |
const Sprite* spr = GetSprite(img); |
0 | 209 |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
210 |
pt.x += spr->x_offs; |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
211 |
pt.y += spr->y_offs; |
0 | 212 |
|
213 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
214 |
||
215 |
v->left_coord = pt.x; |
|
216 |
v->top_coord = pt.y; |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
217 |
v->right_coord = pt.x + spr->width + 2; |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
218 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 219 |
} |
220 |
||
221 |
// 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
|
222 |
void AfterLoadVehicles(void) |
0 | 223 |
{ |
224 |
Vehicle *v; |
|
225 |
||
226 |
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
|
227 |
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
|
228 |
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
|
229 |
} |
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
|
230 |
|
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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
} |
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
|
235 |
|
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
|
236 |
FOR_ALL_VEHICLES(v) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
237 |
switch (v->type) { |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
238 |
case VEH_Train: v->cur_image = GetTrainImage(v, v->direction); break; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
239 |
case VEH_Road: v->cur_image = GetRoadVehImage(v, v->direction); break; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
240 |
case VEH_Ship: v->cur_image = GetShipImage(v, v->direction); break; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
241 |
case VEH_Aircraft: |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
242 |
if (v->subtype == 0 || v->subtype == 2) { |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
243 |
v->cur_image = GetAircraftImage(v, v->direction); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
244 |
if (v->next != NULL) v->next->cur_image = v->cur_image; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
245 |
} |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
246 |
break; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
247 |
default: break; |
0 | 248 |
} |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
249 |
|
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
250 |
v->left_coord = INVALID_COORD; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
251 |
VehiclePositionChanged(v); |
0 | 252 |
} |
253 |
} |
|
254 |
||
255 |
static Vehicle *InitializeVehicle(Vehicle *v) |
|
256 |
{ |
|
257 |
VehicleID index = v->index; |
|
258 |
memset(v, 0, sizeof(Vehicle)); |
|
259 |
v->index = index; |
|
260 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
261 |
assert(v->orders == NULL); |
0 | 262 |
|
263 |
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
|
264 |
v->first = NULL; |
0 | 265 |
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
|
266 |
v->next_hash = INVALID_VEHICLE; |
0 | 267 |
v->string_id = 0; |
1111
6f4d8544e70b
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
268 |
v->next_shared = NULL; |
6f4d8544e70b
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
269 |
v->prev_shared = NULL; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
270 |
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
|
271 |
v->random_bits = 0; |
0 | 272 |
return v; |
273 |
} |
|
274 |
||
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
|
275 |
/** |
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
|
276 |
* 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
|
277 |
* @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
|
278 |
*/ |
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
|
279 |
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
|
280 |
{ |
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
|
281 |
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
|
282 |
} |
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
|
283 |
|
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
|
284 |
Vehicle *ForceAllocateSpecialVehicle(void) |
0 | 285 |
{ |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
286 |
/* 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
|
287 |
* 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
|
288 |
* 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
|
289 |
* 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
|
290 |
* be used for special vehicles.. should work nicely :) */ |
0 | 291 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
292 |
Vehicle *v; |
0 | 293 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
294 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
295 |
* TODO - This is just a temporary stage, this will be removed. */ |
4972 | 296 |
for (v = GetVehicle(0); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) { |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
297 |
/* No more room for the special vehicles, return NULL */ |
4972 | 298 |
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
|
299 |
return NULL; |
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
300 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
301 |
if (!IsValidVehicle(v)) return InitializeVehicle(v); |
0 | 302 |
} |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
303 |
|
0 | 304 |
return NULL; |
305 |
} |
|
306 |
||
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
307 |
/* |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
308 |
* 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
|
309 |
* 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
|
310 |
* *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
|
311 |
* 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
|
312 |
* this feature is used by AllocateVehicles() since it need to allocate more than one and when |
4972 | 313 |
* another block is added to _Vehicle_pool, since we only do that when we know it's already full |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
314 |
*/ |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
315 |
static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles) |
0 | 316 |
{ |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
317 |
/* 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
|
318 |
* first blocks */ |
0 | 319 |
Vehicle *v; |
4972 | 320 |
const int offset = (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES; |
0 | 321 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
322 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
323 |
* TODO - This is just a temporary stage, this will be removed. */ |
4972 | 324 |
if (*skip_vehicles < (_Vehicle_pool.total_items - offset)) { // make sure the offset in the array is not larger than the array itself |
325 |
for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) { |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
326 |
(*skip_vehicles)++; |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
327 |
if (!IsValidVehicle(v)) return InitializeVehicle(v); |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
328 |
} |
0 | 329 |
} |
330 |
||
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
331 |
/* Check if we can add a block to the pool */ |
4972 | 332 |
if (AddBlockToPool(&_Vehicle_pool)) |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
333 |
return AllocateSingleVehicle(skip_vehicles); |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
334 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
335 |
return NULL; |
0 | 336 |
} |
337 |
||
2639 | 338 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
339 |
Vehicle *AllocateVehicle(void) |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
340 |
{ |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
341 |
VehicleID counter = 0; |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
342 |
return AllocateSingleVehicle(&counter); |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
343 |
} |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
344 |
|
2639 | 345 |
|
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 |
/** Allocates a lot of vehicles and frees them again |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
347 |
* @param vl pointer to an array of vehicles to get allocated. Can be NULL if the vehicles aren't needed (makes it test only) |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
348 |
* @param num number of vehicles to allocate room for |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
349 |
* @return true if there is room to allocate all the vehicles |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
350 |
*/ |
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
|
351 |
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
|
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 |
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
|
354 |
Vehicle *v; |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
355 |
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
|
356 |
|
2952 | 357 |
for (i = 0; i != num; i++) { |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
358 |
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
|
359 |
if (v == NULL) { |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
360 |
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
|
361 |
} |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
362 |
if (vl != NULL) { |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
363 |
vl[i] = v; |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
364 |
} |
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
|
365 |
} |
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
|
366 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
367 |
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
|
368 |
} |
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
|
369 |
|
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
|
370 |
|
2651 | 371 |
static VehicleID _vehicle_position_hash[0x1000]; |
372 |
||
0 | 373 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
374 |
{ |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3413
diff
changeset
|
375 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, 0); |
0 | 376 |
|
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
377 |
// The hash area to scan |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
378 |
const int xl = GB(pt.x - 174, 7, 6); |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
379 |
const int xu = GB(pt.x + 104, 7, 6); |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
380 |
const int yl = GB(pt.y - 294, 6, 6) << 6; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
381 |
const int yu = GB(pt.y + 56, 6, 6) << 6; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
382 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
383 |
int x; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
384 |
int y; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
385 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
386 |
for (y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
387 |
for (x = xl;; x = (x + 1) & 0x3F) { |
2639 | 388 |
VehicleID veh = _vehicle_position_hash[(x + y) & 0xFFFF]; |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
389 |
|
0 | 390 |
while (veh != INVALID_VEHICLE) { |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
391 |
Vehicle *v = GetVehicle(veh); |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
392 |
void* a = proc(v, data); |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
393 |
|
2639 | 394 |
if (a != NULL) return a; |
0 | 395 |
veh = v->next_hash; |
396 |
} |
|
397 |
||
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
398 |
if (x == xu) break; |
0 | 399 |
} |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
400 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
401 |
if (y == yu) break; |
0 | 402 |
} |
403 |
return NULL; |
|
404 |
} |
|
405 |
||
406 |
||
2817 | 407 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y) |
0 | 408 |
{ |
409 |
VehicleID *old_hash, *new_hash; |
|
410 |
int old_x = v->left_coord; |
|
411 |
int old_y = v->top_coord; |
|
412 |
Vehicle *u; |
|
413 |
||
414 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)]; |
|
415 |
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
|
416 |
|
2639 | 417 |
if (old_hash == new_hash) return; |
0 | 418 |
|
419 |
/* remove from hash table? */ |
|
420 |
if (old_hash != NULL) { |
|
421 |
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
|
422 |
VehicleID idx = *old_hash; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
423 |
while ((u = GetVehicle(idx)) != v) { |
0 | 424 |
idx = u->next_hash; |
425 |
assert(idx != INVALID_VEHICLE); |
|
426 |
last = u; |
|
427 |
} |
|
428 |
||
2639 | 429 |
if (last == NULL) { |
0 | 430 |
*old_hash = v->next_hash; |
2639 | 431 |
} else { |
0 | 432 |
last->next_hash = v->next_hash; |
2639 | 433 |
} |
0 | 434 |
} |
435 |
||
436 |
/* insert into hash table? */ |
|
437 |
if (new_hash != NULL) { |
|
438 |
v->next_hash = *new_hash; |
|
439 |
*new_hash = v->index; |
|
440 |
} |
|
441 |
} |
|
442 |
||
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
|
443 |
void InitializeVehicles(void) |
0 | 444 |
{ |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
445 |
uint i; |
0 | 446 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
447 |
/* 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
|
448 |
* 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
|
449 |
* vehicles (which is increased on-the-fly) */ |
4972 | 450 |
CleanPool(&_Vehicle_pool); |
451 |
AddBlockToPool(&_Vehicle_pool); |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
452 |
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) |
4972 | 453 |
AddBlockToPool(&_Vehicle_pool); |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
454 |
|
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
455 |
for (i = 0; i < lengthof(_vehicle_position_hash); i++) { |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
456 |
_vehicle_position_hash[i] = INVALID_VEHICLE; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
457 |
} |
0 | 458 |
} |
459 |
||
460 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
461 |
{ |
|
462 |
while (v->next != NULL) v = v->next; |
|
463 |
return v; |
|
464 |
} |
|
465 |
||
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
466 |
/** 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
|
467 |
* 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
|
468 |
* 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
|
469 |
* 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
|
470 |
* called by anything but GetFirstVehicleInChain |
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 |
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
|
473 |
{ |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
474 |
Vehicle *u; |
2006
9d5d7fd428c2
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
475 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
476 |
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
|
477 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
478 |
return NULL; |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
479 |
} |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
480 |
|
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
481 |
/** 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
|
482 |
* 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
|
483 |
* 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
|
484 |
*/ |
1475 | 485 |
Vehicle *GetPrevVehicleInChain(const Vehicle *v) |
0 | 486 |
{ |
1600
d2f718ee5111
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
487 |
Vehicle *u; |
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
488 |
assert(v != NULL); |
0 | 489 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
490 |
u = GetFirstVehicleInChain(v); |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
491 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
492 |
// 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
|
493 |
if (v == u) return NULL; |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
494 |
|
4165
2b5f642aa2bf
(svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents:
4130
diff
changeset
|
495 |
for (; u->next != v; u = u->next) assert(u->next != NULL); |
2b5f642aa2bf
(svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents:
4130
diff
changeset
|
496 |
|
2b5f642aa2bf
(svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents:
4130
diff
changeset
|
497 |
return u; |
0 | 498 |
} |
499 |
||
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
500 |
/** 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
|
501 |
* 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
|
502 |
* 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
|
503 |
*/ |
1475 | 504 |
Vehicle *GetFirstVehicleInChain(const Vehicle *v) |
0 | 505 |
{ |
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
|
506 |
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
|
507 |
|
1985
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
508 |
assert(v != NULL); |
46d2f03f66e4
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
509 |
|
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
|
510 |
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
|
511 |
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
|
512 |
|
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 |
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
|
514 |
} |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
515 |
|
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
|
516 |
/* It is the fact (currently) that newly built vehicles do not have |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
517 |
* their ->first pointer set. When this is the case, go up to the |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
518 |
* first engine and set the pointers correctly. Also the first pointer |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
519 |
* is not saved in a savegame, so this has to be fixed up after loading */ |
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
|
520 |
|
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
|
521 |
/* 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
|
522 |
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
|
523 |
|
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
|
524 |
/* 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
|
525 |
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
|
526 |
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
|
527 |
|
1600
d2f718ee5111
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
528 |
return (Vehicle*)v; |
0 | 529 |
} |
530 |
||
2630 | 531 |
uint CountVehiclesInChain(const Vehicle* v) |
0 | 532 |
{ |
2639 | 533 |
uint count = 0; |
534 |
do count++; while ((v = v->next) != NULL); |
|
0 | 535 |
return count; |
536 |
} |
|
537 |
||
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
538 |
/** Check if a vehicle is counted in num_engines in each player struct |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
539 |
* @param *v Vehicle to test |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
540 |
* @return true if the vehicle is counted in num_engines |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
541 |
*/ |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
542 |
bool IsEngineCountable(const Vehicle *v) |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
543 |
{ |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
544 |
switch (v->type) { |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
545 |
case VEH_Aircraft: return (v->subtype <= 2); // don't count plane shadows and helicopter rotors |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
546 |
case VEH_Train: |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
547 |
return !IsArticulatedPart(v) && // tenders and other articulated parts |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
548 |
(!IsMultiheaded(v) || IsTrainEngine(v)); // rear parts of multiheaded engines |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
549 |
case VEH_Road: |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
550 |
case VEH_Ship: |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
551 |
return true; |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
552 |
default: return false; // Only count player buildable vehicles |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
553 |
} |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
554 |
} |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
555 |
|
4404
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
556 |
void DestroyVehicle(Vehicle *v) |
0 | 557 |
{ |
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
558 |
if (IsEngineCountable(v)) GetPlayer(v->owner)->num_engines[v->engine_type]--; |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
559 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3132
diff
changeset
|
560 |
DeleteVehicleNews(v->index, INVALID_STRING_ID); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3132
diff
changeset
|
561 |
|
4404
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
562 |
DeleteName(v->string_id); |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
563 |
if (v->type == VEH_Road) ClearSlot(v); |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
564 |
|
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
565 |
if (v->type != VEH_Train || (v->type == VEH_Train && (IsFrontEngine(v) || IsFreeWagon(v)))) { |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
566 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
567 |
} |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
568 |
|
4404
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
569 |
UpdateVehiclePosHash(v, INVALID_COORD, 0); |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
570 |
v->next_hash = INVALID_VEHICLE; |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
571 |
if (v->orders != NULL) DeleteVehicleOrders(v); |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
572 |
|
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
573 |
/* Now remove any artic part. This will trigger an other |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
574 |
* destroy vehicle, which on his turn can remove any |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
575 |
* other artic parts. */ |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
576 |
if (EngineHasArticPart(v)) DeleteVehicle(v->next); |
0 | 577 |
} |
578 |
||
579 |
void DeleteVehicleChain(Vehicle *v) |
|
580 |
{ |
|
581 |
do { |
|
582 |
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
|
583 |
v = GetNextVehicle(v); |
0 | 584 |
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
|
585 |
} while (v != NULL); |
0 | 586 |
} |
587 |
||
588 |
||
589 |
void Aircraft_Tick(Vehicle *v); |
|
590 |
void RoadVeh_Tick(Vehicle *v); |
|
591 |
void Ship_Tick(Vehicle *v); |
|
592 |
void Train_Tick(Vehicle *v); |
|
410 | 593 |
static void EffectVehicle_Tick(Vehicle *v); |
0 | 594 |
void DisasterVehicle_Tick(Vehicle *v); |
4676
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
595 |
static int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs); |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
596 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
597 |
// head of the linked list to tell what vehicles that visited a depot in a tick |
2630 | 598 |
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
|
599 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
600 |
/** Adds a vehicle to the list of vehicles, that visited a depot this tick |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
601 |
* @param *v vehicle to add |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
602 |
*/ |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
603 |
void VehicleEnteredDepotThisTick(Vehicle *v) |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
604 |
{ |
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
605 |
// 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
|
606 |
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
|
607 |
// 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
|
608 |
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
|
609 |
} else { |
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
610 |
// 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
|
611 |
// 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
|
612 |
// 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
|
613 |
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
|
614 |
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
|
615 |
} |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
616 |
|
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
617 |
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
|
618 |
_first_veh_in_depot_list = v; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
619 |
} else { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
620 |
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
|
621 |
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
|
622 |
w->depot_list = v; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
623 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
624 |
} |
0 | 625 |
|
4176 | 626 |
typedef void VehicleTickProc(Vehicle*); |
2752 | 627 |
static VehicleTickProc* _vehicle_tick_procs[] = { |
0 | 628 |
Train_Tick, |
629 |
RoadVeh_Tick, |
|
630 |
Ship_Tick, |
|
631 |
Aircraft_Tick, |
|
632 |
EffectVehicle_Tick, |
|
633 |
DisasterVehicle_Tick, |
|
634 |
}; |
|
635 |
||
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
|
636 |
void CallVehicleTicks(void) |
0 | 637 |
{ |
638 |
Vehicle *v; |
|
639 |
||
4130
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
640 |
#ifdef ENABLE_NETWORK |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
641 |
// hotfix for desync problem: |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
642 |
// for MP games invalidate the YAPF cache every tick to keep it exactly the same on the server and all clients |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
643 |
if (_networking) { |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
644 |
YapfNotifyTrackLayoutChange(0, 0); |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
645 |
} |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
646 |
#endif //ENABLE_NETWORK |
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
647 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
648 |
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
649 |
|
0 | 650 |
FOR_ALL_VEHICLES(v) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
651 |
_vehicle_tick_procs[v->type - 0x10](v); |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
652 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
653 |
switch (v->type) { |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
654 |
case VEH_Train: |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
655 |
case VEH_Road: |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
656 |
case VEH_Aircraft: |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
657 |
case VEH_Ship: |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
658 |
if (v->type == VEH_Train && IsTrainWagon(v)) continue; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
659 |
if (v->type == VEH_Aircraft && v->subtype > 0) continue; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
660 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
661 |
v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
662 |
/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */ |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
663 |
if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
664 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
665 |
/* Play an alterate running sound every 16 ticks */ |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
666 |
if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
667 |
} |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
668 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
669 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
670 |
// 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
|
671 |
v = _first_veh_in_depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
672 |
while (v != NULL) { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
673 |
Vehicle *w = v->depot_list; |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
674 |
v->depot_list = NULL; // it should always be NULL at the end of each tick |
4676
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
675 |
MaybeReplaceVehicle(v, false, true); |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
676 |
v = w; |
0 | 677 |
} |
678 |
} |
|
679 |
||
680 |
static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
681 |
{ |
|
682 |
uint32 full = 0, not_full = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
683 |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
684 |
//special handling of aircraft |
941
d271102b3010
(svn r1429) Change: bumped savegame to revision 5.
truelight
parents:
939
diff
changeset
|
685 |
|
924
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
686 |
//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
|
687 |
//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
|
688 |
if (v->type == VEH_Aircraft && |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
689 |
v->cargo_type == CT_PASSENGERS && |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
690 |
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
|
691 |
return true; |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
692 |
} |
6fbd4419db2a
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
693 |
|
0 | 694 |
// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. |
695 |
do { |
|
696 |
//Should never happen, but just in case future additions change this |
|
697 |
assert(v->cargo_type<32); |
|
698 |
||
699 |
if (v->cargo_cap != 0) { |
|
700 |
uint32 mask = 1 << v->cargo_type; |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
701 |
|
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
702 |
if (v->cargo_cap == v->cargo_count) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
703 |
full |= mask; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
704 |
} else { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
705 |
not_full |= mask; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
706 |
} |
0 | 707 |
} |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
708 |
} while ((v = v->next) != NULL); |
0 | 709 |
|
710 |
// continue loading if there is a non full cargo type and no cargo type that is full |
|
711 |
return not_full && (full & ~not_full) == 0; |
|
712 |
} |
|
713 |
||
714 |
bool CanFillVehicle(Vehicle *v) |
|
715 |
{ |
|
1058
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
716 |
TileIndex tile = v->tile; |
0 | 717 |
|
1058
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
718 |
if (IsTileType(tile, MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
719 |
(v->type == VEH_Ship && ( |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
720 |
IsTileType(TILE_ADDXY(tile, 1, 0), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
721 |
IsTileType(TILE_ADDXY(tile, -1, 0), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
722 |
IsTileType(TILE_ADDXY(tile, 0, 1), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
723 |
IsTileType(TILE_ADDXY(tile, 0, -1), MP_STATION) || |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
724 |
IsTileType(TILE_ADDXY(tile, -2, 0), MP_STATION) |
e522c5d6ff69
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
725 |
))) { |
0 | 726 |
|
727 |
// If patch is active, use alternative CanFillVehicle-function |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
728 |
if (_patches.full_load_any) return CanFillVehicle_FullLoadAny(v); |
0 | 729 |
|
730 |
do { |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
731 |
if (v->cargo_count != v->cargo_cap) return true; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
732 |
} while ((v = v->next) != NULL); |
0 | 733 |
} |
734 |
return false; |
|
735 |
} |
|
736 |
||
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
|
737 |
/** 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
|
738 |
* @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
|
739 |
* @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
|
740 |
* @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
|
741 |
*/ |
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
|
742 |
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
|
743 |
{ |
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
|
744 |
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
|
745 |
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
|
746 |
} |
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
|
747 |
|
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
|
748 |
/** 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
|
749 |
* @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
|
750 |
* @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
|
751 |
*/ |
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
|
752 |
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
|
753 |
{ |
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
|
754 |
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
|
755 |
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
|
756 |
|
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
|
757 |
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
|
758 |
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
|
759 |
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
|
760 |
} |
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
|
761 |
} |
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
|
762 |
|
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
|
763 |
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
|
764 |
} |
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
|
765 |
|
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
766 |
/** Learn the price of refitting a certain engine |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
767 |
* @param engine Which engine to refit |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
768 |
* @return Price for refitting |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
769 |
*/ |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
770 |
int32 GetRefitCost(EngineID engine_type) |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
771 |
{ |
4555
b82037f83b53
(svn r6394) -Fix r6393: removed a warning originally removed in r6376 accidentally readded in r6393
bjarni
parents:
4554
diff
changeset
|
772 |
int32 base_cost = 0; |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
773 |
|
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
774 |
switch (GetEngine(engine_type)->type) { |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
775 |
case VEH_Ship: base_cost = _price.ship_base; break; |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
776 |
case VEH_Road: base_cost = _price.roadveh_base; break; |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
777 |
case VEH_Aircraft: base_cost = _price.aircraft_base; break; |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
778 |
case VEH_Train: |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
779 |
base_cost = 2 * ((RailVehInfo(engine_type)->flags & RVI_WAGON) ? |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
780 |
_price.build_railwagon : _price.build_railvehicle); |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
781 |
break; |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
782 |
default: NOT_REACHED(); break; |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
783 |
} |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
784 |
return (EngInfo(engine_type)->refit_cost * base_cost) >> 10; |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
785 |
} |
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
|
786 |
|
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
|
787 |
static void DoDrawVehicle(const Vehicle *v) |
0 | 788 |
{ |
789 |
uint32 image = v->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
790 |
|
4175
b79ec8a94d4e
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4174
diff
changeset
|
791 |
if (v->vehstatus & VS_SHADOW) { |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
792 |
MAKE_TRANSPARENT(image); |
0 | 793 |
} 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
|
794 |
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
|
795 |
} |
0 | 796 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
797 |
AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
0 | 798 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos); |
799 |
} |
|
800 |
||
801 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
802 |
{ |
|
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
803 |
// The bounding rectangle |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
804 |
const int l = dpi->left; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
805 |
const int r = dpi->left + dpi->width; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
806 |
const int t = dpi->top; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
807 |
const int b = dpi->top + dpi->height; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
808 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
809 |
// The hash area to scan |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
810 |
const int xl = GB(l - 70, 7, 6); |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
811 |
const int xu = GB(r, 7, 6); |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
812 |
const int yl = GB(t - 70, 6, 6) << 6; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
813 |
const int yu = GB(b, 6, 6) << 6; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
814 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
815 |
int x; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
816 |
int y; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
817 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
818 |
for (y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
819 |
for (x = xl;; x = (x + 1) & 0x3F) { |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
820 |
VehicleID veh = _vehicle_position_hash[(x + y) & 0xFFFF]; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
821 |
|
0 | 822 |
while (veh != INVALID_VEHICLE) { |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
823 |
const Vehicle* v = GetVehicle(veh); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
824 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
825 |
if (!(v->vehstatus & VS_HIDDEN) && |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
826 |
l <= v->right_coord && |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
827 |
t <= v->bottom_coord && |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
828 |
r >= v->left_coord && |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
829 |
b >= v->top_coord) { |
0 | 830 |
DoDrawVehicle(v); |
831 |
} |
|
832 |
veh = v->next_hash; |
|
833 |
} |
|
834 |
||
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
835 |
if (x == xu) break; |
0 | 836 |
} |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
837 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
838 |
if (y == yu) break; |
0 | 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 ChimneySmokeInit(Vehicle *v) |
0 | 843 |
{ |
844 |
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
|
845 |
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
|
846 |
v->progress = GB(r, 16, 3); |
0 | 847 |
} |
848 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
849 |
static void ChimneySmokeTick(Vehicle *v) |
0 | 850 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
851 |
if (v->progress > 0) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
852 |
v->progress--; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
853 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
854 |
TileIndex tile; |
0 | 855 |
|
856 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
857 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
858 |
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
|
859 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
0 | 860 |
EndVehicleMove(v); |
861 |
DeleteVehicle(v); |
|
862 |
return; |
|
863 |
} |
|
864 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
865 |
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
|
866 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
867 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
868 |
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
|
869 |
} |
0 | 870 |
v->progress = 7; |
871 |
VehiclePositionChanged(v); |
|
872 |
EndVehicleMove(v); |
|
873 |
} |
|
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 SteamSmokeInit(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 |
v->cur_image = SPR_STEAM_SMOKE_0; |
0 | 879 |
v->progress = 12; |
880 |
} |
|
881 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
882 |
static void SteamSmokeTick(Vehicle *v) |
0 | 883 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
884 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
885 |
|
0 | 886 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
887 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
888 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
889 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
890 |
if ((v->progress & 7) == 0) { |
0 | 891 |
v->z_pos++; |
892 |
moved = true; |
|
893 |
} |
|
894 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
895 |
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
|
896 |
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
|
897 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
898 |
} else { |
0 | 899 |
EndVehicleMove(v); |
900 |
DeleteVehicle(v); |
|
901 |
return; |
|
902 |
} |
|
903 |
moved = true; |
|
904 |
} |
|
905 |
||
906 |
if (moved) { |
|
907 |
VehiclePositionChanged(v); |
|
908 |
EndVehicleMove(v); |
|
909 |
} |
|
910 |
} |
|
911 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
912 |
static void DieselSmokeInit(Vehicle *v) |
0 | 913 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
914 |
v->cur_image = SPR_DIESEL_SMOKE_0; |
0 | 915 |
v->progress = 0; |
916 |
} |
|
917 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
918 |
static void DieselSmokeTick(Vehicle *v) |
0 | 919 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
920 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
921 |
|
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
922 |
if ((v->progress & 3) == 0) { |
0 | 923 |
BeginVehicleMove(v); |
924 |
v->z_pos++; |
|
925 |
VehiclePositionChanged(v); |
|
926 |
EndVehicleMove(v); |
|
927 |
} else if ((v->progress & 7) == 1) { |
|
928 |
BeginVehicleMove(v); |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
929 |
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
|
930 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
931 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
932 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
933 |
} else { |
0 | 934 |
EndVehicleMove(v); |
935 |
DeleteVehicle(v); |
|
936 |
} |
|
937 |
} |
|
938 |
} |
|
939 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
940 |
static void ElectricSparkInit(Vehicle *v) |
0 | 941 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
942 |
v->cur_image = SPR_ELECTRIC_SPARK_0; |
0 | 943 |
v->progress = 1; |
944 |
} |
|
945 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
946 |
static void ElectricSparkTick(Vehicle *v) |
0 | 947 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
948 |
if (v->progress < 2) { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
949 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
950 |
} else { |
0 | 951 |
v->progress = 0; |
952 |
BeginVehicleMove(v); |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
953 |
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
|
954 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
955 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
956 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
957 |
} else { |
0 | 958 |
EndVehicleMove(v); |
959 |
DeleteVehicle(v); |
|
960 |
} |
|
961 |
} |
|
962 |
} |
|
963 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
964 |
static void SmokeInit(Vehicle *v) |
0 | 965 |
{ |
1371
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_SMOKE_0; |
0 | 967 |
v->progress = 12; |
968 |
} |
|
969 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
970 |
static void SmokeTick(Vehicle *v) |
0 | 971 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
972 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
973 |
|
0 | 974 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
975 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
976 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
977 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
978 |
if ((v->progress & 3) == 0) { |
0 | 979 |
v->z_pos++; |
980 |
moved = true; |
|
981 |
} |
|
982 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
983 |
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
|
984 |
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
|
985 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
986 |
} else { |
0 | 987 |
EndVehicleMove(v); |
988 |
DeleteVehicle(v); |
|
989 |
return; |
|
990 |
} |
|
991 |
moved = true; |
|
992 |
} |
|
993 |
||
994 |
if (moved) { |
|
995 |
VehiclePositionChanged(v); |
|
996 |
EndVehicleMove(v); |
|
997 |
} |
|
998 |
} |
|
999 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1000 |
static void ExplosionLargeInit(Vehicle *v) |
0 | 1001 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1002 |
v->cur_image = SPR_EXPLOSION_LARGE_0; |
0 | 1003 |
v->progress = 0; |
1004 |
} |
|
1005 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1006 |
static void ExplosionLargeTick(Vehicle *v) |
0 | 1007 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1008 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1009 |
if ((v->progress & 3) == 0) { |
0 | 1010 |
BeginVehicleMove(v); |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1011 |
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
|
1012 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1013 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1014 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1015 |
} else { |
0 | 1016 |
EndVehicleMove(v); |
1017 |
DeleteVehicle(v); |
|
1018 |
} |
|
1019 |
} |
|
1020 |
} |
|
1021 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1022 |
static void BreakdownSmokeInit(Vehicle *v) |
0 | 1023 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1024 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
0 | 1025 |
v->progress = 0; |
1026 |
} |
|
1027 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1028 |
static void BreakdownSmokeTick(Vehicle *v) |
0 | 1029 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1030 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1031 |
if ((v->progress & 7) == 0) { |
0 | 1032 |
BeginVehicleMove(v); |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1033 |
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
|
1034 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1035 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1036 |
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
|
1037 |
} |
0 | 1038 |
VehiclePositionChanged(v); |
1039 |
EndVehicleMove(v); |
|
1040 |
} |
|
1041 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1042 |
v->u.special.unk0--; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1043 |
if (v->u.special.unk0 == 0) { |
0 | 1044 |
BeginVehicleMove(v); |
1045 |
EndVehicleMove(v); |
|
1046 |
DeleteVehicle(v); |
|
1047 |
} |
|
1048 |
} |
|
1049 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1050 |
static void ExplosionSmallInit(Vehicle *v) |
0 | 1051 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1052 |
v->cur_image = SPR_EXPLOSION_SMALL_0; |
0 | 1053 |
v->progress = 0; |
1054 |
} |
|
1055 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1056 |
static void ExplosionSmallTick(Vehicle *v) |
0 | 1057 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1058 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1059 |
if ((v->progress & 3) == 0) { |
0 | 1060 |
BeginVehicleMove(v); |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1061 |
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
|
1062 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1063 |
VehiclePositionChanged(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1064 |
EndVehicleMove(v); |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1065 |
} else { |
0 | 1066 |
EndVehicleMove(v); |
1067 |
DeleteVehicle(v); |
|
1068 |
} |
|
1069 |
} |
|
1070 |
} |
|
1071 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1072 |
static void BulldozerInit(Vehicle *v) |
0 | 1073 |
{ |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1074 |
v->cur_image = SPR_BULLDOZER_NE; |
0 | 1075 |
v->progress = 0; |
1076 |
v->u.special.unk0 = 0; |
|
1077 |
v->u.special.unk2 = 0; |
|
1078 |
} |
|
1079 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1080 |
typedef struct BulldozerMovement { |
1365
3ec3ff0adc01
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1081 |
byte direction:2; |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1082 |
byte image:2; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1083 |
byte duration:3; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1084 |
} BulldozerMovement; |
0 | 1085 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1086 |
static const BulldozerMovement _bulldozer_movement[] = { |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1087 |
{ 0, 0, 4 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1088 |
{ 3, 3, 4 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1089 |
{ 2, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1090 |
{ 0, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1091 |
{ 1, 1, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1092 |
{ 2, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1093 |
{ 0, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1094 |
{ 1, 1, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1095 |
{ 2, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1096 |
{ 0, 2, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1097 |
{ 3, 3, 6 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1098 |
{ 2, 2, 6 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1099 |
{ 1, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1100 |
{ 3, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1101 |
{ 0, 0, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1102 |
{ 1, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1103 |
{ 3, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1104 |
{ 0, 0, 3 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1105 |
{ 1, 1, 7 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1106 |
{ 3, 1, 7 } |
0 | 1107 |
}; |
1108 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1109 |
static const struct { |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1110 |
int8 x; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1111 |
int8 y; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1112 |
} _inc_by_dir[] = { |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1113 |
{ -1, 0 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1114 |
{ 0, 1 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1115 |
{ 1, 0 }, |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1116 |
{ 0, -1 } |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1117 |
}; |
0 | 1118 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1119 |
static void BulldozerTick(Vehicle *v) |
0 | 1120 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1121 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1122 |
if ((v->progress & 7) == 0) { |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1123 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.unk0]; |
0 | 1124 |
|
1125 |
BeginVehicleMove(v); |
|
1126 |
||
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1127 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
0 | 1128 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1129 |
v->x_pos += _inc_by_dir[b->direction].x; |
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1130 |
v->y_pos += _inc_by_dir[b->direction].y; |
0 | 1131 |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1132 |
v->u.special.unk2++; |
1365
3ec3ff0adc01
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1133 |
if (v->u.special.unk2 >= b->duration) { |
0 | 1134 |
v->u.special.unk2 = 0; |
1135 |
v->u.special.unk0++; |
|
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1136 |
if (v->u.special.unk0 == lengthof(_bulldozer_movement)) { |
0 | 1137 |
EndVehicleMove(v); |
1138 |
DeleteVehicle(v); |
|
1139 |
return; |
|
1140 |
} |
|
1141 |
} |
|
1142 |
VehiclePositionChanged(v); |
|
1143 |
EndVehicleMove(v); |
|
1144 |
} |
|
1145 |
} |
|
1146 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1147 |
static void BubbleInit(Vehicle *v) |
0 | 1148 |
{ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1149 |
v->cur_image = SPR_BUBBLE_GENERATE_0; |
0 | 1150 |
v->spritenum = 0; |
1151 |
v->progress = 0; |
|
1152 |
} |
|
1153 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1154 |
typedef struct BubbleMovement { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1155 |
int8 x:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1156 |
int8 y:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1157 |
int8 z:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1158 |
byte image:4; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1159 |
} BubbleMovement; |
0 | 1160 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1161 |
#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
|
1162 |
#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
|
1163 |
|
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1164 |
static const BubbleMovement _bubble_float_sw[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1165 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1166 |
MK(1, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1167 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1168 |
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
|
1169 |
ME(1) |
0 | 1170 |
}; |
1171 |
||
1172 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1173 |
static const BubbleMovement _bubble_float_ne[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1174 |
MK( 0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1175 |
MK(-1, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1176 |
MK( 0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1177 |
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
|
1178 |
ME(1) |
0 | 1179 |
}; |
1180 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1181 |
static const BubbleMovement _bubble_float_se[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1182 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1183 |
MK(0, 1, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1184 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1185 |
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
|
1186 |
ME(1) |
0 | 1187 |
}; |
1188 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1189 |
static const BubbleMovement _bubble_float_nw[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1190 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1191 |
MK(0, -1, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1192 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1193 |
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
|
1194 |
ME(1) |
0 | 1195 |
}; |
1196 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1197 |
static const BubbleMovement _bubble_burst[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1198 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1199 |
MK(0, 0, 1, 7), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1200 |
MK(0, 0, 1, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1201 |
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
|
1202 |
ME(0) |
0 | 1203 |
}; |
1204 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1205 |
static const BubbleMovement _bubble_absorb[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1206 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1207 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1208 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1209 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1210 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1211 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1212 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1213 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1214 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1215 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1216 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1217 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1218 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1219 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1220 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1221 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1222 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1223 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1224 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1225 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1226 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1227 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1228 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1229 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1230 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1231 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1232 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1233 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1234 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1235 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1236 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1237 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1238 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1239 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1240 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1241 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1242 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1243 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1244 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1245 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1246 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1247 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1248 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1249 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1250 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1251 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1252 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1253 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1254 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1255 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1256 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1257 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1258 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1259 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1260 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1261 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1262 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1263 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1264 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1265 |
MK(0, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1266 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1267 |
MK(0, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1268 |
MK(2, 1, 3, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1269 |
MK(1, 1, 3, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1270 |
MK(2, 1, 3, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1271 |
MK(1, 1, 3, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1272 |
MK(2, 1, 3, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1273 |
MK(1, 1, 3, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1274 |
MK(2, 1, 3, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1275 |
MK(1, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1276 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1277 |
MK(1, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1278 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1279 |
MK(1, 0, 1, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1280 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1281 |
MK(1, 0, 1, 1), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1282 |
MK(0, 0, 1, 0), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1283 |
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
|
1284 |
ME(2), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1285 |
MK(0, 0, 0, 0xA), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1286 |
MK(0, 0, 0, 0xB), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1287 |
MK(0, 0, 0, 0xC), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1288 |
MK(0, 0, 0, 0xD), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1289 |
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
|
1290 |
ME(0) |
0 | 1291 |
}; |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1292 |
#undef ME |
0 | 1293 |
#undef MK |
1294 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1295 |
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
|
1296 |
_bubble_float_sw, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1297 |
_bubble_float_ne, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1298 |
_bubble_float_se, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1299 |
_bubble_float_nw, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1300 |
_bubble_burst, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1301 |
_bubble_absorb, |
0 | 1302 |
}; |
1303 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1304 |
static void BubbleTick(Vehicle *v) |
0 | 1305 |
{ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1306 |
/* |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1307 |
* 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
|
1308 |
* InteractiveRandom(), because somehow someone forgot to save |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1309 |
* 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
|
1310 |
* multiplayer!! (that is: in ToyLand) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1311 |
*/ |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1312 |
uint et; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1313 |
const BubbleMovement *b; |
0 | 1314 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1315 |
v->progress++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1316 |
if ((v->progress & 3) != 0) |
0 | 1317 |
return; |
1318 |
||
1319 |
BeginVehicleMove(v); |
|
1320 |
||
1321 |
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
|
1322 |
v->cur_image++; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1323 |
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { |
0 | 1324 |
VehiclePositionChanged(v); |
1325 |
EndVehicleMove(v); |
|
1326 |
return; |
|
1327 |
} |
|
1328 |
if (v->u.special.unk2 != 0) { |
|
2635 | 1329 |
v->spritenum = GB(InteractiveRandom(), 0, 2) + 1; |
0 | 1330 |
} else { |
1331 |
v->spritenum = 6; |
|
1332 |
} |
|
1333 |
et = 0; |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1334 |
} else { |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1335 |
et = v->engine_type + 1; |
0 | 1336 |
} |
1337 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1338 |
b = &_bubble_movement[v->spritenum - 1][et]; |
0 | 1339 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1340 |
if (b->y == 4 && b->x == 0) { |
0 | 1341 |
EndVehicleMove(v); |
1342 |
DeleteVehicle(v); |
|
1343 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1344 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1345 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1346 |
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
|
1347 |
if (v->z_pos > 180 || CHANCE16I(1, 96, InteractiveRandom())) { |
0 | 1348 |
v->spritenum = 5; |
541 | 1349 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1350 |
} |
1351 |
et = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1352 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1353 |
|
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1354 |
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
|
1355 |
TileIndex tile; |
0 | 1356 |
|
1357 |
et++; |
|
541 | 1358 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1359 |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1360 |
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
|
1361 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == 0xA2) AddAnimatedTile(tile); |
0 | 1362 |
} |
1363 |
||
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1364 |
v->engine_type = et; |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1365 |
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
|
1366 |
|
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1367 |
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
|
1368 |
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
|
1369 |
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
|
1370 |
v->cur_image = SPR_BUBBLE_0 + b->image; |
0 | 1371 |
|
1372 |
VehiclePositionChanged(v); |
|
1373 |
EndVehicleMove(v); |
|
1374 |
} |
|
1375 |
||
1376 |
||
1377 |
typedef void EffectInitProc(Vehicle *v); |
|
1378 |
typedef void EffectTickProc(Vehicle *v); |
|
1379 |
||
1380 |
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
|
1381 |
ChimneySmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1382 |
SteamSmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1383 |
DieselSmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1384 |
ElectricSparkInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1385 |
SmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1386 |
ExplosionLargeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1387 |
BreakdownSmokeInit, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1388 |
ExplosionSmallInit, |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1389 |
BulldozerInit, |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1390 |
BubbleInit, |
0 | 1391 |
}; |
1392 |
||
1393 |
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
|
1394 |
ChimneySmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1395 |
SteamSmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1396 |
DieselSmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1397 |
ElectricSparkTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1398 |
SmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1399 |
ExplosionLargeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1400 |
BreakdownSmokeTick, |
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1401 |
ExplosionSmallTick, |
1364
238934514bfd
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1402 |
BulldozerTick, |
1371
fc15eaac6bb2
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1403 |
BubbleTick, |
0 | 1404 |
}; |
1405 |
||
1406 |
||
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
|
1407 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) |
0 | 1408 |
{ |
1409 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1410 |
|
0 | 1411 |
v = ForceAllocateSpecialVehicle(); |
1412 |
if (v != NULL) { |
|
1413 |
v->type = VEH_Special; |
|
1414 |
v->subtype = type; |
|
1415 |
v->x_pos = x; |
|
1416 |
v->y_pos = y; |
|
1417 |
v->z_pos = z; |
|
1418 |
v->z_height = v->sprite_width = v->sprite_height = 1; |
|
1419 |
v->x_offs = v->y_offs = 0; |
|
1420 |
v->tile = 0; |
|
1421 |
v->vehstatus = VS_UNCLICKABLE; |
|
1422 |
||
1423 |
_effect_init_procs[type](v); |
|
1424 |
||
1425 |
VehiclePositionChanged(v); |
|
1426 |
BeginVehicleMove(v); |
|
1427 |
EndVehicleMove(v); |
|
1428 |
} |
|
1429 |
return v; |
|
1430 |
} |
|
1431 |
||
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
|
1432 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type) |
0 | 1433 |
{ |
1434 |
return CreateEffectVehicle(x, y, GetSlopeZ(x, y) + z, type); |
|
1435 |
} |
|
1436 |
||
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
|
1437 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type) |
0 | 1438 |
{ |
1439 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1440 |
} |
|
1441 |
||
410 | 1442 |
static void EffectVehicle_Tick(Vehicle *v) |
0 | 1443 |
{ |
1444 |
_effect_tick_procs[v->subtype](v); |
|
1445 |
} |
|
1446 |
||
2116 | 1447 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 1448 |
{ |
1449 |
Vehicle *found = NULL, *v; |
|
1450 |
uint dist, best_dist = (uint)-1; |
|
1451 |
||
1452 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1453 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1454 |
return NULL; |
|
1455 |
||
1456 |
x = (x << vp->zoom) + vp->virtual_left; |
|
1457 |
y = (y << vp->zoom) + vp->virtual_top; |
|
1458 |
||
1459 |
FOR_ALL_VEHICLES(v) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1460 |
if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1461 |
x >= v->left_coord && x <= v->right_coord && |
1462 |
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
|
1463 |
|
0 | 1464 |
dist = max( |
1465 |
myabs( ((v->left_coord + v->right_coord)>>1) - x ), |
|
1466 |
myabs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
|
1467 |
); |
|
1468 |
||
1469 |
if (dist < best_dist) { |
|
1470 |
found = v; |
|
1471 |
best_dist = dist; |
|
1472 |
} |
|
1473 |
} |
|
1474 |
} |
|
1475 |
||
1476 |
return found; |
|
1477 |
} |
|
1478 |
||
1479 |
||
1480 |
void DecreaseVehicleValue(Vehicle *v) |
|
1481 |
{ |
|
1482 |
v->value -= v->value >> 8; |
|
1483 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1484 |
} |
|
1485 |
||
1486 |
static const byte _breakdown_chance[64] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1487 |
3, 3, 3, 3, 3, 3, 3, 3, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1488 |
4, 4, 5, 5, 6, 6, 7, 7, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1489 |
8, 8, 9, 9, 10, 10, 11, 11, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1490 |
12, 13, 13, 13, 13, 14, 15, 16, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1491 |
17, 19, 21, 25, 28, 31, 34, 37, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1492 |
40, 44, 48, 52, 56, 60, 64, 68, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1493 |
72, 80, 90, 100, 110, 120, 130, 140, |
0 | 1494 |
150, 170, 190, 210, 230, 250, 250, 250, |
1495 |
}; |
|
1496 |
||
1497 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1498 |
{ |
|
1499 |
int rel, rel_old; |
|
1500 |
uint32 r; |
|
1501 |
int chance; |
|
1502 |
||
1503 |
/* decrease reliability */ |
|
1504 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1505 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1506 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1507 |
||
2639 | 1508 |
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED || |
1509 |
v->cur_speed < 5 || _game_mode == GM_MENU) { |
|
1510 |
return; |
|
1511 |
} |
|
0 | 1512 |
|
1513 |
r = Random(); |
|
1514 |
||
1515 |
/* increase chance of failure */ |
|
1516 |
chance = v->breakdown_chance + 1; |
|
1517 |
if (CHANCE16I(1,25,r)) chance += 25; |
|
1518 |
v->breakdown_chance = min(255, chance); |
|
1519 |
||
1520 |
/* calculate reliability value to use in comparison */ |
|
1521 |
rel = v->reliability; |
|
1522 |
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
|
1523 |
|
0 | 1524 |
/* disabled breakdowns? */ |
2639 | 1525 |
if (_opt.diff.vehicle_breakdowns < 1) return; |
0 | 1526 |
|
1527 |
/* reduced breakdowns? */ |
|
1528 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1529 |
||
1530 |
/* check if to break down */ |
|
1531 |
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
|
1532 |
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
|
1533 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 1534 |
v->breakdown_chance = 0; |
1535 |
} |
|
1536 |
} |
|
1537 |
||
1538 |
static const StringID _vehicle_type_names[4] = { |
|
1539 |
STR_019F_TRAIN, |
|
1540 |
STR_019C_ROAD_VEHICLE, |
|
1541 |
STR_019E_SHIP, |
|
1542 |
STR_019D_AIRCRAFT, |
|
1543 |
}; |
|
1544 |
||
1545 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1546 |
{ |
|
2639 | 1547 |
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
|
1548 |
|
26 | 1549 |
// Do not show getting-old message if autorenew is active |
2639 | 1550 |
if (GetPlayer(v->owner)->engine_renew) return; |
0 | 1551 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1552 |
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
|
1553 |
SetDParam(1, v->unitnumber); |
0 | 1554 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1555 |
} |
|
1556 |
||
1557 |
void AgeVehicle(Vehicle *v) |
|
1558 |
{ |
|
1559 |
int age; |
|
1560 |
||
1561 |
if (v->age < 65535) |
|
1562 |
v->age++; |
|
1563 |
||
1564 |
age = v->age - v->max_age; |
|
1565 |
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
|
1566 |
v->reliability_spd_dec <<= 1; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1567 |
|
0 | 1568 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1569 |
||
1570 |
if (age == -366) { |
|
1571 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1572 |
} else if (age == 0) { |
|
1573 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
1574 |
} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) { |
|
1575 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
||
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1579 |
/** Starts or stops a lot of vehicles |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1580 |
* @param tile Tile of the depot where the vehicles are started/stopped (only used for depots) |
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1581 |
* @param p1 Station/Order/Depot ID (only used for vehicle list windows) |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1582 |
* @param p2 bitmask |
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1583 |
* - bit 0-4 Vehicle type |
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1584 |
* - bit 5 false = start vehicles, true = stop vehicles |
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1585 |
* - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1586 |
* - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set) |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1587 |
*/ |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1588 |
int32 CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1589 |
{ |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1590 |
Vehicle **vl = NULL; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1591 |
uint16 engine_list_length = 0; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1592 |
uint16 engine_count = 0; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1593 |
int32 return_value = CMD_ERROR; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1594 |
uint i; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1595 |
uint stop_command; |
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1596 |
byte vehicle_type = GB(p2, 0, 5); |
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1597 |
bool start_stop = HASBIT(p2, 5); |
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1598 |
bool vehicle_list_window = HASBIT(p2, 6); |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1599 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1600 |
switch (vehicle_type) { |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1601 |
case VEH_Train: stop_command = CMD_START_STOP_TRAIN; break; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1602 |
case VEH_Road: stop_command = CMD_START_STOP_ROADVEH; break; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1603 |
case VEH_Ship: stop_command = CMD_START_STOP_SHIP; break; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1604 |
case VEH_Aircraft: stop_command = CMD_START_STOP_AIRCRAFT; break; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1605 |
default: return CMD_ERROR; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1606 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1607 |
|
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1608 |
if (vehicle_list_window) { |
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1609 |
uint16 id = GB(p1, 0, 16); |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1610 |
uint16 window_type = p2 & VLW_MASK; |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1611 |
|
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1612 |
engine_count = GenerateVehicleSortList((const Vehicle***)&vl, &engine_list_length, vehicle_type, _current_player, id, id, id, window_type); |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1613 |
} else { |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1614 |
/* Get the list of vehicles in the depot */ |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1615 |
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1616 |
} |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1617 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1618 |
for (i = 0; i < engine_count; i++) { |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1619 |
const Vehicle *v = vl[i]; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1620 |
int32 ret; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1621 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1622 |
if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1623 |
|
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1624 |
if (!vehicle_list_window) { |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1625 |
if (vehicle_type == VEH_Train) { |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1626 |
if (CheckTrainInDepot(v, false) == -1) continue; |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1627 |
} else { |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1628 |
if (!(v->vehstatus & VS_HIDDEN)) continue; |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1629 |
} |
4648
7bde2a5c36e8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1630 |
} |
7bde2a5c36e8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1631 |
|
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1632 |
ret = DoCommand(tile, v->index, 0, flags, stop_command); |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1633 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1634 |
if (!CmdFailed(ret)) { |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1635 |
return_value = 0; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1636 |
/* We know that the command is valid for at least one vehicle. |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1637 |
* If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1638 |
if (!(flags & DC_EXEC)) break; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1639 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1640 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1641 |
|
4648
7bde2a5c36e8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1642 |
free(vl); |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1643 |
return return_value; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1644 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1645 |
|
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1646 |
/** Sells all vehicles in a depot |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1647 |
* @param tile Tile of the depot where the depot is |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1648 |
* @param p1 Vehicle type |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1649 |
* @param p2 unused |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1650 |
*/ |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1651 |
int32 CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1652 |
{ |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1653 |
Vehicle **engines = NULL; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1654 |
Vehicle **wagons = NULL; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1655 |
uint16 engine_list_length = 0; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1656 |
uint16 engine_count = 0; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1657 |
uint16 wagon_list_length = 0; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1658 |
uint16 wagon_count = 0; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1659 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1660 |
int32 cost = 0; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1661 |
uint i, sell_command, total_number_vehicles; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1662 |
byte vehicle_type = GB(p1, 0, 8); |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1663 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1664 |
switch (vehicle_type) { |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1665 |
case VEH_Train: sell_command = CMD_SELL_RAIL_WAGON; break; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1666 |
case VEH_Road: sell_command = CMD_SELL_ROAD_VEH; break; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1667 |
case VEH_Ship: sell_command = CMD_SELL_SHIP; break; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1668 |
case VEH_Aircraft: sell_command = CMD_SELL_AIRCRAFT; break; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1669 |
default: return CMD_ERROR; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1670 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1671 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1672 |
/* Get the list of vehicles in the depot */ |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1673 |
BuildDepotVehicleList(vehicle_type, tile, &engines, &engine_list_length, &engine_count, |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1674 |
&wagons, &wagon_list_length, &wagon_count); |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1675 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1676 |
total_number_vehicles = engine_count + wagon_count; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1677 |
for (i = 0; i < total_number_vehicles; i++) { |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1678 |
const Vehicle *v; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1679 |
int32 ret; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1680 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1681 |
if (i < engine_count) { |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1682 |
v = engines[i]; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1683 |
} else { |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1684 |
v = wagons[i - engine_count]; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1685 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1686 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1687 |
ret = DoCommand(tile, v->index, 1, flags, sell_command); |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1688 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1689 |
if (!CmdFailed(ret)) cost += ret; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1690 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1691 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1692 |
free(engines); |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1693 |
free(wagons); |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1694 |
if (cost == 0) return CMD_ERROR; // no vehicles to sell |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1695 |
return cost; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1696 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1697 |
|
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1698 |
/** Autoreplace all vehicles in the depot |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1699 |
* @param tile Tile of the depot where the vehicles are |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1700 |
* @param p1 Type of vehicle |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1701 |
* @param p2 Unused |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1702 |
*/ |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1703 |
int32 CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1704 |
{ |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1705 |
Vehicle **vl = NULL; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1706 |
uint16 engine_list_length = 0; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1707 |
uint16 engine_count = 0; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1708 |
uint i, x = 0, y = 0, z = 0; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1709 |
int32 cost = 0; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1710 |
byte vehicle_type = GB(p1, 0, 8); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1711 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1712 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1713 |
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1714 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1715 |
/* Get the list of vehicles in the depot */ |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1716 |
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1717 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1718 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1719 |
for (i = 0; i < engine_count; i++) { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1720 |
Vehicle *v = vl[i]; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1721 |
bool stopped = !(v->vehstatus & VS_STOPPED); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1722 |
int32 ret; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1723 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1724 |
/* Ensure that the vehicle completely in the depot */ |
4736
56f9dcf1d133
(svn r6648) -Codechange: simplified CmdDepotMassAutoReplace() by changing a switch-case into using a function, that was added in r6647
bjarni
parents:
4734
diff
changeset
|
1725 |
if (!IsVehicleInDepot(v)) continue; |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1726 |
|
4676
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1727 |
x = v->x_pos; |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1728 |
y = v->y_pos; |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1729 |
z = v->z_pos; |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1730 |
|
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1731 |
if (stopped) { |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1732 |
v->vehstatus |= VS_STOPPED; // Stop the vehicle |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1733 |
v->leave_depot_instantly = true; |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1734 |
} |
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1735 |
ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false); |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1736 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1737 |
if (!CmdFailed(ret)) { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1738 |
cost += ret; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1739 |
if (!(flags & DC_EXEC)) break; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1740 |
/* There is a problem with autoreplace and newgrf |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1741 |
* It's impossible to tell the length of a train after it's being replaced before it's actually done |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1742 |
* Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1743 |
* Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1744 |
* we should never reach a condition where the player will end up with negative money from doing this */ |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1745 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1746 |
SubtractMoneyFromPlayer(ret); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1747 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1748 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1749 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1750 |
if (cost == 0) { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1751 |
cost = CMD_ERROR; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1752 |
} else { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1753 |
if (flags & DC_EXEC) { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1754 |
/* Display the cost animation now that DoCommandP() can't do it for us (see previous comments) */ |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1755 |
if (IsLocalPlayer()) ShowCostOrIncomeAnimation(x, y, z, cost); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1756 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1757 |
cost = 0; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1758 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1759 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1760 |
free(vl); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1761 |
return cost; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1762 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1763 |
|
2244 | 1764 |
/** Clone a vehicle. If it is a train, it will clone all the cars too |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1765 |
* @param tile tile of the depot where the cloned vehicle is build |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1766 |
* @param p1 the original vehicle's index |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1767 |
* @param p2 1 = shared orders, else copied orders |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1768 |
*/ |
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
|
1769 |
int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2244 | 1770 |
{ |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1771 |
Vehicle *v_front, *v; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1772 |
Vehicle *w_front, *w, *w_rear; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1773 |
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
|
1774 |
uint32 build_argument = 2; |
2244 | 1775 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1776 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
2244 | 1777 |
v = GetVehicle(p1); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1778 |
v_front = v; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1779 |
w = NULL; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1780 |
w_front = NULL; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1781 |
w_rear = NULL; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1782 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1783 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1784 |
/* |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1785 |
* 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
|
1786 |
* 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
|
1787 |
* 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
|
1788 |
* w is the car/vehicle currently being cloned |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1789 |
* 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
|
1790 |
*/ |
2244 | 1791 |
|
2639 | 1792 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1793 |
|
2813
504f3e6d14ff
(svn r3361) - Clone Vehicle: Disallow cloning of crashed rail vehicles after starting removal process.
peter1138
parents:
2805
diff
changeset
|
1794 |
if (v->type == VEH_Train && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR; |
2244 | 1795 |
|
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
|
1796 |
// 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
|
1797 |
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
|
1798 |
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
|
1799 |
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
|
1800 |
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
|
1801 |
} 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
|
1802 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1803 |
if (!AllocateVehicles(NULL, veh_counter)) { |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1804 |
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
|
1805 |
} |
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
|
1806 |
} |
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
|
1807 |
|
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
|
1808 |
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
|
1809 |
|
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1810 |
do { |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1811 |
|
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1812 |
if (IsMultiheaded(v) && !IsTrainEngine(v)) { |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1813 |
/* 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
|
1814 |
continue; |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1815 |
} |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1816 |
|
3815
b91a1d73a857
(svn r4825) - Fix [clone FS#159]: Game crashes when cloning reaches train-limit.
bjarni
parents:
3794
diff
changeset
|
1817 |
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
|
1818 |
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
|
1819 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1820 |
if (CmdFailed(cost)) return cost; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1821 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1822 |
total_cost += cost; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1823 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1824 |
if (flags & DC_EXEC) { |
2639 | 1825 |
w = GetVehicle(_new_vehicle_id); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1826 |
|
4925
74022d4dfd85
(svn r6905) - Codechange: Copy cargo subtype when cloning vehicles.
peter1138
parents:
4912
diff
changeset
|
1827 |
if (v->cargo_type != w->cargo_type || v->cargo_subtype != w->cargo_subtype) { |
4287
eef9ff21519c
(svn r5917) -Fix: [clone vehicles] FS#275 Bugfix: Cloned Road Vehicles Are Not Refitted To Correct Cargo (Mart3p)
bjarni
parents:
4270
diff
changeset
|
1828 |
// we can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build |
eef9ff21519c
(svn r5917) -Fix: [clone vehicles] FS#275 Bugfix: Cloned Road Vehicles Are Not Refitted To Correct Cargo (Mart3p)
bjarni
parents:
4270
diff
changeset
|
1829 |
// if we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert |
4925
74022d4dfd85
(svn r6905) - Codechange: Copy cargo subtype when cloning vehicles.
peter1138
parents:
4912
diff
changeset
|
1830 |
DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8), flags, CMD_REFIT_VEH(v->type)); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1831 |
} |
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
|
1832 |
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
|
1833 |
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
|
1834 |
} |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1835 |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1836 |
if (v->type == VEH_Train && !IsFrontEngine(v)) { |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1837 |
// this s a train car |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1838 |
// 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
|
1839 |
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
|
1840 |
} else { |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1841 |
// 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
|
1842 |
w_front = w; |
3679
252b4ab2aad4
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1843 |
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
|
1844 |
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
|
1845 |
} |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1846 |
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1847 |
} |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
1848 |
} while (v->type == VEH_Train && (v = GetNextVehicle(v)) != NULL); |
2244 | 1849 |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1850 |
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
|
1851 |
// 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
|
1852 |
_new_vehicle_id = w_front->index; |
2244 | 1853 |
} |
1854 |
return total_cost; |
|
1855 |
} |
|
1856 |
||
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
|
1857 |
/* |
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
|
1858 |
* 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
|
1859 |
*/ |
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
|
1860 |
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
|
1861 |
{ |
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
|
1862 |
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
|
1863 |
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
|
1864 |
|
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
|
1865 |
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
|
1866 |
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
|
1867 |
if (source->cargo_type != dest->cargo_type) |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1868 |
continue; // cargo not compatible |
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
|
1869 |
|
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
|
1870 |
if (dest->cargo_count == dest->cargo_cap) |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1871 |
continue; // the destination vehicle is already full |
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
|
1872 |
|
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
|
1873 |
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
|
1874 |
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
|
1875 |
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
|
1876 |
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
|
1877 |
|
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
|
1878 |
// 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
|
1879 |
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
|
1880 |
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
|
1881 |
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
|
1882 |
|
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
|
1883 |
} 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
|
1884 |
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
|
1885 |
} 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
|
1886 |
} |
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
|
1887 |
|
4741
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1888 |
static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, const EngineID engine_type) |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1889 |
{ |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1890 |
const Order *o; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1891 |
const Vehicle *u; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1892 |
|
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1893 |
if (v->type == VEH_Train) { |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1894 |
u = GetFirstVehicleInChain(v); |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1895 |
} else { |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1896 |
u = v; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1897 |
} |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1898 |
|
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1899 |
FOR_VEHICLE_ORDERS(u, o) { |
4782
6aa485b21dae
(svn r6696) -Codechange: changed all comparision for refit cargo in orders against CT_NO_REFIT to checks for valid cargo IDs
bjarni
parents:
4762
diff
changeset
|
1900 |
if (!(o->refit_cargo < NUM_CARGO)) continue; |
4741
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1901 |
if (!CanRefitTo(v->engine_type, o->refit_cargo)) continue; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1902 |
if (!CanRefitTo(engine_type, o->refit_cargo)) return false; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1903 |
} |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1904 |
|
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1905 |
return true; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1906 |
} |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1907 |
|
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1908 |
/** |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1909 |
* Function to find what type of cargo to refit to when autoreplacing |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1910 |
* @param *v Original vehicle, that is being replaced |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1911 |
* @param engine_type The EngineID of the vehicle that is being replaced to |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1912 |
* @return The cargo type to replace to |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1913 |
* CT_NO_REFIT is returned if no refit is needed |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1914 |
* CT_INVALID is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1915 |
*/ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1916 |
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type) |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1917 |
{ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1918 |
bool new_cargo_capacity = true; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1919 |
CargoID new_cargo_type = CT_INVALID; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1920 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1921 |
switch (v->type) { |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1922 |
case VEH_Train: |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1923 |
new_cargo_capacity = (RailVehInfo(engine_type)->capacity > 0); |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1924 |
new_cargo_type = RailVehInfo(engine_type)->cargo_type; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1925 |
break; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1926 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1927 |
case VEH_Road: |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1928 |
new_cargo_capacity = (RoadVehInfo(engine_type)->capacity > 0); |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1929 |
new_cargo_type = RoadVehInfo(engine_type)->cargo_type; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1930 |
break; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1931 |
case VEH_Ship: |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1932 |
new_cargo_capacity = (ShipVehInfo(engine_type)->capacity > 0); |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1933 |
new_cargo_type = ShipVehInfo(engine_type)->cargo_type; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1934 |
break; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1935 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1936 |
case VEH_Aircraft: |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1937 |
/* all aircraft starts as passenger planes with cargo capacity |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1938 |
* new_cargo_capacity is always true for aircraft, which is the init value. No need to set it here */ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1939 |
new_cargo_type = CT_PASSENGERS; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1940 |
break; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1941 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1942 |
default: NOT_REACHED(); break; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1943 |
} |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1944 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1945 |
if (!new_cargo_capacity) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1946 |
|
4741
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1947 |
if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) { |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1948 |
if (VerifyAutoreplaceRefitForOrders(v, engine_type)) { |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1949 |
return v->cargo_type == new_cargo_type ? CT_NO_REFIT : v->cargo_type; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1950 |
} else { |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1951 |
return CT_INVALID; |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1952 |
} |
2828a02d6f26
(svn r6653) -Fix r6624: [autoreplace] autoreplace will no longer replace a vehicle if the old type can refit to the cargo types being used in the refit orders and the new one lacks one or more of those refit capabilities
bjarni
parents:
4739
diff
changeset
|
1953 |
} |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1954 |
if (v->type != VEH_Train) return CT_INVALID; // We can't refit the vehicle to carry the cargo we want |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1955 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1956 |
/* Below this line it's safe to assume that the vehicle in question is a train */ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1957 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1958 |
if (v->cargo_cap != 0) return CT_INVALID; // trying to replace a vehicle with cargo capacity into another one with incompatible cargo type |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1959 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1960 |
/* the old engine didn't have cargo capacity, but the new one does |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1961 |
* now we will figure out what cargo the train is carrying and refit to fit this */ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1962 |
v = GetFirstVehicleInChain(v); |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1963 |
do { |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1964 |
if (v->cargo_cap == 0) continue; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1965 |
/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1966 |
if (v->cargo_type == new_cargo_type) return CT_NO_REFIT; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1967 |
if (CanRefitTo(engine_type, v->cargo_type)) return v->cargo_type; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1968 |
} while ((v=v->next) != NULL); |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1969 |
return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1970 |
} |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1971 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1972 |
/* Replaces a vehicle (used to be called autorenew) |
2639 | 1973 |
* This function is only called from MaybeReplaceVehicle() |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1974 |
* 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
|
1975 |
* @param w Vehicle to replace |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1976 |
* @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts |
2639 | 1977 |
* @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
|
1978 |
*/ |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1979 |
static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost) |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1980 |
{ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1981 |
int32 cost; |
4728
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
1982 |
int32 sell_value; |
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
|
1983 |
Vehicle *old_v = *w; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1984 |
const Player *p = GetPlayer(old_v->owner); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1985 |
EngineID new_engine_type; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1986 |
const UnitID cached_unitnumber = old_v->unitnumber; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1987 |
bool new_front = false; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1988 |
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
|
1989 |
char vehicle_name[32]; |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1990 |
CargoID replacement_cargo_type; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
1991 |
|
2848 | 1992 |
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
|
1993 |
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
|
1994 |
|
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1995 |
replacement_cargo_type = GetNewCargoTypeForReplace(old_v, new_engine_type); |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1996 |
|
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1997 |
/* check if we can't refit to the needed type, so no replace takes place to prevent the vehicle from altering cargo type */ |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1998 |
if (replacement_cargo_type == CT_INVALID) return 0; |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
1999 |
|
4728
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2000 |
sell_value = DoCommand(0, old_v->index, 0, DC_QUERY_COST, CMD_SELL_VEH(old_v->type)); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2001 |
|
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2002 |
/* We give the player a loan of the same amount as the sell value. |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2003 |
* This is needed in case he needs the income from the sale to build the new vehicle. |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2004 |
* We take it back if building fails or when we really sell the old engine */ |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2005 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2006 |
SubtractMoneyFromPlayer(sell_value); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2007 |
|
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
|
2008 |
cost = DoCommand(old_v->tile, new_engine_type, 3, flags, CMD_BUILD_VEH(old_v->type)); |
4728
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2009 |
if (CmdFailed(cost)) { |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2010 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2011 |
SubtractMoneyFromPlayer(-sell_value); // Take back the money we just gave the player |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2012 |
return cost; |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2013 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2014 |
|
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2015 |
if (replacement_cargo_type != CT_NO_REFIT) cost += GetRefitCost(new_engine_type); // add refit cost |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2016 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2017 |
if (flags & DC_EXEC) { |
2564 | 2018 |
new_v = GetVehicle(_new_vehicle_id); |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2019 |
*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
|
2020 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2021 |
/* refit if needed */ |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2022 |
if (replacement_cargo_type != CT_NO_REFIT) { |
4611
89bc316009c9
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
bjarni
parents:
4604
diff
changeset
|
2023 |
if (CmdFailed(DoCommand(0, new_v->index, replacement_cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type)))) { |
4613
6fbc87fa5e3b
(svn r6468) -Codechange r6464: now use error() when failing refit in autoreplace to ensure that such a failure will not break a game
bjarni
parents:
4611
diff
changeset
|
2024 |
/* Being here shows a failure, which most likely is in GetNewCargoTypeForReplace() or incorrect estimation costs */ |
6fbc87fa5e3b
(svn r6468) -Codechange r6464: now use error() when failing refit in autoreplace to ensure that such a failure will not break a game
bjarni
parents:
4611
diff
changeset
|
2025 |
error("Autoreplace failed to refit. Replace engine %d to %d and refit to cargo %d", old_v->engine_type, new_v->engine_type, replacement_cargo_type); |
4611
89bc316009c9
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
bjarni
parents:
4604
diff
changeset
|
2026 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2027 |
} |
4611
89bc316009c9
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
bjarni
parents:
4604
diff
changeset
|
2028 |
|
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
|
2029 |
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
|
2030 |
// 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
|
2031 |
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
|
2032 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2033 |
|
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2034 |
if (old_v->type == VEH_Train && !IsFrontEngine(old_v)) { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2035 |
/* 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
|
2036 |
* 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
|
2037 |
* sell the old engine in a moment |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2038 |
*/ |
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
|
2039 |
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
|
2040 |
/* 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
|
2041 |
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
|
2042 |
} else { |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2043 |
// 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
|
2044 |
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
|
2045 |
new_v->cur_order_index = old_v->cur_order_index; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2046 |
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
|
2047 |
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
|
2048 |
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
|
2049 |
new_v->service_interval = old_v->service_interval; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2050 |
new_front = true; |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2051 |
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
|
2052 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2053 |
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
|
2054 |
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
|
2055 |
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
|
2056 |
|
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
|
2057 |
// 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
|
2058 |
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
|
2059 |
// 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
|
2060 |
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
|
2061 |
} |
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
|
2062 |
|
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
|
2063 |
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
|
2064 |
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
|
2065 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2066 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2067 |
} |
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
|
2068 |
/* 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
|
2069 |
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
|
2070 |
|
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
|
2071 |
// Get the name of the old vehicle if it has a custom name. |
4862
ac034ec9ed2b
(svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents:
4784
diff
changeset
|
2072 |
if (!IsCustomName(old_v->string_id)) { |
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
|
2073 |
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
|
2074 |
} else { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4862
diff
changeset
|
2075 |
GetName(vehicle_name, old_v->string_id & 0x7FF, lastof(vehicle_name)); |
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
|
2076 |
} |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2077 |
} else { // flags & DC_EXEC not set |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2078 |
/* Ensure that the player will not end up having negative money while autoreplacing |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2079 |
* This is needed because the only other check is done after the income from selling the old vehicle is substracted from the cost */ |
4728
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2080 |
if (p->money64 < (cost + total_cost)) { |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2081 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2082 |
SubtractMoneyFromPlayer(-sell_value); // Pay back the loan |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2083 |
return CMD_ERROR; |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2084 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2085 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2086 |
|
4728
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2087 |
/* Take back the money we just gave the player just before building the vehicle |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2088 |
* The player will get the same amount now that the sale actually takes place */ |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2089 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2090 |
SubtractMoneyFromPlayer(-sell_value); |
d4426f6c6191
(svn r6640) -Fix: [autoreplace] autoreplace can now use the money for selling the old vehicle to build the new one
bjarni
parents:
4725
diff
changeset
|
2091 |
|
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2092 |
/* sell the engine/ find out how much you get for the old engine (income is returned as negative cost) */ |
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
|
2093 |
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
|
2094 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2095 |
if (new_front) { |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2096 |
/* now we assign the old unitnumber to the new vehicle */ |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2097 |
new_v->unitnumber = cached_unitnumber; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2098 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2099 |
|
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2100 |
/* Transfer the name of the old 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
|
2101 |
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
|
2102 |
_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
|
2103 |
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
|
2104 |
} |
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
|
2105 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2106 |
return cost; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2107 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2108 |
|
2639 | 2109 |
/** replaces a vehicle if it's set for autoreplace or is too old |
2110 |
* (used to be called autorenew) |
|
2111 |
* @param v The vehicle to replace |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2112 |
* if the vehicle is a train, v needs to be the front engine |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2113 |
* @param check Checks if the replace is valid. No action is done at all |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2114 |
* @param display_costs If set, a cost animation is shown (only if check is false) |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2115 |
* @return CMD_ERROR if something went wrong. Otherwise the price of the replace |
2639 | 2116 |
*/ |
4676
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
2117 |
static int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs) |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2118 |
{ |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2119 |
Vehicle *w; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2120 |
const Player *p = GetPlayer(v->owner); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2121 |
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
|
2122 |
int32 cost, temp_cost = 0; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
2123 |
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
|
2124 |
|
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
|
2125 |
/* 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
|
2126 |
* 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
|
2127 |
* 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
|
2128 |
* 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
|
2129 |
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
|
2130 |
(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
|
2131 |
-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
|
2132 |
); |
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
|
2133 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2134 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2135 |
_current_player = v->owner; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2136 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2137 |
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
|
2138 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2139 |
assert(v->vehstatus & VS_STOPPED); // the vehicle should have been stopped in VehicleEnteredDepotThisTick() if needed |
2590
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
2140 |
|
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
2141 |
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
|
2142 |
// 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
|
2143 |
// 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
|
2144 |
stopped = true; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
2145 |
} |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2146 |
|
2639 | 2147 |
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
|
2148 |
cost = 0; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2149 |
w = v; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2150 |
do { |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2151 |
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
|
2152 |
/* 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
|
2153 |
continue; |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2154 |
} |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2155 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2156 |
// check if the vehicle should be replaced |
2639 | 2157 |
if (!p->engine_renew || |
2158 |
w->age - w->max_age < (p->engine_renew_months * 30) || // replace if engine is too old |
|
2159 |
w->max_age == 0) { // rail cars got a max age of 0 |
|
2848 | 2160 |
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
|
2161 |
continue; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2162 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2163 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2164 |
/* Now replace the vehicle */ |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2165 |
temp_cost = ReplaceVehicle(&w, flags, cost); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2166 |
|
2639 | 2167 |
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
|
2168 |
(w->type != VEH_Train || w->u.rail.first_engine == INVALID_ENGINE)) { |
2639 | 2169 |
/* now we bought a new engine and sold the old one. We need to fix the |
2170 |
* pointers in order to avoid pointing to the old one for trains: these |
|
2171 |
* pointers should point to the front engine and not the cars |
|
2172 |
*/ |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2173 |
v = w; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2174 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2175 |
|
3413
bebbb9d71cc8
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
2176 |
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
|
2177 |
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
|
2178 |
} |
2602
1a6561c9a408
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
2179 |
} while (w->type == VEH_Train && (w = GetNextVehicle(w)) != NULL); |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2180 |
|
4515
6b957ee9f07f
(svn r6300) -Fix: FS#321 autoreplace / wagon removal
bjarni
parents:
4506
diff
changeset
|
2181 |
if (!(flags & DC_EXEC) && (p->money64 < (int32)(cost + p->engine_renew_money) || cost == 0)) { |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2182 |
if (!check && 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
|
2183 |
StringID message; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2184 |
SetDParam(0, v->unitnumber); |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2185 |
switch (v->type) { |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2186 |
case VEH_Train: message = STR_TRAIN_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2187 |
case VEH_Road: message = STR_ROADVEHICLE_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2188 |
case VEH_Ship: message = STR_SHIP_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2189 |
case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2190 |
// This should never happen |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2191 |
default: NOT_REACHED(); message = 0; break; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2192 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2193 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2194 |
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
|
2195 |
} |
2639 | 2196 |
if (stopped) v->vehstatus &= ~VS_STOPPED; |
4676
dd1d2d78d6f2
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
2197 |
if (display_costs) _current_player = OWNER_NONE; |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2198 |
return CMD_ERROR; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2199 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2200 |
|
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2201 |
if (flags & DC_EXEC) { |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2202 |
break; // we are done replacing since the loop ran once with DC_EXEC |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2203 |
} else if (check) { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2204 |
/* It's a test only and we know that we can do this |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2205 |
* NOTE: payment for wagon removal is NOT included in this price */ |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2206 |
return cost; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2207 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2208 |
// 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
|
2209 |
flags |= DC_EXEC; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2210 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2211 |
|
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
|
2212 |
/* 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
|
2213 |
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
|
2214 |
Vehicle *temp; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2215 |
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
|
2216 |
|
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
|
2217 |
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
|
2218 |
// 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
|
2219 |
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
|
2220 |
w = GetNextVehicle(w); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2221 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2222 |
if (w == NULL) { |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2223 |
// 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
|
2224 |
SetDParam(0, v->unitnumber); |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2225 |
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
|
2226 |
break; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2227 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2228 |
temp = w; |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2229 |
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
|
2230 |
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
|
2231 |
MoveVehicleCargo(v, temp); |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2232 |
cost += DoCommand(0, temp->index, 0, DC_EXEC, CMD_SELL_RAIL_WAGON); |
2617
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2233 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2234 |
} |
03120a0b1e39
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2235 |
|
2639 | 2236 |
if (stopped) v->vehstatus &= ~VS_STOPPED; |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2237 |
if (display_costs) { |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2238 |
if (IsLocalPlayer()) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2239 |
_current_player = OWNER_NONE; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2240 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2241 |
return cost; |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2242 |
} |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2243 |
|
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2244 |
/* Extend the list size for BuildDepotVehicleList() */ |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2245 |
static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *engine_list_length, uint16 step_size) |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2246 |
{ |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2247 |
*engine_list_length = min(*engine_list_length + step_size, GetVehicleArraySize()); |
4685 | 2248 |
*engine_list = realloc((void*)*engine_list, (*engine_list_length) * sizeof((*engine_list)[0])); |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2249 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2250 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2251 |
/** Generates a list of vehicles inside a depot |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2252 |
* Will enlarge allocated space for the list if they are too small, so it's ok to call with (pointer to NULL array, pointer to uninitised uint16, pointer to 0) |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2253 |
* If one of the lists is not needed (say wagons when finding ships), all the pointers regarding that list should be set to NULL |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2254 |
* @param Type type of vehicle |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2255 |
* @param tile The tile the depot is located in |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2256 |
* @param ***engine_list Pointer to a pointer to an array of vehicles in the depot (old list is freed and a new one is malloced) |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2257 |
* @param *engine_list_length Allocated size of engine_list. Needs to be set to 0 when engine_list points to a NULL array |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2258 |
* @param *engine_count The number of engines stored in the list |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2259 |
* @param ***wagon_list Pointer to a pointer to an array of free wagons in the depot (old list is freed and a new one is malloced) |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2260 |
* @param *wagon_list_length Allocated size of wagon_list. Needs to be set to 0 when wagon_list points to a NULL array |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2261 |
* @param *wagon_count The number of engines stored in the list |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2262 |
*/ |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2263 |
void BuildDepotVehicleList(byte type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count) |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2264 |
{ |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2265 |
Vehicle *v; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2266 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2267 |
/* This function should never be called without an array to store results */ |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2268 |
assert(!(engine_list == NULL && type != VEH_Train)); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2269 |
assert(!(type == VEH_Train && engine_list == NULL && wagon_list == NULL)); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2270 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2271 |
/* Both array and the length should either be NULL to disable the list or both should not be NULL */ |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2272 |
assert((engine_list == NULL && engine_list_length == NULL) || (engine_list != NULL && engine_list_length != NULL)); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2273 |
assert((wagon_list == NULL && wagon_list_length == NULL) || (wagon_list != NULL && wagon_list_length != NULL)); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2274 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2275 |
assert(!(engine_list != NULL && engine_count == NULL)); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2276 |
assert(!(wagon_list != NULL && wagon_count == NULL)); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2277 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2278 |
if (engine_count != NULL) *engine_count = 0; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2279 |
if (wagon_count != NULL) *wagon_count = 0; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2280 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2281 |
switch (type) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2282 |
case VEH_Train: |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2283 |
FOR_ALL_VEHICLES(v) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2284 |
if (v->tile == tile && v->type == VEH_Train && v->u.rail.track == 0x80) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2285 |
if (IsFrontEngine(v)) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2286 |
if (engine_list == NULL) continue; |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2287 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2288 |
(*engine_list)[(*engine_count)++] = v; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2289 |
} else if (IsFreeWagon(v)) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2290 |
if (wagon_list == NULL) continue; |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2291 |
if (*wagon_count == *wagon_list_length) ExtendVehicleListSize((const Vehicle***)wagon_list, wagon_list_length, 25); |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2292 |
(*wagon_list)[(*wagon_count)++] = v; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2293 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2294 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2295 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2296 |
break; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2297 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2298 |
case VEH_Road: |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2299 |
FOR_ALL_VEHICLES(v) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2300 |
if (v->tile == tile && v->type == VEH_Road && IsRoadVehInDepot(v)) { |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2301 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2302 |
(*engine_list)[(*engine_count)++] = v; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2303 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2304 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2305 |
break; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2306 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2307 |
case VEH_Ship: |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2308 |
FOR_ALL_VEHICLES(v) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2309 |
if (v->tile == tile && v->type == VEH_Ship && IsShipInDepot(v)) { |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2310 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2311 |
(*engine_list)[(*engine_count)++] = v; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2312 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2313 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2314 |
break; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2315 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2316 |
case VEH_Aircraft: |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2317 |
FOR_ALL_VEHICLES(v) { |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2318 |
if (v->tile == tile && |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2319 |
v->type == VEH_Aircraft && |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2320 |
v->subtype <= 2 && |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2321 |
v->vehstatus & VS_HIDDEN) { |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2322 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2323 |
(*engine_list)[(*engine_count)++] = v; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2324 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2325 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2326 |
break; |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2327 |
|
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2328 |
default: NOT_REACHED(); |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2329 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2330 |
} |
1b35cdc018ee
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2331 |
|
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2332 |
/** |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2333 |
* @param sort_list list to store the list in. Either NULL or the length length_of_array tells |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2334 |
* @param length_of_array informs the length allocated for sort_list. This is not the same as the number of vehicles in the list. Needs to be 0 when sort_list is NULL |
4554
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2335 |
* @param type type of vehicle |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2336 |
* @param owner PlayerID of owner to generate a list for |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2337 |
* @param station index of station to generate a list for. INVALID_STATION when not used |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2338 |
* @param order index of oder to generate a list for. INVALID_ORDER when not used |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2339 |
* @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2340 |
* @return the number of vehicles added to the list |
8342a6d0a366
(svn r6393) -Fix: [autoreplace] now refit costs are added to the estimated costs (could spend more than allowed when estimate and actual cost were not the same)
bjarni
parents:
4551
diff
changeset
|
2341 |
*/ |
4681
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2342 |
uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, byte type, PlayerID owner, StationID station, OrderID order, uint16 depot_airport_index, uint16 window_type) |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2343 |
{ |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2344 |
const uint subtype = (type != VEH_Aircraft) ? Train_Front : 2; |
4499
ca3e924db010
(svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents:
4497
diff
changeset
|
2345 |
uint n = 0; |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2346 |
const Vehicle *v; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2347 |
|
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2348 |
switch (window_type) { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2349 |
case VLW_STATION_LIST: { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2350 |
FOR_ALL_VEHICLES(v) { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2351 |
if (v->type == type && ( |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2352 |
(type == VEH_Train && IsFrontEngine(v)) || |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2353 |
(type != VEH_Train && v->subtype <= subtype))) { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2354 |
const Order *order; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2355 |
|
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2356 |
FOR_VEHICLE_ORDERS(v, order) { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
2357 |
if (order->type == OT_GOTO_STATION && order->dest == station) { |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2358 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50); |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2359 |
(*sort_list)[n++] = v; |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2360 |
break; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2361 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2362 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2363 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2364 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2365 |
break; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2366 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2367 |
|
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2368 |
case VLW_SHARED_ORDERS: { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2369 |
FOR_ALL_VEHICLES(v) { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2370 |
/* Find a vehicle with the order in question */ |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2371 |
if (v->orders != NULL && v->orders->index == order) break; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2372 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2373 |
|
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2374 |
if (v != NULL && v->orders != NULL && v->orders->index == order) { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2375 |
/* Only try to make the list if we found a vehicle using the order in question */ |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2376 |
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) { |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2377 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2378 |
(*sort_list)[n++] = v; |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2379 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2380 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2381 |
break; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2382 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2383 |
|
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2384 |
case VLW_STANDARD: { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2385 |
FOR_ALL_VEHICLES(v) { |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2386 |
if (v->type == type && v->owner == owner && ( |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2387 |
(type == VEH_Train && IsFrontEngine(v)) || |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2388 |
(type != VEH_Train && v->subtype <= subtype))) { |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2389 |
/* TODO find a better estimate on the total number of vehicles for current player */ |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2390 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetVehicleArraySize()/4); |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2391 |
(*sort_list)[n++] = v; |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2392 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2393 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2394 |
break; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2395 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2396 |
|
4681
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2397 |
case VLW_DEPOT_LIST: { |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2398 |
FOR_ALL_VEHICLES(v) { |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2399 |
if (v->type == type && ( |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2400 |
(type == VEH_Train && IsFrontEngine(v)) || |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2401 |
(type != VEH_Train && v->subtype <= subtype))) { |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2402 |
const Order *order; |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2403 |
|
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2404 |
FOR_VEHICLE_ORDERS(v, order) { |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2405 |
if (order->type == OT_GOTO_DEPOT && order->dest == depot_airport_index) { |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2406 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2407 |
(*sort_list)[n++] = v; |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2408 |
break; |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2409 |
} |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2410 |
} |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2411 |
} |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2412 |
} |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2413 |
break; |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2414 |
} |
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2415 |
|
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2416 |
default: NOT_REACHED(); break; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2417 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2418 |
|
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2419 |
if ((n + 100) < *length_of_array) { |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2420 |
/* We allocated way too much for sort_list. |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2421 |
* Now we will reduce how much we allocated. |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2422 |
* We will still make it have room for 50 extra vehicles to prevent having |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2423 |
* to move the whole array if just one vehicle is added later */ |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2424 |
*length_of_array = n + 50; |
4685 | 2425 |
*sort_list = realloc((void*)*sort_list, (*length_of_array) * sizeof((*sort_list)[0])); |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2426 |
} |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2427 |
|
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2428 |
return n; |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2429 |
} |
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2430 |
|
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2431 |
/** send all vehicles of type to depots |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2432 |
* @param type type of vehicle |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2433 |
* @param flags the flags used for DoCommand() |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2434 |
* @param service should the vehicles only get service in the depots |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2435 |
* @param owner PlayerID of owner of the vehicles to send |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2436 |
* @param VLW_flag tells what kind of list requested the goto depot |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2437 |
* @return 0 for success and CMD_ERROR if no vehicle is able to go to depot |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2438 |
*/ |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4499
diff
changeset
|
2439 |
int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id) |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2440 |
{ |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2441 |
const Vehicle **sort_list = NULL; |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2442 |
uint n, i; |
4678
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2443 |
uint16 array_length = 0; |
e5fe6e4aca39
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2444 |
|
4681
bc077405e9a8
(svn r6586) -Feature: [depot window] added a vehicle list window with all vehicles having a certain depot in their orders
bjarni
parents:
4678
diff
changeset
|
2445 |
n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, id, id, vlw_flag); |
4465
262c344f6f3d
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
2446 |
|
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2447 |
/* Send all the vehicles to a depot */ |
4499
ca3e924db010
(svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents:
4497
diff
changeset
|
2448 |
for (i = 0; i < n; i++) { |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2449 |
const Vehicle *v = sort_list[i]; |
4560
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2450 |
int32 ret = DoCommand(v->tile, v->index, service | DEPOT_DONT_CANCEL, flags, CMD_SEND_TO_DEPOT(type)); |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2451 |
|
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2452 |
/* Return 0 if DC_EXEC is not set this is a valid goto depot command) |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2453 |
* In this case we know that at least one vehicle can be sent to a depot |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2454 |
* and we will issue the command. We can now safely quit the loop, knowing |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2455 |
* it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2456 |
if (!CmdFailed(ret) && !(flags & DC_EXEC)) { |
4683
700e6d81e214
(svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents:
4681
diff
changeset
|
2457 |
free((void*)sort_list); |
4497
9d43f65d9e78
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2458 |
return 0; |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2459 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2460 |
} |
4465
262c344f6f3d
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
2461 |
|
4683
700e6d81e214
(svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents:
4681
diff
changeset
|
2462 |
free((void*)sort_list); |
4465
262c344f6f3d
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
2463 |
return (flags & DC_EXEC) ? 0 : CMD_ERROR; |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2464 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2465 |
|
4734
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2466 |
bool IsVehicleInDepot(const Vehicle *v) |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2467 |
{ |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2468 |
switch (v->type) { |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2469 |
case VEH_Train: return CheckTrainInDepot(v, false) != -1; |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2470 |
case VEH_Road: return IsRoadVehInDepot(v); |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2471 |
case VEH_Ship: return IsShipInDepot(v); |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2472 |
case VEH_Aircraft: return IsAircraftInHangar(v); |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2473 |
default: NOT_REACHED(); |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2474 |
} |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2475 |
return false; |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2476 |
} |
24b34218c5ce
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2477 |
|
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2478 |
void VehicleEnterDepot(Vehicle *v) |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2479 |
{ |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2480 |
switch (v->type) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2481 |
case VEH_Train: |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2482 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2483 |
if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2484 |
UpdateSignalsOnSegment(v->tile, GetRailDepotDirection(v->tile)); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2485 |
v->load_unload_time_rem = 0; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2486 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2487 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2488 |
case VEH_Road: |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2489 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2490 |
v->u.road.state = 254; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2491 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2492 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2493 |
case VEH_Ship: |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2494 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2495 |
v->u.ship.state = 0x80; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2496 |
RecalcShipStuff(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2497 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2498 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2499 |
case VEH_Aircraft: |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2500 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2501 |
HandleAircraftEnterHangar(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2502 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2503 |
default: NOT_REACHED(); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2504 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2505 |
|
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2506 |
if (v->type != VEH_Train) { |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2507 |
/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters. |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2508 |
* We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */ |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2509 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2510 |
} |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2511 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2512 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2513 |
v->vehstatus |= VS_HIDDEN; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2514 |
v->cur_speed = 0; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2515 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2516 |
VehicleServiceInDepot(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2517 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2518 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2519 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2520 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2521 |
Order t; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2522 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2523 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2524 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2525 |
t = v->current_order; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2526 |
v->current_order.type = OT_DUMMY; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2527 |
v->current_order.flags = 0; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2528 |
|
4782
6aa485b21dae
(svn r6696) -Codechange: changed all comparision for refit cargo in orders against CT_NO_REFIT to checks for valid cargo IDs
bjarni
parents:
4762
diff
changeset
|
2529 |
if (t.refit_cargo < NUM_CARGO) { |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2530 |
int32 cost; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2531 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2532 |
_current_player = v->owner; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2533 |
cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, CMD_REFIT_VEH(v->type)); |
4783
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2534 |
|
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2535 |
if (CmdFailed(cost)) { |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2536 |
v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2537 |
if (v->owner == _local_player) { |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2538 |
/* Notify the user that we stopped the vehicle */ |
4784
7c6ce7c101b3
(svn r6698) -Code cleanup r6697: simplified getting the string of the vehicle type
bjarni
parents:
4783
diff
changeset
|
2539 |
SetDParam(0, _vehicle_type_names[v->type - 0x10]); |
4783
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2540 |
SetDParam(1, v->unitnumber); |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2541 |
AddNewsItem(STR_ORDER_REFIT_FAILED, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2542 |
} |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2543 |
} else if (v->owner == _local_player && cost != 0) { |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2544 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
2545 |
} |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2546 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2547 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2548 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2549 |
/* Part of orders */ |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2550 |
if (v->type == VEH_Train) v->u.rail.days_since_order_progr = 0; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2551 |
v->cur_order_index++; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2552 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2553 |
/* Force depot visit */ |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2554 |
v->vehstatus |= VS_STOPPED; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2555 |
if (v->owner == _local_player) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2556 |
StringID string; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2557 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2558 |
switch (v->type) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2559 |
case VEH_Train: string = STR_8814_TRAIN_IS_WAITING_IN_DEPOT; break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2560 |
case VEH_Road: string = STR_9016_ROAD_VEHICLE_IS_WAITING; break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2561 |
case VEH_Ship: string = STR_981C_SHIP_IS_WAITING_IN_DEPOT; break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2562 |
case VEH_Aircraft: string = STR_A014_AIRCRAFT_IS_WAITING_IN; break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2563 |
default: NOT_REACHED(); string = STR_EMPTY; // Set the string to something to avoid a compiler warning |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2564 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2565 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2566 |
SetDParam(0, v->unitnumber); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2567 |
AddNewsItem(string, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2568 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2569 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2570 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2571 |
} |
2244 | 2572 |
|
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
|
2573 |
/** 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
|
2574 |
* @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
|
2575 |
* @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
|
2576 |
* @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
|
2577 |
*/ |
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
|
2578 |
int32 CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2579 |
{ |
2580 |
Vehicle *v; |
|
2581 |
StringID str; |
|
2582 |
||
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2583 |
if (!IsValidVehicleID(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
|
2584 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2585 |
v = GetVehicle(p1); |
0 | 2586 |
|
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
|
2587 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 2588 |
|
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
|
2589 |
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
|
2590 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2591 |
|
0 | 2592 |
if (flags & DC_EXEC) { |
2593 |
StringID old_str = v->string_id; |
|
2594 |
v->string_id = str; |
|
2595 |
DeleteName(old_str); |
|
588 | 2596 |
ResortVehicleLists(); |
0 | 2597 |
MarkWholeScreenDirty(); |
2598 |
} else { |
|
2599 |
DeleteName(str); |
|
2600 |
} |
|
2601 |
||
2602 |
return 0; |
|
2603 |
} |
|
2604 |
||
2605 |
||
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
|
2606 |
/** 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
|
2607 |
* @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
|
2608 |
* @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
|
2609 |
* @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
|
2610 |
*/ |
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
|
2611 |
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
|
2612 |
{ |
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
|
2613 |
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
|
2614 |
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
|
2615 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2616 |
if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR; |
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
|
2617 |
|
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
|
2618 |
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
|
2619 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2620 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
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
|
2621 |
|
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
|
2622 |
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
|
2623 |
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
|
2624 |
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
|
2625 |
} |
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
|
2626 |
|
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
|
2627 |
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
|
2628 |
} |
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
|
2629 |
|
0 | 2630 |
|
2631 |
static Rect _old_vehicle_coords; |
|
2632 |
||
2633 |
void BeginVehicleMove(Vehicle *v) { |
|
2634 |
_old_vehicle_coords.left = v->left_coord; |
|
2635 |
_old_vehicle_coords.top = v->top_coord; |
|
2636 |
_old_vehicle_coords.right = v->right_coord; |
|
2637 |
_old_vehicle_coords.bottom = v->bottom_coord; |
|
2638 |
} |
|
2639 |
||
2640 |
void EndVehicleMove(Vehicle *v) |
|
2641 |
{ |
|
2642 |
MarkAllViewportsDirty( |
|
2643 |
min(_old_vehicle_coords.left,v->left_coord), |
|
2644 |
min(_old_vehicle_coords.top,v->top_coord), |
|
2645 |
max(_old_vehicle_coords.right,v->right_coord)+1, |
|
2646 |
max(_old_vehicle_coords.bottom,v->bottom_coord)+1 |
|
2647 |
); |
|
2648 |
} |
|
2649 |
||
2650 |
/* 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
|
2651 |
bool GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp) |
0 | 2652 |
{ |
2653 |
static const int8 _delta_coord[16] = { |
|
2654 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
2655 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
2656 |
}; |
|
2657 |
||
2658 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
2659 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
2660 |
||
2661 |
gp->x = x; |
|
2662 |
gp->y = y; |
|
2663 |
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
|
2664 |
gp->new_tile = TileVirtXY(x, y); |
0 | 2665 |
return gp->old_tile == gp->new_tile; |
2666 |
} |
|
2667 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2668 |
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
|
2669 |
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
|
2670 |
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
|
2671 |
DIR_E , DIR_SE, DIR_S |
0 | 2672 |
}; |
2673 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2674 |
Direction GetDirectionTowards(const Vehicle* v, int x, int y) |
0 | 2675 |
{ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2676 |
Direction dir; |
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2677 |
DirDiff dirdiff; |
0 | 2678 |
int i = 0; |
2679 |
||
2680 |
if (y >= v->y_pos) { |
|
2681 |
if (y != v->y_pos) i+=3; |
|
2682 |
i+=3; |
|
2683 |
} |
|
2684 |
||
2685 |
if (x >= v->x_pos) { |
|
2686 |
if (x != v->x_pos) i++; |
|
2687 |
i++; |
|
2688 |
} |
|
2689 |
||
2690 |
dir = v->direction; |
|
2691 |
||
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2692 |
dirdiff = DirDifference(_new_direction_table[i], dir); |
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2693 |
if (dirdiff == DIRDIFF_SAME) return dir; |
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2694 |
return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 2695 |
} |
2696 |
||
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
|
2697 |
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
|
2698 |
{ |
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
|
2699 |
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
|
2700 |
|
2952 | 2701 |
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
|
2702 |
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
|
2703 |
if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */ |
3185 | 2704 |
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
|
2705 |
|
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
|
2706 |
if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */ |
3161 | 2707 |
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
|
2708 |
|
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
|
2709 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.rail.track),v->direction); |
1959 | 2710 |
|
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2711 |
case VEH_Ship: |
3961
9868b766fda7
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
2712 |
if (IsShipInDepot(v)) |
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
2713 |
/* 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
|
2714 |
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
|
2715 |
|
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
|
2716 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction); |
1959 | 2717 |
|
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2718 |
case VEH_Road: |
3959 | 2719 |
if (IsRoadVehInDepot(v)) /* We'll assume the road vehicle is facing outwards */ |
3179 | 2720 |
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
|
2721 |
|
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
|
2722 |
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
|
2723 |
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
|
2724 |
|
4270
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2725 |
/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */ |
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2726 |
if ((v->u.road.state & 7) < 6) return v->u.road.state; |
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2727 |
|
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2728 |
/* Vehicle is turning around, get the direction from vehicle's direction */ |
3161 | 2729 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1959 | 2730 |
|
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
|
2731 |
/* 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
|
2732 |
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
|
2733 |
} |
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2734 |
} |
22 | 2735 |
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, |
2736 |
* result << 8 contains the id of the station entered. If the return value has |
|
2737 |
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there |
|
2738 |
* 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
|
2739 |
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
|
2740 |
{ |
3657 | 2741 |
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
0 | 2742 |
} |
2743 |
||
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
2744 |
UnitID GetFreeUnitNumber(byte type) |
0 | 2745 |
{ |
3018
22ede527b855
(svn r3598) -Fix: suppress invalid warning by assigning value to variable
truelight
parents:
3009
diff
changeset
|
2746 |
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
|
2747 |
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
|
2748 |
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
|
2749 |
static UnitID gmax = 0; |
0 | 2750 |
|
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
|
2751 |
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
|
2752 |
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
|
2753 |
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
|
2754 |
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
|
2755 |
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
|
2756 |
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
|
2757 |
} |
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
|
2758 |
|
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
|
2759 |
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
|
2760 |
/* 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
|
2761 |
* 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
|
2762 |
* 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
|
2763 |
*/ |
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
|
2764 |
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
|
2765 |
} |
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
|
2766 |
|
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
|
2767 |
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
|
2768 |
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
|
2769 |
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
|
2770 |
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
|
2771 |
} |
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
|
2772 |
|
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
|
2773 |
// 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
|
2774 |
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
|
2775 |
|
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
|
2776 |
// Fill the cache |
0 | 2777 |
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
|
2778 |
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
|
2779 |
cache[u->unitnumber] = true; |
0 | 2780 |
} |
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
|
2781 |
|
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
|
2782 |
// 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
|
2783 |
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
|
2784 |
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
|
2785 |
} |
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
|
2786 |
|
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
|
2787 |
return unit; |
0 | 2788 |
} |
2789 |
||
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2790 |
static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, CargoID cargo_type) |
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
|
2791 |
{ |
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
|
2792 |
SpriteID map; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2793 |
const Player *p = GetPlayer(player); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2794 |
LiveryScheme scheme = LS_DEFAULT; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2795 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2796 |
/* The default livery is always available for use, but its in_use flag determines |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2797 |
* whether any _other_ liveries are in use. */ |
4616
3c22e5eb5ffe
(svn r6474) - Add a patch option to control display of liveries, allowing none, your
peter1138
parents:
4613
diff
changeset
|
2798 |
if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2799 |
/* Determine the livery scheme to use */ |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2800 |
switch (GetEngine(engine_type)->type) { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2801 |
case VEH_Train: { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2802 |
switch (_engine_info[engine_type].railtype) { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2803 |
case RAILTYPE_RAIL: |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2804 |
case RAILTYPE_ELECTRIC: |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2805 |
{ |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2806 |
const RailVehicleInfo *rvi = RailVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2807 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2808 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2809 |
if (rvi->flags & RVI_WAGON) { |
4604
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2810 |
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_VALUABLES) { |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2811 |
if (parent_engine_type == INVALID_ENGINE) { |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2812 |
scheme = LS_PASSENGER_WAGON_STEAM; |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2813 |
} else { |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2814 |
switch (RailVehInfo(parent_engine_type)->engclass) { |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2815 |
case 0: scheme = LS_PASSENGER_WAGON_STEAM; break; |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2816 |
case 1: scheme = LS_PASSENGER_WAGON_DIESEL; break; |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2817 |
case 2: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2818 |
} |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2819 |
} |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2820 |
} else { |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2821 |
scheme = LS_FREIGHT_WAGON; |
50d4768623b0
(svn r6456) - Replace single colour scheme for passenger wagons with separate schemes for each of steam, diesel or electric engines. Savegames from the previous revision will not load.
peter1138
parents:
4603
diff
changeset
|
2822 |
} |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2823 |
} else { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2824 |
bool is_mu = HASBIT(_engine_info[engine_type].misc_flags, EF_RAIL_IS_MU); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2825 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2826 |
switch (rvi->engclass) { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2827 |
case 0: scheme = LS_STEAM; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2828 |
case 1: scheme = is_mu ? LS_DMU : LS_DIESEL; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2829 |
case 2: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2830 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2831 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2832 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2833 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2834 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2835 |
case RAILTYPE_MONO: scheme = LS_MONORAIL; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2836 |
case RAILTYPE_MAGLEV: scheme = LS_MAGLEV; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2837 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2838 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2839 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2840 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2841 |
case VEH_Road: { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2842 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2843 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2844 |
scheme = (cargo_type == CT_PASSENGERS) ? LS_BUS : LS_TRUCK; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2845 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2846 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2847 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2848 |
case VEH_Ship: { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2849 |
const ShipVehicleInfo *svi = ShipVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2850 |
if (cargo_type == CT_INVALID) cargo_type = svi->cargo_type; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2851 |
scheme = (cargo_type == CT_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2852 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2853 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2854 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2855 |
case VEH_Aircraft: { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2856 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2857 |
if (cargo_type == CT_INVALID) cargo_type = CT_PASSENGERS; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2858 |
switch (avi->subtype) { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2859 |
case 0: scheme = LS_HELICOPTER; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2860 |
case 1: scheme = LS_SMALL_PLANE; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2861 |
case 3: scheme = LS_LARGE_PLANE; break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2862 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2863 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2864 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2865 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2866 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2867 |
/* Switch back to the default scheme if the resolved scheme is not in use */ |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2868 |
if (!p->livery[scheme].in_use) scheme = LS_DEFAULT; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2869 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2870 |
|
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
|
2871 |
map = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC) ? |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2872 |
(SPR_2CCMAP_BASE + p->livery[scheme].colour1 + p->livery[scheme].colour2 * 16) : |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2873 |
(PALETTE_RECOLOR_START + p->livery[scheme].colour1); |
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
|
2874 |
|
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
|
2875 |
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
|
2876 |
} |
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
|
2877 |
|
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2878 |
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
|
2879 |
{ |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2880 |
return GetEngineColourMap(engine_type, player, INVALID_ENGINE, CT_INVALID); |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2881 |
} |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2882 |
|
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2883 |
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
|
2884 |
{ |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2885 |
if (v->type == VEH_Train) { |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2886 |
return GetEngineColourMap( |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2887 |
(v->u.rail.first_engine != INVALID_ENGINE && (IsArticulatedPart(v) || UsesWagonOverride(v))) ? |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2888 |
v->u.rail.first_engine : v->engine_type, |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2889 |
v->owner, |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2890 |
v->u.rail.first_engine, |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2891 |
v->cargo_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2892 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2893 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
2894 |
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v->cargo_type); |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2895 |
} |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2896 |
|
0 | 2897 |
// 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
|
2898 |
const SaveLoad _common_veh_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2899 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2900 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2901 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2902 |
SLE_VAR(Vehicle, string_id, SLE_STRINGID), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2903 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2904 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, 8, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2905 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2906 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2907 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2908 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2909 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2910 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2911 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2912 |
SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2913 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2914 |
SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2915 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2916 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2917 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2918 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2919 |
SLE_VAR(Vehicle, spritenum, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2920 |
SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2921 |
SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2922 |
SLE_VAR(Vehicle, z_height, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2923 |
SLE_VAR(Vehicle, x_offs, SLE_INT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2924 |
SLE_VAR(Vehicle, y_offs, SLE_INT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2925 |
SLE_VAR(Vehicle, engine_type, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2926 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2927 |
SLE_VAR(Vehicle, max_speed, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2928 |
SLE_VAR(Vehicle, cur_speed, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2929 |
SLE_VAR(Vehicle, subspeed, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2930 |
SLE_VAR(Vehicle, acceleration, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2931 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2932 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2933 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2934 |
SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2935 |
SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, 5, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2936 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2937 |
SLE_VAR(Vehicle, cargo_type, SLE_UINT8), |
4695
3a5bf7ff066b
(svn r6602) - Feature: we now support NewGRF livery refits, as used by DBsetXL, amongst others. This requires a savegame bump to save the cargo subtype.
peter1138
parents:
4685
diff
changeset
|
2938 |
SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, 35, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2939 |
SLE_VAR(Vehicle, cargo_days, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2940 |
SLE_CONDVAR(Vehicle, cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2941 |
SLE_CONDVAR(Vehicle, cargo_source, SLE_UINT16, 7, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2942 |
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2943 |
SLE_VAR(Vehicle, cargo_count, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2944 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2945 |
SLE_VAR(Vehicle, day_counter, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2946 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2947 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2948 |
SLE_VAR(Vehicle, cur_order_index, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2949 |
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
|
2950 |
|
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2951 |
/* 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
|
2952 |
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
|
2953 |
converted correctly */ |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
2954 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 0, 4), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
2955 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2956 |
|
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2957 |
/* Orders for version 5 and on */ |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
2958 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
2959 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
2960 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2961 |
|
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2962 |
/* Refit in current order */ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2963 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION), |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2964 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION), |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2965 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2966 |
SLE_REF(Vehicle, orders, REF_ORDER), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2967 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2968 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2969 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2970 |
SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2971 |
SLE_CONDVAR(Vehicle, max_age, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2972 |
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2973 |
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2974 |
SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2975 |
SLE_CONDVAR(Vehicle, service_interval, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2976 |
SLE_VAR(Vehicle, reliability, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2977 |
SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2978 |
SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2979 |
SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2980 |
SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2981 |
SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2982 |
SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2983 |
SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2984 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2985 |
SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2986 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2987 |
SLE_VAR(Vehicle, profit_this_year, SLE_INT32), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2988 |
SLE_VAR(Vehicle, profit_last_year, SLE_INT32), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2989 |
SLE_VAR(Vehicle, value, SLE_UINT32), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2990 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2991 |
SLE_VAR(Vehicle, random_bits, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2992 |
SLE_VAR(Vehicle, waiting_triggers, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2993 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2994 |
SLE_REF(Vehicle, next_shared, REF_VEHICLE), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2995 |
SLE_REF(Vehicle, prev_shared, REF_VEHICLE), |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2996 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2997 |
// reserve extra space in savegame here. (currently 10 bytes) |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2998 |
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
|
2999 |
|
0 | 3000 |
SLE_END() |
3001 |
}; |
|
3002 |
||
3003 |
||
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
|
3004 |
static const SaveLoad _train_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3005 |
SLE_WRITEBYTE(Vehicle, type, VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file. |
0 | 3006 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3007 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, crash_anim_pos), SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3008 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, force_proceed), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3009 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, railtype), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3010 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, track), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3011 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3012 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRail, flags), SLE_UINT8, 2, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3013 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRail, days_since_order_progr), SLE_UINT16, 2, SL_MAX_VERSION), |
0 | 3014 |
|
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
|
3015 |
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
|
3016 |
// 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
|
3017 |
SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
0 | 3018 |
|
3019 |
SLE_END() |
|
3020 |
}; |
|
3021 |
||
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
|
3022 |
static const SaveLoad _roadveh_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3023 |
SLE_WRITEBYTE(Vehicle, type, VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file. |
0 | 3024 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3025 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, state), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3026 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, frame), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3027 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, blocked_ctr), SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3028 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, overtaking), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3029 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3030 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, crashed_ctr), SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3031 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, reverse_ctr), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3032 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3033 |
SLE_CONDREFX(offsetof(Vehicle, u) + offsetof(VehicleRoad, slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3034 |
SLE_CONDNULL(1, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3035 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
0 | 3036 |
// reserve extra space in savegame here. (currently 16 bytes) |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3037 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3038 |
|
3039 |
SLE_END() |
|
3040 |
}; |
|
3041 |
||
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
|
3042 |
static const SaveLoad _ship_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3043 |
SLE_WRITEBYTE(Vehicle, type, VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file. |
0 | 3044 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3045 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleShip, state), SLE_UINT8), |
0 | 3046 |
|
3047 |
// 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
|
3048 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3049 |
|
3050 |
SLE_END() |
|
3051 |
}; |
|
3052 |
||
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
|
3053 |
static const SaveLoad _aircraft_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3054 |
SLE_WRITEBYTE(Vehicle, type, VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file. |
0 | 3055 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3056 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, crashed_counter), SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3057 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, pos), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3058 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3059 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3060 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3061 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3062 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, state), SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3063 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3064 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 3065 |
|
3066 |
// reserve extra space in savegame here. (currently 15 bytes) |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3067 |
SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
0 | 3068 |
|
3069 |
SLE_END() |
|
3070 |
}; |
|
3071 |
||
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
|
3072 |
static const SaveLoad _special_desc[] = { |
0 | 3073 |
SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4), |
3074 |
||
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3075 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3076 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3077 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3078 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3079 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3080 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3081 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3082 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3083 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3084 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3085 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3086 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3087 |
SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3088 |
SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3089 |
SLE_VAR(Vehicle, z_height, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3090 |
SLE_VAR(Vehicle, x_offs, SLE_INT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3091 |
SLE_VAR(Vehicle, y_offs, SLE_INT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3092 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3093 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3094 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3095 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleSpecial, unk0), SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3096 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleSpecial, unk2), SLE_UINT8), |
0 | 3097 |
|
3098 |
// 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
|
3099 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3100 |
|
3101 |
SLE_END() |
|
3102 |
}; |
|
3103 |
||
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
|
3104 |
static const SaveLoad _disaster_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3105 |
SLE_WRITEBYTE(Vehicle, type, VEH_Disaster, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3106 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3107 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3108 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3109 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3110 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3111 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3112 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3113 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3114 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3115 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3116 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3117 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3118 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3119 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3120 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3121 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3122 |
SLE_VAR(Vehicle, x_offs, SLE_INT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3123 |
SLE_VAR(Vehicle, y_offs, SLE_INT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3124 |
SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3125 |
SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3126 |
SLE_VAR(Vehicle, z_height, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3127 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3128 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
3129 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4515
diff
changeset
|
3130 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3131 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3132 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3133 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3134 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3135 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3136 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3137 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleDisaster, image_override), SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3138 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleDisaster, unk2), SLE_UINT16), |
0 | 3139 |
|
3140 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3141 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3142 |
|
3143 |
SLE_END() |
|
3144 |
}; |
|
3145 |
||
3146 |
||
3147 |
static const void *_veh_descs[] = { |
|
3148 |
_train_desc, |
|
3149 |
_roadveh_desc, |
|
3150 |
_ship_desc, |
|
3151 |
_aircraft_desc, |
|
3152 |
_special_desc, |
|
3153 |
_disaster_desc, |
|
3154 |
}; |
|
3155 |
||
3156 |
// 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
|
3157 |
static void Save_VEHS(void) |
0 | 3158 |
{ |
3159 |
Vehicle *v; |
|
3160 |
// Write the vehicles |
|
3161 |
FOR_ALL_VEHICLES(v) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3162 |
SlSetArrayIndex(v->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3163 |
SlObject(v, _veh_descs[v->type - 0x10]); |
0 | 3164 |
} |
3165 |
} |
|
3166 |
||
3167 |
// 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
|
3168 |
static void Load_VEHS(void) |
0 | 3169 |
{ |
3170 |
int index; |
|
3171 |
Vehicle *v; |
|
3172 |
||
3173 |
while ((index = SlIterateArray()) != -1) { |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3174 |
Vehicle *v; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
3175 |
|
4972 | 3176 |
if (!AddBlockIfNeeded(&_Vehicle_pool, index)) |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3177 |
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
|
3178 |
|
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3179 |
v = GetVehicle(index); |
0 | 3180 |
SlObject(v, _veh_descs[SlReadByte()]); |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3181 |
|
2549 | 3182 |
/* 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
|
3183 |
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
|
3184 |
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
|
3185 |
|
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3186 |
if (CheckSavegameVersion(5)) { |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3187 |
/* Convert the current_order.type (which is a mix of type and flags, because |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
3188 |
* in those versions, they both were 4 bits big) to type and flags */ |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3189 |
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
|
3190 |
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
|
3191 |
} |
0 | 3192 |
} |
3193 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3194 |
/* 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
|
3195 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3196 |
FOR_ALL_VEHICLES(v) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3197 |
Vehicle *u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3198 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3199 |
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
|
3200 |
/* If a vehicle has the same orders, add the link to eachother |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
3201 |
* in both vehicles */ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3202 |
if (v->orders == u->orders) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3203 |
v->next_shared = u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3204 |
u->prev_shared = v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3205 |
break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3206 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3207 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3208 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3209 |
} |
0 | 3210 |
} |
3211 |
||
3212 |
const ChunkHandler _veh_chunk_handlers[] = { |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1541
diff
changeset
|
3213 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 3214 |
}; |