author | rubidium |
Sun, 09 Sep 2007 22:35:21 +0000 | |
branch | 0.5 |
changeset 5543 | 4d8dfa498905 |
parent 5541 | 08e4afe5e927 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
3957
3c39694becd2
(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
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
7 |
#include "ship.h" |
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1328
diff
changeset
|
8 |
#include "spritecache.h" |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
9 |
#include "table/sprites.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
10 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2148
diff
changeset
|
11 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
12 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1192
diff
changeset
|
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
66647f97e7c0
(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
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
23 |
#include "debug.h" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
24 |
#include "vehicle_gui.h" |
1758
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
25 |
#include "depot.h" |
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
26 |
#include "station.h" |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
27 |
#include "rail.h" |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
28 |
#include "train.h" |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
29 |
#include "aircraft.h" |
3428
62682d91b4cd
(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
3ac4f7fedfb5
(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
3c39694becd2
(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
9c293b171871
(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" |
9c293b171871
(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
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4176
diff
changeset
|
35 |
#include "date.h" |
4603
3ccd4ee0a2e2
(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
acffecd6f484
(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 |
|
5512
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
39 |
#define INVALID_COORD (0x7fffffff) |
4174
9ba4e15dac0f
(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
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
42 |
/* |
4434
4175805666a5
(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 |
4175805666a5
(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)) |
4175805666a5
(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 |
4175805666a5
(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
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
47 |
*/ |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
48 |
|
4434
4175805666a5
(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] |
4175805666a5
(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] |
4175805666a5
(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
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
52 |
|
2630 | 53 |
static const uint32 _veh_build_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
54 |
CMD_BUILD_RAIL_VEHICLE, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
55 |
CMD_BUILD_ROAD_VEH, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
56 |
CMD_BUILD_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
57 |
CMD_BUILD_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
58 |
}; |
2630 | 59 |
static const uint32 _veh_sell_proc_table[] = { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
60 |
CMD_SELL_RAIL_WAGON, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
61 |
CMD_SELL_ROAD_VEH, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
62 |
CMD_SELL_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
63 |
CMD_SELL_AIRCRAFT, |
fb174febb0b1
(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
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
67 |
CMD_REFIT_RAIL_VEHICLE, |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
68 |
CMD_REFIT_ROAD_VEH, |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
69 |
CMD_REFIT_SHIP, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
70 |
CMD_REFIT_AIRCRAFT, |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
71 |
}; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
72 |
|
4451
66603f0f732e
(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
b44566fc9025
(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
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
75 |
CMD_SEND_ROADVEH_TO_DEPOT, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
76 |
CMD_SEND_SHIP_TO_DEPOT, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
77 |
CMD_SEND_AIRCRAFT_TO_HANGAR, |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
78 |
}; |
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
79 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
80 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
81 |
enum { |
3173
1b75b9a6ff71
(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
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
83 |
}; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
84 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
85 |
/** |
4f83fbde72de
(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 |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
87 |
*/ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
88 |
static void VehiclePoolNewBlock(uint start_item) |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
89 |
{ |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
90 |
Vehicle *v; |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
91 |
|
4346
3f00094f2670
(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. |
3f00094f2670
(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
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
95 |
} |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
96 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
97 |
/* Initialize the vehicle-pool */ |
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
5211
diff
changeset
|
98 |
DEFINE_OLD_POOL(Vehicle, Vehicle, VehiclePoolNewBlock, NULL) |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
99 |
|
578
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
100 |
void VehicleServiceInDepot(Vehicle *v) |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
101 |
{ |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
102 |
v->date_of_last_service = _date; |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
103 |
v->breakdowns_since_last_service = 0; |
1926
68d60188a22f
(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
f7284b86833f
(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
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
106 |
} |
0 | 107 |
|
593 | 108 |
bool VehicleNeedsService(const Vehicle *v) |
109 |
{ |
|
1757
b179d50241dc
(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) |
b179d50241dc
(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 */ |
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
112 |
|
4262
4657d940a84c
(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
22d7a462e150
(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
4657d940a84c
(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 |
} |
4657d940a84c
(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
79c99885ad00
(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
68d60188a22f
(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
13daba67f217
(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
13daba67f217
(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
88d71dbdcd13
(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
88d71dbdcd13
(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
88d71dbdcd13
(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
88d71dbdcd13
(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; |
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
149 |
|
2871
66b55a022d12
(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
ac26a7b4615d
(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
88d71dbdcd13
(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
56a4c048c5c3
(svn r1583) -Fix: You should no longer be able to delete bridges on any type of underground when there is a vehicle on it
darkvater
parents:
1068
diff
changeset
|
157 |
|
3794
ac26a7b4615d
(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
88d71dbdcd13
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
161 |
|
2871
66b55a022d12
(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
ac26a7b4615d
(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
88d71dbdcd13
(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
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
167 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
168 |
{ |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
169 |
TileInfo ti; |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
170 |
|
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
171 |
ti.tile = tile; |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
172 |
ti.z = z; |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
173 |
|
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
174 |
return VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ); |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
175 |
} |
c4630be67467
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
176 |
|
5427
63ce73145566
(svn r8623) [0.5] -Backport from trunk (8593, 8608, 8619, 8620)
rubidium
parents:
5418
diff
changeset
|
177 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed) |
0 | 178 |
{ |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
179 |
int x1 = TileX(from); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
180 |
int y1 = TileY(from); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
181 |
int x2 = TileX(to); |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
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
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
190 |
FOR_ALL_VEHICLES(veh) { |
5427
63ce73145566
(svn r8623) [0.5] -Backport from trunk (8593, 8608, 8619, 8620)
rubidium
parents:
5418
diff
changeset
|
191 |
if (without_crashed && (veh->vehstatus & VS_CRASHED) != 0) continue; |
0 | 192 |
if ((veh->type == VEH_Train || veh->type == VEH_Road) && (z==0xFF || veh->z_pos == z)) { |
193 |
if ((veh->x_pos>>4) >= x1 && (veh->x_pos>>4) <= x2 && |
|
194 |
(veh->y_pos>>4) >= y1 && (veh->y_pos>>4) <= y2) { |
|
195 |
return veh; |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
return NULL; |
|
200 |
} |
|
201 |
||
2817 | 202 |
|
203 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y); |
|
204 |
||
0 | 205 |
void VehiclePositionChanged(Vehicle *v) |
206 |
{ |
|
207 |
int img = v->cur_image; |
|
208 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
209 |
const Sprite* spr = GetSprite(img); |
0 | 210 |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
211 |
pt.x += spr->x_offs; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
212 |
pt.y += spr->y_offs; |
0 | 213 |
|
214 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
215 |
||
216 |
v->left_coord = pt.x; |
|
217 |
v->top_coord = pt.y; |
|
2319
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
218 |
v->right_coord = pt.x + spr->width + 2; |
9902d3ffa309
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
219 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 220 |
} |
221 |
||
222 |
// Called after load to update coordinates |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
223 |
void AfterLoadVehicles(void) |
0 | 224 |
{ |
225 |
Vehicle *v; |
|
226 |
||
227 |
FOR_ALL_VEHICLES(v) { |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
228 |
v->first = NULL; |
3355
a653b8e47f27
(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 |
if (v->type == VEH_Train) v->u.rail.first_engine = INVALID_ENGINE; |
a653b8e47f27
(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 |
} |
a653b8e47f27
(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 |
|
a653b8e47f27
(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
|
232 |
FOR_ALL_VEHICLES(v) { |
2994
897b81cf1bba
(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 |
if (v->type == VEH_Train && (IsFrontEngine(v) || IsFreeWagon(v))) |
897b81cf1bba
(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 |
TrainConsistChanged(v); |
897b81cf1bba
(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 |
} |
897b81cf1bba
(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 |
|
897b81cf1bba
(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
|
237 |
FOR_ALL_VEHICLES(v) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
238 |
switch (v->type) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
239 |
case VEH_Train: v->cur_image = GetTrainImage(v, v->direction); break; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
240 |
case VEH_Road: v->cur_image = GetRoadVehImage(v, v->direction); break; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
241 |
case VEH_Ship: v->cur_image = GetShipImage(v, v->direction); break; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
242 |
case VEH_Aircraft: |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
243 |
if (v->subtype == 0 || v->subtype == 2) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
244 |
v->cur_image = GetAircraftImage(v, v->direction); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
245 |
if (v->next != NULL) v->next->cur_image = v->cur_image; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
246 |
} |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
247 |
break; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
248 |
default: break; |
0 | 249 |
} |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
250 |
|
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
251 |
v->left_coord = INVALID_COORD; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
252 |
VehiclePositionChanged(v); |
0 | 253 |
} |
254 |
} |
|
255 |
||
256 |
static Vehicle *InitializeVehicle(Vehicle *v) |
|
257 |
{ |
|
258 |
VehicleID index = v->index; |
|
259 |
memset(v, 0, sizeof(Vehicle)); |
|
260 |
v->index = index; |
|
261 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
262 |
assert(v->orders == NULL); |
0 | 263 |
|
264 |
v->left_coord = INVALID_COORD; |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
265 |
v->first = NULL; |
0 | 266 |
v->next = NULL; |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
267 |
v->next_hash = INVALID_VEHICLE; |
0 | 268 |
v->string_id = 0; |
1111
2184bf930d25
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
269 |
v->next_shared = NULL; |
2184bf930d25
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1109
diff
changeset
|
270 |
v->prev_shared = NULL; |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
271 |
v->depot_list = NULL; |
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
272 |
v->random_bits = 0; |
0 | 273 |
return v; |
274 |
} |
|
275 |
||
2804
b932fe148d36
(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 |
/** |
b932fe148d36
(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 |
* Get a value for a vehicle's random_bits. |
b932fe148d36
(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 |
* @return A random value from 0 to 255. |
b932fe148d36
(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 |
*/ |
b932fe148d36
(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 |
byte VehicleRandomBits(void) |
b932fe148d36
(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 |
{ |
b932fe148d36
(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 |
return GB(Random(), 0, 8); |
b932fe148d36
(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 |
} |
b932fe148d36
(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
|
284 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
285 |
Vehicle *ForceAllocateSpecialVehicle(void) |
0 | 286 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
287 |
/* This stays a strange story.. there should always be room for special |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
288 |
* vehicles (special effects all over the map), but with 65k of vehicles |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
289 |
* is this realistic to double-check for that? For now we just reserve |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
290 |
* BLOCKS_FOR_SPECIAL_VEHICLES times block_size vehicles that may only |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
291 |
* be used for special vehicles.. should work nicely :) */ |
0 | 292 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
293 |
Vehicle *v; |
0 | 294 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
295 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
296 |
* TODO - This is just a temporary stage, this will be removed. */ |
4972 | 297 |
for (v = GetVehicle(0); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) { |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
298 |
/* No more room for the special vehicles, return NULL */ |
4972 | 299 |
if (v->index >= (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES) |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
300 |
return NULL; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
301 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
302 |
if (!IsValidVehicle(v)) return InitializeVehicle(v); |
0 | 303 |
} |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
304 |
|
0 | 305 |
return NULL; |
306 |
} |
|
307 |
||
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
308 |
/* |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
309 |
* finds a free vehicle in the memory or allocates a new one |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
310 |
* returns a pointer to the first free vehicle or NULL if all vehicles are in use |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
311 |
* *skip_vehicles is an offset to where in the array we should begin looking |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
312 |
* this is to avoid looping though the same vehicles more than once after we learned that they are not free |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
313 |
* this feature is used by AllocateVehicles() since it need to allocate more than one and when |
4972 | 314 |
* another block is added to _Vehicle_pool, since we only do that when we know it's already full |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
315 |
*/ |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
316 |
static Vehicle *AllocateSingleVehicle(VehicleID *skip_vehicles) |
0 | 317 |
{ |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
318 |
/* See note by ForceAllocateSpecialVehicle() why we skip the |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
319 |
* first blocks */ |
0 | 320 |
Vehicle *v; |
4972 | 321 |
const int offset = (1 << Vehicle_POOL_BLOCK_SIZE_BITS) * BLOCKS_FOR_SPECIAL_VEHICLES; |
0 | 322 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
323 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
324 |
* TODO - This is just a temporary stage, this will be removed. */ |
4972 | 325 |
if (*skip_vehicles < (_Vehicle_pool.total_items - offset)) { // make sure the offset in the array is not larger than the array itself |
326 |
for (v = GetVehicle(offset + *skip_vehicles); v != NULL; v = (v->index + 1U < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL) { |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
327 |
(*skip_vehicles)++; |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
328 |
if (!IsValidVehicle(v)) return InitializeVehicle(v); |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
329 |
} |
0 | 330 |
} |
331 |
||
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
332 |
/* Check if we can add a block to the pool */ |
4972 | 333 |
if (AddBlockToPool(&_Vehicle_pool)) |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
334 |
return AllocateSingleVehicle(skip_vehicles); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
335 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
336 |
return NULL; |
0 | 337 |
} |
338 |
||
2639 | 339 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
340 |
Vehicle *AllocateVehicle(void) |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
341 |
{ |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
342 |
VehicleID counter = 0; |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
343 |
return AllocateSingleVehicle(&counter); |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
344 |
} |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
345 |
|
2639 | 346 |
|
2601
7c94a0e394a6
(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
|
347 |
/** Allocates a lot of vehicles and frees them again |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
348 |
* @param vl pointer to an array of vehicles to get allocated. Can be NULL if the vehicles aren't needed (makes it test only) |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
349 |
* @param num number of vehicles to allocate room for |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
350 |
* @return true if there is room to allocate all the vehicles |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
351 |
*/ |
2601
7c94a0e394a6
(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 |
bool AllocateVehicles(Vehicle **vl, int num) |
7c94a0e394a6
(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 |
{ |
7c94a0e394a6
(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 |
int i; |
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
355 |
Vehicle *v; |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
356 |
VehicleID counter = 0; |
2601
7c94a0e394a6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
357 |
|
2952 | 358 |
for (i = 0; i != num; i++) { |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
359 |
v = AllocateSingleVehicle(&counter); |
2601
7c94a0e394a6
(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
|
360 |
if (v == NULL) { |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
361 |
return false; |
2601
7c94a0e394a6
(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
|
362 |
} |
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
363 |
if (vl != NULL) { |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
364 |
vl[i] = v; |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
365 |
} |
2601
7c94a0e394a6
(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 |
} |
7c94a0e394a6
(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
|
367 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
368 |
return true; |
2601
7c94a0e394a6
(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 |
} |
7c94a0e394a6
(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 |
|
7c94a0e394a6
(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
|
371 |
|
2651 | 372 |
static VehicleID _vehicle_position_hash[0x1000]; |
373 |
||
0 | 374 |
void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
375 |
{ |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3413
diff
changeset
|
376 |
Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, 0); |
0 | 377 |
|
4174
9ba4e15dac0f
(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 |
// The hash area to scan |
9ba4e15dac0f
(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 xl = GB(pt.x - 174, 7, 6); |
9ba4e15dac0f
(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 xu = GB(pt.x + 104, 7, 6); |
9ba4e15dac0f
(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 yl = GB(pt.y - 294, 6, 6) << 6; |
9ba4e15dac0f
(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 |
const int yu = GB(pt.y + 56, 6, 6) << 6; |
9ba4e15dac0f
(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 |
|
9ba4e15dac0f
(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 x; |
9ba4e15dac0f
(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 |
int y; |
9ba4e15dac0f
(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 |
|
9ba4e15dac0f
(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 (y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
9ba4e15dac0f
(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
|
388 |
for (x = xl;; x = (x + 1) & 0x3F) { |
2639 | 389 |
VehicleID veh = _vehicle_position_hash[(x + y) & 0xFFFF]; |
4174
9ba4e15dac0f
(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
|
390 |
|
0 | 391 |
while (veh != INVALID_VEHICLE) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
392 |
Vehicle *v = GetVehicle(veh); |
4174
9ba4e15dac0f
(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 |
void* a = proc(v, data); |
9ba4e15dac0f
(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
|
394 |
|
2639 | 395 |
if (a != NULL) return a; |
0 | 396 |
veh = v->next_hash; |
397 |
} |
|
398 |
||
4174
9ba4e15dac0f
(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
|
399 |
if (x == xu) break; |
0 | 400 |
} |
4174
9ba4e15dac0f
(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 |
|
9ba4e15dac0f
(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
|
402 |
if (y == yu) break; |
0 | 403 |
} |
404 |
return NULL; |
|
405 |
} |
|
406 |
||
407 |
||
2817 | 408 |
static void UpdateVehiclePosHash(Vehicle* v, int x, int y) |
0 | 409 |
{ |
410 |
VehicleID *old_hash, *new_hash; |
|
411 |
int old_x = v->left_coord; |
|
412 |
int old_y = v->top_coord; |
|
413 |
Vehicle *u; |
|
414 |
||
415 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x,y)]; |
|
416 |
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
|
417 |
|
2639 | 418 |
if (old_hash == new_hash) return; |
0 | 419 |
|
420 |
/* remove from hash table? */ |
|
421 |
if (old_hash != NULL) { |
|
422 |
Vehicle *last = NULL; |
|
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2469
diff
changeset
|
423 |
VehicleID idx = *old_hash; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
424 |
while ((u = GetVehicle(idx)) != v) { |
0 | 425 |
idx = u->next_hash; |
426 |
assert(idx != INVALID_VEHICLE); |
|
427 |
last = u; |
|
428 |
} |
|
429 |
||
2639 | 430 |
if (last == NULL) { |
0 | 431 |
*old_hash = v->next_hash; |
2639 | 432 |
} else { |
0 | 433 |
last->next_hash = v->next_hash; |
2639 | 434 |
} |
0 | 435 |
} |
436 |
||
437 |
/* insert into hash table? */ |
|
438 |
if (new_hash != NULL) { |
|
439 |
v->next_hash = *new_hash; |
|
440 |
*new_hash = v->index; |
|
441 |
} |
|
442 |
} |
|
443 |
||
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
444 |
void ResetVehiclePosHash(void) |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
445 |
{ |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
446 |
uint i; |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
447 |
for (i = 0; i < lengthof(_vehicle_position_hash); i++) { |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
448 |
_vehicle_position_hash[i] = INVALID_VEHICLE; |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
449 |
} |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
450 |
} |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
451 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
452 |
void InitializeVehicles(void) |
0 | 453 |
{ |
4174
9ba4e15dac0f
(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
|
454 |
uint i; |
0 | 455 |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
456 |
/* Clean the vehicle pool, and reserve enough blocks |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
457 |
* for the special vehicles, plus one for all the other |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
458 |
* vehicles (which is increased on-the-fly) */ |
4972 | 459 |
CleanPool(&_Vehicle_pool); |
460 |
AddBlockToPool(&_Vehicle_pool); |
|
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
461 |
for (i = 0; i < BLOCKS_FOR_SPECIAL_VEHICLES; i++) { |
4972 | 462 |
AddBlockToPool(&_Vehicle_pool); |
4174
9ba4e15dac0f
(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
|
463 |
} |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
464 |
|
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
465 |
ResetVehiclePosHash(); |
0 | 466 |
} |
467 |
||
468 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
469 |
{ |
|
470 |
while (v->next != NULL) v = v->next; |
|
471 |
return v; |
|
472 |
} |
|
473 |
||
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
474 |
/** Finds the previous vehicle in a chain, by a brute force search. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
475 |
* This old function is REALLY slow because it searches through all vehicles to |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
476 |
* find the previous vehicle, but if v->first has not been set, then this function |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
477 |
* will need to be used to find the previous one. This function should never be |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
478 |
* called by anything but GetFirstVehicleInChain |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
479 |
*/ |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
480 |
static Vehicle *GetPrevVehicleInChain_bruteforce(const Vehicle *v) |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
481 |
{ |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
482 |
Vehicle *u; |
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
483 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
484 |
FOR_ALL_VEHICLES(u) if (u->type == VEH_Train && u->next == v) return u; |
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1985
diff
changeset
|
485 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
486 |
return NULL; |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
487 |
} |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
488 |
|
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
489 |
/** Find the previous vehicle in a chain, by using the v->first cache. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
490 |
* While this function is fast, it cannot be used in the GetFirstVehicleInChain |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
491 |
* function, otherwise you'll end up in an infinite loop call |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
492 |
*/ |
1475 | 493 |
Vehicle *GetPrevVehicleInChain(const Vehicle *v) |
0 | 494 |
{ |
1600
b2bd1eaed056
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
495 |
Vehicle *u; |
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
496 |
assert(v != NULL); |
0 | 497 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
498 |
u = GetFirstVehicleInChain(v); |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
499 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
500 |
// Check to see if this is the first |
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
501 |
if (v == u) return NULL; |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
502 |
|
4165
cc731ade23bb
(svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents:
4130
diff
changeset
|
503 |
for (; u->next != v; u = u->next) assert(u->next != NULL); |
cc731ade23bb
(svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents:
4130
diff
changeset
|
504 |
|
cc731ade23bb
(svn r5599) GetPrevVehicleInChain() may never fail to find a valid vehicle. Reflect this in the code
tron
parents:
4130
diff
changeset
|
505 |
return u; |
0 | 506 |
} |
507 |
||
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
508 |
/** Finds the first vehicle in a chain. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
509 |
* This function reads out the v->first cache. Should the cache be dirty, |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
510 |
* it determines the first vehicle in a chain, and updates the cache. |
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
511 |
*/ |
1475 | 512 |
Vehicle *GetFirstVehicleInChain(const Vehicle *v) |
0 | 513 |
{ |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
514 |
Vehicle* u; |
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
515 |
|
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
516 |
assert(v != NULL); |
5446
68d042c57e9e
(svn r8874) [0.5] -Backport from trunk (r8744, r8685):
Darkvater
parents:
5442
diff
changeset
|
517 |
assert(v->type == VEH_Train); |
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
518 |
|
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
519 |
if (v->first != NULL) { |
2998
811ec359a2e3
(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
|
520 |
if (IsFrontEngine(v->first) || IsFreeWagon(v->first)) return v->first; |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
521 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
522 |
DEBUG(misc, 0) ("v->first cache faulty. We shouldn't be here, rebuilding cache!"); |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
523 |
} |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
524 |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
525 |
/* It is the fact (currently) that newly built vehicles do not have |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
526 |
* their ->first pointer set. When this is the case, go up to the |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
527 |
* first engine and set the pointers correctly. Also the first pointer |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
528 |
* is not saved in a savegame, so this has to be fixed up after loading */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
529 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
530 |
/* Find the 'locomotive' or the first wagon in a chain */ |
1985
c4ec1653a337
(svn r2491) -Fix: Solved a performance problem introduced in r2467. While busy
celestar
parents:
1980
diff
changeset
|
531 |
while ((u = GetPrevVehicleInChain_bruteforce(v)) != NULL) v = u; |
1600
b2bd1eaed056
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
532 |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
533 |
/* Set the first pointer of all vehicles in that chain to the first wagon */ |
2998
811ec359a2e3
(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
|
534 |
if (IsFrontEngine(v) || IsFreeWagon(v)) |
1601
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
535 |
for (u = (Vehicle *)v; u != NULL; u = u->next) u->first = (Vehicle *)v; |
9fd461d00287
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
536 |
|
1600
b2bd1eaed056
(svn r2104) Simplify implementation of Get{First,Prev}VehicleInChain() and remove a pointless check
tron
parents:
1542
diff
changeset
|
537 |
return (Vehicle*)v; |
0 | 538 |
} |
539 |
||
2630 | 540 |
uint CountVehiclesInChain(const Vehicle* v) |
0 | 541 |
{ |
2639 | 542 |
uint count = 0; |
543 |
do count++; while ((v = v->next) != NULL); |
|
0 | 544 |
return count; |
545 |
} |
|
546 |
||
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
547 |
/** Check if a vehicle is counted in num_engines in each player struct |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
548 |
* @param *v Vehicle to test |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
549 |
* @return true if the vehicle is counted in num_engines |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
550 |
*/ |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
551 |
bool IsEngineCountable(const Vehicle *v) |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
552 |
{ |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
553 |
switch (v->type) { |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
554 |
case VEH_Aircraft: return (v->subtype <= 2); // don't count plane shadows and helicopter rotors |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
555 |
case VEH_Train: |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
556 |
return !IsArticulatedPart(v) && // tenders and other articulated parts |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
557 |
(!IsMultiheaded(v) || IsTrainEngine(v)); // rear parts of multiheaded engines |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
558 |
case VEH_Road: |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
559 |
case VEH_Ship: |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
560 |
return true; |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
561 |
default: return false; // Only count player buildable vehicles |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
562 |
} |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
563 |
} |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
564 |
|
4404
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
565 |
void DestroyVehicle(Vehicle *v) |
0 | 566 |
{ |
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
567 |
if (IsEngineCountable(v)) GetPlayer(v->owner)->num_engines[v->engine_type]--; |
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
568 |
|
3139
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3132
diff
changeset
|
569 |
DeleteVehicleNews(v->index, INVALID_STRING_ID); |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3132
diff
changeset
|
570 |
|
4404
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
571 |
DeleteName(v->string_id); |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
572 |
if (v->type == VEH_Road) ClearSlot(v); |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
573 |
|
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
574 |
if (v->type != VEH_Train || (v->type == VEH_Train && (IsFrontEngine(v) || IsFreeWagon(v)))) { |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
575 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
576 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
577 |
|
4404
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
578 |
UpdateVehiclePosHash(v, INVALID_COORD, 0); |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
579 |
v->next_hash = INVALID_VEHICLE; |
5430
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5427
diff
changeset
|
580 |
if (IsPlayerBuildableVehicleType(v)) DeleteVehicleOrders(v); |
4404
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
581 |
|
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
582 |
/* Now remove any artic part. This will trigger an other |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
583 |
* destroy vehicle, which on his turn can remove any |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
584 |
* other artic parts. */ |
484c76b14294
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
585 |
if (EngineHasArticPart(v)) DeleteVehicle(v->next); |
0 | 586 |
} |
587 |
||
588 |
void DeleteVehicleChain(Vehicle *v) |
|
589 |
{ |
|
590 |
do { |
|
591 |
Vehicle *u = v; |
|
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
592 |
v = GetNextVehicle(v); |
0 | 593 |
DeleteVehicle(u); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
594 |
} while (v != NULL); |
0 | 595 |
} |
596 |
||
597 |
||
598 |
void Aircraft_Tick(Vehicle *v); |
|
599 |
void RoadVeh_Tick(Vehicle *v); |
|
600 |
void Ship_Tick(Vehicle *v); |
|
601 |
void Train_Tick(Vehicle *v); |
|
410 | 602 |
static void EffectVehicle_Tick(Vehicle *v); |
0 | 603 |
void DisasterVehicle_Tick(Vehicle *v); |
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
604 |
static int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs); |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
605 |
|
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
606 |
// head of the linked list to tell what vehicles that visited a depot in a tick |
2630 | 607 |
static Vehicle* _first_veh_in_depot_list; |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
608 |
|
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
609 |
/** Adds a vehicle to the list of vehicles, that visited a depot this tick |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
610 |
* @param *v vehicle to add |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
611 |
*/ |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
612 |
void VehicleEnteredDepotThisTick(Vehicle *v) |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
613 |
{ |
2579
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
614 |
// we need to set v->leave_depot_instantly as we have no control of it's contents at this time |
2600
2e6079e37708
(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
|
615 |
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
5603f43c8cd3
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
616 |
// we keep the vehicle in the depot since the user ordered it to stay |
5603f43c8cd3
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
617 |
v->leave_depot_instantly = false; |
5603f43c8cd3
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
618 |
} else { |
2579
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
619 |
// the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
620 |
// out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
621 |
// we store that we stopped the vehicle, so autoreplace can start it again |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
622 |
v->vehstatus |= VS_STOPPED; |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
623 |
v->leave_depot_instantly = true; |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
624 |
} |
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
625 |
|
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
626 |
if (_first_veh_in_depot_list == NULL) { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
627 |
_first_veh_in_depot_list = v; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
628 |
} else { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
629 |
Vehicle *w = _first_veh_in_depot_list; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
630 |
while (w->depot_list != NULL) w = w->depot_list; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
631 |
w->depot_list = v; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
632 |
} |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
633 |
} |
0 | 634 |
|
4176 | 635 |
typedef void VehicleTickProc(Vehicle*); |
2752 | 636 |
static VehicleTickProc* _vehicle_tick_procs[] = { |
0 | 637 |
Train_Tick, |
638 |
RoadVeh_Tick, |
|
639 |
Ship_Tick, |
|
640 |
Aircraft_Tick, |
|
641 |
EffectVehicle_Tick, |
|
642 |
DisasterVehicle_Tick, |
|
643 |
}; |
|
644 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
645 |
void CallVehicleTicks(void) |
0 | 646 |
{ |
647 |
Vehicle *v; |
|
648 |
||
4130
9c293b171871
(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
|
649 |
#ifdef ENABLE_NETWORK |
9c293b171871
(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
|
650 |
// hotfix for desync problem: |
9c293b171871
(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
|
651 |
// for MP games invalidate the YAPF cache every tick to keep it exactly the same on the server and all clients |
9c293b171871
(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
|
652 |
if (_networking) { |
9c293b171871
(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
|
653 |
YapfNotifyTrackLayoutChange(0, 0); |
9c293b171871
(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
|
654 |
} |
9c293b171871
(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
|
655 |
#endif //ENABLE_NETWORK |
9c293b171871
(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
|
656 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
657 |
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
658 |
|
0 | 659 |
FOR_ALL_VEHICLES(v) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
660 |
_vehicle_tick_procs[v->type - 0x10](v); |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
661 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
662 |
switch (v->type) { |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
663 |
case VEH_Train: |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
664 |
case VEH_Road: |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
665 |
case VEH_Aircraft: |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
666 |
case VEH_Ship: |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
667 |
if (v->type == VEH_Train && IsTrainWagon(v)) continue; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
668 |
if (v->type == VEH_Aircraft && v->subtype > 0) continue; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
669 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
670 |
v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
671 |
/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
672 |
if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
673 |
|
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
674 |
/* Play an alterate running sound every 16 ticks */ |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
675 |
if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
676 |
} |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
677 |
} |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
678 |
|
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
679 |
// now we handle all the vehicles that entered a depot this tick |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
680 |
v = _first_veh_in_depot_list; |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
681 |
while (v != NULL) { |
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
682 |
Vehicle *w = v->depot_list; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
683 |
v->depot_list = NULL; // it should always be NULL at the end of each tick |
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
684 |
MaybeReplaceVehicle(v, false, true); |
2574
382fd3f37604
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
685 |
v = w; |
0 | 686 |
} |
687 |
} |
|
688 |
||
689 |
static bool CanFillVehicle_FullLoadAny(Vehicle *v) |
|
690 |
{ |
|
691 |
uint32 full = 0, not_full = 0; |
|
5357
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
692 |
bool keep_loading = false; |
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
693 |
const GoodsEntry *ge = GetStation(v->last_station_visited)->goods; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
694 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
695 |
//special handling of aircraft |
941
4a695e126035
(svn r1429) Change: bumped savegame to revision 5.
truelight
parents:
939
diff
changeset
|
696 |
|
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
697 |
//if the aircraft carries passengers and is NOT full, then |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
698 |
//continue loading, no matter how much mail is in |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
699 |
if (v->type == VEH_Aircraft && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
700 |
v->cargo_type == CT_PASSENGERS && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
701 |
v->cargo_cap != v->cargo_count) { |
924
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
702 |
return true; |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
703 |
} |
433faaf547c1
(svn r1412) -Feature/Fix: Aircraft refit options have been restricted to "sane"
celestar
parents:
922
diff
changeset
|
704 |
|
0 | 705 |
// patch should return "true" to continue loading, i.e. when there is no cargo type that is fully loaded. |
706 |
do { |
|
707 |
//Should never happen, but just in case future additions change this |
|
708 |
assert(v->cargo_type<32); |
|
709 |
||
710 |
if (v->cargo_cap != 0) { |
|
711 |
uint32 mask = 1 << v->cargo_type; |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
712 |
|
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
713 |
if (v->cargo_cap == v->cargo_count) { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
714 |
full |= mask; |
5357
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
715 |
} else if (GB(ge[v->cargo_type].waiting_acceptance, 0, 12) > 0 || |
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
716 |
(HASBIT(v->load_status, LS_CARGO_UNLOADING) && (ge[v->cargo_type].waiting_acceptance & 0x8000))) { |
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
717 |
/* If there is any cargo waiting, or this vehicle is still unloading |
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
718 |
* and the station accepts the cargo, don't leave the station. */ |
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
719 |
keep_loading = true; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
720 |
} else { |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
721 |
not_full |= mask; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
722 |
} |
0 | 723 |
} |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
724 |
} while ((v = v->next) != NULL); |
0 | 725 |
|
726 |
// continue loading if there is a non full cargo type and no cargo type that is full |
|
5357
5b116a5a3044
(svn r7535) -Fix (r7326): Always unload cargo if the station accepts it, and always load cargo
Darkvater
parents:
5352
diff
changeset
|
727 |
return keep_loading || (not_full && (full & ~not_full) == 0); |
0 | 728 |
} |
729 |
||
730 |
bool CanFillVehicle(Vehicle *v) |
|
731 |
{ |
|
1058
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
732 |
TileIndex tile = v->tile; |
0 | 733 |
|
1058
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
734 |
if (IsTileType(tile, MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
735 |
(v->type == VEH_Ship && ( |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
736 |
IsTileType(TILE_ADDXY(tile, 1, 0), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
737 |
IsTileType(TILE_ADDXY(tile, -1, 0), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
738 |
IsTileType(TILE_ADDXY(tile, 0, 1), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
739 |
IsTileType(TILE_ADDXY(tile, 0, -1), MP_STATION) || |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
740 |
IsTileType(TILE_ADDXY(tile, -2, 0), MP_STATION) |
0a1a77da0a03
(svn r1559) Use IsTileType() instead of bit shifting and comparisons
tron
parents:
1037
diff
changeset
|
741 |
))) { |
0 | 742 |
|
743 |
// If patch is active, use alternative CanFillVehicle-function |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5062
diff
changeset
|
744 |
if (_patches.full_load_any && v->current_order.flags & OF_FULL_LOAD) return CanFillVehicle_FullLoadAny(v); |
0 | 745 |
|
746 |
do { |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
747 |
if (v->cargo_count != v->cargo_cap) return true; |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
748 |
} while ((v = v->next) != NULL); |
0 | 749 |
} |
750 |
return false; |
|
751 |
} |
|
752 |
||
2704
dc9ae68dfd74
(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
|
753 |
/** Check if a given engine type can be refitted to a given cargo |
dc9ae68dfd74
(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
|
754 |
* @param engine_type Engine type to check |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
755 |
* @param cid_to check refit to this cargo-type |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
756 |
* @return true if it is possible, false otherwise |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
757 |
*/ |
2704
dc9ae68dfd74
(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
|
758 |
bool CanRefitTo(EngineID engine_type, CargoID cid_to) |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
759 |
{ |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
760 |
CargoID cid = _global_cargo_id[_opt_ptr->landscape][cid_to]; |
3393
48ce4c723a76
(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
|
761 |
return HASBIT(EngInfo(engine_type)->refit_mask, cid); |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
762 |
} |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
763 |
|
3973
7624a250577b
(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 |
/** Find the first cargo type that an engine can be refitted to. |
7624a250577b
(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 |
* @param engine Which engine to find cargo for. |
7624a250577b
(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
|
766 |
* @return A climate dependent cargo type. CT_INVALID is returned if not refittable. |
7624a250577b
(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
|
767 |
*/ |
7624a250577b
(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
|
768 |
CargoID FindFirstRefittableCargo(EngineID engine_type) |
7624a250577b
(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
|
769 |
{ |
7624a250577b
(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
|
770 |
CargoID cid; |
7624a250577b
(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
|
771 |
uint32 refit_mask = EngInfo(engine_type)->refit_mask; |
7624a250577b
(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
|
772 |
|
7624a250577b
(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
|
773 |
if (refit_mask != 0) { |
7624a250577b
(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
|
774 |
for (cid = CT_PASSENGERS; cid < NUM_CARGO; cid++) { |
7624a250577b
(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
|
775 |
if (HASBIT(refit_mask, _global_cargo_id[_opt_ptr->landscape][cid])) return cid; |
7624a250577b
(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
|
776 |
} |
7624a250577b
(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
|
777 |
} |
7624a250577b
(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
|
778 |
|
7624a250577b
(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
|
779 |
return CT_INVALID; |
7624a250577b
(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
|
780 |
} |
7624a250577b
(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
|
781 |
|
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
782 |
/** Learn the price of refitting a certain engine |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
783 |
* @param engine Which engine to refit |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
784 |
* @return Price for refitting |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
785 |
*/ |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
786 |
int32 GetRefitCost(EngineID engine_type) |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
787 |
{ |
4555
19987258e62d
(svn r6394) -Fix r6393: removed a warning originally removed in r6376 accidentally readded in r6393
bjarni
parents:
4554
diff
changeset
|
788 |
int32 base_cost = 0; |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
789 |
|
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
790 |
switch (GetEngine(engine_type)->type) { |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
791 |
case VEH_Ship: base_cost = _price.ship_base; break; |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
792 |
case VEH_Road: base_cost = _price.roadveh_base; break; |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
793 |
case VEH_Aircraft: base_cost = _price.aircraft_base; break; |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
794 |
case VEH_Train: |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
795 |
base_cost = 2 * ((RailVehInfo(engine_type)->flags & RVI_WAGON) ? |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
796 |
_price.build_railwagon : _price.build_railvehicle); |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
797 |
break; |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
798 |
default: NOT_REACHED(); break; |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
799 |
} |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
800 |
return (EngInfo(engine_type)->refit_cost * base_cost) >> 10; |
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
801 |
} |
3973
7624a250577b
(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
|
802 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
803 |
static void DoDrawVehicle(const Vehicle *v) |
0 | 804 |
{ |
805 |
uint32 image = v->cur_image; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
806 |
|
4175
c0bcc65f36d4
(svn r5613) Rename VS_DISASTER to VS_SHADOW, because this is what this flag actually means
tron
parents:
4174
diff
changeset
|
807 |
if (v->vehstatus & VS_SHADOW) { |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
808 |
MAKE_TRANSPARENT(image); |
0 | 809 |
} else if (v->vehstatus & VS_DEFPAL) { |
3040
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
810 |
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
|
811 |
} |
0 | 812 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
813 |
AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
0 | 814 |
v->sprite_width, v->sprite_height, v->z_height, v->z_pos); |
815 |
} |
|
816 |
||
817 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
818 |
{ |
|
4174
9ba4e15dac0f
(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 |
// The bounding rectangle |
9ba4e15dac0f
(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 |
const int l = dpi->left; |
9ba4e15dac0f
(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 |
const int r = dpi->left + dpi->width; |
9ba4e15dac0f
(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
|
822 |
const int t = dpi->top; |
9ba4e15dac0f
(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 int b = dpi->top + dpi->height; |
9ba4e15dac0f
(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
|
824 |
|
9ba4e15dac0f
(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
|
825 |
// The hash area to scan |
5512
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
826 |
int xl, xu, yl, yu, x, y; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
827 |
|
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
828 |
if (dpi->width + 70 < (1 << (7 + 6))) { |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
829 |
xl = GB(l - 70, 7, 6); |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
830 |
xu = GB(r, 7, 6); |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
831 |
} else { |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
832 |
/* scan whole hash row */ |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
833 |
xl = 0; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
834 |
xu = 0x3F; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
835 |
} |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
836 |
|
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
837 |
if (dpi->height + 70 < (1 << (6 + 6))) { |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
838 |
yl = GB(t - 70, 6, 6) << 6; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
839 |
yu = GB(b, 6, 6) << 6; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
840 |
} else { |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
841 |
/* scan whole column */ |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
842 |
yl = 0; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
843 |
yu = 0x3F << 6; |
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
844 |
} |
4174
9ba4e15dac0f
(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
|
845 |
|
9ba4e15dac0f
(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
|
846 |
for (y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
9ba4e15dac0f
(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
|
847 |
for (x = xl;; x = (x + 1) & 0x3F) { |
5512
52869fa67090
(svn r10279) [0.5] -Backport from trunk (r10139, r10153, r10154, r10155, r10165, r10187):
rubidium
parents:
5510
diff
changeset
|
848 |
VehicleID veh = _vehicle_position_hash[x + y]; // already masked & 0xFFF |
4174
9ba4e15dac0f
(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
|
849 |
|
0 | 850 |
while (veh != INVALID_VEHICLE) { |
4174
9ba4e15dac0f
(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
|
851 |
const Vehicle* v = GetVehicle(veh); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
852 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
853 |
if (!(v->vehstatus & VS_HIDDEN) && |
4174
9ba4e15dac0f
(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
|
854 |
l <= v->right_coord && |
9ba4e15dac0f
(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
|
855 |
t <= v->bottom_coord && |
9ba4e15dac0f
(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
|
856 |
r >= v->left_coord && |
9ba4e15dac0f
(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
|
857 |
b >= v->top_coord) { |
0 | 858 |
DoDrawVehicle(v); |
859 |
} |
|
860 |
veh = v->next_hash; |
|
861 |
} |
|
862 |
||
4174
9ba4e15dac0f
(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
|
863 |
if (x == xu) break; |
0 | 864 |
} |
4174
9ba4e15dac0f
(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
|
865 |
|
9ba4e15dac0f
(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
|
866 |
if (y == yu) break; |
0 | 867 |
} |
868 |
} |
|
869 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
870 |
static void ChimneySmokeInit(Vehicle *v) |
0 | 871 |
{ |
872 |
uint32 r = Random(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
873 |
v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
874 |
v->progress = GB(r, 16, 3); |
0 | 875 |
} |
876 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
877 |
static void ChimneySmokeTick(Vehicle *v) |
0 | 878 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
879 |
if (v->progress > 0) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
880 |
v->progress--; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
881 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
882 |
TileIndex tile; |
0 | 883 |
|
884 |
BeginVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
885 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
886 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
887 |
if (!IsTileType(tile, MP_INDUSTRY)) { |
0 | 888 |
EndVehicleMove(v); |
889 |
DeleteVehicle(v); |
|
890 |
return; |
|
891 |
} |
|
892 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
893 |
if (v->cur_image != SPR_CHIMNEY_SMOKE_7) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
894 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
895 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
896 |
v->cur_image = SPR_CHIMNEY_SMOKE_0; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
897 |
} |
0 | 898 |
v->progress = 7; |
899 |
VehiclePositionChanged(v); |
|
900 |
EndVehicleMove(v); |
|
901 |
} |
|
902 |
} |
|
903 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
904 |
static void SteamSmokeInit(Vehicle *v) |
0 | 905 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
906 |
v->cur_image = SPR_STEAM_SMOKE_0; |
0 | 907 |
v->progress = 12; |
908 |
} |
|
909 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
910 |
static void SteamSmokeTick(Vehicle *v) |
0 | 911 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
912 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
913 |
|
0 | 914 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
915 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
916 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
917 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
918 |
if ((v->progress & 7) == 0) { |
0 | 919 |
v->z_pos++; |
920 |
moved = true; |
|
921 |
} |
|
922 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
923 |
if ((v->progress & 0xF) == 4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
924 |
if (v->cur_image != SPR_STEAM_SMOKE_4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
925 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
926 |
} else { |
0 | 927 |
EndVehicleMove(v); |
928 |
DeleteVehicle(v); |
|
929 |
return; |
|
930 |
} |
|
931 |
moved = true; |
|
932 |
} |
|
933 |
||
934 |
if (moved) { |
|
935 |
VehiclePositionChanged(v); |
|
936 |
EndVehicleMove(v); |
|
937 |
} |
|
938 |
} |
|
939 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
940 |
static void DieselSmokeInit(Vehicle *v) |
0 | 941 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
942 |
v->cur_image = SPR_DIESEL_SMOKE_0; |
0 | 943 |
v->progress = 0; |
944 |
} |
|
945 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
946 |
static void DieselSmokeTick(Vehicle *v) |
0 | 947 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
948 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
949 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
950 |
if ((v->progress & 3) == 0) { |
0 | 951 |
BeginVehicleMove(v); |
952 |
v->z_pos++; |
|
953 |
VehiclePositionChanged(v); |
|
954 |
EndVehicleMove(v); |
|
955 |
} else if ((v->progress & 7) == 1) { |
|
956 |
BeginVehicleMove(v); |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
957 |
if (v->cur_image != SPR_DIESEL_SMOKE_5) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
958 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
959 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
960 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
961 |
} else { |
0 | 962 |
EndVehicleMove(v); |
963 |
DeleteVehicle(v); |
|
964 |
} |
|
965 |
} |
|
966 |
} |
|
967 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
968 |
static void ElectricSparkInit(Vehicle *v) |
0 | 969 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
970 |
v->cur_image = SPR_ELECTRIC_SPARK_0; |
0 | 971 |
v->progress = 1; |
972 |
} |
|
973 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
974 |
static void ElectricSparkTick(Vehicle *v) |
0 | 975 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
976 |
if (v->progress < 2) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
977 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
978 |
} else { |
0 | 979 |
v->progress = 0; |
980 |
BeginVehicleMove(v); |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
981 |
if (v->cur_image != SPR_ELECTRIC_SPARK_5) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
982 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
983 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
984 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
985 |
} else { |
0 | 986 |
EndVehicleMove(v); |
987 |
DeleteVehicle(v); |
|
988 |
} |
|
989 |
} |
|
990 |
} |
|
991 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
992 |
static void SmokeInit(Vehicle *v) |
0 | 993 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
994 |
v->cur_image = SPR_SMOKE_0; |
0 | 995 |
v->progress = 12; |
996 |
} |
|
997 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
998 |
static void SmokeTick(Vehicle *v) |
0 | 999 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1000 |
bool moved = false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1001 |
|
0 | 1002 |
BeginVehicleMove(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1003 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1004 |
v->progress++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1005 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1006 |
if ((v->progress & 3) == 0) { |
0 | 1007 |
v->z_pos++; |
1008 |
moved = true; |
|
1009 |
} |
|
1010 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1011 |
if ((v->progress & 0xF) == 4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1012 |
if (v->cur_image != SPR_SMOKE_4) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1013 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1014 |
} else { |
0 | 1015 |
EndVehicleMove(v); |
1016 |
DeleteVehicle(v); |
|
1017 |
return; |
|
1018 |
} |
|
1019 |
moved = true; |
|
1020 |
} |
|
1021 |
||
1022 |
if (moved) { |
|
1023 |
VehiclePositionChanged(v); |
|
1024 |
EndVehicleMove(v); |
|
1025 |
} |
|
1026 |
} |
|
1027 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1028 |
static void ExplosionLargeInit(Vehicle *v) |
0 | 1029 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1030 |
v->cur_image = SPR_EXPLOSION_LARGE_0; |
0 | 1031 |
v->progress = 0; |
1032 |
} |
|
1033 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1034 |
static void ExplosionLargeTick(Vehicle *v) |
0 | 1035 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1036 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1037 |
if ((v->progress & 3) == 0) { |
0 | 1038 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1039 |
if (v->cur_image != SPR_EXPLOSION_LARGE_F) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1040 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1041 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1042 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1043 |
} else { |
0 | 1044 |
EndVehicleMove(v); |
1045 |
DeleteVehicle(v); |
|
1046 |
} |
|
1047 |
} |
|
1048 |
} |
|
1049 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1050 |
static void BreakdownSmokeInit(Vehicle *v) |
0 | 1051 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1052 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
0 | 1053 |
v->progress = 0; |
1054 |
} |
|
1055 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1056 |
static void BreakdownSmokeTick(Vehicle *v) |
0 | 1057 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1058 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1059 |
if ((v->progress & 7) == 0) { |
0 | 1060 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(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_BREAKDOWN_SMOKE_3) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1062 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1063 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1064 |
v->cur_image = SPR_BREAKDOWN_SMOKE_0; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1065 |
} |
0 | 1066 |
VehiclePositionChanged(v); |
1067 |
EndVehicleMove(v); |
|
1068 |
} |
|
1069 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1070 |
v->u.special.unk0--; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1071 |
if (v->u.special.unk0 == 0) { |
0 | 1072 |
BeginVehicleMove(v); |
1073 |
EndVehicleMove(v); |
|
1074 |
DeleteVehicle(v); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1078 |
static void ExplosionSmallInit(Vehicle *v) |
0 | 1079 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1080 |
v->cur_image = SPR_EXPLOSION_SMALL_0; |
0 | 1081 |
v->progress = 0; |
1082 |
} |
|
1083 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1084 |
static void ExplosionSmallTick(Vehicle *v) |
0 | 1085 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1086 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1087 |
if ((v->progress & 3) == 0) { |
0 | 1088 |
BeginVehicleMove(v); |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1089 |
if (v->cur_image != SPR_EXPLOSION_SMALL_B) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1090 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1091 |
VehiclePositionChanged(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1092 |
EndVehicleMove(v); |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1093 |
} else { |
0 | 1094 |
EndVehicleMove(v); |
1095 |
DeleteVehicle(v); |
|
1096 |
} |
|
1097 |
} |
|
1098 |
} |
|
1099 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1100 |
static void BulldozerInit(Vehicle *v) |
0 | 1101 |
{ |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1102 |
v->cur_image = SPR_BULLDOZER_NE; |
0 | 1103 |
v->progress = 0; |
1104 |
v->u.special.unk0 = 0; |
|
1105 |
v->u.special.unk2 = 0; |
|
1106 |
} |
|
1107 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1108 |
typedef struct BulldozerMovement { |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1109 |
byte direction:2; |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1110 |
byte image:2; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1111 |
byte duration:3; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1112 |
} BulldozerMovement; |
0 | 1113 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1114 |
static const BulldozerMovement _bulldozer_movement[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1115 |
{ 0, 0, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1116 |
{ 3, 3, 4 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1117 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1118 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1119 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1120 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1121 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1122 |
{ 1, 1, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1123 |
{ 2, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1124 |
{ 0, 2, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1125 |
{ 3, 3, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1126 |
{ 2, 2, 6 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1127 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1128 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1129 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1130 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1131 |
{ 3, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1132 |
{ 0, 0, 3 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1133 |
{ 1, 1, 7 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1134 |
{ 3, 1, 7 } |
0 | 1135 |
}; |
1136 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1137 |
static const struct { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1138 |
int8 x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1139 |
int8 y; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1140 |
} _inc_by_dir[] = { |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1141 |
{ -1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1142 |
{ 0, 1 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1143 |
{ 1, 0 }, |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1144 |
{ 0, -1 } |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1145 |
}; |
0 | 1146 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1147 |
static void BulldozerTick(Vehicle *v) |
0 | 1148 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1149 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1150 |
if ((v->progress & 7) == 0) { |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1151 |
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.unk0]; |
0 | 1152 |
|
1153 |
BeginVehicleMove(v); |
|
1154 |
||
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1155 |
v->cur_image = SPR_BULLDOZER_NE + b->image; |
0 | 1156 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1157 |
v->x_pos += _inc_by_dir[b->direction].x; |
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1158 |
v->y_pos += _inc_by_dir[b->direction].y; |
0 | 1159 |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1160 |
v->u.special.unk2++; |
1365
7eff6abe942a
(svn r1869) Fix some bugs in the bulldozer movement implementation.
tron
parents:
1364
diff
changeset
|
1161 |
if (v->u.special.unk2 >= b->duration) { |
0 | 1162 |
v->u.special.unk2 = 0; |
1163 |
v->u.special.unk0++; |
|
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1164 |
if (v->u.special.unk0 == lengthof(_bulldozer_movement)) { |
0 | 1165 |
EndVehicleMove(v); |
1166 |
DeleteVehicle(v); |
|
1167 |
return; |
|
1168 |
} |
|
1169 |
} |
|
1170 |
VehiclePositionChanged(v); |
|
1171 |
EndVehicleMove(v); |
|
1172 |
} |
|
1173 |
} |
|
1174 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1175 |
static void BubbleInit(Vehicle *v) |
0 | 1176 |
{ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1177 |
v->cur_image = SPR_BUBBLE_GENERATE_0; |
0 | 1178 |
v->spritenum = 0; |
1179 |
v->progress = 0; |
|
1180 |
} |
|
1181 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1182 |
typedef struct BubbleMovement { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1183 |
int8 x:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1184 |
int8 y:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1185 |
int8 z:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1186 |
byte image:4; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1187 |
} BubbleMovement; |
0 | 1188 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1189 |
#define MK(x, y, z, i) { x, y, z, i } |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1190 |
#define ME(i) { i, 4, 0, 0 } |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1191 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1192 |
static const BubbleMovement _bubble_float_sw[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1194 |
MK(1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1195 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1196 |
MK(1, 0, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1197 |
ME(1) |
0 | 1198 |
}; |
1199 |
||
1200 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1201 |
static const BubbleMovement _bubble_float_ne[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1202 |
MK( 0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1203 |
MK(-1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1204 |
MK( 0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1205 |
MK(-1, 0, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1206 |
ME(1) |
0 | 1207 |
}; |
1208 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1209 |
static const BubbleMovement _bubble_float_se[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1214 |
ME(1) |
0 | 1215 |
}; |
1216 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1217 |
static const BubbleMovement _bubble_float_nw[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, -1, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, -1, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1222 |
ME(1) |
0 | 1223 |
}; |
1224 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1225 |
static const BubbleMovement _bubble_burst[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 7), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 9), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1230 |
ME(0) |
0 | 1231 |
}; |
1232 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1233 |
static const BubbleMovement _bubble_absorb[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1284 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1290 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1291 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1292 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1293 |
MK(0, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1294 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1295 |
MK(0, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1296 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1297 |
MK(1, 1, 3, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1298 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1299 |
MK(1, 1, 3, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1300 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1301 |
MK(1, 1, 3, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1302 |
MK(2, 1, 3, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1303 |
MK(1, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1304 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1305 |
MK(1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1306 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1307 |
MK(1, 0, 1, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1308 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1309 |
MK(1, 0, 1, 1), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1310 |
MK(0, 0, 1, 0), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1311 |
MK(1, 0, 1, 2), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1312 |
ME(2), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1313 |
MK(0, 0, 0, 0xA), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1314 |
MK(0, 0, 0, 0xB), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1315 |
MK(0, 0, 0, 0xC), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1316 |
MK(0, 0, 0, 0xD), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1317 |
MK(0, 0, 0, 0xE), |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1318 |
ME(0) |
0 | 1319 |
}; |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1320 |
#undef ME |
0 | 1321 |
#undef MK |
1322 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1323 |
static const BubbleMovement * const _bubble_movement[] = { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1324 |
_bubble_float_sw, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1325 |
_bubble_float_ne, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1326 |
_bubble_float_se, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1327 |
_bubble_float_nw, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1328 |
_bubble_burst, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1329 |
_bubble_absorb, |
0 | 1330 |
}; |
1331 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1332 |
static void BubbleTick(Vehicle *v) |
0 | 1333 |
{ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1334 |
/* |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1335 |
* Warning: those effects can NOT use Random(), and have to use |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1336 |
* InteractiveRandom(), because somehow someone forgot to save |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1337 |
* spritenum to the savegame, and so it will cause desyncs in |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1338 |
* multiplayer!! (that is: in ToyLand) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1339 |
*/ |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1340 |
uint et; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1341 |
const BubbleMovement *b; |
0 | 1342 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1343 |
v->progress++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1344 |
if ((v->progress & 3) != 0) |
0 | 1345 |
return; |
1346 |
||
1347 |
BeginVehicleMove(v); |
|
1348 |
||
1349 |
if (v->spritenum == 0) { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1350 |
v->cur_image++; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1351 |
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { |
0 | 1352 |
VehiclePositionChanged(v); |
1353 |
EndVehicleMove(v); |
|
1354 |
return; |
|
1355 |
} |
|
1356 |
if (v->u.special.unk2 != 0) { |
|
2635 | 1357 |
v->spritenum = GB(InteractiveRandom(), 0, 2) + 1; |
0 | 1358 |
} else { |
1359 |
v->spritenum = 6; |
|
1360 |
} |
|
1361 |
et = 0; |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1362 |
} else { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1363 |
et = v->engine_type + 1; |
0 | 1364 |
} |
1365 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1366 |
b = &_bubble_movement[v->spritenum - 1][et]; |
0 | 1367 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1368 |
if (b->y == 4 && b->x == 0) { |
0 | 1369 |
EndVehicleMove(v); |
1370 |
DeleteVehicle(v); |
|
1371 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1372 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1373 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1374 |
if (b->y == 4 && b->x == 1) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1375 |
if (v->z_pos > 180 || CHANCE16I(1, 96, InteractiveRandom())) { |
0 | 1376 |
v->spritenum = 5; |
541 | 1377 |
SndPlayVehicleFx(SND_2F_POP, v); |
0 | 1378 |
} |
1379 |
et = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1380 |
} |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1381 |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1382 |
if (b->y == 4 && b->x == 2) { |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1383 |
TileIndex tile; |
0 | 1384 |
|
1385 |
et++; |
|
541 | 1386 |
SndPlayVehicleFx(SND_31_EXTRACT, v); |
0 | 1387 |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
1388 |
tile = TileVirtXY(v->x_pos, v->y_pos); |
3428
62682d91b4cd
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
1389 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == 0xA2) AddAnimatedTile(tile); |
0 | 1390 |
} |
1391 |
||
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1392 |
v->engine_type = et; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1393 |
b = &_bubble_movement[v->spritenum - 1][et]; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1394 |
|
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1395 |
v->x_pos += b->x; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1396 |
v->y_pos += b->y; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1397 |
v->z_pos += b->z; |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1398 |
v->cur_image = SPR_BUBBLE_0 + b->image; |
0 | 1399 |
|
1400 |
VehiclePositionChanged(v); |
|
1401 |
EndVehicleMove(v); |
|
1402 |
} |
|
1403 |
||
1404 |
||
1405 |
typedef void EffectInitProc(Vehicle *v); |
|
1406 |
typedef void EffectTickProc(Vehicle *v); |
|
1407 |
||
1408 |
static EffectInitProc * const _effect_init_procs[] = { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1409 |
ChimneySmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1410 |
SteamSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1411 |
DieselSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1412 |
ElectricSparkInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1413 |
SmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1414 |
ExplosionLargeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1415 |
BreakdownSmokeInit, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1416 |
ExplosionSmallInit, |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1417 |
BulldozerInit, |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1418 |
BubbleInit, |
0 | 1419 |
}; |
1420 |
||
1421 |
static EffectTickProc * const _effect_tick_procs[] = { |
|
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1422 |
ChimneySmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1423 |
SteamSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1424 |
DieselSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1425 |
ElectricSparkTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1426 |
SmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1427 |
ExplosionLargeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1428 |
BreakdownSmokeTick, |
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1429 |
ExplosionSmallTick, |
1364
9fad41818ac1
(svn r1868) Improve readability of the bulldozer movement code
tron
parents:
1359
diff
changeset
|
1430 |
BulldozerTick, |
1371
76c98f1ff2bf
(svn r1875) Effect vehicle overhaul: enumerate sprites, descriptive names for functions and miscellaneous improvements
tron
parents:
1365
diff
changeset
|
1431 |
BubbleTick, |
0 | 1432 |
}; |
1433 |
||
1434 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1435 |
Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) |
0 | 1436 |
{ |
1437 |
Vehicle *v; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1438 |
|
0 | 1439 |
v = ForceAllocateSpecialVehicle(); |
1440 |
if (v != NULL) { |
|
1441 |
v->type = VEH_Special; |
|
1442 |
v->subtype = type; |
|
1443 |
v->x_pos = x; |
|
1444 |
v->y_pos = y; |
|
1445 |
v->z_pos = z; |
|
1446 |
v->z_height = v->sprite_width = v->sprite_height = 1; |
|
1447 |
v->x_offs = v->y_offs = 0; |
|
1448 |
v->tile = 0; |
|
1449 |
v->vehstatus = VS_UNCLICKABLE; |
|
1450 |
||
1451 |
_effect_init_procs[type](v); |
|
1452 |
||
1453 |
VehiclePositionChanged(v); |
|
1454 |
BeginVehicleMove(v); |
|
1455 |
EndVehicleMove(v); |
|
1456 |
} |
|
1457 |
return v; |
|
1458 |
} |
|
1459 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1460 |
Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicle type) |
0 | 1461 |
{ |
5295
ab31e01faa80
(svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents:
5256
diff
changeset
|
1462 |
int safe_x = clamp(x, 0, MapMaxX() * TILE_SIZE); |
ab31e01faa80
(svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents:
5256
diff
changeset
|
1463 |
int safe_y = clamp(y, 0, MapMaxY() * TILE_SIZE); |
ab31e01faa80
(svn r7448) -Fix (r5794): use the height of the edge of the map for effect vehicles that are outside the map.
rubidium
parents:
5256
diff
changeset
|
1464 |
return CreateEffectVehicle(x, y, GetSlopeZ(safe_x, safe_y) + z, type); |
0 | 1465 |
} |
1466 |
||
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1349
diff
changeset
|
1467 |
Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicle type) |
0 | 1468 |
{ |
1469 |
return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type); |
|
1470 |
} |
|
1471 |
||
410 | 1472 |
static void EffectVehicle_Tick(Vehicle *v) |
0 | 1473 |
{ |
1474 |
_effect_tick_procs[v->subtype](v); |
|
1475 |
} |
|
1476 |
||
2116 | 1477 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 1478 |
{ |
1479 |
Vehicle *found = NULL, *v; |
|
1480 |
uint dist, best_dist = (uint)-1; |
|
1481 |
||
1482 |
if ( (uint)(x -= vp->left) >= (uint)vp->width || |
|
1483 |
(uint)(y -= vp->top) >= (uint)vp->height) |
|
1484 |
return NULL; |
|
1485 |
||
1486 |
x = (x << vp->zoom) + vp->virtual_left; |
|
1487 |
y = (y << vp->zoom) + vp->virtual_top; |
|
1488 |
||
1489 |
FOR_ALL_VEHICLES(v) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1490 |
if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 1491 |
x >= v->left_coord && x <= v->right_coord && |
1492 |
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
|
1493 |
|
0 | 1494 |
dist = max( |
1495 |
myabs( ((v->left_coord + v->right_coord)>>1) - x ), |
|
1496 |
myabs( ((v->top_coord + v->bottom_coord)>>1) - y ) |
|
1497 |
); |
|
1498 |
||
1499 |
if (dist < best_dist) { |
|
1500 |
found = v; |
|
1501 |
best_dist = dist; |
|
1502 |
} |
|
1503 |
} |
|
1504 |
} |
|
1505 |
||
1506 |
return found; |
|
1507 |
} |
|
1508 |
||
1509 |
||
1510 |
void DecreaseVehicleValue(Vehicle *v) |
|
1511 |
{ |
|
1512 |
v->value -= v->value >> 8; |
|
1513 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1514 |
} |
|
1515 |
||
1516 |
static const byte _breakdown_chance[64] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1517 |
3, 3, 3, 3, 3, 3, 3, 3, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1518 |
4, 4, 5, 5, 6, 6, 7, 7, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1519 |
8, 8, 9, 9, 10, 10, 11, 11, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1520 |
12, 13, 13, 13, 13, 14, 15, 16, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1521 |
17, 19, 21, 25, 28, 31, 34, 37, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1522 |
40, 44, 48, 52, 56, 60, 64, 68, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1523 |
72, 80, 90, 100, 110, 120, 130, 140, |
0 | 1524 |
150, 170, 190, 210, 230, 250, 250, 250, |
1525 |
}; |
|
1526 |
||
1527 |
void CheckVehicleBreakdown(Vehicle *v) |
|
1528 |
{ |
|
1529 |
int rel, rel_old; |
|
1530 |
uint32 r; |
|
1531 |
int chance; |
|
1532 |
||
1533 |
/* decrease reliability */ |
|
1534 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
1535 |
if ((rel_old >> 8) != (rel >> 8)) |
|
1536 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1537 |
||
2639 | 1538 |
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED || |
1539 |
v->cur_speed < 5 || _game_mode == GM_MENU) { |
|
1540 |
return; |
|
1541 |
} |
|
0 | 1542 |
|
1543 |
r = Random(); |
|
1544 |
||
1545 |
/* increase chance of failure */ |
|
1546 |
chance = v->breakdown_chance + 1; |
|
1547 |
if (CHANCE16I(1,25,r)) chance += 25; |
|
1548 |
v->breakdown_chance = min(255, chance); |
|
1549 |
||
1550 |
/* calculate reliability value to use in comparison */ |
|
1551 |
rel = v->reliability; |
|
1552 |
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
|
1553 |
|
0 | 1554 |
/* disabled breakdowns? */ |
2639 | 1555 |
if (_opt.diff.vehicle_breakdowns < 1) return; |
0 | 1556 |
|
1557 |
/* reduced breakdowns? */ |
|
1558 |
if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666; |
|
1559 |
||
1560 |
/* check if to break down */ |
|
1561 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
1562 |
v->breakdown_ctr = GB(r, 16, 6) + 0x3F; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
1563 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 1564 |
v->breakdown_chance = 0; |
1565 |
} |
|
1566 |
} |
|
1567 |
||
1568 |
static const StringID _vehicle_type_names[4] = { |
|
1569 |
STR_019F_TRAIN, |
|
1570 |
STR_019C_ROAD_VEHICLE, |
|
1571 |
STR_019E_SHIP, |
|
1572 |
STR_019D_AIRCRAFT, |
|
1573 |
}; |
|
1574 |
||
1575 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
1576 |
{ |
|
2639 | 1577 |
if (v->owner != _local_player) return; |
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1578 |
|
26 | 1579 |
// Do not show getting-old message if autorenew is active |
2639 | 1580 |
if (GetPlayer(v->owner)->engine_renew) return; |
0 | 1581 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1582 |
SetDParam(0, _vehicle_type_names[v->type - 0x10]); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1583 |
SetDParam(1, v->unitnumber); |
0 | 1584 |
AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
1585 |
} |
|
1586 |
||
1587 |
void AgeVehicle(Vehicle *v) |
|
1588 |
{ |
|
1589 |
int age; |
|
1590 |
||
1591 |
if (v->age < 65535) |
|
1592 |
v->age++; |
|
1593 |
||
1594 |
age = v->age - v->max_age; |
|
1595 |
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
|
1596 |
v->reliability_spd_dec <<= 1; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1597 |
|
0 | 1598 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
1599 |
||
1600 |
if (age == -366) { |
|
1601 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
1602 |
} else if (age == 0) { |
|
1603 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
1604 |
} else if (age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4 || age == 366*5) { |
|
1605 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
|
1606 |
} |
|
1607 |
} |
|
1608 |
||
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1609 |
/** Starts or stops a lot of vehicles |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1610 |
* @param tile Tile of the depot where the vehicles are started/stopped (only used for depots) |
4762
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1611 |
* @param p1 Station/Order/Depot ID (only used for vehicle list windows) |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1612 |
* @param p2 bitmask |
4762
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1613 |
* - bit 0-4 Vehicle type |
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1614 |
* - bit 5 false = start vehicles, true = stop vehicles |
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1615 |
* - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1616 |
* - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set) |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1617 |
*/ |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1618 |
int32 CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1619 |
{ |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1620 |
Vehicle **vl = NULL; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1621 |
uint16 engine_list_length = 0; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1622 |
uint16 engine_count = 0; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1623 |
int32 return_value = CMD_ERROR; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1624 |
uint i; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1625 |
uint stop_command; |
4762
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1626 |
byte vehicle_type = GB(p2, 0, 5); |
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1627 |
bool start_stop = HASBIT(p2, 5); |
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1628 |
bool vehicle_list_window = HASBIT(p2, 6); |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1629 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1630 |
switch (vehicle_type) { |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1631 |
case VEH_Train: stop_command = CMD_START_STOP_TRAIN; break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1632 |
case VEH_Road: stop_command = CMD_START_STOP_ROADVEH; break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1633 |
case VEH_Ship: stop_command = CMD_START_STOP_SHIP; break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1634 |
case VEH_Aircraft: stop_command = CMD_START_STOP_AIRCRAFT; break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1635 |
default: return CMD_ERROR; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1636 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1637 |
|
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1638 |
if (vehicle_list_window) { |
5430
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5427
diff
changeset
|
1639 |
uint32 id = p1; |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1640 |
uint16 window_type = p2 & VLW_MASK; |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1641 |
|
4762
58d2f43ebdda
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
1642 |
engine_count = GenerateVehicleSortList((const Vehicle***)&vl, &engine_list_length, vehicle_type, _current_player, id, id, id, window_type); |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1643 |
} else { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1644 |
/* Get the list of vehicles in the depot */ |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1645 |
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1646 |
} |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1647 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1648 |
for (i = 0; i < engine_count; i++) { |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1649 |
const Vehicle *v = vl[i]; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1650 |
int32 ret; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1651 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1652 |
if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
4673
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1653 |
|
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1654 |
if (!vehicle_list_window) { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1655 |
if (vehicle_type == VEH_Train) { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1656 |
if (CheckTrainInDepot(v, false) == -1) continue; |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1657 |
} else { |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1658 |
if (!(v->vehstatus & VS_HIDDEN)) continue; |
a2cdac5529f7
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1659 |
} |
4648
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1660 |
} |
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1661 |
|
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1662 |
ret = DoCommand(tile, v->index, 0, flags, stop_command); |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1663 |
|
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1664 |
if (!CmdFailed(ret)) { |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1665 |
return_value = 0; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1666 |
/* We know that the command is valid for at least one vehicle. |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1667 |
* If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1668 |
if (!(flags & DC_EXEC)) break; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1669 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1670 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1671 |
|
4648
ab94e3a447a8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1672 |
free(vl); |
4640
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1673 |
return return_value; |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1674 |
} |
cabffc571e55
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1675 |
|
4659
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1676 |
/** Sells all vehicles in a depot |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1677 |
* @param tile Tile of the depot where the depot is |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1678 |
* @param p1 Vehicle type |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1679 |
* @param p2 unused |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1680 |
*/ |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1681 |
int32 CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1682 |
{ |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1683 |
Vehicle **engines = NULL; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1684 |
Vehicle **wagons = NULL; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1685 |
uint16 engine_list_length = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1686 |
uint16 engine_count = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1687 |
uint16 wagon_list_length = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1688 |
uint16 wagon_count = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1689 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1690 |
int32 cost = 0; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1691 |
uint i, sell_command, total_number_vehicles; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1692 |
byte vehicle_type = GB(p1, 0, 8); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1693 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1694 |
switch (vehicle_type) { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1695 |
case VEH_Train: sell_command = CMD_SELL_RAIL_WAGON; break; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1696 |
case VEH_Road: sell_command = CMD_SELL_ROAD_VEH; break; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1697 |
case VEH_Ship: sell_command = CMD_SELL_SHIP; break; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1698 |
case VEH_Aircraft: sell_command = CMD_SELL_AIRCRAFT; break; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1699 |
default: return CMD_ERROR; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1700 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1701 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1702 |
/* Get the list of vehicles in the depot */ |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1703 |
BuildDepotVehicleList(vehicle_type, tile, &engines, &engine_list_length, &engine_count, |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1704 |
&wagons, &wagon_list_length, &wagon_count); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1705 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1706 |
total_number_vehicles = engine_count + wagon_count; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1707 |
for (i = 0; i < total_number_vehicles; i++) { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1708 |
const Vehicle *v; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1709 |
int32 ret; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1710 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1711 |
if (i < engine_count) { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1712 |
v = engines[i]; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1713 |
} else { |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1714 |
v = wagons[i - engine_count]; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1715 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1716 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1717 |
ret = DoCommand(tile, v->index, 1, flags, sell_command); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1718 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1719 |
if (!CmdFailed(ret)) cost += ret; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1720 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1721 |
|
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1722 |
free(engines); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1723 |
free(wagons); |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1724 |
if (cost == 0) return CMD_ERROR; // no vehicles to sell |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1725 |
return cost; |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1726 |
} |
2f99f35d5813
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1727 |
|
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1728 |
/** Autoreplace all vehicles in the depot |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1729 |
* @param tile Tile of the depot where the vehicles are |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1730 |
* @param p1 Type of vehicle |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1731 |
* @param p2 Unused |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1732 |
*/ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1733 |
int32 CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1734 |
{ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1735 |
Vehicle **vl = NULL; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1736 |
uint16 engine_list_length = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1737 |
uint16 engine_count = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1738 |
uint i, x = 0, y = 0, z = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1739 |
int32 cost = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1740 |
byte vehicle_type = GB(p1, 0, 8); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1741 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1742 |
|
5541
08e4afe5e927
(svn r11073) [0.5] -Backport from trunk (r11039, r11029, r11027, r11024, r11021, r11020, r11018):
rubidium
parents:
5540
diff
changeset
|
1743 |
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1744 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1745 |
/* Get the list of vehicles in the depot */ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1746 |
BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1747 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1748 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1749 |
for (i = 0; i < engine_count; i++) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1750 |
Vehicle *v = vl[i]; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1751 |
bool stopped = !(v->vehstatus & VS_STOPPED); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1752 |
int32 ret; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1753 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1754 |
/* Ensure that the vehicle completely in the depot */ |
4736
b830a9f1703c
(svn r6648) -Codechange: simplified CmdDepotMassAutoReplace() by changing a switch-case into using a function, that was added in r6647
bjarni
parents:
4734
diff
changeset
|
1755 |
if (!IsVehicleInDepot(v)) continue; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1756 |
|
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1757 |
x = v->x_pos; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1758 |
y = v->y_pos; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1759 |
z = v->z_pos; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1760 |
|
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1761 |
if (stopped) { |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1762 |
v->vehstatus |= VS_STOPPED; // Stop the vehicle |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1763 |
v->leave_depot_instantly = true; |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1764 |
} |
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
1765 |
ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1766 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1767 |
if (!CmdFailed(ret)) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1768 |
cost += ret; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1769 |
if (!(flags & DC_EXEC)) break; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1770 |
/* There is a problem with autoreplace and newgrf |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1771 |
* It's impossible to tell the length of a train after it's being replaced before it's actually done |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1772 |
* Because of this, we can't estimate costs due to wagon removal and we will have to always return 0 and pay manually |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1773 |
* Since we pay after each vehicle is replaced and MaybeReplaceVehicle() check if the player got enough money |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1774 |
* we should never reach a condition where the player will end up with negative money from doing this */ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1775 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1776 |
SubtractMoneyFromPlayer(ret); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1777 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1778 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1779 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1780 |
if (cost == 0) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1781 |
cost = CMD_ERROR; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1782 |
} else { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1783 |
if (flags & DC_EXEC) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1784 |
/* Display the cost animation now that DoCommandP() can't do it for us (see previous comments) */ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1785 |
if (IsLocalPlayer()) ShowCostOrIncomeAnimation(x, y, z, cost); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1786 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1787 |
cost = 0; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1788 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1789 |
|
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1790 |
free(vl); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1791 |
return cost; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1792 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1793 |
|
2244 | 1794 |
/** Clone a vehicle. If it is a train, it will clone all the cars too |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1795 |
* @param tile tile of the depot where the cloned vehicle is build |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1796 |
* @param p1 the original vehicle's index |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1797 |
* @param p2 1 = shared orders, else copied orders |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1798 |
*/ |
3491
4c8427796c64
(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
|
1799 |
int32 CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2244 | 1800 |
{ |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1801 |
Vehicle *v_front, *v; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1802 |
Vehicle *w_front, *w, *w_rear; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1803 |
int cost, total_cost = 0; |
3816
2cdb29b57c1f
(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
|
1804 |
uint32 build_argument = 2; |
2244 | 1805 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1806 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
2244 | 1807 |
v = GetVehicle(p1); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1808 |
v_front = v; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1809 |
w = NULL; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1810 |
w_front = NULL; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1811 |
w_rear = NULL; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1812 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1813 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1814 |
/* |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1815 |
* v_front is the front engine in the original vehicle |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1816 |
* v is the car/vehicle of the original vehicle, that is currently being copied |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1817 |
* w_front is the front engine of the cloned vehicle |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1818 |
* w is the car/vehicle currently being cloned |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1819 |
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1820 |
*/ |
2244 | 1821 |
|
2639 | 1822 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1823 |
|
2813
018e421127ee
(svn r3361) - Clone Vehicle: Disallow cloning of crashed rail vehicles after starting removal process.
peter1138
parents:
2805
diff
changeset
|
1824 |
if (v->type == VEH_Train && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR; |
2244 | 1825 |
|
2601
7c94a0e394a6
(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
|
1826 |
// check that we can allocate enough vehicles |
7c94a0e394a6
(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
|
1827 |
if (!(flags & DC_EXEC)) { |
7c94a0e394a6
(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
|
1828 |
int veh_counter = 0; |
7c94a0e394a6
(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
|
1829 |
do { |
7c94a0e394a6
(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
|
1830 |
veh_counter++; |
7c94a0e394a6
(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
|
1831 |
} while ((v = v->next) != NULL); |
7c94a0e394a6
(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
|
1832 |
|
2606
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1833 |
if (!AllocateVehicles(NULL, veh_counter)) { |
7ae924de184b
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1834 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
2601
7c94a0e394a6
(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
|
1835 |
} |
7c94a0e394a6
(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
|
1836 |
} |
7c94a0e394a6
(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
|
1837 |
|
7c94a0e394a6
(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
|
1838 |
v = v_front; |
7c94a0e394a6
(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
|
1839 |
|
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1840 |
do { |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1841 |
|
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1842 |
if (IsMultiheaded(v) && !IsTrainEngine(v)) { |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1843 |
/* we build the rear ends of multiheaded trains with the front ones */ |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1844 |
continue; |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1845 |
} |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1846 |
|
3815
4c4175bc0749
(svn r4825) - Fix [clone FS#159]: Game crashes when cloning reaches train-limit.
bjarni
parents:
3794
diff
changeset
|
1847 |
cost = DoCommand(tile, v->engine_type, build_argument, flags, CMD_BUILD_VEH(v->type)); |
3819
281ac50dba17
(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
|
1848 |
build_argument = 3; // ensure that we only assign a number to the first engine |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1849 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1850 |
if (CmdFailed(cost)) return cost; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1851 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1852 |
total_cost += cost; |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1853 |
|
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1854 |
if (flags & DC_EXEC) { |
5442
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1855 |
Vehicle *v2, *w2; |
2639 | 1856 |
w = GetVehicle(_new_vehicle_id); |
5442
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1857 |
w2 = w; |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1858 |
v2 = v; |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1859 |
|
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1860 |
do { |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1861 |
if (v->cargo_type != w->cargo_type || v->cargo_subtype != w->cargo_subtype) { |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1862 |
/* We can't pay for refitting because we can't estimate refitting costs for a vehicle before it's build. |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1863 |
* If we pay for it anyway, the cost and the estimated cost will not be the same and we will have an assert. |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1864 |
* We need to check the whole chain if it is a train because some newgrf articulated engines can refit some |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1865 |
* units only (and not the front) */ |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1866 |
DoCommand(0, w->index, v2->cargo_type | (v2->cargo_subtype << 8), flags, CMD_REFIT_VEH(v->type)); |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1867 |
break; // We learned that the engine in question needed a refit. No need to check anymore |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1868 |
} |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1869 |
} while (v->type == VEH_Train && (w2 = w2->next) != NULL && (v2 = v2->next) != NULL); |
427c81cfd6f6
(svn r8870) [0.5] -Backport from trunk (r8684, r8709, r8738, r8777, r8828):
Darkvater
parents:
5430
diff
changeset
|
1870 |
|
3896
292881445b9c
(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
|
1871 |
if (v->type == VEH_Train && HASBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { |
292881445b9c
(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
|
1872 |
SETBIT(w->u.rail.flags, VRF_REVERSE_DIRECTION); |
292881445b9c
(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
|
1873 |
} |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1874 |
|
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1875 |
if (v->type == VEH_Train && !IsFrontEngine(v)) { |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1876 |
// this s a train car |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1877 |
// add this unit to the end of the train |
3491
4c8427796c64
(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
|
1878 |
DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1879 |
} else { |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1880 |
// this is a front engine or not a train. It need orders |
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1881 |
w_front = w; |
3679
8e7e14ee361a
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1882 |
w->service_interval = v->service_interval; |
3491
4c8427796c64
(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
|
1883 |
DoCommand(0, (v->index << 16) | w->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER); |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1884 |
} |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1885 |
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop |
2563
99292721b8af
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1886 |
} |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
1887 |
} while (v->type == VEH_Train && (v = GetNextVehicle(v)) != NULL); |
2244 | 1888 |
|
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1889 |
if (flags & DC_EXEC && v_front->type == VEH_Train) { |
3948
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3896
diff
changeset
|
1890 |
// for trains this needs to be the front engine due to the callback function |
95f9fa0ac551
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3896
diff
changeset
|
1891 |
_new_vehicle_id = w_front->index; |
2244 | 1892 |
} |
5062
7c341b020f5f
(svn r7115) -Fix [FS#371]: Cloning a vehicle that has been refitted would incur the expense as running costs, not new vehicles.
peter1138
parents:
4972
diff
changeset
|
1893 |
|
7c341b020f5f
(svn r7115) -Fix [FS#371]: Cloning a vehicle that has been refitted would incur the expense as running costs, not new vehicles.
peter1138
parents:
4972
diff
changeset
|
1894 |
/* Set the expense type last as refitting will make the cost go towards |
7c341b020f5f
(svn r7115) -Fix [FS#371]: Cloning a vehicle that has been refitted would incur the expense as running costs, not new vehicles.
peter1138
parents:
4972
diff
changeset
|
1895 |
* running costs... */ |
7c341b020f5f
(svn r7115) -Fix [FS#371]: Cloning a vehicle that has been refitted would incur the expense as running costs, not new vehicles.
peter1138
parents:
4972
diff
changeset
|
1896 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
2244 | 1897 |
return total_cost; |
1898 |
} |
|
1899 |
||
2599
7dd6060f9749
(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
|
1900 |
/* |
7dd6060f9749
(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
|
1901 |
* move the cargo from one engine to another if possible |
7dd6060f9749
(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
|
1902 |
*/ |
7dd6060f9749
(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
|
1903 |
static void MoveVehicleCargo(Vehicle *dest, Vehicle *source) |
7dd6060f9749
(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
|
1904 |
{ |
7dd6060f9749
(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
|
1905 |
Vehicle *v = dest; |
7dd6060f9749
(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
|
1906 |
int units_moved; |
7dd6060f9749
(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
|
1907 |
|
7dd6060f9749
(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
|
1908 |
do { |
7dd6060f9749
(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
|
1909 |
do { |
7dd6060f9749
(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
|
1910 |
if (source->cargo_type != dest->cargo_type) |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1911 |
continue; // cargo not compatible |
2599
7dd6060f9749
(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
|
1912 |
|
7dd6060f9749
(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
|
1913 |
if (dest->cargo_count == dest->cargo_cap) |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1914 |
continue; // the destination vehicle is already full |
2599
7dd6060f9749
(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
|
1915 |
|
7dd6060f9749
(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
|
1916 |
units_moved = min(source->cargo_count, dest->cargo_cap - dest->cargo_count); |
7dd6060f9749
(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
|
1917 |
source->cargo_count -= units_moved; |
7dd6060f9749
(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
|
1918 |
dest->cargo_count += units_moved; |
7dd6060f9749
(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
|
1919 |
dest->cargo_source = source->cargo_source; |
7dd6060f9749
(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
|
1920 |
|
7dd6060f9749
(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
|
1921 |
// copy the age of the cargo |
7dd6060f9749
(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
|
1922 |
dest->cargo_days = source->cargo_days; |
7dd6060f9749
(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
|
1923 |
dest->day_counter = source->day_counter; |
7dd6060f9749
(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
|
1924 |
dest->tick_counter = source->tick_counter; |
7dd6060f9749
(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
|
1925 |
|
2678
a0af6bded583
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1926 |
} while (source->cargo_count > 0 && (dest = dest->next) != NULL); |
2599
7dd6060f9749
(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
|
1927 |
dest = v; |
2678
a0af6bded583
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
1928 |
} while ((source = source->next) != NULL); |
5418
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1929 |
|
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1930 |
/* |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1931 |
* The of the train will be incorrect at this moment. This is due |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1932 |
* to the fact that removing the old wagon updates the weight of |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1933 |
* the complete train, which is without the weight of cargo we just |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1934 |
* moved back into some (of the) new wagon(s). |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1935 |
*/ |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
1936 |
if (dest->type == VEH_Train) TrainConsistChanged(dest->first); |
2599
7dd6060f9749
(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
|
1937 |
} |
7dd6060f9749
(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
|
1938 |
|
4741
7e0ebb20950d
(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
|
1939 |
static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, const EngineID engine_type) |
7e0ebb20950d
(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
|
1940 |
{ |
7e0ebb20950d
(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
|
1941 |
const Order *o; |
7e0ebb20950d
(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
|
1942 |
const Vehicle *u; |
7e0ebb20950d
(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
|
1943 |
|
7e0ebb20950d
(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
|
1944 |
if (v->type == VEH_Train) { |
7e0ebb20950d
(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
|
1945 |
u = GetFirstVehicleInChain(v); |
7e0ebb20950d
(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
|
1946 |
} else { |
7e0ebb20950d
(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 |
u = v; |
7e0ebb20950d
(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 |
} |
7e0ebb20950d
(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 |
|
7e0ebb20950d
(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 |
FOR_VEHICLE_ORDERS(u, o) { |
4782
3ee91034a50e
(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
|
1951 |
if (!(o->refit_cargo < NUM_CARGO)) continue; |
4741
7e0ebb20950d
(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 |
if (!CanRefitTo(v->engine_type, o->refit_cargo)) continue; |
7e0ebb20950d
(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 |
if (!CanRefitTo(engine_type, o->refit_cargo)) return false; |
7e0ebb20950d
(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
|
1954 |
} |
7e0ebb20950d
(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
|
1955 |
|
7e0ebb20950d
(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
|
1956 |
return true; |
7e0ebb20950d
(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
|
1957 |
} |
7e0ebb20950d
(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
|
1958 |
|
4554
ff008b423676
(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 |
/** |
ff008b423676
(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 |
* Function to find what type of cargo to refit to when autoreplacing |
ff008b423676
(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 |
* @param *v Original vehicle, that is being replaced |
ff008b423676
(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 |
* @param engine_type The EngineID of the vehicle that is being replaced to |
ff008b423676
(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 |
* @return The cargo type to replace to |
ff008b423676
(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 |
* CT_NO_REFIT is returned if no refit is needed |
ff008b423676
(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 |
* 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 |
ff008b423676
(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 |
*/ |
ff008b423676
(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 |
static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type) |
ff008b423676
(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 |
{ |
ff008b423676
(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 |
bool new_cargo_capacity = true; |
ff008b423676
(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 |
CargoID new_cargo_type = CT_INVALID; |
ff008b423676
(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 |
|
ff008b423676
(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
|
1972 |
switch (v->type) { |
ff008b423676
(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
|
1973 |
case VEH_Train: |
ff008b423676
(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
|
1974 |
new_cargo_capacity = (RailVehInfo(engine_type)->capacity > 0); |
ff008b423676
(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
|
1975 |
new_cargo_type = RailVehInfo(engine_type)->cargo_type; |
ff008b423676
(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
|
1976 |
break; |
ff008b423676
(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
|
1977 |
|
ff008b423676
(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
|
1978 |
case VEH_Road: |
ff008b423676
(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 |
new_cargo_capacity = (RoadVehInfo(engine_type)->capacity > 0); |
ff008b423676
(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
|
1980 |
new_cargo_type = RoadVehInfo(engine_type)->cargo_type; |
ff008b423676
(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
|
1981 |
break; |
ff008b423676
(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
|
1982 |
case VEH_Ship: |
ff008b423676
(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
|
1983 |
new_cargo_capacity = (ShipVehInfo(engine_type)->capacity > 0); |
ff008b423676
(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
|
1984 |
new_cargo_type = ShipVehInfo(engine_type)->cargo_type; |
ff008b423676
(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
|
1985 |
break; |
ff008b423676
(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
|
1986 |
|
ff008b423676
(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
|
1987 |
case VEH_Aircraft: |
ff008b423676
(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
|
1988 |
/* all aircraft starts as passenger planes with cargo capacity |
ff008b423676
(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
|
1989 |
* new_cargo_capacity is always true for aircraft, which is the init value. No need to set it here */ |
ff008b423676
(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 |
new_cargo_type = CT_PASSENGERS; |
ff008b423676
(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
|
1991 |
break; |
ff008b423676
(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
|
1992 |
|
ff008b423676
(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
|
1993 |
default: NOT_REACHED(); break; |
ff008b423676
(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
|
1994 |
} |
ff008b423676
(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 |
|
ff008b423676
(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 |
if (!new_cargo_capacity) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity |
ff008b423676
(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 |
|
4741
7e0ebb20950d
(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
|
1998 |
if (v->cargo_type == new_cargo_type || CanRefitTo(engine_type, v->cargo_type)) { |
7e0ebb20950d
(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
|
1999 |
if (VerifyAutoreplaceRefitForOrders(v, engine_type)) { |
7e0ebb20950d
(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
|
2000 |
return v->cargo_type == new_cargo_type ? CT_NO_REFIT : v->cargo_type; |
7e0ebb20950d
(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
|
2001 |
} else { |
7e0ebb20950d
(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
|
2002 |
return CT_INVALID; |
7e0ebb20950d
(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
|
2003 |
} |
7e0ebb20950d
(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
|
2004 |
} |
4554
ff008b423676
(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
|
2005 |
if (v->type != VEH_Train) return CT_INVALID; // We can't refit the vehicle to carry the cargo we want |
ff008b423676
(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
|
2006 |
|
ff008b423676
(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
|
2007 |
/* Below this line it's safe to assume that the vehicle in question is a train */ |
ff008b423676
(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
|
2008 |
|
ff008b423676
(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
|
2009 |
if (v->cargo_cap != 0) return CT_INVALID; // trying to replace a vehicle with cargo capacity into another one with incompatible cargo type |
ff008b423676
(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
|
2010 |
|
ff008b423676
(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
|
2011 |
/* the old engine didn't have cargo capacity, but the new one does |
ff008b423676
(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
|
2012 |
* now we will figure out what cargo the train is carrying and refit to fit this */ |
ff008b423676
(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
|
2013 |
v = GetFirstVehicleInChain(v); |
ff008b423676
(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
|
2014 |
do { |
ff008b423676
(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 (v->cargo_cap == 0) continue; |
ff008b423676
(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 |
/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */ |
ff008b423676
(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
|
2017 |
if (v->cargo_type == new_cargo_type) return CT_NO_REFIT; |
ff008b423676
(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
|
2018 |
if (CanRefitTo(engine_type, v->cargo_type)) return v->cargo_type; |
ff008b423676
(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
|
2019 |
} while ((v=v->next) != NULL); |
ff008b423676
(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
|
2020 |
return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one |
ff008b423676
(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
|
2021 |
} |
ff008b423676
(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 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2023 |
/* Replaces a vehicle (used to be called autorenew) |
2639 | 2024 |
* This function is only called from MaybeReplaceVehicle() |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2025 |
* Must be called with _current_player set to the owner of the vehicle |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2026 |
* @param w Vehicle to replace |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2027 |
* @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts |
2639 | 2028 |
* @return value is cost of the replacement or CMD_ERROR |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2029 |
*/ |
4554
ff008b423676
(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
|
2030 |
static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost) |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2031 |
{ |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2032 |
int32 cost; |
4728
cdc127bf9ac4
(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
|
2033 |
int32 sell_value; |
2599
7dd6060f9749
(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
|
2034 |
Vehicle *old_v = *w; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2035 |
const Player *p = GetPlayer(old_v->owner); |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2036 |
EngineID new_engine_type; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2037 |
const UnitID cached_unitnumber = old_v->unitnumber; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2038 |
bool new_front = false; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2039 |
Vehicle *new_v = NULL; |
2716
bc7847ae0e43
(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
|
2040 |
char vehicle_name[32]; |
4554
ff008b423676
(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
|
2041 |
CargoID replacement_cargo_type; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2042 |
|
2848 | 2043 |
new_engine_type = EngineReplacementForPlayer(p, old_v->engine_type); |
2697
c7b1a950c4cf
(svn r3239) - Codechange: Introduce and use helper functions for engine replacement code.
peter1138
parents:
2685
diff
changeset
|
2044 |
if (new_engine_type == INVALID_ENGINE) new_engine_type = old_v->engine_type; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2045 |
|
4554
ff008b423676
(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
|
2046 |
replacement_cargo_type = GetNewCargoTypeForReplace(old_v, new_engine_type); |
ff008b423676
(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
|
2047 |
|
ff008b423676
(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
|
2048 |
/* check if we can't refit to the needed type, so no replace takes place to prevent the vehicle from altering cargo type */ |
ff008b423676
(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
|
2049 |
if (replacement_cargo_type == CT_INVALID) return 0; |
ff008b423676
(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
|
2050 |
|
4728
cdc127bf9ac4
(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
|
2051 |
sell_value = DoCommand(0, old_v->index, 0, DC_QUERY_COST, CMD_SELL_VEH(old_v->type)); |
cdc127bf9ac4
(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
|
2052 |
|
cdc127bf9ac4
(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
|
2053 |
/* We give the player a loan of the same amount as the sell value. |
cdc127bf9ac4
(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
|
2054 |
* This is needed in case he needs the income from the sale to build the new vehicle. |
cdc127bf9ac4
(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
|
2055 |
* We take it back if building fails or when we really sell the old engine */ |
cdc127bf9ac4
(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
|
2056 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
cdc127bf9ac4
(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
|
2057 |
SubtractMoneyFromPlayer(sell_value); |
cdc127bf9ac4
(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
|
2058 |
|
3816
2cdb29b57c1f
(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
|
2059 |
cost = DoCommand(old_v->tile, new_engine_type, 3, flags, CMD_BUILD_VEH(old_v->type)); |
4728
cdc127bf9ac4
(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
|
2060 |
if (CmdFailed(cost)) { |
cdc127bf9ac4
(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
|
2061 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
cdc127bf9ac4
(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
|
2062 |
SubtractMoneyFromPlayer(-sell_value); // Take back the money we just gave the player |
cdc127bf9ac4
(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
|
2063 |
return cost; |
cdc127bf9ac4
(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
|
2064 |
} |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2065 |
|
4554
ff008b423676
(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
|
2066 |
if (replacement_cargo_type != CT_NO_REFIT) cost += GetRefitCost(new_engine_type); // add refit cost |
ff008b423676
(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
|
2067 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2068 |
if (flags & DC_EXEC) { |
2564 | 2069 |
new_v = GetVehicle(_new_vehicle_id); |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2070 |
*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
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2071 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2072 |
/* refit if needed */ |
4554
ff008b423676
(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
|
2073 |
if (replacement_cargo_type != CT_NO_REFIT) { |
4611
bb035900cae5
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
bjarni
parents:
4604
diff
changeset
|
2074 |
if (CmdFailed(DoCommand(0, new_v->index, replacement_cargo_type, DC_EXEC, CMD_REFIT_VEH(new_v->type)))) { |
4613
8b561558309f
(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
|
2075 |
/* Being here shows a failure, which most likely is in GetNewCargoTypeForReplace() or incorrect estimation costs */ |
8b561558309f
(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
|
2076 |
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
bb035900cae5
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
bjarni
parents:
4604
diff
changeset
|
2077 |
} |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2078 |
} |
4611
bb035900cae5
(svn r6464) -Fix r6393: killed a warning when compiling without asserts
bjarni
parents:
4604
diff
changeset
|
2079 |
|
3896
292881445b9c
(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
|
2080 |
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))) { |
292881445b9c
(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
|
2081 |
// we are autorenewing to a single engine, so we will turn it as the old one was turned as well |
292881445b9c
(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
|
2082 |
SETBIT(new_v->u.rail.flags, VRF_REVERSE_DIRECTION); |
292881445b9c
(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
|
2083 |
} |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2084 |
|
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2085 |
if (old_v->type == VEH_Train && !IsFrontEngine(old_v)) { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2086 |
/* this is a railcar. We need to move the car into the train |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2087 |
* We add the new engine after the old one instead of replacing it. It will give the same result anyway when we |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2088 |
* sell the old engine in a moment |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2089 |
*/ |
3491
4c8427796c64
(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
|
2090 |
DoCommand(0, (GetPrevVehicleInChain(old_v)->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2678
a0af6bded583
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
2091 |
/* Now we move the old one out of the train */ |
3491
4c8427796c64
(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
|
2092 |
DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2093 |
} else { |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2094 |
// copy/clone the orders |
3491
4c8427796c64
(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
|
2095 |
DoCommand(0, (old_v->index << 16) | new_v->index, IsOrderListShared(old_v) ? CO_SHARE : CO_COPY, DC_EXEC, CMD_CLONE_ORDER); |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2096 |
new_v->cur_order_index = old_v->cur_order_index; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2097 |
ChangeVehicleViewWindow(old_v, new_v); |
2575
44f0dd3b4a97
(svn r3112) -Feature: [autoreplace] profit counters are now remembered too (request by Darkvater)
bjarni
parents:
2574
diff
changeset
|
2098 |
new_v->profit_this_year = old_v->profit_this_year; |
44f0dd3b4a97
(svn r3112) -Feature: [autoreplace] profit counters are now remembered too (request by Darkvater)
bjarni
parents:
2574
diff
changeset
|
2099 |
new_v->profit_last_year = old_v->profit_last_year; |
3679
8e7e14ee361a
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
2100 |
new_v->service_interval = old_v->service_interval; |
5540
f96ccea118f5
(svn r11071) [0.5] -Fix [FS#1218]: crash when quiting the game in one of the end score windows.
rubidium
parents:
5512
diff
changeset
|
2101 |
new_v->load_status = old_v->load_status; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2102 |
new_front = true; |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2103 |
new_v->unitnumber = old_v->unitnumber; // use the same unit number |
5495
ccc57a497257
(svn r9851) [0.5] -Backport from trunk (r9731, r9741, r9743, r9753, r9757):
rubidium
parents:
5446
diff
changeset
|
2104 |
new_v->dest_tile = old_v->dest_tile; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2105 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2106 |
new_v->current_order = old_v->current_order; |
2842
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2107 |
if (old_v->type == VEH_Train && GetNextVehicle(old_v) != NULL){ |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2108 |
Vehicle *temp_v = GetNextVehicle(old_v); |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2109 |
|
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2110 |
// move the entire train to the new engine, excluding the old engine |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2111 |
if (IsMultiheaded(old_v) && temp_v == old_v->u.rail.other_multiheaded_part) { |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2112 |
// we got front and rear of a multiheaded engine right after each other. We should work with the next in line instead |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2113 |
temp_v = GetNextVehicle(temp_v); |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2114 |
} |
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2115 |
|
48ac5c48f78a
(svn r3390) -Fix: [autoreplace] fixed issue where autoreplace failed to attach the cars if the front engine was replaced
bjarni
parents:
2819
diff
changeset
|
2116 |
if (temp_v != NULL) { |
3491
4c8427796c64
(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
|
2117 |
DoCommand(0, (new_v->index << 16) | temp_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2681
ac4d59ac8651
(svn r3223) -Fix: [autoreplace] fixed crash when replacing a train engine without any cars (introduced in r3220)
bjarni
parents:
2678
diff
changeset
|
2118 |
} |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2119 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2120 |
} |
2678
a0af6bded583
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
2121 |
/* We are done setting up the new vehicle. Now we move the cargo from the old one to the new one */ |
a0af6bded583
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
2122 |
MoveVehicleCargo(new_v->type == VEH_Train ? GetFirstVehicleInChain(new_v) : new_v, old_v); |
2716
bc7847ae0e43
(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
|
2123 |
|
bc7847ae0e43
(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
|
2124 |
// Get the name of the old vehicle if it has a custom name. |
4862
b45c1e638e7f
(svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents:
4784
diff
changeset
|
2125 |
if (!IsCustomName(old_v->string_id)) { |
2716
bc7847ae0e43
(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
|
2126 |
vehicle_name[0] = '\0'; |
bc7847ae0e43
(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
|
2127 |
} else { |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4862
diff
changeset
|
2128 |
GetName(vehicle_name, old_v->string_id & 0x7FF, lastof(vehicle_name)); |
2716
bc7847ae0e43
(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
|
2129 |
} |
4554
ff008b423676
(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
|
2130 |
} else { // flags & DC_EXEC not set |
ff008b423676
(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
|
2131 |
/* Ensure that the player will not end up having negative money while autoreplacing |
ff008b423676
(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
|
2132 |
* This is needed because the only other check is done after the income from selling the old vehicle is substracted from the cost */ |
4728
cdc127bf9ac4
(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
|
2133 |
if (p->money64 < (cost + total_cost)) { |
cdc127bf9ac4
(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
|
2134 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
cdc127bf9ac4
(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
|
2135 |
SubtractMoneyFromPlayer(-sell_value); // Pay back the loan |
cdc127bf9ac4
(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
|
2136 |
return CMD_ERROR; |
cdc127bf9ac4
(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
|
2137 |
} |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2138 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2139 |
|
4728
cdc127bf9ac4
(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
|
2140 |
/* Take back the money we just gave the player just before building the vehicle |
cdc127bf9ac4
(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
|
2141 |
* The player will get the same amount now that the sale actually takes place */ |
cdc127bf9ac4
(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
|
2142 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
cdc127bf9ac4
(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
|
2143 |
SubtractMoneyFromPlayer(-sell_value); |
cdc127bf9ac4
(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
|
2144 |
|
4554
ff008b423676
(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
|
2145 |
/* sell the engine/ find out how much you get for the old engine (income is returned as negative cost) */ |
3491
4c8427796c64
(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
|
2146 |
cost += DoCommand(0, old_v->index, 0, flags, CMD_SELL_VEH(old_v->type)); |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2147 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2148 |
if (new_front) { |
4554
ff008b423676
(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
|
2149 |
/* now we assign the old unitnumber to the new vehicle */ |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2150 |
new_v->unitnumber = cached_unitnumber; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2151 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2152 |
|
4554
ff008b423676
(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
|
2153 |
/* Transfer the name of the old vehicle */ |
2716
bc7847ae0e43
(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
|
2154 |
if ((flags & DC_EXEC) && vehicle_name[0] != '\0') { |
bc7847ae0e43
(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
|
2155 |
_cmd_text = vehicle_name; |
3491
4c8427796c64
(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
|
2156 |
DoCommand(0, new_v->index, 0, DC_EXEC, CMD_NAME_VEHICLE); |
2716
bc7847ae0e43
(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
|
2157 |
} |
bc7847ae0e43
(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
|
2158 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2159 |
return cost; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2160 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2161 |
|
2639 | 2162 |
/** replaces a vehicle if it's set for autoreplace or is too old |
2163 |
* (used to be called autorenew) |
|
2164 |
* @param v The vehicle to replace |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2165 |
* if the vehicle is a train, v needs to be the front engine |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2166 |
* @param check Checks if the replace is valid. No action is done at all |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2167 |
* @param display_costs If set, a cost animation is shown (only if check is false) |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2168 |
* @return CMD_ERROR if something went wrong. Otherwise the price of the replace |
2639 | 2169 |
*/ |
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
2170 |
static int32 MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs) |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2171 |
{ |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2172 |
Vehicle *w; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2173 |
const Player *p = GetPlayer(v->owner); |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2174 |
byte flags = 0; |
2591
76a053785b35
(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
|
2175 |
int32 cost, temp_cost = 0; |
5418
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
2176 |
bool stopped; |
2805
b6098e7ca457
(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
|
2177 |
|
b6098e7ca457
(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
|
2178 |
/* Remember the length in case we need to trim train later on |
3175
bc706c6deaee
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
2179 |
* If it's not a train, the value is unused |
bc706c6deaee
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
2180 |
* round up to the length of the tiles used for the train instead of the train length instead |
bc706c6deaee
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
2181 |
* Useful when newGRF uses custom length */ |
3422
12cdb13ddb56
(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
|
2182 |
uint16 old_total_length = (v->type == VEH_Train ? |
12cdb13ddb56
(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
|
2183 |
(v->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE * TILE_SIZE : |
12cdb13ddb56
(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
|
2184 |
-1 |
12cdb13ddb56
(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
|
2185 |
); |
3175
bc706c6deaee
(svn r3811) -Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length
bjarni
parents:
3173
diff
changeset
|
2186 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2187 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2188 |
_current_player = v->owner; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2189 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2190 |
assert(v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship || v->type == VEH_Aircraft); |
2579
1662ff19b404
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
2191 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2192 |
assert(v->vehstatus & VS_STOPPED); // the vehicle should have been stopped in VehicleEnteredDepotThisTick() if needed |
2590
5603f43c8cd3
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
2193 |
|
5418
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
2194 |
/* Remember the flag v->leave_depot_instantly because if we replace the vehicle, the vehicle holding this flag will be sold |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
2195 |
* If it is set, then we only stopped the vehicle to replace it (if needed) and we will need to start it again. |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
2196 |
* We also need to reset the flag since it should remain false except from when the vehicle enters a depot until autoreplace is handled in the same tick */ |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
2197 |
stopped = v->leave_depot_instantly; |
ee2e44854454
(svn r8182) -Backport from trunk (r8137, r8147, r8157):
Darkvater
parents:
5357
diff
changeset
|
2198 |
v->leave_depot_instantly = false; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2199 |
|
2639 | 2200 |
for (;;) { |
2591
76a053785b35
(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
|
2201 |
cost = 0; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2202 |
w = v; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2203 |
do { |
2676
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2204 |
if (w->type == VEH_Train && IsMultiheaded(w) && !IsTrainEngine(w)) { |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2205 |
/* we build the rear ends of multiheaded trains with the front ones */ |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2206 |
continue; |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2207 |
} |
2ba71e034d97
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
2208 |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2209 |
// check if the vehicle should be replaced |
2639 | 2210 |
if (!p->engine_renew || |
2211 |
w->age - w->max_age < (p->engine_renew_months * 30) || // replace if engine is too old |
|
2212 |
w->max_age == 0) { // rail cars got a max age of 0 |
|
2848 | 2213 |
if (!EngineHasReplacementForPlayer(p, w->engine_type)) // updates to a new model |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2214 |
continue; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2215 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2216 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2217 |
/* Now replace the vehicle */ |
4554
ff008b423676
(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
|
2218 |
temp_cost = ReplaceVehicle(&w, flags, cost); |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2219 |
|
2639 | 2220 |
if (flags & DC_EXEC && |
2999
f5351c475765
(svn r3579) v->u.rail.first_engine holds an engine type, not a vehicle index, so use INVALID_ENGINE.
peter1138
parents:
2998
diff
changeset
|
2221 |
(w->type != VEH_Train || w->u.rail.first_engine == INVALID_ENGINE)) { |
2639 | 2222 |
/* now we bought a new engine and sold the old one. We need to fix the |
2223 |
* pointers in order to avoid pointing to the old one for trains: these |
|
2224 |
* pointers should point to the front engine and not the cars |
|
2225 |
*/ |
|
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2226 |
v = w; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2227 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2228 |
|
3413
903b3cc14bb7
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
2229 |
if (!CmdFailed(temp_cost)) { |
903b3cc14bb7
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
2230 |
cost += temp_cost; |
903b3cc14bb7
(svn r4228) -Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
bjarni
parents:
3412
diff
changeset
|
2231 |
} |
2602
f0e2dcce3695
(svn r3139) -NewGRF, Feature: support for articulated rail vehicles. This is used, for example, by coal tenders.
peter1138
parents:
2601
diff
changeset
|
2232 |
} while (w->type == VEH_Train && (w = GetNextVehicle(w)) != NULL); |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2233 |
|
4515
e4e8556f69a2
(svn r6300) -Fix: FS#321 autoreplace / wagon removal
bjarni
parents:
4506
diff
changeset
|
2234 |
if (!(flags & DC_EXEC) && (p->money64 < (int32)(cost + p->engine_renew_money) || cost == 0)) { |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2235 |
if (!check && p->money64 < (int32)(cost + p->engine_renew_money) && ( _local_player == v->owner ) && cost != 0) { |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2236 |
StringID message; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2237 |
SetDParam(0, v->unitnumber); |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2238 |
switch (v->type) { |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2239 |
case VEH_Train: message = STR_TRAIN_AUTORENEW_FAILED; break; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2240 |
case VEH_Road: message = STR_ROADVEHICLE_AUTORENEW_FAILED; break; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2241 |
case VEH_Ship: message = STR_SHIP_AUTORENEW_FAILED; break; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2242 |
case VEH_Aircraft: message = STR_AIRCRAFT_AUTORENEW_FAILED; break; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2243 |
// This should never happen |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2244 |
default: NOT_REACHED(); message = 0; break; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2245 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2246 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2247 |
AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2248 |
} |
2639 | 2249 |
if (stopped) v->vehstatus &= ~VS_STOPPED; |
4676
e58dba0b7093
(svn r6580) -Fix r6552: [depot window] fixed issue where vehicles sometimes failed to restart after being replaced
bjarni
parents:
4675
diff
changeset
|
2250 |
if (display_costs) _current_player = OWNER_NONE; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2251 |
return CMD_ERROR; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2252 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2253 |
|
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2254 |
if (flags & DC_EXEC) { |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
2255 |
break; // we are done replacing since the loop ran once with DC_EXEC |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2256 |
} else if (check) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2257 |
/* It's a test only and we know that we can do this |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2258 |
* NOTE: payment for wagon removal is NOT included in this price */ |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2259 |
return cost; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2260 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2261 |
// now we redo the loop, but this time we actually do stuff since we know that we can do it |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2262 |
flags |= DC_EXEC; |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2263 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2264 |
|
2805
b6098e7ca457
(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
|
2265 |
/* If setting is on to try not to exceed the old length of the train with the replacement */ |
b6098e7ca457
(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
|
2266 |
if (v->type == VEH_Train && p->renew_keep_length) { |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2267 |
Vehicle *temp; |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2268 |
w = v; |
2805
b6098e7ca457
(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
|
2269 |
|
b6098e7ca457
(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
|
2270 |
while (v->u.rail.cached_total_length > old_total_length) { |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2271 |
// the train is too long. We will remove cars one by one from the start of the train until it's short enough |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2272 |
while (w != NULL && !(RailVehInfo(w->engine_type)->flags&RVI_WAGON) ) { |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2273 |
w = GetNextVehicle(w); |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2274 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2275 |
if (w == NULL) { |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2276 |
// we failed to make the train short enough |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2277 |
SetDParam(0, v->unitnumber); |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2278 |
AddNewsItem(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2279 |
break; |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2280 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2281 |
temp = w; |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2282 |
w = GetNextVehicle(w); |
3491
4c8427796c64
(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
|
2283 |
DoCommand(0, (INVALID_VEHICLE << 16) | temp->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); |
2678
a0af6bded583
(svn r3220) -Fix: [autoreplace] Autoreplaced trains now replace their cargo to the train instead of just the new engine
bjarni
parents:
2677
diff
changeset
|
2284 |
MoveVehicleCargo(v, temp); |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2285 |
cost += DoCommand(0, temp->index, 0, DC_EXEC, CMD_SELL_RAIL_WAGON); |
2617
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2286 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2287 |
} |
a9e1a187de99
(svn r3155) -Feature: [autoreplace] autoreplace can now remove cars from too long trains
bjarni
parents:
2611
diff
changeset
|
2288 |
|
2639 | 2289 |
if (stopped) v->vehstatus &= ~VS_STOPPED; |
4662
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2290 |
if (display_costs) { |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2291 |
if (IsLocalPlayer()) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2292 |
_current_player = OWNER_NONE; |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2293 |
} |
a20121e5442b
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
2294 |
return cost; |
2552
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2295 |
} |
fb174febb0b1
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
2296 |
|
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2297 |
/* Extend the list size for BuildDepotVehicleList() */ |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2298 |
static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *engine_list_length, uint16 step_size) |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2299 |
{ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
2300 |
*engine_list_length = min(*engine_list_length + step_size, GetMaxVehicleIndex() + 1); |
4685 | 2301 |
*engine_list = realloc((void*)*engine_list, (*engine_list_length) * sizeof((*engine_list)[0])); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2302 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2303 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2304 |
/** Generates a list of vehicles inside a depot |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2305 |
* 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) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2306 |
* If one of the lists is not needed (say wagons when finding ships), all the pointers regarding that list should be set to NULL |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2307 |
* @param Type type of vehicle |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2308 |
* @param tile The tile the depot is located in |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2309 |
* @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) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2310 |
* @param *engine_list_length Allocated size of engine_list. Needs to be set to 0 when engine_list points to a NULL array |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2311 |
* @param *engine_count The number of engines stored in the list |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2312 |
* @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) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2313 |
* @param *wagon_list_length Allocated size of wagon_list. Needs to be set to 0 when wagon_list points to a NULL array |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2314 |
* @param *wagon_count The number of engines stored in the list |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2315 |
*/ |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2316 |
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) |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2317 |
{ |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2318 |
Vehicle *v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2319 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2320 |
/* This function should never be called without an array to store results */ |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2321 |
assert(!(engine_list == NULL && type != VEH_Train)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2322 |
assert(!(type == VEH_Train && engine_list == NULL && wagon_list == NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2323 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2324 |
/* Both array and the length should either be NULL to disable the list or both should not be NULL */ |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2325 |
assert((engine_list == NULL && engine_list_length == NULL) || (engine_list != NULL && engine_list_length != NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2326 |
assert((wagon_list == NULL && wagon_list_length == NULL) || (wagon_list != NULL && wagon_list_length != NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2327 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2328 |
assert(!(engine_list != NULL && engine_count == NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2329 |
assert(!(wagon_list != NULL && wagon_count == NULL)); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2330 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2331 |
if (engine_count != NULL) *engine_count = 0; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2332 |
if (wagon_count != NULL) *wagon_count = 0; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2333 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2334 |
switch (type) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2335 |
case VEH_Train: |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2336 |
FOR_ALL_VEHICLES(v) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2337 |
if (v->tile == tile && v->type == VEH_Train && v->u.rail.track == 0x80) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2338 |
if (IsFrontEngine(v)) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2339 |
if (engine_list == NULL) continue; |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2340 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2341 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2342 |
} else if (IsFreeWagon(v)) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2343 |
if (wagon_list == NULL) continue; |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2344 |
if (*wagon_count == *wagon_list_length) ExtendVehicleListSize((const Vehicle***)wagon_list, wagon_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2345 |
(*wagon_list)[(*wagon_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2346 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2347 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2348 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2349 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2350 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2351 |
case VEH_Road: |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2352 |
FOR_ALL_VEHICLES(v) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2353 |
if (v->tile == tile && v->type == VEH_Road && IsRoadVehInDepot(v)) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2354 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2355 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2356 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2357 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2358 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2359 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2360 |
case VEH_Ship: |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2361 |
FOR_ALL_VEHICLES(v) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2362 |
if (v->tile == tile && v->type == VEH_Ship && IsShipInDepot(v)) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2363 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2364 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2365 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2366 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2367 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2368 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2369 |
case VEH_Aircraft: |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2370 |
FOR_ALL_VEHICLES(v) { |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2371 |
if (v->tile == tile && |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2372 |
v->type == VEH_Aircraft && |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2373 |
v->subtype <= 2 && |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2374 |
v->vehstatus & VS_HIDDEN) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2375 |
if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25); |
4635
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2376 |
(*engine_list)[(*engine_count)++] = v; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2377 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2378 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2379 |
break; |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2380 |
|
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2381 |
default: NOT_REACHED(); |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2382 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2383 |
} |
b9fb2f19eb64
(svn r6503) -Codechange: added a function to tell what vehicles a depot contains
bjarni
parents:
4616
diff
changeset
|
2384 |
|
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2385 |
/** |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2386 |
* @param sort_list list to store the list in. Either NULL or the length length_of_array tells |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2387 |
* @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
ff008b423676
(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
|
2388 |
* @param type type of vehicle |
ff008b423676
(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
|
2389 |
* @param owner PlayerID of owner to generate a list for |
ff008b423676
(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
|
2390 |
* @param station index of station to generate a list for. INVALID_STATION when not used |
ff008b423676
(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
|
2391 |
* @param order index of oder to generate a list for. INVALID_ORDER when not used |
ff008b423676
(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
|
2392 |
* @param window_type tells what kind of window the list is for. Use the VLW flags in vehicle_gui.h |
ff008b423676
(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
|
2393 |
* @return the number of vehicles added to the list |
ff008b423676
(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
|
2394 |
*/ |
5430
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5427
diff
changeset
|
2395 |
uint GenerateVehicleSortList(const Vehicle ***sort_list, uint16 *length_of_array, byte type, PlayerID owner, StationID station, OrderID order, uint32 depot_airport_index, uint16 window_type) |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2396 |
{ |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2397 |
const uint subtype = (type != VEH_Aircraft) ? Train_Front : 2; |
4499
c57155fea7a5
(svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents:
4497
diff
changeset
|
2398 |
uint n = 0; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2399 |
const Vehicle *v; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2400 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2401 |
switch (window_type) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2402 |
case VLW_STATION_LIST: { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2403 |
FOR_ALL_VEHICLES(v) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2404 |
if (v->type == type && ( |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2405 |
(type == VEH_Train && IsFrontEngine(v)) || |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2406 |
(type != VEH_Train && v->subtype <= subtype))) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2407 |
const Order *order; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2408 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2409 |
FOR_VEHICLE_ORDERS(v, order) { |
4527
b18634a31a4a
(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
|
2410 |
if (order->type == OT_GOTO_STATION && order->dest == station) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2411 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 50); |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2412 |
(*sort_list)[n++] = v; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2413 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2414 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2415 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2416 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2417 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2418 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2419 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2420 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2421 |
case VLW_SHARED_ORDERS: { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2422 |
FOR_ALL_VEHICLES(v) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2423 |
/* Find a vehicle with the order in question */ |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2424 |
if (v->orders != NULL && v->orders->index == order) break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2425 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2426 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2427 |
if (v != NULL && v->orders != NULL && v->orders->index == order) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2428 |
/* Only try to make the list if we found a vehicle using the order in question */ |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2429 |
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2430 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2431 |
(*sort_list)[n++] = v; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2432 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2433 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2434 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2435 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2436 |
|
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2437 |
case VLW_STANDARD: { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2438 |
FOR_ALL_VEHICLES(v) { |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2439 |
if (v->type == type && v->owner == owner && ( |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2440 |
(type == VEH_Train && IsFrontEngine(v)) || |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2441 |
(type != VEH_Train && v->subtype <= subtype))) { |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2442 |
/* TODO find a better estimate on the total number of vehicles for current player */ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
2443 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, GetNumVehicles()/4); |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2444 |
(*sort_list)[n++] = v; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2445 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2446 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2447 |
break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2448 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2449 |
|
4681
7d7a89b32dd0
(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
|
2450 |
case VLW_DEPOT_LIST: { |
7d7a89b32dd0
(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
|
2451 |
FOR_ALL_VEHICLES(v) { |
7d7a89b32dd0
(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
|
2452 |
if (v->type == type && ( |
7d7a89b32dd0
(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
|
2453 |
(type == VEH_Train && IsFrontEngine(v)) || |
7d7a89b32dd0
(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
|
2454 |
(type != VEH_Train && v->subtype <= subtype))) { |
7d7a89b32dd0
(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
|
2455 |
const Order *order; |
7d7a89b32dd0
(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
|
2456 |
|
7d7a89b32dd0
(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
|
2457 |
FOR_VEHICLE_ORDERS(v, order) { |
7d7a89b32dd0
(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
|
2458 |
if (order->type == OT_GOTO_DEPOT && order->dest == depot_airport_index) { |
7d7a89b32dd0
(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
|
2459 |
if (n == *length_of_array) ExtendVehicleListSize(sort_list, length_of_array, 25); |
7d7a89b32dd0
(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
|
2460 |
(*sort_list)[n++] = v; |
7d7a89b32dd0
(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
|
2461 |
break; |
7d7a89b32dd0
(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
|
2462 |
} |
7d7a89b32dd0
(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
|
2463 |
} |
7d7a89b32dd0
(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
|
2464 |
} |
7d7a89b32dd0
(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
|
2465 |
} |
7d7a89b32dd0
(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
|
2466 |
break; |
7d7a89b32dd0
(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
|
2467 |
} |
7d7a89b32dd0
(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
|
2468 |
|
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2469 |
default: NOT_REACHED(); break; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2470 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2471 |
|
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2472 |
if ((n + 100) < *length_of_array) { |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2473 |
/* We allocated way too much for sort_list. |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2474 |
* Now we will reduce how much we allocated. |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2475 |
* We will still make it have room for 50 extra vehicles to prevent having |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2476 |
* to move the whole array if just one vehicle is added later */ |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2477 |
*length_of_array = n + 50; |
4685 | 2478 |
*sort_list = realloc((void*)*sort_list, (*length_of_array) * sizeof((*sort_list)[0])); |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2479 |
} |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2480 |
|
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2481 |
return n; |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2482 |
} |
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2483 |
|
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2484 |
/** send all vehicles of type to depots |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2485 |
* @param type type of vehicle |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2486 |
* @param flags the flags used for DoCommand() |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2487 |
* @param service should the vehicles only get service in the depots |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2488 |
* @param owner PlayerID of owner of the vehicles to send |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2489 |
* @param VLW_flag tells what kind of list requested the goto depot |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2490 |
* @return 0 for success and CMD_ERROR if no vehicle is able to go to depot |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2491 |
*/ |
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4499
diff
changeset
|
2492 |
int32 SendAllVehiclesToDepot(byte type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id) |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2493 |
{ |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2494 |
const Vehicle **sort_list = NULL; |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2495 |
uint n, i; |
4678
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2496 |
uint16 array_length = 0; |
073e56e25e83
(svn r6582) -Codechange: changed GenerateVehicleSortList() to reuse the same allocation over and over if possible (like BuildDepotVehicleList() )
bjarni
parents:
4676
diff
changeset
|
2497 |
|
4681
7d7a89b32dd0
(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
|
2498 |
n = GenerateVehicleSortList(&sort_list, &array_length, type, owner, id, id, id, vlw_flag); |
4465
852cf43b354f
(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
|
2499 |
|
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2500 |
/* Send all the vehicles to a depot */ |
4499
c57155fea7a5
(svn r6284) -Code Cleanup r6282: cleaned up the code a bit
bjarni
parents:
4497
diff
changeset
|
2501 |
for (i = 0; i < n; i++) { |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2502 |
const Vehicle *v = sort_list[i]; |
4560
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2503 |
int32 ret = DoCommand(v->tile, v->index, service | DEPOT_DONT_CANCEL, flags, CMD_SEND_TO_DEPOT(type)); |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2504 |
|
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2505 |
/* Return 0 if DC_EXEC is not set this is a valid goto depot command) |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2506 |
* In this case we know that at least one vehicle can be sent to a depot |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2507 |
* and we will issue the command. We can now safely quit the loop, knowing |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2508 |
* it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
f744bf3dd85a
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
2509 |
if (!CmdFailed(ret) && !(flags & DC_EXEC)) { |
4683
13d7b7d779cf
(svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents:
4681
diff
changeset
|
2510 |
free((void*)sort_list); |
4497
7ef263b6c05c
(svn r6282) -Codechange: made a function to create the vehicle list for vehicle list windows
bjarni
parents:
4495
diff
changeset
|
2511 |
return 0; |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2512 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2513 |
} |
4465
852cf43b354f
(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
|
2514 |
|
4683
13d7b7d779cf
(svn r6588) -Fix r6582: killed some windows only warnings (thanks webfreakz for testing)
bjarni
parents:
4681
diff
changeset
|
2515 |
free((void*)sort_list); |
4465
852cf43b354f
(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
|
2516 |
return (flags & DC_EXEC) ? 0 : CMD_ERROR; |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2517 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
2518 |
|
4734
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2519 |
bool IsVehicleInDepot(const Vehicle *v) |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2520 |
{ |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2521 |
switch (v->type) { |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2522 |
case VEH_Train: return CheckTrainInDepot(v, false) != -1; |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2523 |
case VEH_Road: return IsRoadVehInDepot(v); |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2524 |
case VEH_Ship: return IsShipInDepot(v); |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2525 |
case VEH_Aircraft: return IsAircraftInHangar(v); |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2526 |
default: NOT_REACHED(); |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2527 |
} |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2528 |
return false; |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2529 |
} |
20770a208a04
(svn r6646) -Codechange: [vehicle list window] Cleaned up the drawing code
bjarni
parents:
4728
diff
changeset
|
2530 |
|
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2531 |
void VehicleEnterDepot(Vehicle *v) |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2532 |
{ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2533 |
switch (v->type) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2534 |
case VEH_Train: |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2535 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2536 |
if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2537 |
UpdateSignalsOnSegment(v->tile, GetRailDepotDirection(v->tile)); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2538 |
v->load_unload_time_rem = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2539 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2540 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2541 |
case VEH_Road: |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2542 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2543 |
v->u.road.state = 254; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2544 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2545 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2546 |
case VEH_Ship: |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2547 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2548 |
v->u.ship.state = 0x80; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2549 |
RecalcShipStuff(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2550 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2551 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2552 |
case VEH_Aircraft: |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2553 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2554 |
HandleAircraftEnterHangar(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2555 |
break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2556 |
default: NOT_REACHED(); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2557 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2558 |
|
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2559 |
if (v->type != VEH_Train) { |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2560 |
/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters. |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2561 |
* 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 */ |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2562 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
2563 |
} |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2564 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2565 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2566 |
v->vehstatus |= VS_HIDDEN; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2567 |
v->cur_speed = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2568 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2569 |
VehicleServiceInDepot(v); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2570 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2571 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2572 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2573 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2574 |
Order t; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2575 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2576 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2577 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2578 |
t = v->current_order; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2579 |
v->current_order.type = OT_DUMMY; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2580 |
v->current_order.flags = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2581 |
|
4782
3ee91034a50e
(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
|
2582 |
if (t.refit_cargo < NUM_CARGO) { |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2583 |
int32 cost; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2584 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2585 |
_current_player = v->owner; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2586 |
cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, CMD_REFIT_VEH(v->type)); |
4783
77a455254ab0
(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
|
2587 |
|
77a455254ab0
(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
|
2588 |
if (CmdFailed(cost)) { |
77a455254ab0
(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
|
2589 |
v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot |
77a455254ab0
(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
|
2590 |
if (v->owner == _local_player) { |
77a455254ab0
(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
|
2591 |
/* Notify the user that we stopped the vehicle */ |
4784
97863deac573
(svn r6698) -Code cleanup r6697: simplified getting the string of the vehicle type
bjarni
parents:
4783
diff
changeset
|
2592 |
SetDParam(0, _vehicle_type_names[v->type - 0x10]); |
4783
77a455254ab0
(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
|
2593 |
SetDParam(1, v->unitnumber); |
77a455254ab0
(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
|
2594 |
AddNewsItem(STR_ORDER_REFIT_FAILED, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
77a455254ab0
(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
|
2595 |
} |
77a455254ab0
(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
|
2596 |
} else if (v->owner == _local_player && cost != 0) { |
77a455254ab0
(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
|
2597 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost); |
77a455254ab0
(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
|
2598 |
} |
4725
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2599 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2600 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2601 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2602 |
/* Part of orders */ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2603 |
if (v->type == VEH_Train) v->u.rail.days_since_order_progr = 0; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2604 |
v->cur_order_index++; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2605 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2606 |
/* Force depot visit */ |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2607 |
v->vehstatus |= VS_STOPPED; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2608 |
if (v->owner == _local_player) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2609 |
StringID string; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2610 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2611 |
switch (v->type) { |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2612 |
case VEH_Train: string = STR_8814_TRAIN_IS_WAITING_IN_DEPOT; break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2613 |
case VEH_Road: string = STR_9016_ROAD_VEHICLE_IS_WAITING; break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2614 |
case VEH_Ship: string = STR_981C_SHIP_IS_WAITING_IN_DEPOT; break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2615 |
case VEH_Aircraft: string = STR_A014_AIRCRAFT_IS_WAITING_IN; break; |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2616 |
default: NOT_REACHED(); string = STR_EMPTY; // Set the string to something to avoid a compiler warning |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2617 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2618 |
|
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2619 |
SetDParam(0, v->unitnumber); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2620 |
AddNewsItem(string, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0); |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2621 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2622 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2623 |
} |
f7284b86833f
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
2624 |
} |
2244 | 2625 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2626 |
/** Give a custom name to your vehicle |
3491
4c8427796c64
(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
|
2627 |
* @param tile unused |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2628 |
* @param p1 vehicle ID to name |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2629 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2630 |
*/ |
3491
4c8427796c64
(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
|
2631 |
int32 CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2632 |
{ |
2633 |
Vehicle *v; |
|
2634 |
StringID str; |
|
2635 |
||
5543
4d8dfa498905
(svn r11077) [0.5] -Fix: Possible NULL pointer dereference.
rubidium
parents:
5541
diff
changeset
|
2636 |
if (!IsValidVehicleID(p1) || _cmd_text == NULL || _cmd_text[0] == '\0') return CMD_ERROR; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
2637 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
2638 |
v = GetVehicle(p1); |
0 | 2639 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2640 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 2641 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1802
diff
changeset
|
2642 |
str = AllocateNameUnique(_cmd_text, 2); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
2643 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
2644 |
|
0 | 2645 |
if (flags & DC_EXEC) { |
2646 |
StringID old_str = v->string_id; |
|
2647 |
v->string_id = str; |
|
2648 |
DeleteName(old_str); |
|
588 | 2649 |
ResortVehicleLists(); |
0 | 2650 |
MarkWholeScreenDirty(); |
2651 |
} else { |
|
2652 |
DeleteName(str); |
|
2653 |
} |
|
2654 |
||
2655 |
return 0; |
|
2656 |
} |
|
2657 |
||
2658 |
||
2819
710436dd4288
(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
|
2659 |
/** Change the service interval of a vehicle |
3491
4c8427796c64
(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
|
2660 |
* @param tile unused |
2819
710436dd4288
(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
|
2661 |
* @param p1 vehicle ID that is being service-interval-changed |
710436dd4288
(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
|
2662 |
* @param p2 new service interval |
710436dd4288
(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
|
2663 |
*/ |
3491
4c8427796c64
(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
|
2664 |
int32 CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2819
710436dd4288
(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
|
2665 |
{ |
710436dd4288
(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
|
2666 |
Vehicle* v; |
710436dd4288
(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
|
2667 |
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */ |
710436dd4288
(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
|
2668 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2669 |
if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR; |
2819
710436dd4288
(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
|
2670 |
|
710436dd4288
(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
|
2671 |
v = GetVehicle(p1); |
710436dd4288
(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
|
2672 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2673 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2819
710436dd4288
(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
|
2674 |
|
710436dd4288
(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
|
2675 |
if (flags & DC_EXEC) { |
710436dd4288
(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
|
2676 |
v->service_interval = serv_int; |
710436dd4288
(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
|
2677 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
710436dd4288
(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
|
2678 |
} |
710436dd4288
(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
|
2679 |
|
710436dd4288
(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
|
2680 |
return 0; |
710436dd4288
(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
|
2681 |
} |
710436dd4288
(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
|
2682 |
|
0 | 2683 |
|
2684 |
static Rect _old_vehicle_coords; |
|
2685 |
||
2686 |
void BeginVehicleMove(Vehicle *v) { |
|
2687 |
_old_vehicle_coords.left = v->left_coord; |
|
2688 |
_old_vehicle_coords.top = v->top_coord; |
|
2689 |
_old_vehicle_coords.right = v->right_coord; |
|
2690 |
_old_vehicle_coords.bottom = v->bottom_coord; |
|
2691 |
} |
|
2692 |
||
2693 |
void EndVehicleMove(Vehicle *v) |
|
2694 |
{ |
|
2695 |
MarkAllViewportsDirty( |
|
2696 |
min(_old_vehicle_coords.left,v->left_coord), |
|
2697 |
min(_old_vehicle_coords.top,v->top_coord), |
|
2698 |
max(_old_vehicle_coords.right,v->right_coord)+1, |
|
2699 |
max(_old_vehicle_coords.bottom,v->bottom_coord)+1 |
|
2700 |
); |
|
2701 |
} |
|
2702 |
||
2703 |
/* returns true if staying in the same tile */ |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
2704 |
bool GetNewVehiclePos(const Vehicle *v, GetNewVehiclePosResult *gp) |
0 | 2705 |
{ |
2706 |
static const int8 _delta_coord[16] = { |
|
2707 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
2708 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
2709 |
}; |
|
2710 |
||
2711 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
2712 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
2713 |
||
2714 |
gp->x = x; |
|
2715 |
gp->y = y; |
|
2716 |
gp->old_tile = v->tile; |
|
1980
9ea0c89fbb58
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
2717 |
gp->new_tile = TileVirtXY(x, y); |
0 | 2718 |
return gp->old_tile == gp->new_tile; |
2719 |
} |
|
2720 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2721 |
static const Direction _new_direction_table[] = { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2722 |
DIR_N , DIR_NW, DIR_W , |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2723 |
DIR_NE, DIR_SE, DIR_SW, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2724 |
DIR_E , DIR_SE, DIR_S |
0 | 2725 |
}; |
2726 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2727 |
Direction GetDirectionTowards(const Vehicle* v, int x, int y) |
0 | 2728 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
2729 |
Direction dir; |
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2730 |
DirDiff dirdiff; |
0 | 2731 |
int i = 0; |
2732 |
||
2733 |
if (y >= v->y_pos) { |
|
2734 |
if (y != v->y_pos) i+=3; |
|
2735 |
i+=3; |
|
2736 |
} |
|
2737 |
||
2738 |
if (x >= v->x_pos) { |
|
2739 |
if (x != v->x_pos) i++; |
|
2740 |
i++; |
|
2741 |
} |
|
2742 |
||
2743 |
dir = v->direction; |
|
2744 |
||
3158
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2745 |
dirdiff = DirDifference(_new_direction_table[i], dir); |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2746 |
if (dirdiff == DIRDIFF_SAME) return dir; |
a821c8fec829
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
2747 |
return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 2748 |
} |
2749 |
||
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
2750 |
Trackdir GetVehicleTrackdir(const Vehicle* v) |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2751 |
{ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2752 |
if (v->vehstatus & VS_CRASHED) return 0xFF; |
1758
68668114f92e
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
2753 |
|
2952 | 2754 |
switch (v->type) { |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2755 |
case VEH_Train: |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2756 |
if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */ |
3185 | 2757 |
return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); /* Train in depot */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2758 |
|
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2759 |
if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */ |
3161 | 2760 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2761 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
2762 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.rail.track),v->direction); |
1959 | 2763 |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2764 |
case VEH_Ship: |
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
2765 |
if (IsShipInDepot(v)) |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1926
diff
changeset
|
2766 |
/* We'll assume the ship is facing outwards */ |
3953
db302c2d1a2a
(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
|
2767 |
return DiagdirToDiagTrackdir(GetShipDepotDirection(v->tile)); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2768 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
2769 |
return TrackDirectionToTrackdir(FIND_FIRST_BIT(v->u.ship.state),v->direction); |
1959 | 2770 |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2771 |
case VEH_Road: |
3959 | 2772 |
if (IsRoadVehInDepot(v)) /* We'll assume the road vehicle is facing outwards */ |
3179 | 2773 |
return DiagdirToDiagTrackdir(GetRoadDepotDirection(v->tile)); |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2774 |
|
3404
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
2775 |
if (IsRoadStopTile(v->tile)) /* We'll assume the road vehicle is facing outwards */ |
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
2776 |
return DiagdirToDiagTrackdir(GetRoadStopDir(v->tile)); /* Road vehicle in a station */ |
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2777 |
|
4270
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2778 |
/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */ |
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2779 |
if ((v->u.road.state & 7) < 6) return v->u.road.state; |
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2780 |
|
cfb529779a26
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
2781 |
/* Vehicle is turning around, get the direction from vehicle's direction */ |
3161 | 2782 |
return DiagdirToDiagTrackdir(DirToDiagDir(v->direction)); |
1959 | 2783 |
|
1765
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2784 |
/* case VEH_Aircraft: case VEH_Special: case VEH_Disaster: */ |
f8d29d5462c9
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
2785 |
default: return 0xFF; |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2786 |
} |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
2787 |
} |
22 | 2788 |
/* Return value has bit 0x2 set, when the vehicle enters a station. Then, |
2789 |
* result << 8 contains the id of the station entered. If the return value has |
|
2790 |
* bit 0x8 set, the vehicle could not and did not enter the tile. Are there |
|
2791 |
* other bits that can be set? */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2792 |
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
|
2793 |
{ |
3657 | 2794 |
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
0 | 2795 |
} |
2796 |
||
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1279
diff
changeset
|
2797 |
UnitID GetFreeUnitNumber(byte type) |
0 | 2798 |
{ |
3018
79f51529a689
(svn r3598) -Fix: suppress invalid warning by assigning value to variable
truelight
parents:
3009
diff
changeset
|
2799 |
UnitID unit, max = 0; |
2995
4e16e4fc54ac
(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
|
2800 |
const Vehicle *u; |
4e16e4fc54ac
(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
|
2801 |
static bool *cache = NULL; |
4e16e4fc54ac
(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
|
2802 |
static UnitID gmax = 0; |
0 | 2803 |
|
2995
4e16e4fc54ac
(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
|
2804 |
switch (type) { |
4e16e4fc54ac
(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
|
2805 |
case VEH_Train: max = _patches.max_trains; break; |
4e16e4fc54ac
(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
|
2806 |
case VEH_Road: max = _patches.max_roadveh; break; |
4e16e4fc54ac
(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
|
2807 |
case VEH_Ship: max = _patches.max_ships; break; |
4e16e4fc54ac
(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
|
2808 |
case VEH_Aircraft: max = _patches.max_aircraft; break; |
2996
8087faf157d8
(svn r3573) - Replace assert(0) with NOT_REACHED(). This commit sponsored by "giving Darkvater credit for the last three".
peter1138
parents:
2995
diff
changeset
|
2809 |
default: NOT_REACHED(); |
2995
4e16e4fc54ac
(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
|
2810 |
} |
4e16e4fc54ac
(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
|
2811 |
|
4096
c7259875a856
(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
|
2812 |
if (max == 0) { |
c7259875a856
(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
|
2813 |
/* we can't build any of this kind of vehicle, so we just return 1 instead of looking for a free number |
c7259875a856
(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
|
2814 |
* a max of 0 will cause the following code to write to a NULL pointer |
c7259875a856
(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
|
2815 |
* We know that 1 is bigger than the max allowed vehicle number, so it's the same as returning something, that is too big |
c7259875a856
(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
|
2816 |
*/ |
c7259875a856
(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
|
2817 |
return 1; |
c7259875a856
(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
|
2818 |
} |
c7259875a856
(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
|
2819 |
|
2995
4e16e4fc54ac
(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
|
2820 |
if (max > gmax) { |
4e16e4fc54ac
(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
|
2821 |
gmax = max; |
4e16e4fc54ac
(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
|
2822 |
free(cache); |
4e16e4fc54ac
(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
|
2823 |
cache = malloc((max + 1) * sizeof(*cache)); |
4e16e4fc54ac
(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
|
2824 |
} |
4e16e4fc54ac
(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
|
2825 |
|
4e16e4fc54ac
(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
|
2826 |
// Clear the cache |
4e16e4fc54ac
(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
|
2827 |
memset(cache, 0, (max + 1) * sizeof(*cache)); |
4e16e4fc54ac
(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
|
2828 |
|
4e16e4fc54ac
(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
|
2829 |
// Fill the cache |
0 | 2830 |
FOR_ALL_VEHICLES(u) { |
2995
4e16e4fc54ac
(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
|
2831 |
if (u->type == type && u->owner == _current_player && u->unitnumber != 0 && u->unitnumber <= max) |
4e16e4fc54ac
(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
|
2832 |
cache[u->unitnumber] = true; |
0 | 2833 |
} |
2995
4e16e4fc54ac
(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
|
2834 |
|
4e16e4fc54ac
(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
|
2835 |
// Find the first unused unit number |
4e16e4fc54ac
(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
|
2836 |
for (unit = 1; unit <= max; unit++) { |
4e16e4fc54ac
(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
|
2837 |
if (!cache[unit]) break; |
4e16e4fc54ac
(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
|
2838 |
} |
4e16e4fc54ac
(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
|
2839 |
|
4e16e4fc54ac
(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
|
2840 |
return unit; |
0 | 2841 |
} |
2842 |
||
4603
3ccd4ee0a2e2
(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 |
static PalSpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, CargoID cargo_type) |
3040
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2844 |
{ |
3113
c0f312f22238
(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
|
2845 |
SpriteID map; |
4603
3ccd4ee0a2e2
(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 |
const Player *p = GetPlayer(player); |
3ccd4ee0a2e2
(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 |
LiveryScheme scheme = LS_DEFAULT; |
3ccd4ee0a2e2
(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 |
|
3ccd4ee0a2e2
(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 |
/* The default livery is always available for use, but its in_use flag determines |
3ccd4ee0a2e2
(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 |
* whether any _other_ liveries are in use. */ |
4616
baa9d4436b9e
(svn r6474) - Add a patch option to control display of liveries, allowing none, your
peter1138
parents:
4613
diff
changeset
|
2851 |
if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) { |
4603
3ccd4ee0a2e2
(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 |
/* Determine the livery scheme to use */ |
3ccd4ee0a2e2
(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 |
switch (GetEngine(engine_type)->type) { |
3ccd4ee0a2e2
(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 |
case VEH_Train: { |
3ccd4ee0a2e2
(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 |
switch (_engine_info[engine_type].railtype) { |
3ccd4ee0a2e2
(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 |
case RAILTYPE_RAIL: |
3ccd4ee0a2e2
(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 |
case RAILTYPE_ELECTRIC: |
3ccd4ee0a2e2
(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 |
{ |
3ccd4ee0a2e2
(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 |
const RailVehicleInfo *rvi = RailVehInfo(engine_type); |
3ccd4ee0a2e2
(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 |
|
3ccd4ee0a2e2
(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 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
3ccd4ee0a2e2
(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 |
if (rvi->flags & RVI_WAGON) { |
4604
f99f5de6077a
(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
|
2863 |
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_VALUABLES) { |
f99f5de6077a
(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
|
2864 |
if (parent_engine_type == INVALID_ENGINE) { |
f99f5de6077a
(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
|
2865 |
scheme = LS_PASSENGER_WAGON_STEAM; |
f99f5de6077a
(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
|
2866 |
} else { |
f99f5de6077a
(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
|
2867 |
switch (RailVehInfo(parent_engine_type)->engclass) { |
f99f5de6077a
(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
|
2868 |
case 0: scheme = LS_PASSENGER_WAGON_STEAM; break; |
f99f5de6077a
(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
|
2869 |
case 1: scheme = LS_PASSENGER_WAGON_DIESEL; break; |
f99f5de6077a
(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
|
2870 |
case 2: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; |
f99f5de6077a
(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
|
2871 |
} |
f99f5de6077a
(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
|
2872 |
} |
f99f5de6077a
(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
|
2873 |
} else { |
f99f5de6077a
(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
|
2874 |
scheme = LS_FREIGHT_WAGON; |
f99f5de6077a
(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
|
2875 |
} |
4603
3ccd4ee0a2e2
(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
|
2876 |
} else { |
3ccd4ee0a2e2
(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
|
2877 |
bool is_mu = HASBIT(_engine_info[engine_type].misc_flags, EF_RAIL_IS_MU); |
3ccd4ee0a2e2
(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
|
2878 |
|
3ccd4ee0a2e2
(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
|
2879 |
switch (rvi->engclass) { |
3ccd4ee0a2e2
(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 |
case 0: scheme = LS_STEAM; break; |
3ccd4ee0a2e2
(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
|
2881 |
case 1: scheme = is_mu ? LS_DMU : LS_DIESEL; break; |
3ccd4ee0a2e2
(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
|
2882 |
case 2: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break; |
3ccd4ee0a2e2
(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
|
2883 |
} |
3ccd4ee0a2e2
(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
|
2884 |
} |
3ccd4ee0a2e2
(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 |
break; |
3ccd4ee0a2e2
(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 |
} |
3ccd4ee0a2e2
(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 |
|
3ccd4ee0a2e2
(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 |
case RAILTYPE_MONO: scheme = LS_MONORAIL; break; |
3ccd4ee0a2e2
(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 |
case RAILTYPE_MAGLEV: scheme = LS_MAGLEV; break; |
3ccd4ee0a2e2
(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 |
} |
3ccd4ee0a2e2
(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 |
break; |
3ccd4ee0a2e2
(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 |
} |
3ccd4ee0a2e2
(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 |
|
3ccd4ee0a2e2
(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 |
case VEH_Road: { |
3ccd4ee0a2e2
(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
|
2895 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine_type); |
3ccd4ee0a2e2
(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
|
2896 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
3ccd4ee0a2e2
(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
|
2897 |
scheme = (cargo_type == CT_PASSENGERS) ? LS_BUS : LS_TRUCK; |
3ccd4ee0a2e2
(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
|
2898 |
break; |
3ccd4ee0a2e2
(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
|
2899 |
} |
3ccd4ee0a2e2
(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
|
2900 |
|
3ccd4ee0a2e2
(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
|
2901 |
case VEH_Ship: { |
3ccd4ee0a2e2
(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
|
2902 |
const ShipVehicleInfo *svi = ShipVehInfo(engine_type); |
3ccd4ee0a2e2
(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
|
2903 |
if (cargo_type == CT_INVALID) cargo_type = svi->cargo_type; |
3ccd4ee0a2e2
(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
|
2904 |
scheme = (cargo_type == CT_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; |
3ccd4ee0a2e2
(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
|
2905 |
break; |
3ccd4ee0a2e2
(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
|
2906 |
} |
3ccd4ee0a2e2
(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
|
2907 |
|
3ccd4ee0a2e2
(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
|
2908 |
case VEH_Aircraft: { |
3ccd4ee0a2e2
(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
|
2909 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type); |
3ccd4ee0a2e2
(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
|
2910 |
if (cargo_type == CT_INVALID) cargo_type = CT_PASSENGERS; |
3ccd4ee0a2e2
(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
|
2911 |
switch (avi->subtype) { |
3ccd4ee0a2e2
(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
|
2912 |
case 0: scheme = LS_HELICOPTER; break; |
3ccd4ee0a2e2
(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
|
2913 |
case 1: scheme = LS_SMALL_PLANE; break; |
3ccd4ee0a2e2
(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
|
2914 |
case 3: scheme = LS_LARGE_PLANE; break; |
3ccd4ee0a2e2
(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
|
2915 |
} |
3ccd4ee0a2e2
(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
|
2916 |
break; |
3ccd4ee0a2e2
(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
|
2917 |
} |
3ccd4ee0a2e2
(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
|
2918 |
} |
3ccd4ee0a2e2
(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
|
2919 |
|
3ccd4ee0a2e2
(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
|
2920 |
/* Switch back to the default scheme if the resolved scheme is not in use */ |
3ccd4ee0a2e2
(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
|
2921 |
if (!p->livery[scheme].in_use) scheme = LS_DEFAULT; |
3ccd4ee0a2e2
(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
|
2922 |
} |
3ccd4ee0a2e2
(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
|
2923 |
|
3393
48ce4c723a76
(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
|
2924 |
map = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC) ? |
4603
3ccd4ee0a2e2
(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
|
2925 |
(SPR_2CCMAP_BASE + p->livery[scheme].colour1 + p->livery[scheme].colour2 * 16) : |
3ccd4ee0a2e2
(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
|
2926 |
(PALETTE_RECOLOR_START + p->livery[scheme].colour1); |
3113
c0f312f22238
(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
|
2927 |
|
c0f312f22238
(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
|
2928 |
return SPRITE_PALETTE(map << PALETTE_SPRITE_START); |
3040
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2929 |
} |
c3473d1fb81f
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
2930 |
|
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2931 |
PalSpriteID GetEnginePalette(EngineID engine_type, PlayerID player) |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2932 |
{ |
4603
3ccd4ee0a2e2
(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
|
2933 |
return GetEngineColourMap(engine_type, player, INVALID_ENGINE, CT_INVALID); |
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2934 |
} |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2935 |
|
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2936 |
PalSpriteID GetVehiclePalette(const Vehicle *v) |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2937 |
{ |
4603
3ccd4ee0a2e2
(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
|
2938 |
if (v->type == VEH_Train) { |
3ccd4ee0a2e2
(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
|
2939 |
return GetEngineColourMap( |
5510
d4b8e7933d5e
(svn r10275) [0.5] -Backport from trunk (r10048, r10068, r10075, r10082, r10085, r10087):
rubidium
parents:
5495
diff
changeset
|
2940 |
(v->u.rail.first_engine != INVALID_ENGINE && (UsesWagonOverride(v) || (IsArticulatedPart(v) && (RailVehInfo(v->engine_type)->flags & RVI_WAGON) != 0))) ? |
4603
3ccd4ee0a2e2
(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
|
2941 |
v->u.rail.first_engine : v->engine_type, |
3ccd4ee0a2e2
(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
|
2942 |
v->owner, |
3ccd4ee0a2e2
(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
|
2943 |
v->u.rail.first_engine, |
3ccd4ee0a2e2
(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
|
2944 |
v->cargo_type); |
3ccd4ee0a2e2
(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
|
2945 |
} |
3ccd4ee0a2e2
(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
|
2946 |
|
3ccd4ee0a2e2
(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
|
2947 |
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v->cargo_type); |
3105
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2948 |
} |
4a6514d7a8ba
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
2949 |
|
0 | 2950 |
// Save and load of vehicles |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2951 |
const SaveLoad _common_veh_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2952 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2953 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2954 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2955 |
SLE_VAR(Vehicle, string_id, SLE_STRINGID), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2956 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2957 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, 8, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2958 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2959 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2960 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2962 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2963 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2964 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2965 |
SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, z_pos, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, direction, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, cur_image, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, spritenum, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, sprite_width, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, sprite_height, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, z_height, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, x_offs, SLE_INT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, y_offs, SLE_INT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, engine_type, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, max_speed, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, cur_speed, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, subspeed, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, acceleration, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, 5, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VAR(Vehicle, cargo_type, SLE_UINT8), |
4695
52419a88345d
(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
|
2991 |
SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, 35, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, cargo_days, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDVAR(Vehicle, cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, cargo_source, SLE_UINT16, 7, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, cargo_cap, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2996 |
SLE_VAR(Vehicle, cargo_count, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2997 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, day_counter, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2999 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3000 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3001 |
SLE_VAR(Vehicle, cur_order_index, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3002 |
SLE_VAR(Vehicle, num_orders, SLE_UINT8), |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3003 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3004 |
/* This next line is for version 4 and prior compatibility.. it temporarily reads |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3005 |
type and flags (which were both 4 bits) into type. Later on this is |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3006 |
converted correctly */ |
4527
b18634a31a4a
(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
|
3007 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 0, 4), |
b18634a31a4a
(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
|
3008 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3009 |
|
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3010 |
/* Orders for version 5 and on */ |
4527
b18634a31a4a
(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
|
3011 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
b18634a31a4a
(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
|
3012 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
b18634a31a4a
(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
|
3013 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3014 |
|
4712
273ec3b182bf
(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
|
3015 |
/* Refit in current order */ |
273ec3b182bf
(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
|
3016 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION), |
273ec3b182bf
(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
|
3017 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION), |
273ec3b182bf
(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
|
3018 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3019 |
SLE_REF(Vehicle, orders, REF_ORDER), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3020 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3021 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3022 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3024 |
SLE_CONDVAR(Vehicle, max_age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, service_interval, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, service_interval, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, reliability, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, reliability_spd_dec, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, breakdown_ctr, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, breakdown_chance, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3036 |
SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3038 |
SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16), |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5062
diff
changeset
|
3039 |
SLE_CONDVAR(Vehicle, load_status, SLE_UINT8, 40, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3040 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3041 |
SLE_VAR(Vehicle, profit_this_year, SLE_INT32), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3042 |
SLE_VAR(Vehicle, profit_last_year, SLE_INT32), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, value, SLE_UINT32), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3044 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, random_bits, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3046 |
SLE_VAR(Vehicle, waiting_triggers, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3047 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3048 |
SLE_REF(Vehicle, next_shared, REF_VEHICLE), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3049 |
SLE_REF(Vehicle, prev_shared, REF_VEHICLE), |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3050 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3051 |
// reserve extra space in savegame here. (currently 10 bytes) |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3052 |
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
|
3053 |
|
0 | 3054 |
SLE_END() |
3055 |
}; |
|
3056 |
||
3057 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
3058 |
static const SaveLoad _train_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_WRITEBYTE(Vehicle, type, VEH_Train, 0), // Train type. VEH_Train in mem, 0 in file. |
0 | 3060 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, crash_anim_pos), SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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(VehicleRail, force_proceed), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, railtype), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleRail, track), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3065 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3066 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRail, flags), SLE_UINT8, 2, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRail, days_since_order_progr), SLE_UINT16, 2, SL_MAX_VERSION), |
0 | 3068 |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
3069 |
SLE_CONDNULL(2, 2, 19), |
2926
d503d725d7d4
(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
|
3070 |
// reserve extra space in savegame here. (currently 11 bytes) |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
3071 |
SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
0 | 3072 |
|
3073 |
SLE_END() |
|
3074 |
}; |
|
3075 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
3076 |
static const SaveLoad _roadveh_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_WRITEBYTE(Vehicle, type, VEH_Road, 1), // Road type. VEH_Road in mem, 1 in file. |
0 | 3078 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, state), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, frame), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, blocked_ctr), SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, overtaking), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, crashed_ctr), SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, reverse_ctr), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDREFX(offsetof(Vehicle, u) + offsetof(VehicleRoad, slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDNULL(1, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
0 | 3090 |
// reserve extra space in savegame here. (currently 16 bytes) |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3092 |
|
3093 |
SLE_END() |
|
3094 |
}; |
|
3095 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
3096 |
static const SaveLoad _ship_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3097 |
SLE_WRITEBYTE(Vehicle, type, VEH_Ship, 2), // Ship type. VEH_Ship in mem, 2 in file. |
0 | 3098 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3099 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleShip, state), SLE_UINT8), |
0 | 3100 |
|
3101 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
3102 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3103 |
|
3104 |
SLE_END() |
|
3105 |
}; |
|
3106 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
3107 |
static const SaveLoad _aircraft_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_WRITEBYTE(Vehicle, type, VEH_Aircraft, 3), // Aircraft type. VEH_Aircraft in mem, 3 in file. |
0 | 3109 |
SLE_INCLUDEX(0, INC_VEHICLE_COMMON), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, crashed_counter), SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, pos), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VARX(offsetof(Vehicle, u) + offsetof(VehicleAir, state), SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVARX(offsetof(Vehicle, u) + offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 3119 |
|
3120 |
// reserve extra space in savegame here. (currently 15 bytes) |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
0 | 3122 |
|
3123 |
SLE_END() |
|
3124 |
}; |
|
3125 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
3126 |
static const SaveLoad _special_desc[] = { |
0 | 3127 |
SLE_WRITEBYTE(Vehicle,type,VEH_Special, 4), |
3128 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3129 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3130 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, z_pos, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3139 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3140 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, 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_VAR(Vehicle, sprite_width, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3142 |
SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3143 |
SLE_VAR(Vehicle, z_height, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3144 |
SLE_VAR(Vehicle, x_offs, SLE_INT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3145 |
SLE_VAR(Vehicle, y_offs, SLE_INT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3146 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3147 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3148 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3149 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleSpecial, unk0), SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3150 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleSpecial, unk2), SLE_UINT8), |
0 | 3151 |
|
3152 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
3153 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3154 |
|
3155 |
SLE_END() |
|
3156 |
}; |
|
3157 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
3158 |
static const SaveLoad _disaster_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3159 |
SLE_WRITEBYTE(Vehicle, type, VEH_Disaster, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3160 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3161 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3162 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3163 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3164 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3165 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3166 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3167 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3168 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3169 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3170 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3171 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3172 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3173 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3174 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3175 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3176 |
SLE_VAR(Vehicle, x_offs, SLE_INT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3177 |
SLE_VAR(Vehicle, y_offs, SLE_INT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3178 |
SLE_VAR(Vehicle, sprite_width, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3179 |
SLE_VAR(Vehicle, sprite_height, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3180 |
SLE_VAR(Vehicle, z_height, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3181 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3182 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
4527
b18634a31a4a
(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
|
3183 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
b18634a31a4a
(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
|
3184 |
SLE_CONDVARX(offsetof(Vehicle, current_order) + offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3185 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3186 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3187 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3188 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3189 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3190 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3191 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleDisaster, image_override), SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3192 |
SLE_VARX(offsetof(Vehicle, u) + offsetof(VehicleDisaster, unk2), SLE_UINT16), |
0 | 3193 |
|
3194 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
3195 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 3196 |
|
3197 |
SLE_END() |
|
3198 |
}; |
|
3199 |
||
3200 |
||
3201 |
static const void *_veh_descs[] = { |
|
3202 |
_train_desc, |
|
3203 |
_roadveh_desc, |
|
3204 |
_ship_desc, |
|
3205 |
_aircraft_desc, |
|
3206 |
_special_desc, |
|
3207 |
_disaster_desc, |
|
3208 |
}; |
|
3209 |
||
3210 |
// Will be called when the vehicles need to be saved. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
3211 |
static void Save_VEHS(void) |
0 | 3212 |
{ |
3213 |
Vehicle *v; |
|
3214 |
// Write the vehicles |
|
3215 |
FOR_ALL_VEHICLES(v) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3216 |
SlSetArrayIndex(v->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
3217 |
SlObject(v, _veh_descs[v->type - 0x10]); |
0 | 3218 |
} |
3219 |
} |
|
3220 |
||
3221 |
// Will be called when vehicles need to be loaded. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1082
diff
changeset
|
3222 |
static void Load_VEHS(void) |
0 | 3223 |
{ |
3224 |
int index; |
|
3225 |
Vehicle *v; |
|
3226 |
||
3227 |
while ((index = SlIterateArray()) != -1) { |
|
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3228 |
Vehicle *v; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
3229 |
|
4972 | 3230 |
if (!AddBlockIfNeeded(&_Vehicle_pool, index)) |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3231 |
error("Vehicles: failed loading savegame: too many vehicles"); |
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3232 |
|
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3233 |
v = GetVehicle(index); |
0 | 3234 |
SlObject(v, _veh_descs[SlReadByte()]); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
3235 |
|
2549 | 3236 |
/* Old savegames used 'last_station_visited = 0xFF' */ |
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3237 |
if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF) |
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2467
diff
changeset
|
3238 |
v->last_station_visited = INVALID_STATION; |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3239 |
|
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3240 |
if (CheckSavegameVersion(5)) { |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3241 |
/* Convert the current_order.type (which is a mix of type and flags, because |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
3242 |
* in those versions, they both were 4 bits big) to type and flags */ |
956
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3243 |
v->current_order.flags = (v->current_order.type & 0xF0) >> 4; |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3244 |
v->current_order.type = v->current_order.type & 0x0F; |
d72a565cc672
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
3245 |
} |
0 | 3246 |
} |
3247 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3248 |
/* Check for shared order-lists (we now use pointers for that) */ |
2685
00111d5ca47f
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
3249 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3250 |
FOR_ALL_VEHICLES(v) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3251 |
Vehicle *u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3252 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3253 |
FOR_ALL_VEHICLES_FROM(u, v->index + 1) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3254 |
/* If a vehicle has the same orders, add the link to eachother |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
3255 |
* in both vehicles */ |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3256 |
if (v->orders == u->orders) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3257 |
v->next_shared = u; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3258 |
u->prev_shared = v; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3259 |
break; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3260 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3261 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3262 |
} |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
3263 |
} |
0 | 3264 |
} |
3265 |
||
3266 |
const ChunkHandler _veh_chunk_handlers[] = { |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1541
diff
changeset
|
3267 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 3268 |
}; |