author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9808 | a914bcdca6fb |
child 9891 | edc31db66fbb |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9081
diff
changeset
|
3 |
/** @file vehicle.cpp Base implementations of all vehicles. */ |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
3957
25f4a4f22e05
(svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents:
3953
diff
changeset
|
7 |
#include "road_map.h" |
3959 | 8 |
#include "roadveh.h" |
3961
9868b766fda7
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3959
diff
changeset
|
9 |
#include "ship.h" |
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1328
diff
changeset
|
10 |
#include "spritecache.h" |
8119
52b48108425a
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8116
diff
changeset
|
11 |
#include "tile_cmd.h" |
6453
226bcddeba32
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6444
diff
changeset
|
12 |
#include "landscape.h" |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
13 |
#include "timetable.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8214
diff
changeset
|
14 |
#include "viewport_func.h" |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8214
diff
changeset
|
15 |
#include "gfx_func.h" |
8763
81fadd257f67
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
8736
diff
changeset
|
16 |
#include "news_func.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
17 |
#include "command_func.h" |
0 | 18 |
#include "saveload.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8245
diff
changeset
|
19 |
#include "player_func.h" |
1601
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
20 |
#include "debug.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
21 |
#include "vehicle_gui.h" |
8103
cf92483a0abf
(svn r11664) -Codechange: use more specific ("rail_type.h" instead of "rail.h" that includes way more than only "rail_type.h") includes at some places.
rubidium
parents:
8081
diff
changeset
|
22 |
#include "rail_type.h" |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
23 |
#include "train.h" |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
24 |
#include "aircraft.h" |
3428
146dc5f172fc
(svn r4256) - Codechange: Replace lone map access in vehicle.c with its map accessor.
peter1138
parents:
3422
diff
changeset
|
25 |
#include "industry_map.h" |
3404
eb8ebfe5df67
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3393
diff
changeset
|
26 |
#include "station_map.h" |
3957
25f4a4f22e05
(svn r5116) Move the overly generic GetDepotDirection() from a header to its only consumer
tron
parents:
3953
diff
changeset
|
27 |
#include "water_map.h" |
4130
fd86f49a1e96
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
KUDr
parents:
4124
diff
changeset
|
28 |
#include "yapf/yapf.h" |
5717
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
29 |
#include "newgrf_callbacks.h" |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
30 |
#include "newgrf_engine.h" |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
31 |
#include "newgrf_sound.h" |
9041
2e64f7dc7a48
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138
parents:
9009
diff
changeset
|
32 |
#include "newgrf_station.h" |
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
33 |
#include "group.h" |
8784
c2e9d649a9ce
(svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents:
8763
diff
changeset
|
34 |
#include "order_func.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8108
diff
changeset
|
35 |
#include "strings_func.h" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
36 |
#include "zoom_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8130
diff
changeset
|
37 |
#include "functions.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8139
diff
changeset
|
38 |
#include "date_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8130
diff
changeset
|
39 |
#include "window_func.h" |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
40 |
#include "vehicle_func.h" |
8238
d47a86c79603
(svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents:
8230
diff
changeset
|
41 |
#include "signal_func.h" |
8157
1505def01945
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8144
diff
changeset
|
42 |
#include "sound_func.h" |
8211
29a8510dfd62
(svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents:
8172
diff
changeset
|
43 |
#include "variables.h" |
8212
cf3fce5c7464
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8211
diff
changeset
|
44 |
#include "autoreplace_func.h" |
cf3fce5c7464
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8211
diff
changeset
|
45 |
#include "autoreplace_gui.h" |
8214
971f861d5543
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8212
diff
changeset
|
46 |
#include "string_func.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
47 |
#include "settings_type.h" |
8847
426dd2d582e7
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents:
8843
diff
changeset
|
48 |
#include "oldpool_func.h" |
8962
1b263c69799d
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium
parents:
8961
diff
changeset
|
49 |
#include "depot_map.h" |
9005
d6b0e0a54ef2
(svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
rubidium
parents:
8997
diff
changeset
|
50 |
#include "animated_tile_func.h" |
9009
6684576ef32b
(svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents:
9008
diff
changeset
|
51 |
#include "effectvehicle_base.h" |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
52 |
#include "core/alloc_func.hpp" |
9396
3f70b1b8642c
(svn r13307) -Codechange: Separate VehicleList and its two functions so only the 3 users include it, reducing dependencies on misc/smallvec.h
peter1138
parents:
9365
diff
changeset
|
53 |
#include "vehiclelist.h" |
0 | 54 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
55 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
56 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8258
diff
changeset
|
57 |
|
6904
cc02894b3cce
(svn r10153) -Fix [FS#869]: vehicles disappear when crossing certain tiles. Fix by B. N. SmatZ!.
rubidium
parents:
6886
diff
changeset
|
58 |
#define INVALID_COORD (0x7fffffff) |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
59 |
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
0 | 60 |
|
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
61 |
VehicleID _vehicle_id_ctr_day; |
9344
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
62 |
const Vehicle *_place_clicked_vehicle; |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
63 |
VehicleID _new_vehicle_id; |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
64 |
uint16 _returned_refit_capacity; |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
65 |
|
5792
c4dad358b30b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
5763
diff
changeset
|
66 |
|
c4dad358b30b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
5763
diff
changeset
|
67 |
/* Tables used in vehicle.h to find the right command for a certain vehicle type */ |
c4dad358b30b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
5763
diff
changeset
|
68 |
const uint32 _veh_build_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
69 |
CMD_BUILD_RAIL_VEHICLE, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
70 |
CMD_BUILD_ROAD_VEH, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
71 |
CMD_BUILD_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
72 |
CMD_BUILD_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
73 |
}; |
5792
c4dad358b30b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
5763
diff
changeset
|
74 |
const uint32 _veh_sell_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
75 |
CMD_SELL_RAIL_WAGON, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
76 |
CMD_SELL_ROAD_VEH, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
77 |
CMD_SELL_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
78 |
CMD_SELL_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
79 |
}; |
2753 | 80 |
|
5792
c4dad358b30b
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni
parents:
5763
diff
changeset
|
81 |
const uint32 _veh_refit_proc_table[] = { |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
82 |
CMD_REFIT_RAIL_VEHICLE, |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3973
diff
changeset
|
83 |
CMD_REFIT_ROAD_VEH, |
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
84 |
CMD_REFIT_SHIP, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
85 |
CMD_REFIT_AIRCRAFT, |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
86 |
}; |
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
87 |
|
4451
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
88 |
const uint32 _send_to_depot_proc_table[] = { |
4495
b6381e4bcb61
(svn r6280) -Codechange: Use the same naming for trains as for other vehicles:
Darkvater
parents:
4465
diff
changeset
|
89 |
CMD_SEND_TRAIN_TO_DEPOT, |
4451
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
90 |
CMD_SEND_ROADVEH_TO_DEPOT, |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
91 |
CMD_SEND_SHIP_TO_DEPOT, |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
92 |
CMD_SEND_AIRCRAFT_TO_HANGAR, |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
93 |
}; |
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4434
diff
changeset
|
94 |
|
2552
5b586a545665
(svn r3081) -Codechange: [autoreplace] complete rewrite of autoreplace
bjarni
parents:
2549
diff
changeset
|
95 |
|
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
96 |
/* Initialize the vehicle-pool */ |
7400
e211c7b9cb8f
(svn r10772) -Codechange: also make use of the generic clean and destroy pool callback functions for vehicle.
rubidium
parents:
7398
diff
changeset
|
97 |
DEFINE_OLD_POOL_GENERIC(Vehicle, Vehicle) |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
98 |
|
8629
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
99 |
/** Function to tell if a vehicle needs to be autorenewed |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
100 |
* @param *p The vehicle owner |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
101 |
* @return true if the vehicle is old enough for replacement |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
102 |
*/ |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
103 |
bool Vehicle::NeedsAutorenewing(const Player *p) const |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
104 |
{ |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
105 |
/* We can always generate the Player pointer when we have the vehicle. |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
106 |
* However this takes time and since the Player pointer is often present |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
107 |
* when this function is called then it's faster to pass the pointer as an |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
108 |
* argument rather than finding it again. */ |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
109 |
assert(p == GetPlayer(this->owner)); |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
110 |
|
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
111 |
if (!p->engine_renew) return false; |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
112 |
if (this->age - this->max_age < (p->engine_renew_months * 30)) return false; |
8997
3ee8e18dff23
(svn r12792) -Codechange: [autoreplace] added a function to figure out if a replacement is needed and if so, to which EngineID
bjarni
parents:
8996
diff
changeset
|
113 |
if (this->age == 0) return false; // rail cars don't age and lacks a max age |
8629
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
114 |
|
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
115 |
return true; |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
116 |
} |
f61bb746249f
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni
parents:
8582
diff
changeset
|
117 |
|
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
118 |
void VehicleServiceInDepot(Vehicle *v) |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
119 |
{ |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
120 |
v->date_of_last_service = _date; |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
121 |
v->breakdowns_since_last_service = 0; |
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1922
diff
changeset
|
122 |
v->reliability = GetEngine(v->engine_type)->reliability; |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
123 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated |
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
577
diff
changeset
|
124 |
} |
0 | 125 |
|
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
126 |
bool Vehicle::NeedsServicing() const |
593 | 127 |
{ |
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
128 |
if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false; |
1757
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
129 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
130 |
if (_settings_game.order.no_servicing_if_no_breakdowns && _settings_game.difficulty.vehicle_breakdowns == 0) { |
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
131 |
/* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off. |
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
132 |
* Note: If servicing is enabled, we postpone replacement till next service. */ |
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
133 |
return EngineHasReplacementForPlayer(GetPlayer(this->owner), this->engine_type, this->group_id); |
4262
048f6a144c7c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
134 |
} |
048f6a144c7c
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
bjarni
parents:
4261
diff
changeset
|
135 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
136 |
return _settings_game.vehicle.servint_ispercent ? |
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
137 |
(this->reliability < GetEngine(this->engine_type)->reliability * (100 - this->service_interval) / 100) : |
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
138 |
(this->date_of_last_service + this->service_interval < _date); |
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
139 |
} |
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
140 |
|
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
141 |
bool Vehicle::NeedsAutomaticServicing() const |
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
142 |
{ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
143 |
if (_settings_game.order.gotodepot && VehicleHasDepotOrders(this)) return false; |
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
144 |
if (this->current_order.IsType(OT_LOADING)) return false; |
8914
6bbc5f1455f7
(svn r12684) -Fix [FS#1891]: manually given service at depot order is not forgotten anymore when autoservice 'interferes'.
rubidium
parents:
8902
diff
changeset
|
145 |
if (this->current_order.IsType(OT_GOTO_DEPOT) && this->current_order.GetDepotOrderType() != ODTFB_SERVICE) return false; |
8862
f72f256c0259
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch
parents:
8855
diff
changeset
|
146 |
return NeedsServicing(); |
593 | 147 |
} |
148 |
||
3881 | 149 |
StringID VehicleInTheWayErrMsg(const Vehicle* v) |
0 | 150 |
{ |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
151 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
152 |
case VEH_TRAIN: return STR_8803_TRAIN_IN_THE_WAY; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
153 |
case VEH_ROAD: return STR_9000_ROAD_VEHICLE_IN_THE_WAY; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
154 |
case VEH_AIRCRAFT: return STR_A015_AIRCRAFT_IN_THE_WAY; |
3881 | 155 |
default: return STR_980E_SHIP_IN_THE_WAY; |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
156 |
} |
0 | 157 |
} |
158 |
||
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
159 |
static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
0 | 160 |
{ |
8081
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
161 |
byte z = *(byte*)data; |
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
162 |
|
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
163 |
if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; |
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
164 |
if (v->z_pos > z) return NULL; |
0 | 165 |
|
3881 | 166 |
_error_message = VehicleInTheWayErrMsg(v); |
537
901bd4c077f0
(svn r909) Small cleanup in vehicle.c, this should fix some warnings on 64bit machines
tron
parents:
534
diff
changeset
|
167 |
return v; |
0 | 168 |
} |
169 |
||
1605
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
170 |
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
171 |
{ |
8081
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
172 |
return (Vehicle*)VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ); |
1605
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
173 |
} |
279dd2265cae
(svn r2109) -Fix: use FindVehicleOnTileZ(tile, 0) over FindVehicleBetween(tile, tile, 0)
truelight
parents:
1601
diff
changeset
|
174 |
|
8078
d7c60bf804d5
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz
parents:
8076
diff
changeset
|
175 |
bool EnsureNoVehicleOnGround(TileIndex tile) |
d7c60bf804d5
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz
parents:
8076
diff
changeset
|
176 |
{ |
d7c60bf804d5
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz
parents:
8076
diff
changeset
|
177 |
return FindVehicleOnTileZ(tile, GetTileMaxZ(tile)) == NULL; |
d7c60bf804d5
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz
parents:
8076
diff
changeset
|
178 |
} |
d7c60bf804d5
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz
parents:
8076
diff
changeset
|
179 |
|
5940
3bb99a7ad58f
(svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents:
5888
diff
changeset
|
180 |
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_crashed) |
0 | 181 |
{ |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
182 |
int x1 = TileX(from); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
183 |
int y1 = TileY(from); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
184 |
int x2 = TileX(to); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
924
diff
changeset
|
185 |
int y2 = TileY(to); |
0 | 186 |
Vehicle *veh; |
187 |
||
188 |
/* Make sure x1 < x2 or y1 < y2 */ |
|
189 |
if (x1 > x2 || y1 > y2) { |
|
6106 | 190 |
Swap(x1, x2); |
191 |
Swap(y1, y2); |
|
0 | 192 |
} |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
193 |
FOR_ALL_VEHICLES(veh) { |
5940
3bb99a7ad58f
(svn r8593) -Fix (FS#564): bridges do not get destroyed when the bridge head gets flooded and there is a vehicle on the bridge. Original patch by KeeperofTheSoul.
rubidium
parents:
5888
diff
changeset
|
194 |
if (without_crashed && (veh->vehstatus & VS_CRASHED) != 0) continue; |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6490
diff
changeset
|
195 |
if ((veh->type == VEH_TRAIN || veh->type == VEH_ROAD) && (z == 0xFF || veh->z_pos == z)) { |
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6490
diff
changeset
|
196 |
if ((veh->x_pos >> 4) >= x1 && (veh->x_pos >> 4) <= x2 && |
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6490
diff
changeset
|
197 |
(veh->y_pos >> 4) >= y1 && (veh->y_pos >> 4) <= y2) { |
0 | 198 |
return veh; |
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
return NULL; |
|
203 |
} |
|
204 |
||
2817 | 205 |
|
8072
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
206 |
/** Procedure called for every vehicle found in tunnel/bridge in the hash map */ |
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
207 |
static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) |
8072
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
208 |
{ |
9495
cafcf9e8dbdf
(svn r13475) -Fix (r13464): crash on destroying aquaduct with ship on in and on company bankrupt
smatz
parents:
9428
diff
changeset
|
209 |
if (v->type != VEH_TRAIN && v->type != VEH_ROAD && v->type != VEH_SHIP) return NULL; |
8072
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
210 |
|
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
211 |
_error_message = VehicleInTheWayErrMsg(v); |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
212 |
return v; |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
213 |
} |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
214 |
|
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
215 |
/** |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
216 |
* Finds vehicle in tunnel / bridge |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
217 |
* @param tile first end |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
218 |
* @param endtile second end |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
219 |
* @return pointer to vehicle found |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
220 |
*/ |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
221 |
Vehicle *GetVehicleTunnelBridge(TileIndex tile, TileIndex endtile) |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
222 |
{ |
8081
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
223 |
Vehicle *v = (Vehicle*)VehicleFromPos(tile, NULL, &GetVehicleTunnelBridgeProc); |
8072
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
224 |
if (v != NULL) return v; |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
225 |
|
8081
4fddceb00aa6
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz
parents:
8078
diff
changeset
|
226 |
return (Vehicle*)VehicleFromPos(endtile, NULL, &GetVehicleTunnelBridgeProc); |
8072
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
227 |
} |
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
228 |
|
7b188d7b8199
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz
parents:
8071
diff
changeset
|
229 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
230 |
static void UpdateVehiclePosHash(Vehicle *v, int x, int y); |
2817 | 231 |
|
0 | 232 |
void VehiclePositionChanged(Vehicle *v) |
233 |
{ |
|
234 |
int img = v->cur_image; |
|
235 |
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
236 |
const Sprite *spr = GetSprite(img); |
0 | 237 |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
238 |
pt.x += spr->x_offs; |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
239 |
pt.y += spr->y_offs; |
0 | 240 |
|
241 |
UpdateVehiclePosHash(v, pt.x, pt.y); |
|
242 |
||
243 |
v->left_coord = pt.x; |
|
244 |
v->top_coord = pt.y; |
|
2319
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
245 |
v->right_coord = pt.x + spr->width + 2; |
fba7d61df04a
(svn r2845) Remove sprite size caching, it was unused
tron
parents:
2296
diff
changeset
|
246 |
v->bottom_coord = pt.y + spr->height + 2; |
0 | 247 |
} |
248 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
249 |
/** Called after load to update coordinates */ |
8172
bcad4f33bd3d
(svn r11735) -Fix [FS#1574]: Don't reset loading indicator IDs when only reloading NewGRFs.
peter1138
parents:
8157
diff
changeset
|
250 |
void AfterLoadVehicles(bool clear_te_id) |
0 | 251 |
{ |
252 |
Vehicle *v; |
|
253 |
||
254 |
FOR_ALL_VEHICLES(v) { |
|
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
255 |
/* Reinstate the previous pointer */ |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
256 |
if (v->Next() != NULL) v->Next()->previous = v; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
257 |
|
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6553
diff
changeset
|
258 |
v->UpdateDeltaXY(v->direction); |
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6553
diff
changeset
|
259 |
|
8172
bcad4f33bd3d
(svn r11735) -Fix [FS#1574]: Don't reset loading indicator IDs when only reloading NewGRFs.
peter1138
parents:
8157
diff
changeset
|
260 |
if (clear_te_id) v->fill_percent_te_id = INVALID_TE_ID; |
1601
83fbe3bfb847
(svn r2105) -Codechange: Added a cache for the first vehicle of a chain to increase performance, especially with many long trains
celestar
parents:
1600
diff
changeset
|
261 |
v->first = NULL; |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
262 |
if (v->type == VEH_TRAIN) v->u.rail.first_engine = INVALID_ENGINE; |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
263 |
if (v->type == VEH_ROAD) v->u.road.first_engine = INVALID_ENGINE; |
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
264 |
|
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
265 |
v->cargo.InvalidateCache(); |
3355
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
266 |
} |
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
267 |
|
e414a0b104a6
(svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents:
3326
diff
changeset
|
268 |
FOR_ALL_VEHICLES(v) { |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
269 |
/* Fill the first pointers */ |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
270 |
if (v->Previous() == NULL) { |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
271 |
for (Vehicle *u = v; u != NULL; u = u->Next()) { |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
272 |
u->first = v; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
273 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
274 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
275 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
276 |
|
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
277 |
FOR_ALL_VEHICLES(v) { |
9625
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
278 |
assert(v->first != NULL); |
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
279 |
|
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
280 |
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) { |
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
281 |
if (IsFrontEngine(v)) v->u.rail.last_speed = v->cur_speed; // update displayed train speed |
9704
54123af5f9a5
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents:
9652
diff
changeset
|
282 |
TrainConsistChanged(v, false); |
9625
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
283 |
} else if (v->type == VEH_ROAD && IsRoadVehFront(v)) { |
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
284 |
RoadVehUpdateCache(v); |
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
285 |
} |
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
286 |
} |
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
287 |
|
9f6c09b4a030
(svn r13681) -Revert (r13678, r13677): the fixes didn't work in all cases (assertions on savegame loads).
rubidium
parents:
9624
diff
changeset
|
288 |
FOR_ALL_VEHICLES(v) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
289 |
switch (v->type) { |
6683
b88ae30866ce
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
6665
diff
changeset
|
290 |
case VEH_ROAD: |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
291 |
v->u.road.roadtype = HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; |
6683
b88ae30866ce
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
6665
diff
changeset
|
292 |
v->u.road.compatible_roadtypes = RoadTypeToRoadTypes(v->u.road.roadtype); |
7134
5b2d47128d05
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7108
diff
changeset
|
293 |
/* FALL THROUGH */ |
5b2d47128d05
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7108
diff
changeset
|
294 |
case VEH_TRAIN: |
5b2d47128d05
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7108
diff
changeset
|
295 |
case VEH_SHIP: |
5b2d47128d05
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7108
diff
changeset
|
296 |
v->cur_image = v->GetImage(v->direction); |
6683
b88ae30866ce
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
6665
diff
changeset
|
297 |
break; |
b88ae30866ce
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
6665
diff
changeset
|
298 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
299 |
case VEH_AIRCRAFT: |
5854
9eee280920f0
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents:
5823
diff
changeset
|
300 |
if (IsNormalAircraft(v)) { |
7134
5b2d47128d05
(svn r10408) -Codechange: make GetImage a class method of Vehicle instead of Get(Aircraft|RoadVeh|Ship|Train)Image.
rubidium
parents:
7108
diff
changeset
|
301 |
v->cur_image = v->GetImage(v->direction); |
5866
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
302 |
|
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
303 |
/* The plane's shadow will have the same image as the plane */ |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
304 |
Vehicle *shadow = v->Next(); |
5866
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
305 |
shadow->cur_image = v->cur_image; |
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
306 |
|
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
307 |
/* In the case of a helicopter we will update the rotor sprites */ |
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
308 |
if (v->subtype == AIR_HELICOPTER) { |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
309 |
Vehicle *rotor = shadow->Next(); |
5866
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
310 |
rotor->cur_image = GetRotorImage(v); |
60ee9fff5c99
(svn r8448) -Codechange/Fix (r2993): Also update the helicopter's rotor when loading the game. This can solve crashes when a game is loaded with missing GRF's
Darkvater
parents:
5855
diff
changeset
|
311 |
} |
6490
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6484
diff
changeset
|
312 |
|
fe4443fba5e3
(svn r9671) -Codechange: Implement NewGRF callback 36, which allows changing of various properties which were previously static. Vehicle max speed and train power/te/running costs are adjustable.
peter1138
parents:
6484
diff
changeset
|
313 |
UpdateAircraftCache(v); |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
314 |
} |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
315 |
break; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
316 |
default: break; |
0 | 317 |
} |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
318 |
|
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
319 |
v->left_coord = INVALID_COORD; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
320 |
VehiclePositionChanged(v); |
0 | 321 |
} |
322 |
} |
|
323 |
||
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
324 |
Vehicle::Vehicle() |
0 | 325 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
326 |
this->type = VEH_INVALID; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
327 |
this->left_coord = INVALID_COORD; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
328 |
this->group_id = DEFAULT_GROUP; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
329 |
this->fill_percent_te_id = INVALID_TE_ID; |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
330 |
this->first = this; |
7802
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
331 |
this->colormap = PAL_NONE; |
0 | 332 |
} |
333 |
||
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
334 |
/** |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
335 |
* Get a value for a vehicle's random_bits. |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
336 |
* @return A random value from 0 to 255. |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
337 |
*/ |
6247 | 338 |
byte VehicleRandomBits() |
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
339 |
{ |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
340 |
return GB(Random(), 0, 8); |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
341 |
} |
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
342 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
343 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
344 |
/* static */ bool Vehicle::AllocateList(Vehicle **vl, int num) |
0 | 345 |
{ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
346 |
uint counter = _Vehicle_pool.first_free_index; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
347 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
348 |
for (int i = 0; i != num; i++) { |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
349 |
Vehicle *v = AllocateRaw(counter); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
350 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
351 |
if (v == NULL) return false; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
352 |
v = new (v) InvalidVehicle(); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
353 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
354 |
if (vl != NULL) { |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
355 |
vl[i] = v; |
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
356 |
} |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
357 |
counter++; |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
358 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
359 |
|
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
360 |
return true; |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
361 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
362 |
|
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
363 |
/* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
364 |
* lookup times at the expense of memory usage. */ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
365 |
const int HASH_BITS = 7; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
366 |
const int HASH_SIZE = 1 << HASH_BITS; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
367 |
const int HASH_MASK = HASH_SIZE - 1; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
368 |
const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
369 |
const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
370 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
371 |
/* Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc. |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
372 |
* Profiling results show that 0 is fastest. */ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
373 |
const int HASH_RES = 0; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
374 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
375 |
static Vehicle *_new_vehicle_position_hash[TOTAL_HASH_SIZE]; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
376 |
|
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
377 |
static Vehicle *VehicleFromHash(int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc) |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
378 |
{ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
379 |
for (int y = yl; ; y = (y + (1 << HASH_BITS)) & (HASH_MASK << HASH_BITS)) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
380 |
for (int x = xl; ; x = (x + 1) & HASH_MASK) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
381 |
Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
382 |
for (; v != NULL; v = v->next_new_hash) { |
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
383 |
Vehicle *a = proc(v, data); |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
384 |
if (a != NULL) return a; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
385 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
386 |
if (x == xu) break; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
387 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
388 |
if (y == yu) break; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
389 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
390 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
391 |
return NULL; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
392 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
393 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
394 |
|
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
395 |
Vehicle *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc) |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
396 |
{ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
397 |
const int COLL_DIST = 6; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
398 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
399 |
/* Hash area to scan is from xl,yl to xu,yu */ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
400 |
int xl = GB((x - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
401 |
int xu = GB((x + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
402 |
int yl = GB((y - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
403 |
int yu = GB((y + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
404 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
405 |
return VehicleFromHash(xl, yl, xu, yu, data, proc); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
406 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
407 |
|
2651 | 408 |
|
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
409 |
Vehicle *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
0 | 410 |
{ |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
411 |
int x = GB(TileX(tile), HASH_RES, HASH_BITS); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
412 |
int y = GB(TileY(tile), HASH_RES, HASH_BITS) << HASH_BITS; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
413 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
414 |
Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
415 |
for (; v != NULL; v = v->next_new_hash) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
416 |
if (v->tile != tile) continue; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
417 |
|
9775
22e256c3bf46
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents:
9704
diff
changeset
|
418 |
Vehicle *a = proc(v, data); |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
419 |
if (a != NULL) return a; |
0 | 420 |
} |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
421 |
|
0 | 422 |
return NULL; |
423 |
} |
|
424 |
||
6886
e7f939f0206d
(svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138
parents:
6883
diff
changeset
|
425 |
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove) |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
426 |
{ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
427 |
Vehicle **old_hash = v->old_new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
428 |
Vehicle **new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
429 |
|
6886
e7f939f0206d
(svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138
parents:
6883
diff
changeset
|
430 |
if (remove) { |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
431 |
new_hash = NULL; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
432 |
} else { |
7371
0bb7e1279675
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
peter1138
parents:
7358
diff
changeset
|
433 |
int x = GB(TileX(v->tile), HASH_RES, HASH_BITS); |
0bb7e1279675
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
peter1138
parents:
7358
diff
changeset
|
434 |
int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
435 |
new_hash = &_new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
436 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
437 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
438 |
if (old_hash == new_hash) return; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
439 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
440 |
/* Remove from the old position in the hash table */ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
441 |
if (old_hash != NULL) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
442 |
Vehicle *last = NULL; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
443 |
Vehicle *u = *old_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
444 |
while (u != v) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
445 |
last = u; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
446 |
u = u->next_new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
447 |
assert(u != NULL); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
448 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
449 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
450 |
if (last == NULL) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
451 |
*old_hash = v->next_new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
452 |
} else { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
453 |
last->next_new_hash = v->next_new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
454 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
455 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
456 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
457 |
/* Insert vehicle at beginning of the new position in the hash table */ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
458 |
if (new_hash != NULL) { |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
459 |
v->next_new_hash = *new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
460 |
*new_hash = v; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
461 |
assert(v != v->next_new_hash); |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
462 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
463 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
464 |
/* Remember current hash position */ |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
465 |
v->old_new_hash = new_hash; |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
466 |
} |
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
467 |
|
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
468 |
static Vehicle *_vehicle_position_hash[0x1000]; |
0 | 469 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
470 |
static void UpdateVehiclePosHash(Vehicle *v, int x, int y) |
0 | 471 |
{ |
6886
e7f939f0206d
(svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138
parents:
6883
diff
changeset
|
472 |
UpdateNewVehiclePosHash(v, x == INVALID_COORD); |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
473 |
|
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
474 |
Vehicle **old_hash, **new_hash; |
0 | 475 |
int old_x = v->left_coord; |
476 |
int old_y = v->top_coord; |
|
477 |
||
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6490
diff
changeset
|
478 |
new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x, y)]; |
0 | 479 |
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
|
480 |
|
2639 | 481 |
if (old_hash == new_hash) return; |
0 | 482 |
|
483 |
/* remove from hash table? */ |
|
484 |
if (old_hash != NULL) { |
|
485 |
Vehicle *last = NULL; |
|
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
486 |
Vehicle *u = *old_hash; |
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
487 |
while (u != v) { |
0 | 488 |
last = u; |
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
489 |
u = u->next_hash; |
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
490 |
assert(u != NULL); |
0 | 491 |
} |
492 |
||
2639 | 493 |
if (last == NULL) { |
0 | 494 |
*old_hash = v->next_hash; |
2639 | 495 |
} else { |
0 | 496 |
last->next_hash = v->next_hash; |
2639 | 497 |
} |
0 | 498 |
} |
499 |
||
500 |
/* insert into hash table? */ |
|
501 |
if (new_hash != NULL) { |
|
502 |
v->next_hash = *new_hash; |
|
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
503 |
*new_hash = v; |
0 | 504 |
} |
505 |
} |
|
506 |
||
6247 | 507 |
void ResetVehiclePosHash() |
5352
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
508 |
{ |
6883
a7be3fb54737
(svn r10126) -Fix (r10111, FS#864): old_new_hash cache was not reset when the position hash were
glx
parents:
6871
diff
changeset
|
509 |
Vehicle *v; |
a7be3fb54737
(svn r10126) -Fix (r10111, FS#864): old_new_hash cache was not reset when the position hash were
glx
parents:
6871
diff
changeset
|
510 |
FOR_ALL_VEHICLES(v) { v->old_new_hash = NULL; } |
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
511 |
memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_hash)); |
6871
d8b53c9f0b13
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138
parents:
6857
diff
changeset
|
512 |
memset(_new_vehicle_position_hash, 0, sizeof(_new_vehicle_position_hash)); |
5352
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
513 |
} |
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
514 |
|
7802
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
515 |
void ResetVehicleColorMap() |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
516 |
{ |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
517 |
Vehicle *v; |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
518 |
FOR_ALL_VEHICLES(v) { v->colormap = PAL_NONE; } |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
519 |
} |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
520 |
|
6247 | 521 |
void InitializeVehicles() |
0 | 522 |
{ |
7400
e211c7b9cb8f
(svn r10772) -Codechange: also make use of the generic clean and destroy pool callback functions for vehicle.
rubidium
parents:
7398
diff
changeset
|
523 |
_Vehicle_pool.CleanPool(); |
e211c7b9cb8f
(svn r10772) -Codechange: also make use of the generic clean and destroy pool callback functions for vehicle.
rubidium
parents:
7398
diff
changeset
|
524 |
_Vehicle_pool.AddBlockToPool(); |
5352
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
525 |
|
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5295
diff
changeset
|
526 |
ResetVehiclePosHash(); |
0 | 527 |
} |
528 |
||
529 |
Vehicle *GetLastVehicleInChain(Vehicle *v) |
|
530 |
{ |
|
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
531 |
while (v->Next() != NULL) v = v->Next(); |
0 | 532 |
return v; |
533 |
} |
|
534 |
||
9344
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
535 |
const Vehicle *GetLastVehicleInChain(const Vehicle *v) |
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
536 |
{ |
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
537 |
while (v->Next() != NULL) v = v->Next(); |
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
538 |
return v; |
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
539 |
} |
d3b1b1fbbad9
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138
parents:
9340
diff
changeset
|
540 |
|
2630 | 541 |
uint CountVehiclesInChain(const Vehicle* v) |
0 | 542 |
{ |
2639 | 543 |
uint count = 0; |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
544 |
do count++; while ((v = v->Next()) != NULL); |
0 | 545 |
return count; |
546 |
} |
|
547 |
||
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
548 |
/** Check if a vehicle is counted in num_engines in each player struct |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
549 |
* @param *v Vehicle to test |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
550 |
* @return true if the vehicle is counted in num_engines |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
551 |
*/ |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
552 |
bool IsEngineCountable(const Vehicle *v) |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
553 |
{ |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
554 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
555 |
case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
556 |
case VEH_TRAIN: |
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
557 |
return !IsArticulatedPart(v) && // tenders and other articulated parts |
7526
27c4fbf8aef0
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents:
7512
diff
changeset
|
558 |
!IsRearDualheaded(v); // rear parts of multiheaded engines |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
559 |
case VEH_ROAD: return IsRoadVehFront(v); |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
560 |
case VEH_SHIP: return true; |
4574
61a17f80cfb9
(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 |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
562 |
} |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
563 |
} |
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
564 |
|
7412
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
565 |
void Vehicle::PreDestructor() |
0 | 566 |
{ |
7413
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7412
diff
changeset
|
567 |
if (CleaningPool()) return; |
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7412
diff
changeset
|
568 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
569 |
if (IsValidStationID(this->last_station_visited)) { |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
570 |
GetStation(this->last_station_visited)->loading_vehicles.remove(this); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
571 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
572 |
HideFillingPercent(this->fill_percent_te_id); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
573 |
this->fill_percent_te_id = INVALID_TE_ID; |
6500
f12678890222
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents:
6492
diff
changeset
|
574 |
} |
f12678890222
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents:
6492
diff
changeset
|
575 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
576 |
if (IsEngineCountable(this)) { |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
577 |
GetPlayer(this->owner)->num_engines[this->engine_type]--; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
578 |
if (this->owner == _local_player) InvalidateAutoreplaceWindow(this->engine_type, this->group_id); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
579 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
580 |
if (IsValidGroupID(this->group_id)) GetGroup(this->group_id)->num_engines[this->engine_type]--; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
581 |
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id); |
5944
6d059cc8662b
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
5940
diff
changeset
|
582 |
} |
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4560
diff
changeset
|
583 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
584 |
if (this->type == VEH_ROAD) ClearSlot(this); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
585 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
586 |
if (this->type != VEH_TRAIN || (this->type == VEH_TRAIN && (IsFrontEngine(this) || IsFreeWagon(this)))) { |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
587 |
InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile); |
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
588 |
} |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
589 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
590 |
this->cargo.Truncate(0); |
7412
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
591 |
DeleteVehicleOrders(this); |
4404
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
592 |
|
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
593 |
/* Now remove any artic part. This will trigger an other |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
594 |
* destroy vehicle, which on his turn can remove any |
b58b0af53da3
(svn r6157) -Codechange: DeleteVehicle removes a vehicle from the pool
truelight
parents:
4389
diff
changeset
|
595 |
* other artic parts. */ |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
596 |
if ((this->type == VEH_TRAIN && EngineHasArticPart(this)) || (this->type == VEH_ROAD && RoadVehHasArticPart(this))) { |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
597 |
delete this->Next(); |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
598 |
} |
7765
a09738561237
(svn r11314) -Fix [FS#1356]: stop following a vehicle when you sell/destroyed it.
rubidium
parents:
7758
diff
changeset
|
599 |
|
9274
42b67e65f1c2
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium
parents:
9259
diff
changeset
|
600 |
extern void StopGlobalFollowVehicle(const Vehicle *v); |
42b67e65f1c2
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium
parents:
9259
diff
changeset
|
601 |
StopGlobalFollowVehicle(this); |
7412
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
602 |
} |
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
603 |
|
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
604 |
Vehicle::~Vehicle() |
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
605 |
{ |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
606 |
free(this->name); |
7413
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7412
diff
changeset
|
607 |
|
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7412
diff
changeset
|
608 |
if (CleaningPool()) return; |
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7412
diff
changeset
|
609 |
|
7499
7b5d83a10725
(svn r11014) -Fix (r11011) [FS#1170]: crash when selling the first train of a consist.
rubidium
parents:
7497
diff
changeset
|
610 |
this->SetNext(NULL); |
7412
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
611 |
UpdateVehiclePosHash(this, INVALID_COORD, 0); |
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
612 |
this->next_hash = NULL; |
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
613 |
this->next_new_hash = NULL; |
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
614 |
|
51db351a3313
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium
parents:
7400
diff
changeset
|
615 |
DeleteVehicleNews(this->index, INVALID_STRING_ID); |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
616 |
|
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
617 |
new (this) InvalidVehicle(); |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
618 |
} |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
619 |
|
6782
e36e22d356a9
(svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents:
6773
diff
changeset
|
620 |
/** |
e36e22d356a9
(svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents:
6773
diff
changeset
|
621 |
* Deletes all vehicles in a chain. |
e36e22d356a9
(svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents:
6773
diff
changeset
|
622 |
* @param v The first vehicle in the chain. |
e36e22d356a9
(svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents:
6773
diff
changeset
|
623 |
*/ |
0 | 624 |
void DeleteVehicleChain(Vehicle *v) |
625 |
{ |
|
7702
f963cd54d4d5
(svn r11236) -Fix [FS#1322]: DeleteVehicleChain can just work as good for all vehicles, instead of not allowing trains to use it (enforced by an assert), but actually using it for trains. Patch by SmatZ.
rubidium
parents:
7642
diff
changeset
|
626 |
assert(v->First() == v); |
6782
e36e22d356a9
(svn r10020) -Fix [FS#824]: GetNextVehicle() is invalid for anything that isn't a train.
maedhros
parents:
6773
diff
changeset
|
627 |
|
0 | 628 |
do { |
629 |
Vehicle *u = v; |
|
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
630 |
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
631 |
* it may happen that vehicle chain is deleted when visible */ |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
632 |
if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v); |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
633 |
v = v->Next(); |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
634 |
delete u; |
1765
155dfdbbbc8d
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
635 |
} while (v != NULL); |
0 | 636 |
} |
637 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
638 |
/** head of the linked list to tell what vehicles that visited a depot in a tick */ |
2630 | 639 |
static Vehicle* _first_veh_in_depot_list; |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
640 |
|
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
641 |
/** Adds a vehicle to the list of vehicles, that visited a depot this tick |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
642 |
* @param *v vehicle to add |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
643 |
*/ |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
644 |
void VehicleEnteredDepotThisTick(Vehicle *v) |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
645 |
{ |
8582
601d2fafb775
(svn r12163) -Fix [FS#1705]: if a train is 'stopping' when entering a depot, do not let it leave again
smatz
parents:
8556
diff
changeset
|
646 |
/* We need to set v->leave_depot_instantly as we have no control of it's contents at this time. |
601d2fafb775
(svn r12163) -Fix [FS#1705]: if a train is 'stopping' when entering a depot, do not let it leave again
smatz
parents:
8556
diff
changeset
|
647 |
* Vehicle should stop in the depot if it was in 'stopping' state - train intered depot while slowing down. */ |
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8848
diff
changeset
|
648 |
if (((v->current_order.GetDepotActionType() & ODATFB_HALT) && !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) && v->current_order.IsType(OT_GOTO_DEPOT)) || |
8582
601d2fafb775
(svn r12163) -Fix [FS#1705]: if a train is 'stopping' when entering a depot, do not let it leave again
smatz
parents:
8556
diff
changeset
|
649 |
(v->vehstatus & VS_STOPPED)) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
650 |
/* we keep the vehicle in the depot since the user ordered it to stay */ |
2590
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
651 |
v->leave_depot_instantly = false; |
64e3f69a4ad8
(svn r3127) -Fix: [autoreplace] fixed a condition where a vehicle could fail to stop when autoreplacing
bjarni
parents:
2579
diff
changeset
|
652 |
} else { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
653 |
/* the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
654 |
* out of the depot before we might autoreplace it to a different engine. The new engine would not own the reserved path |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
655 |
* we store that we stopped the vehicle, so autoreplace can start it again */ |
2579
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
656 |
v->vehstatus |= VS_STOPPED; |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
657 |
v->leave_depot_instantly = true; |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
658 |
} |
8048bed6e67e
(svn r3116) -Fix: [autoreplace] fixed issue where autorenewing/autoreplacing a plane could lock up an airport
bjarni
parents:
2575
diff
changeset
|
659 |
|
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
660 |
if (_first_veh_in_depot_list == NULL) { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
661 |
_first_veh_in_depot_list = v; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
662 |
} else { |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
663 |
Vehicle *w = _first_veh_in_depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
664 |
while (w->depot_list != NULL) w = w->depot_list; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
665 |
w->depot_list = v; |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
666 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
667 |
} |
0 | 668 |
|
6247 | 669 |
void CallVehicleTicks() |
0 | 670 |
{ |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
671 |
_first_veh_in_depot_list = NULL; // now we are sure it's initialized at the start of each tick |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
672 |
|
6616
0b3835bdd796
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents:
6611
diff
changeset
|
673 |
Station *st; |
0b3835bdd796
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents:
6611
diff
changeset
|
674 |
FOR_ALL_STATIONS(st) LoadUnloadStation(st); |
0b3835bdd796
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents:
6611
diff
changeset
|
675 |
|
0b3835bdd796
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents:
6611
diff
changeset
|
676 |
Vehicle *v; |
0 | 677 |
FOR_ALL_VEHICLES(v) { |
7135
3c1bcca0d6bb
(svn r10409) -Codechange: replace (Aircraft|RoadVeh|Ship|Train)_Tick with a Tick method in the Vehicle class.
rubidium
parents:
7134
diff
changeset
|
678 |
v->Tick(); |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
679 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
680 |
switch (v->type) { |
6621
441559124aea
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents:
6616
diff
changeset
|
681 |
default: break; |
441559124aea
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents:
6616
diff
changeset
|
682 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
683 |
case VEH_TRAIN: |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
684 |
case VEH_ROAD: |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
685 |
case VEH_AIRCRAFT: |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
686 |
case VEH_SHIP: |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
687 |
if (v->type == VEH_TRAIN && IsTrainWagon(v)) continue; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
688 |
if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue; |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
689 |
if (v->type == VEH_ROAD && !IsRoadVehFront(v)) continue; |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
690 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
691 |
v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
692 |
/* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */ |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
693 |
if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
694 |
|
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
695 |
/* Play an alterate running sound every 16 ticks */ |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
696 |
if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4648
diff
changeset
|
697 |
} |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
698 |
} |
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
699 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
700 |
/* now we handle all the vehicles that entered a depot this tick */ |
2574
70a4e3cb85bf
(svn r3111) -Fix: [autoreplace] [ 1341783 ] Assertion failure in vehicle.c line 378
bjarni
parents:
2564
diff
changeset
|
701 |
v = _first_veh_in_depot_list; |
8996
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
702 |
if (v != NULL) { |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
703 |
while (v != NULL) { |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
704 |
/* Autoreplace needs the current player set as the vehicle owner */ |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
705 |
_current_player = v->owner; |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
706 |
|
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
707 |
/* Buffer v->depot_list and clear it. |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
708 |
* Autoreplace might clear this so it has to be buffered. */ |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
709 |
Vehicle *w = v->depot_list; |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
710 |
v->depot_list = NULL; // it should always be NULL at the end of each tick |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
711 |
|
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
712 |
/* Start vehicle if we stopped them in VehicleEnteredDepotThisTick() |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
713 |
* We need to stop them between VehicleEnteredDepotThisTick() and here or we risk that |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
714 |
* they are already leaving the depot again before being replaced. */ |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
715 |
if (v->leave_depot_instantly) { |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
716 |
v->leave_depot_instantly = false; |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
717 |
v->vehstatus &= ~VS_STOPPED; |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
718 |
} |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
719 |
MaybeReplaceVehicle(v, DC_EXEC, true); |
8996
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
720 |
v = w; |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
721 |
} |
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
722 |
_current_player = OWNER_NONE; |
0 | 723 |
} |
724 |
} |
|
725 |
||
2704
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
726 |
/** Check if a given engine type can be refitted to a given cargo |
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
727 |
* @param engine_type Engine type to check |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
728 |
* @param cid_to check refit to this cargo-type |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
729 |
* @return true if it is possible, false otherwise |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
730 |
*/ |
2704
bdf6ae0cb27c
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2697
diff
changeset
|
731 |
bool CanRefitTo(EngineID engine_type, CargoID cid_to) |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
732 |
{ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
733 |
return HasBit(EngInfo(engine_type)->refit_mask, cid_to); |
1802
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
734 |
} |
da61740cc1e7
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1796
diff
changeset
|
735 |
|
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
736 |
/** Find the first cargo type that an engine can be refitted to. |
6484
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6453
diff
changeset
|
737 |
* @param engine_type Which engine to find cargo for. |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
738 |
* @return A climate dependent cargo type. CT_INVALID is returned if not refittable. |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
739 |
*/ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
740 |
CargoID FindFirstRefittableCargo(EngineID engine_type) |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
741 |
{ |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
742 |
uint32 refit_mask = EngInfo(engine_type)->refit_mask; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
743 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
744 |
if (refit_mask != 0) { |
6350
04b19f551aec
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6331
diff
changeset
|
745 |
for (CargoID cid = 0; cid < NUM_CARGO; cid++) { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
746 |
if (HasBit(refit_mask, cid)) return cid; |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
747 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
748 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
749 |
|
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
750 |
return CT_INVALID; |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
751 |
} |
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
752 |
|
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
753 |
/** Learn the price of refitting a certain engine |
6484
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6453
diff
changeset
|
754 |
* @param engine_type Which engine to refit |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
755 |
* @return Price for refitting |
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
756 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
757 |
CommandCost GetRefitCost(EngineID engine_type) |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
758 |
{ |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
759 |
Money base_cost; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
760 |
ExpensesType expense_type; |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
761 |
switch (GetEngine(engine_type)->type) { |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
762 |
case VEH_SHIP: |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
763 |
base_cost = _price.ship_base; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
764 |
expense_type = EXPENSES_SHIP_RUN; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
765 |
break; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
766 |
|
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
767 |
case VEH_ROAD: |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
768 |
base_cost = _price.roadveh_base; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
769 |
expense_type = EXPENSES_ROADVEH_RUN; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
770 |
break; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
771 |
|
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
772 |
case VEH_AIRCRAFT: |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
773 |
base_cost = _price.aircraft_base; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
774 |
expense_type = EXPENSES_AIRCRAFT_RUN; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
775 |
break; |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
776 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
777 |
case VEH_TRAIN: |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
778 |
base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
779 |
_price.build_railwagon : _price.build_railvehicle); |
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
780 |
expense_type = EXPENSES_TRAIN_RUN; |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
781 |
break; |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
782 |
|
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
783 |
default: NOT_REACHED(); |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
784 |
} |
8230
64f28fe2d5c8
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8224
diff
changeset
|
785 |
return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10); |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4527
diff
changeset
|
786 |
} |
3973
9d3cd1ed6ac0
(svn r5146) - NewGRF: Support selection of aircraft default cargo type by checking its refit mask. If aircraft can be refitted to passengers, no change happens, else the first refittable type is chosen. Also use refit capacity to determine the default capacity.
peter1138
parents:
3961
diff
changeset
|
787 |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2425
diff
changeset
|
788 |
static void DoDrawVehicle(const Vehicle *v) |
0 | 789 |
{ |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
790 |
SpriteID image = v->cur_image; |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
791 |
SpriteID pal = PAL_NONE; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
792 |
|
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
793 |
if (v->vehstatus & VS_DEFPAL) pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
0 | 794 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
795 |
AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
8793
5e35232593c3
(svn r12531) -Codechange: Rename some variables for consistency.
frosch
parents:
8786
diff
changeset
|
796 |
v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & VS_SHADOW) != 0); |
0 | 797 |
} |
798 |
||
799 |
void ViewportAddVehicles(DrawPixelInfo *dpi) |
|
800 |
{ |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
801 |
/* The bounding rectangle */ |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
802 |
const int l = dpi->left; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
803 |
const int r = dpi->left + dpi->width; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
804 |
const int t = dpi->top; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
805 |
const int b = dpi->top + dpi->height; |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
806 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
807 |
/* The hash area to scan */ |
6905
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
808 |
int xl, xu, yl, yu; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
809 |
|
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
810 |
if (dpi->width + 70 < (1 << (7 + 6))) { |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
811 |
xl = GB(l - 70, 7, 6); |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
812 |
xu = GB(r, 7, 6); |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
813 |
} else { |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
814 |
/* scan whole hash row */ |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
815 |
xl = 0; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
816 |
xu = 0x3F; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
817 |
} |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
818 |
|
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
819 |
if (dpi->height + 70 < (1 << (6 + 6))) { |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
820 |
yl = GB(t - 70, 6, 6) << 6; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
821 |
yu = GB(b, 6, 6) << 6; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
822 |
} else { |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
823 |
/* scan whole column */ |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
824 |
yl = 0; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
825 |
yu = 0x3F << 6; |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
826 |
} |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
827 |
|
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
828 |
for (int y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
829 |
for (int x = xl;; x = (x + 1) & 0x3F) { |
cc682e1608bf
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium
parents:
6904
diff
changeset
|
830 |
const Vehicle *v = _vehicle_position_hash[x + y]; // already masked & 0xFFF |
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
831 |
|
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
832 |
while (v != NULL) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
833 |
if (!(v->vehstatus & VS_HIDDEN) && |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
834 |
l <= v->right_coord && |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
835 |
t <= v->bottom_coord && |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
836 |
r >= v->left_coord && |
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
837 |
b >= v->top_coord) { |
0 | 838 |
DoDrawVehicle(v); |
839 |
} |
|
5574
2cb543714009
(svn r8007) -Codechange: Change _vehicle_position_hash from VehicleID to Vehicle*. This removes the need for look ups by index. Also declare the array static.
peter1138
parents:
5475
diff
changeset
|
840 |
v = v->next_hash; |
0 | 841 |
} |
842 |
||
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
843 |
if (x == xu) break; |
0 | 844 |
} |
4174
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
845 |
|
0b13c25586f7
(svn r5612) Restructure some code which uses the vehicle position hash to make it a bit clearer what's going on
tron
parents:
4165
diff
changeset
|
846 |
if (y == yu) break; |
0 | 847 |
} |
848 |
} |
|
849 |
||
2116 | 850 |
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
0 | 851 |
{ |
852 |
Vehicle *found = NULL, *v; |
|
853 |
uint dist, best_dist = (uint)-1; |
|
854 |
||
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
855 |
if ((uint)(x -= vp->left) >= (uint)vp->width || (uint)(y -= vp->top) >= (uint)vp->height) return NULL; |
0 | 856 |
|
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6621
diff
changeset
|
857 |
x = ScaleByZoom(x, vp->zoom) + vp->virtual_left; |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6621
diff
changeset
|
858 |
y = ScaleByZoom(y, vp->zoom) + vp->virtual_top; |
0 | 859 |
|
860 |
FOR_ALL_VEHICLES(v) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
861 |
if ((v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0 && |
0 | 862 |
x >= v->left_coord && x <= v->right_coord && |
863 |
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
|
864 |
|
0 | 865 |
dist = max( |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
866 |
abs(((v->left_coord + v->right_coord) >> 1) - x), |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
867 |
abs(((v->top_coord + v->bottom_coord) >> 1) - y) |
0 | 868 |
); |
869 |
||
870 |
if (dist < best_dist) { |
|
871 |
found = v; |
|
872 |
best_dist = dist; |
|
873 |
} |
|
874 |
} |
|
875 |
} |
|
876 |
||
877 |
return found; |
|
878 |
} |
|
879 |
||
7803
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
880 |
void CheckVehicle32Day(Vehicle *v) |
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
881 |
{ |
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
882 |
if ((v->day_counter & 0x1F) != 0) return; |
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
883 |
|
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
884 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_32DAY_CALLBACK, 0, 0, v->engine_type, v); |
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
885 |
if (callback == CALLBACK_FAILED) return; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
886 |
if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10 |
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
887 |
if (HasBit(callback, 1)) v->colormap = PAL_NONE; // Update colormap via callback 2D |
7803
55307751965b
(svn r11353) -Codechange: add support for newgrf callback 32
glx
parents:
7802
diff
changeset
|
888 |
} |
0 | 889 |
|
890 |
void DecreaseVehicleValue(Vehicle *v) |
|
891 |
{ |
|
892 |
v->value -= v->value >> 8; |
|
893 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
894 |
} |
|
895 |
||
896 |
static const byte _breakdown_chance[64] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
897 |
3, 3, 3, 3, 3, 3, 3, 3, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
898 |
4, 4, 5, 5, 6, 6, 7, 7, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
899 |
8, 8, 9, 9, 10, 10, 11, 11, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
900 |
12, 13, 13, 13, 13, 14, 15, 16, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
901 |
17, 19, 21, 25, 28, 31, 34, 37, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
902 |
40, 44, 48, 52, 56, 60, 64, 68, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
903 |
72, 80, 90, 100, 110, 120, 130, 140, |
0 | 904 |
150, 170, 190, 210, 230, 250, 250, 250, |
905 |
}; |
|
906 |
||
907 |
void CheckVehicleBreakdown(Vehicle *v) |
|
908 |
{ |
|
909 |
int rel, rel_old; |
|
910 |
||
911 |
/* decrease reliability */ |
|
912 |
v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
|
8980
3f434ded0a30
(svn r12772) -Codechange: some vehicle.cpp coding style.
rubidium
parents:
8970
diff
changeset
|
913 |
if ((rel_old >> 8) != (rel >> 8)) InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
0 | 914 |
|
2639 | 915 |
if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED || |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
916 |
_settings_game.difficulty.vehicle_breakdowns < 1 || |
2639 | 917 |
v->cur_speed < 5 || _game_mode == GM_MENU) { |
918 |
return; |
|
919 |
} |
|
0 | 920 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
921 |
uint32 r = Random(); |
0 | 922 |
|
923 |
/* increase chance of failure */ |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
924 |
int chance = v->breakdown_chance + 1; |
8980
3f434ded0a30
(svn r12772) -Codechange: some vehicle.cpp coding style.
rubidium
parents:
8970
diff
changeset
|
925 |
if (Chance16I(1, 25, r)) chance += 25; |
0 | 926 |
v->breakdown_chance = min(255, chance); |
927 |
||
928 |
/* calculate reliability value to use in comparison */ |
|
929 |
rel = v->reliability; |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
930 |
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
|
931 |
|
0 | 932 |
/* reduced breakdowns? */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
933 |
if (_settings_game.difficulty.vehicle_breakdowns == 1) rel += 0x6666; |
0 | 934 |
|
935 |
/* check if to break down */ |
|
936 |
if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
937 |
v->breakdown_ctr = GB(r, 16, 6) + 0x3F; |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2116
diff
changeset
|
938 |
v->breakdown_delay = GB(r, 24, 7) + 0x80; |
0 | 939 |
v->breakdown_chance = 0; |
940 |
} |
|
941 |
} |
|
942 |
||
943 |
static const StringID _vehicle_type_names[4] = { |
|
944 |
STR_019F_TRAIN, |
|
945 |
STR_019C_ROAD_VEHICLE, |
|
946 |
STR_019E_SHIP, |
|
947 |
STR_019D_AIRCRAFT, |
|
948 |
}; |
|
949 |
||
950 |
static void ShowVehicleGettingOld(Vehicle *v, StringID msg) |
|
951 |
{ |
|
2639 | 952 |
if (v->owner != _local_player) return; |
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
953 |
|
7544
cac538ba670a
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium
parents:
7532
diff
changeset
|
954 |
/* Do not show getting-old message if autorenew is active (and it can replace the vehicle) */ |
cac538ba670a
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium
parents:
7532
diff
changeset
|
955 |
if (GetPlayer(v->owner)->engine_renew && GetEngine(v->engine_type)->player_avail != 0) return; |
0 | 956 |
|
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5944
diff
changeset
|
957 |
SetDParam(0, _vehicle_type_names[v->type]); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
958 |
SetDParam(1, v->unitnumber); |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9224
diff
changeset
|
959 |
AddNewsItem(msg, NS_ADVICE, v->index, 0); |
0 | 960 |
} |
961 |
||
962 |
void AgeVehicle(Vehicle *v) |
|
963 |
{ |
|
7544
cac538ba670a
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium
parents:
7532
diff
changeset
|
964 |
if (v->age < 65535) v->age++; |
cac538ba670a
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium
parents:
7532
diff
changeset
|
965 |
|
cac538ba670a
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium
parents:
7532
diff
changeset
|
966 |
int age = v->age - v->max_age; |
cac538ba670a
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium
parents:
7532
diff
changeset
|
967 |
if (age == 366*0 || age == 366*1 || age == 366*2 || age == 366*3 || age == 366*4) v->reliability_spd_dec <<= 1; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
968 |
|
0 | 969 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
970 |
||
971 |
if (age == -366) { |
|
972 |
ShowVehicleGettingOld(v, STR_01A0_IS_GETTING_OLD); |
|
973 |
} else if (age == 0) { |
|
974 |
ShowVehicleGettingOld(v, STR_01A1_IS_GETTING_VERY_OLD); |
|
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7544
diff
changeset
|
975 |
} else if (age > 0 && (age % 366) == 0) { |
0 | 976 |
ShowVehicleGettingOld(v, STR_01A2_IS_GETTING_VERY_OLD_AND); |
977 |
} |
|
978 |
} |
|
979 |
||
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
980 |
/** Starts or stops a lot of vehicles |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
981 |
* @param tile Tile of the depot where the vehicles are started/stopped (only used for depots) |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
982 |
* @param flags type of operation |
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
983 |
* @param p1 Station/Order/Depot ID (only used for vehicle list windows) |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
984 |
* @param p2 bitmask |
4762
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
985 |
* - bit 0-4 Vehicle type |
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
986 |
* - bit 5 false = start vehicles, true = stop vehicles |
771ccf746531
(svn r6676) -Fix: [vehicle list windows] mass start/stop now works correctly in shared orders and station lists
bjarni
parents:
4741
diff
changeset
|
987 |
* - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
988 |
* - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set) |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
989 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
990 |
CommandCost CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
991 |
{ |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
992 |
VehicleList list; |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
993 |
CommandCost return_value = CMD_ERROR; |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
994 |
uint stop_command; |
6641
1b14f8887cb7
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents:
6638
diff
changeset
|
995 |
VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5); |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
996 |
bool start_stop = HasBit(p2, 5); |
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
997 |
bool vehicle_list_window = HasBit(p2, 6); |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
998 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
999 |
switch (vehicle_type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1000 |
case VEH_TRAIN: stop_command = CMD_START_STOP_TRAIN; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1001 |
case VEH_ROAD: stop_command = CMD_START_STOP_ROADVEH; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1002 |
case VEH_SHIP: stop_command = CMD_START_STOP_SHIP; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1003 |
case VEH_AIRCRAFT: stop_command = CMD_START_STOP_AIRCRAFT; break; |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1004 |
default: return CMD_ERROR; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1005 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1006 |
|
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1007 |
if (vehicle_list_window) { |
5748
cf2f07fa20ca
(svn r8296) -Fix: GenerateVehicleSortList() tried to put a TileIndex into an uint16
bjarni
parents:
5747
diff
changeset
|
1008 |
uint32 id = p1; |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1009 |
uint16 window_type = p2 & VLW_MASK; |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1010 |
|
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1011 |
GenerateVehicleSortList(&list, vehicle_type, _current_player, id, window_type); |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1012 |
} else { |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1013 |
/* Get the list of vehicles in the depot */ |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1014 |
BuildDepotVehicleList(vehicle_type, tile, &list, NULL); |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1015 |
} |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1016 |
|
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1017 |
for (uint i = 0; i < list.Length(); i++) { |
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1018 |
const Vehicle *v = list[i]; |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1019 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1020 |
if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1021 |
|
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1022 |
if (!vehicle_list_window) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1023 |
if (vehicle_type == VEH_TRAIN) { |
4673
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1024 |
if (CheckTrainInDepot(v, false) == -1) continue; |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1025 |
} else { |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1026 |
if (!(v->vehstatus & VS_HIDDEN)) continue; |
3160067b8751
(svn r6570) -Feature: added "start all" and "stop all" buttons to the vehicle lists
bjarni
parents:
4662
diff
changeset
|
1027 |
} |
4648
7bde2a5c36e8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1028 |
} |
7bde2a5c36e8
(svn r6524) -Code cleanup r6515: cleaned up the command to start/stop all vehicles in a depot.
bjarni
parents:
4640
diff
changeset
|
1029 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1030 |
CommandCost ret = DoCommand(tile, v->index, 0, flags, stop_command); |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1031 |
|
6946
a48b23f1cc8a
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
6943
diff
changeset
|
1032 |
if (CmdSucceeded(ret)) { |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1033 |
return_value = CommandCost(); |
4640
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1034 |
/* We know that the command is valid for at least one vehicle. |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1035 |
* If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1036 |
if (!(flags & DC_EXEC)) break; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1037 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1038 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1039 |
|
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1040 |
return return_value; |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1041 |
} |
4e380e2ecfa7
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
bjarni
parents:
4635
diff
changeset
|
1042 |
|
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1043 |
/** Sells all vehicles in a depot |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1044 |
* @param tile Tile of the depot where the depot is |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1045 |
* @param flags type of operation |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1046 |
* @param p1 Vehicle type |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1047 |
* @param p2 unused |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1048 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1049 |
CommandCost CmdDepotSellAllVehicles(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1050 |
{ |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1051 |
VehicleList list; |
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1052 |
|
8245
86caf8eb69dd
(svn r11809) -Fix [FS#1643]: set expenses type when selling all vehicles in depot
smatz
parents:
8238
diff
changeset
|
1053 |
CommandCost cost(EXPENSES_NEW_VEHICLES); |
9345
498b7ff11b25
(svn r13241) -Codechange: Simplify CmdDepotSellAllVehicles() a bit
peter1138
parents:
9344
diff
changeset
|
1054 |
uint sell_command; |
6641
1b14f8887cb7
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents:
6638
diff
changeset
|
1055 |
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1056 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1057 |
switch (vehicle_type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1058 |
case VEH_TRAIN: sell_command = CMD_SELL_RAIL_WAGON; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1059 |
case VEH_ROAD: sell_command = CMD_SELL_ROAD_VEH; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1060 |
case VEH_SHIP: sell_command = CMD_SELL_SHIP; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1061 |
case VEH_AIRCRAFT: sell_command = CMD_SELL_AIRCRAFT; break; |
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1062 |
default: return CMD_ERROR; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1063 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1064 |
|
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1065 |
/* Get the list of vehicles in the depot */ |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1066 |
BuildDepotVehicleList(vehicle_type, tile, &list, &list); |
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1067 |
|
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1068 |
for (uint i = 0; i < list.Length(); i++) { |
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1069 |
CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command); |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1070 |
if (CmdSucceeded(ret)) cost.AddCost(ret); |
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1071 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1072 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1073 |
if (cost.GetCost() == 0) return CMD_ERROR; // no vehicles to sell |
4659
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1074 |
return cost; |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1075 |
} |
e476c76389a8
(svn r6542) -Feature: [depot window] added a "sell all vehicles in depot" button
bjarni
parents:
4656
diff
changeset
|
1076 |
|
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1077 |
/** Autoreplace all vehicles in the depot |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1078 |
* Note: this command can make incorrect cost estimations |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1079 |
* Luckily the final price can only drop, not increase. This is due to the fact that |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1080 |
* estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons. |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1081 |
* @param tile Tile of the depot where the vehicles are |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1082 |
* @param flags type of operation |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1083 |
* @param p1 Type of vehicle |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1084 |
* @param p2 If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out) |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1085 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1086 |
CommandCost CmdDepotMassAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1087 |
{ |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1088 |
VehicleList list; |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1089 |
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES); |
6641
1b14f8887cb7
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents:
6638
diff
changeset
|
1090 |
VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1091 |
bool all_or_nothing = HasBit(p2, 0); |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1092 |
|
7512
dd5d439e1337
(svn r11027) -Fix: do not unconditionally assume that a tile has a depot.
rubidium
parents:
7502
diff
changeset
|
1093 |
if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR; |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1094 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1095 |
/* Get the list of vehicles in the depot */ |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1096 |
BuildDepotVehicleList(vehicle_type, tile, &list, &list); |
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1097 |
|
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1098 |
for (uint i = 0; i < list.Length(); i++) { |
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1099 |
Vehicle *v = (Vehicle*)list[i]; |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1100 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1101 |
/* Ensure that the vehicle completely in the depot */ |
7490
bb27d92565d3
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7486
diff
changeset
|
1102 |
if (!v->IsInDepot()) continue; |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1103 |
|
8996
0873e8d827e7
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni
parents:
8980
diff
changeset
|
1104 |
CommandCost ret = MaybeReplaceVehicle(v, flags, false); |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1105 |
|
6946
a48b23f1cc8a
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
6943
diff
changeset
|
1106 |
if (CmdSucceeded(ret)) { |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1107 |
cost.AddCost(ret); |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1108 |
} else { |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1109 |
if (all_or_nothing) { |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1110 |
/* We failed to replace a vehicle even though we set all or nothing. |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1111 |
* We should never reach this if DC_EXEC is set since then it should |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1112 |
* have failed the estimation guess. */ |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1113 |
assert(!(flags & DC_EXEC)); |
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1114 |
/* Now we will have to return an error. */ |
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1115 |
return CMD_ERROR; |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1116 |
} |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1117 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1118 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1119 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1120 |
if (cost.GetCost() == 0) { |
8736
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1121 |
/* Either we didn't replace anything or something went wrong. |
ff99c0258370
(svn r12421) -Feature: [autoreplace] the autoreplace button in train depots will now also replace wagons even if they aren't connected to a locomotive
bjarni
parents:
8673
diff
changeset
|
1122 |
* Either way we want to return an error and not execute this command. */ |
4662
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1123 |
cost = CMD_ERROR; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1124 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1125 |
|
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1126 |
return cost; |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1127 |
} |
e36935c7bdde
(svn r6552) -Feature: [depot window] added a "autoreplace all vehicles in depot" button
bjarni
parents:
4659
diff
changeset
|
1128 |
|
2244 | 1129 |
/** Clone a vehicle. If it is a train, it will clone all the cars too |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1130 |
* @param tile tile of the depot where the cloned vehicle is build |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1131 |
* @param flags type of operation |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1132 |
* @param p1 the original vehicle's index |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1133 |
* @param p2 1 = shared orders, else copied orders |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1134 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1135 |
CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2244 | 1136 |
{ |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1137 |
CommandCost total_cost(EXPENSES_NEW_VEHICLES); |
3816
28ee8b8c2522
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3815
diff
changeset
|
1138 |
uint32 build_argument = 2; |
2244 | 1139 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1140 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1141 |
|
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1142 |
Vehicle *v = GetVehicle(p1); |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1143 |
Vehicle *v_front = v; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1144 |
Vehicle *w = NULL; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1145 |
Vehicle *w_front = NULL; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1146 |
Vehicle *w_rear = NULL; |
6444
31f400a4b890
(svn r9581) -Revert (r9562): This broke as much as it fixed, so revert until a proper way of paying for refits when cloning can be found.
maedhros
parents:
6426
diff
changeset
|
1147 |
|
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1148 |
/* |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1149 |
* v_front is the front engine in the original vehicle |
6444
31f400a4b890
(svn r9581) -Revert (r9562): This broke as much as it fixed, so revert until a proper way of paying for refits when cloning can be found.
maedhros
parents:
6426
diff
changeset
|
1150 |
* v is the car/vehicle of the original vehicle, that is currently being copied |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1151 |
* w_front is the front engine of the cloned vehicle |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1152 |
* w is the car/vehicle currently being cloned |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1153 |
* w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1154 |
*/ |
2244 | 1155 |
|
2639 | 1156 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2244 | 1157 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1158 |
if (v->type == VEH_TRAIN && (!IsFrontEngine(v) || v->u.rail.crash_anim_pos >= 4400)) return CMD_ERROR; |
2244 | 1159 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1160 |
/* check that we can allocate enough vehicles */ |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1161 |
if (!(flags & DC_EXEC)) { |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1162 |
int veh_counter = 0; |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1163 |
do { |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1164 |
veh_counter++; |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
1165 |
} while ((v = v->Next()) != NULL); |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1166 |
|
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
1167 |
if (!Vehicle::AllocateList(NULL, veh_counter)) { |
2606
715bba67addf
(svn r3143) -Codechange: greatly increased speed when allocating vehicles
bjarni
parents:
2602
diff
changeset
|
1168 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
2601
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1169 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1170 |
} |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1171 |
|
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1172 |
v = v_front; |
d1a193af01e6
(svn r3138) -Fix: [clone vehicles] fixed assert when it was possible to allocate some vehicles to clone a train, but not for all cars
bjarni
parents:
2600
diff
changeset
|
1173 |
|
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1174 |
do { |
7526
27c4fbf8aef0
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni
parents:
7512
diff
changeset
|
1175 |
if (v->type == VEH_TRAIN && IsRearDualheaded(v)) { |
2676
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1176 |
/* we build the rear ends of multiheaded trains with the front ones */ |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1177 |
continue; |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1178 |
} |
59b65b4fb480
(svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents:
2666
diff
changeset
|
1179 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1180 |
CommandCost cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v)); |
3819
64c55c77567a
(svn r4829) -Codechage: [clone vehilces] only check for a free unitnumber for the first engine in the test run as well as execute run (to improve speed. The result should be unchanged)
bjarni
parents:
3816
diff
changeset
|
1181 |
build_argument = 3; // ensure that we only assign a number to the first engine |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1182 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1183 |
if (CmdFailed(cost)) return cost; |
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1184 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1185 |
total_cost.AddCost(cost); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1186 |
|
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1187 |
if (flags & DC_EXEC) { |
2639 | 1188 |
w = GetVehicle(_new_vehicle_id); |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1189 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1190 |
if (v->type == VEH_TRAIN && HasBit(v->u.rail.flags, VRF_REVERSE_DIRECTION)) { |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
1191 |
SetBit(w->u.rail.flags, VRF_REVERSE_DIRECTION); |
3896
580ff4e6a49e
(svn r4967) -Fix: [clone vehicles] a cloned train engine heads the same way as the original (pointed out by bobingabout)
bjarni
parents:
3881
diff
changeset
|
1192 |
} |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1193 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1194 |
if (v->type == VEH_TRAIN && !IsFrontEngine(v)) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1195 |
/* this s a train car |
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1196 |
* add this unit to the end of the train */ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1197 |
CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
6838
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1198 |
if (CmdFailed(result)) { |
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1199 |
/* The train can't be joined to make the same consist as the original. |
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1200 |
* Sell what we already made (clean up) and return an error. */ |
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1201 |
DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1202 |
DoCommand(w_front->tile, w->index, 1, flags, GetCmdSellVeh(w)); |
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1203 |
return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE |
243a588e6a0d
(svn r10077) -Fix: FS#845 Cloning Trains Longer Than 8 Units Causes Crash
bjarni
parents:
6823
diff
changeset
|
1204 |
} |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1205 |
} else { |
7850
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1206 |
/* this is a front engine or not a train. */ |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1207 |
w_front = w; |
3679
252b4ab2aad4
(svn r4599) -Fix: [Cloning, autoreplace] FS#141 clone service-interval
bjarni
parents:
3657
diff
changeset
|
1208 |
w->service_interval = v->service_interval; |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1209 |
} |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4404
diff
changeset
|
1210 |
w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop |
2563
abf7a5e73988
(svn r3100) -Codechange [Clone vehicles] Major change to clone vehicles
bjarni
parents:
2558
diff
changeset
|
1211 |
} |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1212 |
} while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1213 |
|
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1214 |
if (flags & DC_EXEC && v_front->type == VEH_TRAIN) { |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1215 |
/* for trains this needs to be the front engine due to the callback function */ |
3948
a09379beffd5
(svn r5094) Remove _new_{aircraft,roadveh,ship,train,wagon}_id. _new_vehicle_id is enough.
tron
parents:
3896
diff
changeset
|
1216 |
_new_vehicle_id = w_front->index; |
2244 | 1217 |
} |
5062
470335730a60
(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
|
1218 |
|
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
1219 |
if (flags & DC_EXEC) { |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
1220 |
/* Cloned vehicles belong to the same group */ |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
1221 |
DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP); |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
1222 |
} |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
1223 |
|
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
1224 |
|
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1225 |
/* Take care of refitting. */ |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1226 |
w = w_front; |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1227 |
v = v_front; |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1228 |
|
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1229 |
/* Both building and refitting are influenced by newgrf callbacks, which |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1230 |
* makes it impossible to accurately estimate the cloning costs. In |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1231 |
* particular, it is possible for engines of the same type to be built with |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1232 |
* different numbers of articulated parts, so when refitting we have to |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1233 |
* loop over real vehicles first, and then the articulated parts of those |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1234 |
* vehicles in a different loop. */ |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1235 |
do { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1236 |
do { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1237 |
if (flags & DC_EXEC) { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1238 |
assert(w != NULL); |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1239 |
|
7812
9b694475d8f5
(svn r11362) -Fix [FS#1380]: cloning vehicles with non-standard sub-cargotypes (i.e. livery refits) failed.
rubidium
parents:
7803
diff
changeset
|
1240 |
if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) { |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1241 |
CommandCost cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v)); |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1242 |
if (CmdSucceeded(cost)) total_cost.AddCost(cost); |
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1243 |
} |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1244 |
|
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1245 |
if (w->type == VEH_TRAIN && EngineHasArticPart(w)) { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1246 |
w = GetNextArticPart(w); |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1247 |
} else if (w->type == VEH_ROAD && RoadVehHasArticPart(w)) { |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
1248 |
w = w->Next(); |
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1249 |
} else { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1250 |
break; |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1251 |
} |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1252 |
} else { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1253 |
CargoID initial_cargo = GetEngineCargoType(v->engine_type); |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1254 |
|
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1255 |
if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) { |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1256 |
total_cost.AddCost(GetRefitCost(v->engine_type)); |
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1257 |
} |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1258 |
} |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1259 |
|
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1260 |
if (v->type == VEH_TRAIN && EngineHasArticPart(v)) { |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1261 |
v = GetNextArticPart(v); |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1262 |
} else if (v->type == VEH_ROAD && RoadVehHasArticPart(v)) { |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
1263 |
v = v->Next(); |
6857
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1264 |
} else { |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1265 |
break; |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1266 |
} |
60130753e595
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents:
6838
diff
changeset
|
1267 |
} while (v != NULL); |
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1268 |
|
6727
7b016b7e17af
(svn r9959) -Fix: Only call GetNextVehicle for trains.
maedhros
parents:
6724
diff
changeset
|
1269 |
if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = GetNextVehicle(w); |
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1270 |
} while (v->type == VEH_TRAIN && (v = GetNextVehicle(v)) != NULL); |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1271 |
|
7850
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1272 |
if (flags & DC_EXEC) { |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1273 |
/* |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1274 |
* Set the orders of the vehicle. Cannot do it earlier as we need |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1275 |
* the vehicle refitted before doing this, otherwise the moved |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1276 |
* cargo types might not match (passenger vs non-passenger) |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1277 |
*/ |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1278 |
DoCommand(0, (v_front->index << 16) | w_front->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER); |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1279 |
} |
1001568e7551
(svn r11400) -Fix [FS#1409]: assign orders during cloning after refitting as it needs the cargo types to be the same.
rubidium
parents:
7812
diff
changeset
|
1280 |
|
6546
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1281 |
/* Since we can't estimate the cost of cloning a vehicle accurately we must |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1282 |
* check whether the player has enough money manually. */ |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1283 |
if (!CheckPlayerHasMoney(total_cost)) { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1284 |
if (flags & DC_EXEC) { |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1285 |
/* The vehicle has already been bought, so now it must be sold again. */ |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1286 |
DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1287 |
} |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1288 |
return CMD_ERROR; |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1289 |
} |
4c6d90bde803
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
6526
diff
changeset
|
1290 |
|
2244 | 1291 |
return total_cost; |
1292 |
} |
|
1293 |
||
9348
dc680f675138
(svn r13245) -Codechange: Use SmallVectors for generating vehicle lists, simplifying calling code somewhat.
peter1138
parents:
9345
diff
changeset
|
1294 |
/** |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1295 |
* Send all vehicles of type to depots |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1296 |
* @param type type of vehicle |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1297 |
* @param flags the flags used for DoCommand() |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1298 |
* @param service should the vehicles only get service in the depots |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1299 |
* @param owner PlayerID of owner of the vehicles to send |
6484
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6453
diff
changeset
|
1300 |
* @param vlw_flag tells what kind of list requested the goto depot |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1301 |
* @return 0 for success and CMD_ERROR if no vehicle is able to go to depot |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
1302 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1303 |
CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id) |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1304 |
{ |
9353
9d76aef9fe2b
(svn r13250) -Codechange: Use VehicleList in SendAllVehiclesToDepot()
peter1138
parents:
9351
diff
changeset
|
1305 |
VehicleList list; |
9d76aef9fe2b
(svn r13250) -Codechange: Use VehicleList in SendAllVehiclesToDepot()
peter1138
parents:
9351
diff
changeset
|
1306 |
|
9d76aef9fe2b
(svn r13250) -Codechange: Use VehicleList in SendAllVehiclesToDepot()
peter1138
parents:
9351
diff
changeset
|
1307 |
GenerateVehicleSortList(&list, type, owner, id, vlw_flag); |
4465
262c344f6f3d
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
1308 |
|
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1309 |
/* Send all the vehicles to a depot */ |
9353
9d76aef9fe2b
(svn r13250) -Codechange: Use VehicleList in SendAllVehiclesToDepot()
peter1138
parents:
9351
diff
changeset
|
1310 |
for (uint i = 0; i < list.Length(); i++) { |
9d76aef9fe2b
(svn r13250) -Codechange: Use VehicleList in SendAllVehiclesToDepot()
peter1138
parents:
9351
diff
changeset
|
1311 |
const Vehicle *v = list[i]; |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1312 |
CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type)); |
4560
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
1313 |
|
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
1314 |
/* Return 0 if DC_EXEC is not set this is a valid goto depot command) |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
1315 |
* In this case we know that at least one vehicle can be sent to a depot |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
1316 |
* and we will issue the command. We can now safely quit the loop, knowing |
434cb4b568d4
(svn r6407) -Fix: Check return values of DoCommand() with CmdFailed and that of DoCommandP
Darkvater
parents:
4555
diff
changeset
|
1317 |
* it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
6946
a48b23f1cc8a
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
6943
diff
changeset
|
1318 |
if (CmdSucceeded(ret) && !(flags & DC_EXEC)) { |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1319 |
return CommandCost(); |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1320 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1321 |
} |
4465
262c344f6f3d
(svn r6249) -Fix: fixed assert when pressing goto depot in an empty list (forgot to disable the button in this condition)
bjarni
parents:
4463
diff
changeset
|
1322 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1323 |
return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR; |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1324 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
1325 |
|
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1326 |
/** |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1327 |
* Calculates how full a vehicle is. |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1328 |
* @param v The Vehicle to check. For trains, use the first engine. |
7014
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1329 |
* @param color The string to show depending on if we are unloading or loading |
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1330 |
* @return A percentage of how full the Vehicle is. |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1331 |
*/ |
9221
1cd04b558663
(svn r13087) -Codechange: Constify CalcPercentVehicleFilled() (michi_cc)
peter1138
parents:
9184
diff
changeset
|
1332 |
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *color) |
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1333 |
{ |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1334 |
int count = 0; |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1335 |
int max = 0; |
7014
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1336 |
int cars = 0; |
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1337 |
int unloading = 0; |
7087
0e076cedc6fd
(svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents:
7086
diff
changeset
|
1338 |
bool loading = false; |
7014
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1339 |
|
7087
0e076cedc6fd
(svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents:
7086
diff
changeset
|
1340 |
const Vehicle *u = v; |
8902
545851a52ad5
(svn r12669) -Fix (r12667): crash when a vehicle has never been to a station and the load percentage conditional variable is evaluated.
rubidium
parents:
8897
diff
changeset
|
1341 |
const Station *st = v->last_station_visited != INVALID_STATION ? GetStation(v->last_station_visited) : NULL; |
7087
0e076cedc6fd
(svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium
parents:
7086
diff
changeset
|
1342 |
|
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1343 |
/* Count up max and used */ |
7492
35acee076719
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium
parents:
7490
diff
changeset
|
1344 |
for (; v != NULL; v = v->Next()) { |
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1345 |
count += v->cargo.Count(); |
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1346 |
max += v->cargo_cap; |
8902
545851a52ad5
(svn r12669) -Fix (r12667): crash when a vehicle has never been to a station and the load percentage conditional variable is evaluated.
rubidium
parents:
8897
diff
changeset
|
1347 |
if (v->cargo_cap != 0 && color != NULL) { |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1348 |
unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; |
8855
6d841d5d4789
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium
parents:
8853
diff
changeset
|
1349 |
loading |= !(u->current_order.GetUnloadType() & OUFB_UNLOAD) && st->goods[v->cargo_type].days_since_pickup != 255; |
7014
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1350 |
cars++; |
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1351 |
} |
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1352 |
} |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1353 |
|
8897
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1354 |
if (color != NULL) { |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1355 |
if (unloading == 0 && loading) { |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1356 |
*color = STR_PERCENT_UP; |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1357 |
} else if (cars == unloading || !loading) { |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1358 |
*color = STR_PERCENT_DOWN; |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1359 |
} else { |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1360 |
*color = STR_PERCENT_UP_DOWN; |
d53dbad308cc
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium
parents:
8892
diff
changeset
|
1361 |
} |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1362 |
} |
7014
533521754123
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight
parents:
7010
diff
changeset
|
1363 |
|
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1364 |
/* Train without capacity */ |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1365 |
if (max == 0) return 100; |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1366 |
|
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1367 |
/* Return the percentage */ |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1368 |
return (count * 100) / max; |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1369 |
} |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
1370 |
|
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1371 |
void VehicleEnterDepot(Vehicle *v) |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1372 |
{ |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1373 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1374 |
case VEH_TRAIN: |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1375 |
InvalidateWindowClasses(WC_TRAINS_LIST); |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
1376 |
if (!IsFrontEngine(v)) v = v->First(); |
8300
dfd530665621
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents:
8270
diff
changeset
|
1377 |
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1378 |
v->load_unload_time_rem = 0; |
8938 | 1379 |
ClrBit(v->u.rail.flags, VRF_TOGGLE_REVERSE); |
9704
54123af5f9a5
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz
parents:
9652
diff
changeset
|
1380 |
TrainConsistChanged(v, true); |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1381 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1382 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1383 |
case VEH_ROAD: |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1384 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
1385 |
if (!IsRoadVehFront(v)) v = v->First(); |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1386 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1387 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1388 |
case VEH_SHIP: |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1389 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
5993
956d341d930e
(svn r8701) -Codechange: replace magic numbers with enums for u.rail.track.
rubidium
parents:
5991
diff
changeset
|
1390 |
v->u.ship.state = TRACK_BIT_DEPOT; |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1391 |
RecalcShipStuff(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1392 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1393 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1394 |
case VEH_AIRCRAFT: |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1395 |
InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1396 |
HandleAircraftEnterHangar(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1397 |
break; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1398 |
default: NOT_REACHED(); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1399 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1400 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1401 |
if (v->type != VEH_TRAIN) { |
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
1402 |
/* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters. |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
1403 |
* We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */ |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
1404 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4736
diff
changeset
|
1405 |
} |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1406 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1407 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1408 |
v->vehstatus |= VS_HIDDEN; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1409 |
v->cur_speed = 0; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1410 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1411 |
VehicleServiceInDepot(v); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1412 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1413 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1414 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
1415 |
if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1416 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1417 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1418 |
Order t = v->current_order; |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
1419 |
v->current_order.MakeDummy(); |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1420 |
|
8838
068d63397dc3
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium
parents:
8837
diff
changeset
|
1421 |
if (t.IsRefit()) { |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1422 |
_current_player = v->owner; |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1423 |
CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v)); |
4783
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1424 |
|
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1425 |
if (CmdFailed(cost)) { |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1426 |
v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1427 |
if (v->owner == _local_player) { |
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1428 |
/* Notify the user that we stopped the vehicle */ |
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5944
diff
changeset
|
1429 |
SetDParam(0, _vehicle_type_names[v->type]); |
4783
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1430 |
SetDParam(1, v->unitnumber); |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9224
diff
changeset
|
1431 |
AddNewsItem(STR_ORDER_REFIT_FAILED, NS_ADVICE, v->index, 0); |
4783
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1432 |
} |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1433 |
} else if (v->owner == _local_player && cost.GetCost() != 0) { |
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1434 |
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost()); |
4783
3d3cbea8b503
(svn r6697) -Fix: [order refit] if an order refit fails, the vehicle is now stopped and the player gets a message (like vehicle stopped in depot)
bjarni
parents:
4782
diff
changeset
|
1435 |
} |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1436 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1437 |
|
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8848
diff
changeset
|
1438 |
if (t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) { |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1439 |
/* Part of orders */ |
7070
2f4e1b2facc6
(svn r10335) -Fix (r10331): Increment the current order index *after* using it in UpdateVehicleTimetable.
maedhros
parents:
7038
diff
changeset
|
1440 |
UpdateVehicleTimetable(v, true); |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1441 |
v->cur_order_index++; |
8853
3266f0374302
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
8848
diff
changeset
|
1442 |
} else if (t.GetDepotActionType() & ODATFB_HALT) { |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1443 |
/* Force depot visit */ |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1444 |
v->vehstatus |= VS_STOPPED; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1445 |
if (v->owner == _local_player) { |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1446 |
StringID string; |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1447 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1448 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1449 |
case VEH_TRAIN: string = STR_8814_TRAIN_IS_WAITING_IN_DEPOT; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1450 |
case VEH_ROAD: string = STR_9016_ROAD_VEHICLE_IS_WAITING; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1451 |
case VEH_SHIP: string = STR_981C_SHIP_IS_WAITING_IN_DEPOT; break; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1452 |
case VEH_AIRCRAFT: string = STR_A014_AIRCRAFT_IS_WAITING_IN; break; |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1453 |
default: NOT_REACHED(); string = STR_EMPTY; // Set the string to something to avoid a compiler warning |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1454 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1455 |
|
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1456 |
SetDParam(0, v->unitnumber); |
9234
bfc9d27d3d0d
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents:
9224
diff
changeset
|
1457 |
AddNewsItem(string, NS_ADVICE, v->index, 0); |
4725
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1458 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1459 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1460 |
} |
40cccaaa042c
(svn r6637) -Codechange: merged all (vehicle type)EnterDepot into VehicleEnterDepot()
bjarni
parents:
4712
diff
changeset
|
1461 |
} |
2244 | 1462 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1463 |
static bool IsUniqueVehicleName(const char *name) |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1464 |
{ |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1465 |
const Vehicle *v; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1466 |
char buf[512]; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1467 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1468 |
FOR_ALL_VEHICLES(v) { |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1469 |
switch (v->type) { |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1470 |
case VEH_TRAIN: |
7108
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1471 |
if (!IsTrainEngine(v)) continue; |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1472 |
break; |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1473 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1474 |
case VEH_ROAD: |
7358
29ceb533895a
(svn r10721) -Fix [FS#1084]: Skip articulated parts of road vehicles during unique name check.
peter1138
parents:
7351
diff
changeset
|
1475 |
if (!IsRoadVehFront(v)) continue; |
7108
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1476 |
break; |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1477 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1478 |
case VEH_AIRCRAFT: |
7108
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1479 |
if (!IsNormalAircraft(v)) continue; |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1480 |
break; |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1481 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1482 |
case VEH_SHIP: |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1483 |
break; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1484 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1485 |
default: |
7108
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1486 |
continue; |
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1487 |
} |
7108
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1488 |
|
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1489 |
SetDParam(0, v->index); |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1490 |
GetString(buf, STR_VEHICLE_NAME, lastof(buf)); |
fef4440c4063
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7097
diff
changeset
|
1491 |
if (strcmp(buf, name) == 0) return false; |
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1492 |
} |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1493 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1494 |
return true; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1495 |
} |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1496 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1497 |
/** Give a custom name to your vehicle |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1498 |
* @param tile unused |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1499 |
* @param flags type of operation |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1500 |
* @param p1 vehicle ID to name |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1501 |
* @param p2 unused |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1502 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1503 |
CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1504 |
{ |
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1505 |
if (!IsValidVehicleID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1217
diff
changeset
|
1506 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1507 |
Vehicle *v = GetVehicle(p1); |
0 | 1508 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1765
diff
changeset
|
1509 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1510 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1511 |
if (!IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7096
diff
changeset
|
1512 |
|
0 | 1513 |
if (flags & DC_EXEC) { |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1514 |
free(v->name); |
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1515 |
v->name = strdup(_cmd_text); |
9297
1cb8d7bbdc8a
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents:
9280
diff
changeset
|
1516 |
InvalidateWindowClassesData(WC_TRAINS_LIST, 1); |
0 | 1517 |
MarkWholeScreenDirty(); |
1518 |
} |
|
1519 |
||
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1520 |
return CommandCost(); |
0 | 1521 |
} |
1522 |
||
1523 |
||
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1524 |
/** Change the service interval of a vehicle |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3490
diff
changeset
|
1525 |
* @param tile unused |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1526 |
* @param flags type of operation |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1527 |
* @param p1 vehicle ID that is being service-interval-changed |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1528 |
* @param p2 new service interval |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1529 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6905
diff
changeset
|
1530 |
CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1531 |
{ |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1532 |
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */ |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1533 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1534 |
if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR; |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1535 |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1536 |
Vehicle *v = GetVehicle(p1); |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1537 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1538 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1539 |
|
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1540 |
if (flags & DC_EXEC) { |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1541 |
v->service_interval = serv_int; |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1542 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1543 |
} |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1544 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1545 |
return CommandCost(); |
2819
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1546 |
} |
f25fb6ee397f
(svn r3367) Unify the 4 distinct CMD_CHANGE_{AIRCRAFT,ROADVEH,SHIP,TRAIN}_SERVICE_INT commands into one CMD_CHANGE_SERVICE_INT command.
tron
parents:
2817
diff
changeset
|
1547 |
|
0 | 1548 |
|
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1549 |
static Rect _old_vehicle_coords; ///< coords of vehicle before it has moved |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1550 |
|
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1551 |
/** |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1552 |
* Stores the vehicle image coords for later call to EndVehicleMove() |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1553 |
* @param v vehicle which image's coords to store |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1554 |
* @see _old_vehicle_coords |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1555 |
* @see EndVehicleMove() |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1556 |
*/ |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1557 |
void BeginVehicleMove(const Vehicle *v) |
7321
f91bdca345e8
(svn r10684) -Codechange: some more coding style related changes. Primarily moving { to a new line.
rubidium
parents:
7273
diff
changeset
|
1558 |
{ |
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1559 |
_old_vehicle_coords.left = v->left_coord; |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1560 |
_old_vehicle_coords.top = v->top_coord; |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1561 |
_old_vehicle_coords.right = v->right_coord; |
0 | 1562 |
_old_vehicle_coords.bottom = v->bottom_coord; |
1563 |
} |
|
1564 |
||
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1565 |
/** |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1566 |
* Marks screen dirty after a vehicle has moved |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1567 |
* @param v vehicle which is marked dirty |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1568 |
* @see _old_vehicle_coords |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1569 |
* @see BeginVehicleMove() |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1570 |
*/ |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1571 |
void EndVehicleMove(const Vehicle *v) |
0 | 1572 |
{ |
1573 |
MarkAllViewportsDirty( |
|
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1574 |
min(_old_vehicle_coords.left, v->left_coord), |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1575 |
min(_old_vehicle_coords.top, v->top_coord), |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1576 |
max(_old_vehicle_coords.right, v->right_coord) + 1, |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1577 |
max(_old_vehicle_coords.bottom, v->bottom_coord) + 1 |
0 | 1578 |
); |
1579 |
} |
|
1580 |
||
8317
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1581 |
/** |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1582 |
* Marks viewports dirty where the vehicle's image is |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1583 |
* In fact, it equals |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1584 |
* BeginVehicleMove(v); EndVehicleMove(v); |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1585 |
* @param v vehicle to mark dirty |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1586 |
* @see BeginVehicleMove() |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1587 |
* @see EndVehicleMove() |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1588 |
*/ |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1589 |
void MarkSingleVehicleDirty(const Vehicle *v) |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1590 |
{ |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1591 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1592 |
} |
539038de35cb
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz
parents:
8309
diff
changeset
|
1593 |
|
0 | 1594 |
/* returns true if staying in the same tile */ |
6153 | 1595 |
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v) |
0 | 1596 |
{ |
1597 |
static const int8 _delta_coord[16] = { |
|
1598 |
-1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
|
1599 |
-1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
|
1600 |
}; |
|
1601 |
||
1602 |
int x = v->x_pos + _delta_coord[v->direction]; |
|
1603 |
int y = v->y_pos + _delta_coord[v->direction + 8]; |
|
1604 |
||
6153 | 1605 |
GetNewVehiclePosResult gp; |
1606 |
gp.x = x; |
|
1607 |
gp.y = y; |
|
1608 |
gp.old_tile = v->tile; |
|
1609 |
gp.new_tile = TileVirtXY(x, y); |
|
1610 |
return gp; |
|
0 | 1611 |
} |
1612 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1613 |
static const Direction _new_direction_table[] = { |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1614 |
DIR_N , DIR_NW, DIR_W , |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1615 |
DIR_NE, DIR_SE, DIR_SW, |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3139
diff
changeset
|
1616 |
DIR_E , DIR_SE, DIR_S |
0 | 1617 |
}; |
1618 |
||
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1619 |
Direction GetDirectionTowards(const Vehicle *v, int x, int y) |
0 | 1620 |
{ |
1621 |
int i = 0; |
|
1622 |
||
1623 |
if (y >= v->y_pos) { |
|
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1624 |
if (y != v->y_pos) i += 3; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1625 |
i += 3; |
0 | 1626 |
} |
1627 |
||
1628 |
if (x >= v->x_pos) { |
|
1629 |
if (x != v->x_pos) i++; |
|
1630 |
i++; |
|
1631 |
} |
|
1632 |
||
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1633 |
Direction dir = v->direction; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1634 |
|
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1635 |
DirDiff dirdiff = DirDifference(_new_direction_table[i], dir); |
3158
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1636 |
if (dirdiff == DIRDIFF_SAME) return dir; |
696a6ca0bfa9
(svn r3784) Add a type and functions to handle direction changes
tron
parents:
3157
diff
changeset
|
1637 |
return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
0 | 1638 |
} |
1639 |
||
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1640 |
Trackdir GetVehicleTrackdir(const Vehicle *v) |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1641 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1642 |
if (v->vehstatus & VS_CRASHED) return INVALID_TRACKDIR; |
1758
2158a0938e45
(svn r2262) - Fix: Assertion when vehicle in a depot wants to do pathfinding.
matthijs
parents:
1757
diff
changeset
|
1643 |
|
2952 | 1644 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1645 |
case VEH_TRAIN: |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1646 |
if (v->u.rail.track == TRACK_BIT_DEPOT) // We'll assume the train is facing outwards |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1647 |
return DiagDirToDiagTrackdir(GetRailDepotDirection(v->tile)); // Train in depot |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1648 |
|
9624
957b141496ee
(svn r13680) -Fix: NPF crashing when a ship tried to find a nearby depot when on an aqueduct.
rubidium
parents:
9622
diff
changeset
|
1649 |
if (v->u.rail.track == TRACK_BIT_WORMHOLE) // train in tunnel or on bridge, so just use his direction and assume a diagonal track |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1650 |
return DiagDirToDiagTrackdir(DirToDiagDir(v->direction)); |
1765
155dfdbbbc8d
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1651 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1652 |
return TrackDirectionToTrackdir(FindFirstTrack(v->u.rail.track), v->direction); |
1959 | 1653 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1654 |
case VEH_SHIP: |
7490
bb27d92565d3
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7486
diff
changeset
|
1655 |
if (v->IsInDepot()) |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1656 |
// We'll assume the ship is facing outwards |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1657 |
return DiagDirToDiagTrackdir(GetShipDepotDirection(v->tile)); |
1765
155dfdbbbc8d
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1658 |
|
9624
957b141496ee
(svn r13680) -Fix: NPF crashing when a ship tried to find a nearby depot when on an aqueduct.
rubidium
parents:
9622
diff
changeset
|
1659 |
if (v->u.ship.state == TRACK_BIT_WORMHOLE) // ship on aqueduct, so just use his direction and assume a diagonal track |
957b141496ee
(svn r13680) -Fix: NPF crashing when a ship tried to find a nearby depot when on an aqueduct.
rubidium
parents:
9622
diff
changeset
|
1660 |
return DiagDirToDiagTrackdir(DirToDiagDir(v->direction)); |
957b141496ee
(svn r13680) -Fix: NPF crashing when a ship tried to find a nearby depot when on an aqueduct.
rubidium
parents:
9622
diff
changeset
|
1661 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1662 |
return TrackDirectionToTrackdir(FindFirstTrack(v->u.ship.state), v->direction); |
1959 | 1663 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1664 |
case VEH_ROAD: |
7490
bb27d92565d3
(svn r11001) -Codechange: unify the way to determine whether a vehicle is in a depot.
rubidium
parents:
7486
diff
changeset
|
1665 |
if (v->IsInDepot()) // We'll assume the road vehicle is facing outwards |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1666 |
return DiagDirToDiagTrackdir(GetRoadDepotDirection(v->tile)); |
1765
155dfdbbbc8d
(svn r2269) - CodeChange: no else after return; exchange some magic 0xffff with INVALID_VEHICLE, vehicle index is of type VehicleID
Darkvater
parents:
1758
diff
changeset
|
1667 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1668 |
if (IsStandardRoadStopTile(v->tile)) // We'll assume the road vehicle is facing outwards |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1669 |
return DiagDirToDiagTrackdir(GetRoadStopDir(v->tile)); // Road vehicle in a station |
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1670 |
|
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1671 |
if (IsDriveThroughStopTile(v->tile)) return DiagDirToDiagTrackdir(DirToDiagDir(v->direction)); |
6012
065d7234a7a9
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6009
diff
changeset
|
1672 |
|
4270
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
1673 |
/* If vehicle's state is a valid track direction (vehicle is not turning around) return it */ |
6009
bbe756070082
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6000
diff
changeset
|
1674 |
if (!IsReversingRoadTrackdir((Trackdir)v->u.road.state)) return (Trackdir)v->u.road.state; |
4270
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
1675 |
|
923ac6b88dad
(svn r5898) -Fix [FS#249]: Bugfix: Goto Depot not always working for road vehicles. (mart3p)
Darkvater
parents:
4263
diff
changeset
|
1676 |
/* Vehicle is turning around, get the direction from vehicle's direction */ |
9224
93528d9cb96d
(svn r13090) -Codechange: add functions for direct conversion from DiagDirection to Track and Trackbits
smatz
parents:
9221
diff
changeset
|
1677 |
return DiagDirToDiagTrackdir(DirToDiagDir(v->direction)); |
1959 | 1678 |
|
9008
de19c73e405f
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents:
9005
diff
changeset
|
1679 |
/* case VEH_AIRCRAFT: case VEH_EFFECT: case VEH_DISASTER: */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1680 |
default: return INVALID_TRACKDIR; |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1681 |
} |
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1735
diff
changeset
|
1682 |
} |
5991
ec2eebfe86de
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
5955
diff
changeset
|
1683 |
|
ec2eebfe86de
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
5955
diff
changeset
|
1684 |
/** |
ec2eebfe86de
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
5955
diff
changeset
|
1685 |
* Returns some meta-data over the to be entered tile. |
ec2eebfe86de
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
5955
diff
changeset
|
1686 |
* @see VehicleEnterTileStatus to see what the bits in the return value mean. |
ec2eebfe86de
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
5955
diff
changeset
|
1687 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1688 |
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
|
1689 |
{ |
3657 | 1690 |
return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
0 | 1691 |
} |
1692 |
||
6641
1b14f8887cb7
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium
parents:
6638
diff
changeset
|
1693 |
UnitID GetFreeUnitNumber(VehicleType type) |
0 | 1694 |
{ |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1695 |
UnitID max = 0; |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1696 |
const Vehicle *u; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1697 |
static bool *cache = NULL; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1698 |
static UnitID gmax = 0; |
0 | 1699 |
|
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1700 |
switch (type) { |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1701 |
case VEH_TRAIN: max = _settings_game.vehicle.max_trains; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1702 |
case VEH_ROAD: max = _settings_game.vehicle.max_roadveh; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1703 |
case VEH_SHIP: max = _settings_game.vehicle.max_ships; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1704 |
case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break; |
2996
9d77b3aec341
(svn r3573) - Replace assert(0) with NOT_REACHED(). This commit sponsored by "giving Darkvater credit for the last three".
peter1138
parents:
2995
diff
changeset
|
1705 |
default: NOT_REACHED(); |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1706 |
} |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1707 |
|
4096
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1708 |
if (max == 0) { |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1709 |
/* we can't build any of this kind of vehicle, so we just return 1 instead of looking for a free number |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1710 |
* a max of 0 will cause the following code to write to a NULL pointer |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1711 |
* We know that 1 is bigger than the max allowed vehicle number, so it's the same as returning something, that is too big |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1712 |
*/ |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1713 |
return 1; |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1714 |
} |
3ee959ce63c9
(svn r5428) -Fix: [vehicles] sovled crash when trying to build a vehicle type, that is set to max 0 (spotted by roboman)
bjarni
parents:
4077
diff
changeset
|
1715 |
|
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1716 |
if (max > gmax) { |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1717 |
gmax = max; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1718 |
free(cache); |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
1719 |
cache = MallocT<bool>(max + 1); |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1720 |
} |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1721 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1722 |
/* Clear the cache */ |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1723 |
memset(cache, 0, (max + 1) * sizeof(*cache)); |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1724 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1725 |
/* Fill the cache */ |
0 | 1726 |
FOR_ALL_VEHICLES(u) { |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1727 |
if (u->type == type && u->owner == _current_player && u->unitnumber != 0 && u->unitnumber <= max) |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1728 |
cache[u->unitnumber] = true; |
0 | 1729 |
} |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1730 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1731 |
/* Find the first unused unit number */ |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1732 |
UnitID unit = 1; |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
1733 |
for (; unit <= max; unit++) { |
2995
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1734 |
if (!cache[unit]) break; |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1735 |
} |
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1736 |
|
fcc4c71eccda
(svn r3572) - Rewrite GetFreeUnitNumber() so that only one loop of vehicles is required. Instead a list of used/unused numbers is created and the first unused number is chosen. This significantly improves performance in large games.
peter1138
parents:
2994
diff
changeset
|
1737 |
return unit; |
0 | 1738 |
} |
1739 |
||
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1740 |
|
7086
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1741 |
/** |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1742 |
* Check whether we can build infrastructure for the given |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1743 |
* vehicle type. This to disable building stations etc. when |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1744 |
* you are not allowed/able to have the vehicle type yet. |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1745 |
* @param type the vehicle type to check this for |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1746 |
* @return true if there is any reason why you may build |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1747 |
* the infrastructure for the given vehicle type |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1748 |
*/ |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1749 |
bool CanBuildVehicleInfrastructure(VehicleType type) |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1750 |
{ |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1751 |
assert(IsPlayerBuildableVehicleType(type)); |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1752 |
|
9652
0405e98d8e96
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents:
9625
diff
changeset
|
1753 |
if (!IsValidPlayerID(_current_player)) return false; |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1754 |
if (_settings_client.gui.always_build_infrastructure) return true; |
7086
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1755 |
|
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1756 |
UnitID max; |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1757 |
switch (type) { |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1758 |
case VEH_TRAIN: max = _settings_game.vehicle.max_trains; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1759 |
case VEH_ROAD: max = _settings_game.vehicle.max_roadveh; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1760 |
case VEH_SHIP: max = _settings_game.vehicle.max_ships; break; |
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1761 |
case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break; |
7086
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1762 |
default: NOT_REACHED(); |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1763 |
} |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1764 |
|
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1765 |
/* We can build vehicle infrastructure when we may build the vehicle type */ |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1766 |
if (max > 0) { |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1767 |
/* Can we actually build the vehicle type? */ |
9070
dd0121143eba
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
9065
diff
changeset
|
1768 |
const Engine *e; |
dd0121143eba
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
9065
diff
changeset
|
1769 |
FOR_ALL_ENGINES_OF_TYPE(e, type) { |
dd0121143eba
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
9065
diff
changeset
|
1770 |
if (HasBit(e->player_avail, _local_player)) return true; |
7086
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1771 |
} |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1772 |
return false; |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1773 |
} |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1774 |
|
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1775 |
/* We should be able to build infrastructure when we have the actual vehicle type */ |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1776 |
const Vehicle *v; |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1777 |
FOR_ALL_VEHICLES(v) { |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1778 |
if (v->owner == _local_player && v->type == type) return true; |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1779 |
} |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1780 |
|
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1781 |
return false; |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1782 |
} |
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1783 |
|
de7e83fb1602
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium
parents:
7076
diff
changeset
|
1784 |
|
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1785 |
const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) |
3040
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
1786 |
{ |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1787 |
const Player *p = GetPlayer(player); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1788 |
LiveryScheme scheme = LS_DEFAULT; |
5717
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1789 |
CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type; |
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1790 |
|
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1791 |
/* The default livery is always available for use, but its in_use flag determines |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1792 |
* whether any _other_ liveries are in use. */ |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
1793 |
if (p->livery[LS_DEFAULT].in_use && (_settings_client.gui.liveries == 2 || (_settings_client.gui.liveries == 1 && player == _local_player))) { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1794 |
/* Determine the livery scheme to use */ |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1795 |
switch (GetEngine(engine_type)->type) { |
6638
09c5d7bf69a5
(svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium
parents:
6626
diff
changeset
|
1796 |
default: NOT_REACHED(); |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1797 |
case VEH_TRAIN: { |
5763 | 1798 |
const RailVehicleInfo *rvi = RailVehInfo(engine_type); |
1799 |
||
8309
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1800 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1801 |
if (rvi->railveh_type == RAILVEH_WAGON) { |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1802 |
if (!GetCargo(cargo_type)->is_freight) { |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1803 |
if (parent_engine_type == INVALID_ENGINE) { |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1804 |
scheme = LS_PASSENGER_WAGON_STEAM; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1805 |
} else { |
8309
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1806 |
switch (RailVehInfo(parent_engine_type)->engclass) { |
6585
46035c6baa8d
(svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium
parents:
6581
diff
changeset
|
1807 |
default: NOT_REACHED(); |
8309
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1808 |
case EC_STEAM: scheme = LS_PASSENGER_WAGON_STEAM; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1809 |
case EC_DIESEL: scheme = LS_PASSENGER_WAGON_DIESEL; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1810 |
case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1811 |
case EC_MONORAIL: scheme = LS_PASSENGER_WAGON_MONORAIL; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1812 |
case EC_MAGLEV: scheme = LS_PASSENGER_WAGON_MAGLEV; break; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1813 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1814 |
} |
8309
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1815 |
} else { |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1816 |
scheme = LS_FREIGHT_WAGON; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1817 |
} |
8309
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1818 |
} else { |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1819 |
bool is_mu = HasBit(EngInfo(engine_type)->misc_flags, EF_RAIL_IS_MU); |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1820 |
|
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1821 |
switch (rvi->engclass) { |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1822 |
default: NOT_REACHED(); |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1823 |
case EC_STEAM: scheme = LS_STEAM; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1824 |
case EC_DIESEL: scheme = is_mu ? LS_DMU : LS_DIESEL; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1825 |
case EC_ELECTRIC: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1826 |
case EC_MONORAIL: scheme = LS_MONORAIL; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1827 |
case EC_MAGLEV: scheme = LS_MAGLEV; break; |
5d3e63cd70e0
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium
parents:
8302
diff
changeset
|
1828 |
} |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1829 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1830 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1831 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1832 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1833 |
case VEH_ROAD: { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1834 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1835 |
if (cargo_type == CT_INVALID) cargo_type = rvi->cargo_type; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1836 |
if (HasBit(EngInfo(engine_type)->misc_flags, EF_ROAD_TRAM)) { |
6724
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6721
diff
changeset
|
1837 |
/* Tram */ |
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6721
diff
changeset
|
1838 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; |
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6721
diff
changeset
|
1839 |
} else { |
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6721
diff
changeset
|
1840 |
/* Bus or truck */ |
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6721
diff
changeset
|
1841 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
4f404dfe9752
(svn r9956) -Codechange: Add tram livery schemes
peter1138
parents:
6721
diff
changeset
|
1842 |
} |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1843 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1844 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1845 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1846 |
case VEH_SHIP: { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1847 |
const ShipVehicleInfo *svi = ShipVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1848 |
if (cargo_type == CT_INVALID) cargo_type = svi->cargo_type; |
6330
989ca49d0da3
(svn r9302) -Codechange: Use cargo class to test for passengers when deciding on the livery scheme to use.
peter1138
parents:
6264
diff
changeset
|
1849 |
scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1850 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1851 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1852 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1853 |
case VEH_AIRCRAFT: { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1854 |
const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type); |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1855 |
if (cargo_type == CT_INVALID) cargo_type = CT_PASSENGERS; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1856 |
switch (avi->subtype) { |
5855
6f273e99a57a
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents:
5854
diff
changeset
|
1857 |
case AIR_HELI: scheme = LS_HELICOPTER; break; |
6f273e99a57a
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents:
5854
diff
changeset
|
1858 |
case AIR_CTOL: scheme = LS_SMALL_PLANE; break; |
6f273e99a57a
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater
parents:
5854
diff
changeset
|
1859 |
case AIR_CTOL | AIR_FAST: scheme = LS_LARGE_PLANE; break; |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1860 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1861 |
break; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1862 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1863 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1864 |
|
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1865 |
/* Switch back to the default scheme if the resolved scheme is not in use */ |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1866 |
if (!p->livery[scheme].in_use) scheme = LS_DEFAULT; |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1867 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1868 |
|
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1869 |
return &p->livery[scheme]; |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1870 |
} |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1871 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1872 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1873 |
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v) |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1874 |
{ |
7802
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1875 |
SpriteID map = (v != NULL) ? v->colormap : PAL_NONE; |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1876 |
|
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1877 |
/* Return cached value if any */ |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1878 |
if (map != PAL_NONE) return map; |
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1879 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1880 |
/* Check if we should use the colour map callback */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1881 |
if (HasBit(EngInfo(engine_type)->callbackmask, CBM_VEHICLE_COLOUR_REMAP)) { |
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1882 |
uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v); |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1883 |
/* A return value of 0xC000 is stated to "use the default two-color |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1884 |
* maps" which happens to be the failure action too... */ |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1885 |
if (callback != CALLBACK_FAILED && callback != 0xC000) { |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1886 |
map = GB(callback, 0, 14); |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1887 |
/* If bit 14 is set, then the company colours are applied to the |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1888 |
* map else it's returned as-is. */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1889 |
if (!HasBit(callback, 14)) { |
7802
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1890 |
/* Update cache */ |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1891 |
if (v != NULL) ((Vehicle*)v)->colormap = map; |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1892 |
return map; |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1893 |
} |
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1894 |
} |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1895 |
} |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1896 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
1897 |
bool twocc = HasBit(EngInfo(engine_type)->misc_flags, EF_USES_2CC); |
5717
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1898 |
|
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1899 |
if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOR_START; |
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1900 |
|
6516
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1901 |
const Livery *livery = GetEngineLivery(engine_type, player, parent_engine_type, v); |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1902 |
|
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1903 |
map += livery->colour1; |
0d14650b196b
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138
parents:
6509
diff
changeset
|
1904 |
if (twocc) map += livery->colour2 * 16; |
3113
d79500c648da
(svn r3717) - [2cc] Add 2cc colour maps and use for newgrf engines requiring them. Currently the second colour is fixed to be the player's colour.
peter1138
parents:
3105
diff
changeset
|
1905 |
|
7802
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1906 |
/* Update cache */ |
246a94599679
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
7765
diff
changeset
|
1907 |
if (v != NULL) ((Vehicle*)v)->colormap = map; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
1908 |
return map; |
3040
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
1909 |
} |
7043c0de7c6d
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
peter1138
parents:
3039
diff
changeset
|
1910 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
1911 |
SpriteID GetEnginePalette(EngineID engine_type, PlayerID player) |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1912 |
{ |
5717
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1913 |
return GetEngineColourMap(engine_type, player, INVALID_ENGINE, NULL); |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1914 |
} |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1915 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
1916 |
SpriteID GetVehiclePalette(const Vehicle *v) |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1917 |
{ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
1918 |
if (v->type == VEH_TRAIN) { |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1919 |
return GetEngineColourMap( |
6809
0f306c3e1030
(svn r10048) -Fix (r6455): Don't use override engine type for articulated wagon parts.
peter1138
parents:
6782
diff
changeset
|
1920 |
(v->u.rail.first_engine != INVALID_ENGINE && (UsesWagonOverride(v) || (IsArticulatedPart(v) && RailVehInfo(v->engine_type)->railveh_type != RAILVEH_WAGON))) ? |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1921 |
v->u.rail.first_engine : v->engine_type, |
5717
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1922 |
v->owner, v->u.rail.first_engine, v); |
4603
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1923 |
} |
20c816f664de
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4574
diff
changeset
|
1924 |
|
5717
b6fb89cd9cce
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138
parents:
5693
diff
changeset
|
1925 |
return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v); |
3105
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1926 |
} |
02f849f946d0
(svn r3701) [2cc] move vehicle/engine palette functions out of header file and document the remaining definitions
peter1138
parents:
3047
diff
changeset
|
1927 |
|
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1928 |
static uint8 _cargo_days; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1929 |
static uint16 _cargo_source; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1930 |
static uint32 _cargo_source_xy; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1931 |
static uint16 _cargo_count; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1932 |
static uint16 _cargo_paid_for; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1933 |
static Money _cargo_feeder_share; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1934 |
static uint32 _cargo_loaded_at_xy; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1935 |
|
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1936 |
/** |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1937 |
* Make it possible to make the saveload tables "friends" of other classes. |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1938 |
* @param vt the vehicle type. Can be VEH_END for the common vehicle description data |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1939 |
* @return the saveload description |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1940 |
*/ |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1941 |
const SaveLoad *GetVehicleDescription(VehicleType vt) |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1942 |
{ |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
1943 |
/** Save and load of vehicles */ |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
1944 |
static const SaveLoad _common_veh_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1945 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1946 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1947 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
8258
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1948 |
SLE_CONDVAR(Vehicle, name, SLE_NAME, 0, 83), |
9fa31acb07bc
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8254
diff
changeset
|
1949 |
SLE_CONDSTR(Vehicle, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1950 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1951 |
SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, 8, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1952 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1953 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1954 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1955 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1956 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1957 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1958 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1959 |
SLE_CONDVAR(Vehicle, x_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1960 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1961 |
SLE_CONDVAR(Vehicle, y_pos, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1962 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1963 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1964 |
|
6561
073e48516812
(svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents:
6558
diff
changeset
|
1965 |
SLE_CONDNULL(2, 0, 57), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1966 |
SLE_VAR(Vehicle, spritenum, SLE_UINT8), |
6561
073e48516812
(svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents:
6558
diff
changeset
|
1967 |
SLE_CONDNULL(5, 0, 57), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1968 |
SLE_VAR(Vehicle, engine_type, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1969 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1970 |
SLE_VAR(Vehicle, max_speed, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1971 |
SLE_VAR(Vehicle, cur_speed, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1972 |
SLE_VAR(Vehicle, subspeed, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1973 |
SLE_VAR(Vehicle, acceleration, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1974 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1975 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1976 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1977 |
SLE_CONDVAR(Vehicle, last_station_visited, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1978 |
SLE_CONDVAR(Vehicle, last_station_visited, SLE_UINT16, 5, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1979 |
|
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1980 |
SLE_VAR(Vehicle, cargo_type, SLE_UINT8), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1981 |
SLE_CONDVAR(Vehicle, cargo_subtype, SLE_UINT8, 35, SL_MAX_VERSION), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1982 |
SLEG_CONDVAR( _cargo_days, SLE_UINT8, 0, 67), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1983 |
SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, 0, 6), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1984 |
SLEG_CONDVAR( _cargo_source, SLE_UINT16, 7, 67), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1985 |
SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, 44, 67), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1986 |
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1987 |
SLEG_CONDVAR( _cargo_count, SLE_UINT16, 0, 67), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
1988 |
SLE_CONDLST(Vehicle, cargo, REF_CARGO_PACKET, 68, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1989 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1990 |
SLE_VAR(Vehicle, day_counter, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1991 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
8556
ce8d86cc14d2
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
smatz
parents:
8522
diff
changeset
|
1992 |
SLE_CONDVAR(Vehicle, running_ticks, SLE_UINT8, 88, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1993 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1994 |
SLE_VAR(Vehicle, cur_order_index, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
1995 |
SLE_VAR(Vehicle, num_orders, SLE_UINT8), |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1996 |
|
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1997 |
/* This next line is for version 4 and prior compatibility.. it temporarily reads |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1998 |
type and flags (which were both 4 bits) into type. Later on this is |
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
1999 |
converted correctly */ |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2000 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8, 0, 4), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2001 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2002 |
|
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2003 |
/* Orders for version 5 and on */ |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2004 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, type), SLE_UINT8, 5, SL_MAX_VERSION), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2005 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, flags), SLE_UINT8, 5, SL_MAX_VERSION), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2006 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2007 |
|
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2008 |
/* Refit in current order */ |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2009 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_cargo), SLE_UINT8, 36, SL_MAX_VERSION), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2010 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, refit_subtype), SLE_UINT8, 36, SL_MAX_VERSION), |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4695
diff
changeset
|
2011 |
|
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2012 |
/* Timetable in current order */ |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2013 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, wait_time), SLE_UINT16, 67, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2014 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, travel_time), SLE_UINT16, 67, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2015 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2016 |
SLE_REF(Vehicle, orders, REF_ORDER), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2017 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2018 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2019 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2020 |
SLE_CONDVAR(Vehicle, max_age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2021 |
SLE_CONDVAR(Vehicle, max_age, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2022 |
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2023 |
SLE_CONDVAR(Vehicle, date_of_last_service, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2024 |
SLE_CONDVAR(Vehicle, service_interval, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2025 |
SLE_CONDVAR(Vehicle, service_interval, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2026 |
SLE_VAR(Vehicle, reliability, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2027 |
SLE_VAR(Vehicle, reliability_spd_dec, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2028 |
SLE_VAR(Vehicle, breakdown_ctr, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2029 |
SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2030 |
SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2031 |
SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2032 |
SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2033 |
SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2034 |
|
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2035 |
SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2036 |
SLEG_CONDVAR( _cargo_paid_for, SLE_UINT16, 45, SL_MAX_VERSION), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2037 |
SLE_CONDVAR(Vehicle, vehicle_flags, SLE_UINT8, 40, SL_MAX_VERSION), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2038 |
|
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2039 |
SLE_CONDVAR(Vehicle, profit_this_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2040 |
SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, 65, SL_MAX_VERSION), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2041 |
SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2042 |
SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, 65, SL_MAX_VERSION), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2043 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64,51, 64), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2044 |
SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2045 |
SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, 51, 67), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2046 |
SLE_CONDVAR(Vehicle, value, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2047 |
SLE_CONDVAR(Vehicle, value, SLE_INT64, 65, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2048 |
|
8522
956a6b77e0ee
(svn r12097) -Fix (r654, r1525): loading old, pre savegame version 2, savegames.
glx
parents:
8463
diff
changeset
|
2049 |
SLE_CONDVAR(Vehicle, random_bits, SLE_UINT8, 2, SL_MAX_VERSION), |
956a6b77e0ee
(svn r12097) -Fix (r654, r1525): loading old, pre savegame version 2, savegames.
glx
parents:
8463
diff
changeset
|
2050 |
SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, 2, SL_MAX_VERSION), |
956a6b77e0ee
(svn r12097) -Fix (r654, r1525): loading old, pre savegame version 2, savegames.
glx
parents:
8463
diff
changeset
|
2051 |
|
956a6b77e0ee
(svn r12097) -Fix (r654, r1525): loading old, pre savegame version 2, savegames.
glx
parents:
8463
diff
changeset
|
2052 |
SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, 2, SL_MAX_VERSION), |
956a6b77e0ee
(svn r12097) -Fix (r654, r1525): loading old, pre savegame version 2, savegames.
glx
parents:
8463
diff
changeset
|
2053 |
SLE_CONDREF(Vehicle, prev_shared, REF_VEHICLE, 2, SL_MAX_VERSION), |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2054 |
|
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
2055 |
SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, 60, SL_MAX_VERSION), |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
2056 |
|
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2057 |
SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, 67, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2058 |
SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, 67, SL_MAX_VERSION), |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2059 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2060 |
/* reserve extra space in savegame here. (currently 10 bytes) */ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2061 |
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
|
2062 |
|
0 | 2063 |
SLE_END() |
2064 |
}; |
|
2065 |
||
2066 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2067 |
static const SaveLoad _train_desc[] = { |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2068 |
SLE_WRITEBYTE(Vehicle, type, VEH_TRAIN), |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2069 |
SLE_VEH_INCLUDEX(), |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2070 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, crash_anim_pos), SLE_UINT16), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2071 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, force_proceed), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2072 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, railtype), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2073 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, track), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2074 |
|
9808
a914bcdca6fb
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium
parents:
9775
diff
changeset
|
2075 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, flags), SLE_FILE_U8 | SLE_VAR_U16, 2, 99), |
a914bcdca6fb
(svn r13950) -Add [YAPP]: Trains can now also be in a 'stuck' state when waiting on a path reservation. (michi_cc)
rubidium
parents:
9775
diff
changeset
|
2076 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRail, flags), SLE_UINT16,100, SL_MAX_VERSION), |
6573 | 2077 |
SLE_CONDNULL(2, 2, 59), |
0 | 2078 |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2079 |
SLE_CONDNULL(2, 2, 19), |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2080 |
/* reserve extra space in savegame here. (currently 11 bytes) */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2081 |
SLE_CONDNULL(11, 2, SL_MAX_VERSION), |
0 | 2082 |
|
2083 |
SLE_END() |
|
2084 |
}; |
|
2085 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2086 |
static const SaveLoad _roadveh_desc[] = { |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2087 |
SLE_WRITEBYTE(Vehicle, type, VEH_ROAD), |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2088 |
SLE_VEH_INCLUDEX(), |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2089 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, state), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2090 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, frame), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2091 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, blocked_ctr), SLE_UINT16), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2092 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2093 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, overtaking_ctr), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2094 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, crashed_ctr), SLE_UINT16), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2095 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, reverse_ctr), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2096 |
|
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2097 |
SLE_CONDREFX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot), REF_ROADSTOPS, 6, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2098 |
SLE_CONDNULL(1, 6, SL_MAX_VERSION), |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2099 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleRoad, slot_age), SLE_UINT8, 6, SL_MAX_VERSION), |
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2100 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2101 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2102 |
|
2103 |
SLE_END() |
|
2104 |
}; |
|
2105 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2106 |
static const SaveLoad _ship_desc[] = { |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2107 |
SLE_WRITEBYTE(Vehicle, type, VEH_SHIP), |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2108 |
SLE_VEH_INCLUDEX(), |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2109 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleShip, state), SLE_UINT8), |
0 | 2110 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2111 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2112 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2113 |
|
2114 |
SLE_END() |
|
2115 |
}; |
|
2116 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2117 |
static const SaveLoad _aircraft_desc[] = { |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2118 |
SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT), |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2119 |
SLE_VEH_INCLUDEX(), |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2120 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, crashed_counter), SLE_UINT16), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2121 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, pos), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2122 |
|
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2123 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2124 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, targetairport), SLE_UINT16, 5, SL_MAX_VERSION), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2125 |
|
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2126 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, state), SLE_UINT8), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2127 |
|
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2128 |
SLE_CONDVARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleAir, previous_pos), SLE_UINT8, 2, SL_MAX_VERSION), |
0 | 2129 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2130 |
/* reserve extra space in savegame here. (currently 15 bytes) */ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2131 |
SLE_CONDNULL(15, 2, SL_MAX_VERSION), |
0 | 2132 |
|
2133 |
SLE_END() |
|
2134 |
}; |
|
2135 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2136 |
static const SaveLoad _special_desc[] = { |
9008
de19c73e405f
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents:
9005
diff
changeset
|
2137 |
SLE_WRITEBYTE(Vehicle, type, VEH_EFFECT), |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2138 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2139 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2140 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2141 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2142 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2143 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2144 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2145 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2146 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2147 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2148 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2149 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2150 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
6561
073e48516812
(svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents:
6558
diff
changeset
|
2151 |
SLE_CONDNULL(5, 0, 57), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2152 |
SLE_VAR(Vehicle, progress, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2153 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2154 |
|
9008
de19c73e405f
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents:
9005
diff
changeset
|
2155 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleEffect, animation_state), SLE_UINT16), |
de19c73e405f
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents:
9005
diff
changeset
|
2156 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleEffect, animation_substate), SLE_UINT8), |
0 | 2157 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2158 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3185
diff
changeset
|
2159 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2160 |
|
2161 |
SLE_END() |
|
2162 |
}; |
|
2163 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2164 |
static const SaveLoad _disaster_desc[] = { |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2165 |
SLE_WRITEBYTE(Vehicle, type, VEH_DISASTER), |
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2166 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2167 |
SLE_REF(Vehicle, next, REF_VEHICLE_OLD), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2168 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2169 |
SLE_VAR(Vehicle, subtype, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2170 |
SLE_CONDVAR(Vehicle, tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2171 |
SLE_CONDVAR(Vehicle, tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2172 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2173 |
SLE_CONDVAR(Vehicle, dest_tile, SLE_UINT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2174 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2175 |
SLE_CONDVAR(Vehicle, x_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2176 |
SLE_CONDVAR(Vehicle, x_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2177 |
SLE_CONDVAR(Vehicle, y_pos, SLE_FILE_I16 | SLE_VAR_I32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2178 |
SLE_CONDVAR(Vehicle, y_pos, SLE_INT32, 6, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2179 |
SLE_VAR(Vehicle, z_pos, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2180 |
SLE_VAR(Vehicle, direction, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2181 |
|
6561
073e48516812
(svn r9763) -Codechange/Fix (r9760): don't read the variables that are calculated automatically either.
rubidium
parents:
6558
diff
changeset
|
2182 |
SLE_CONDNULL(5, 0, 57), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2183 |
SLE_VAR(Vehicle, owner, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2184 |
SLE_VAR(Vehicle, vehstatus, SLE_UINT8), |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2185 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_FILE_U8 | SLE_VAR_U16, 0, 4), |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2186 |
SLE_CONDVARX(cpp_offsetof(Vehicle, current_order) + cpp_offsetof(Order, dest), SLE_UINT16, 5, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2187 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2188 |
SLE_VAR(Vehicle, cur_image, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2189 |
SLE_CONDVAR(Vehicle, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2190 |
SLE_CONDVAR(Vehicle, age, SLE_INT32, 31, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2191 |
SLE_VAR(Vehicle, tick_counter, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2192 |
|
7334
ed9a43cf642a
(svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents:
7333
diff
changeset
|
2193 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, image_override), SLE_UINT16), |
ed9a43cf642a
(svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents:
7333
diff
changeset
|
2194 |
SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleDisaster, big_ufo_destroyer_target), SLE_UINT16), |
0 | 2195 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2196 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
2197 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 2198 |
|
2199 |
SLE_END() |
|
2200 |
}; |
|
2201 |
||
2202 |
||
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2203 |
static const SaveLoad *_veh_descs[] = { |
0 | 2204 |
_train_desc, |
2205 |
_roadveh_desc, |
|
2206 |
_ship_desc, |
|
2207 |
_aircraft_desc, |
|
2208 |
_special_desc, |
|
2209 |
_disaster_desc, |
|
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2210 |
_common_veh_desc, |
0 | 2211 |
}; |
2212 |
||
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2213 |
return _veh_descs[vt]; |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2214 |
} |
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2215 |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2216 |
/** Will be called when the vehicles need to be saved. */ |
6247 | 2217 |
static void Save_VEHS() |
0 | 2218 |
{ |
2219 |
Vehicle *v; |
|
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2220 |
/* Write the vehicles */ |
0 | 2221 |
FOR_ALL_VEHICLES(v) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2222 |
SlSetArrayIndex(v->index); |
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2223 |
SlObject(v, GetVehicleDescription(v->type)); |
0 | 2224 |
} |
2225 |
} |
|
2226 |
||
6423
8e10e79e0fd1
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas
parents:
6350
diff
changeset
|
2227 |
/** Will be called when vehicles need to be loaded. */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
2228 |
void Load_VEHS() |
0 | 2229 |
{ |
2230 |
int index; |
|
2231 |
Vehicle *v; |
|
2232 |
||
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2233 |
_cargo_count = 0; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2234 |
|
0 | 2235 |
while ((index = SlIterateArray()) != -1) { |
1279
bc761aad52b3
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1266
diff
changeset
|
2236 |
Vehicle *v; |
6817
ca1cc2fd4cfa
(svn r10056) -Revert (r10049): removing SLE_WRITEBYTE didn't work as expected :(. Somehow SlIterateArray and SlObject depend on eachother and adding a some arbitrary data before the SlObject makes it go crazy.
rubidium
parents:
6810
diff
changeset
|
2237 |
VehicleType vtype = (VehicleType)SlReadByte(); |
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2238 |
|
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2239 |
switch (vtype) { |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2240 |
case VEH_TRAIN: v = new (index) Train(); break; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2241 |
case VEH_ROAD: v = new (index) RoadVehicle(); break; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2242 |
case VEH_SHIP: v = new (index) Ship(); break; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2243 |
case VEH_AIRCRAFT: v = new (index) Aircraft(); break; |
9008
de19c73e405f
(svn r12803) -Cleanup: rename SpecialVehicle to EffectVehicle to have a uniform naming of the thing instead of using both names for the same thing.
rubidium
parents:
9005
diff
changeset
|
2244 |
case VEH_EFFECT: v = new (index) EffectVehicle(); break; |
7398
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2245 |
case VEH_DISASTER: v = new (index) DisasterVehicle(); break; |
b933416cf32b
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium
parents:
7387
diff
changeset
|
2246 |
case VEH_INVALID: v = new (index) InvalidVehicle(); break; |
6621
441559124aea
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium
parents:
6616
diff
changeset
|
2247 |
default: NOT_REACHED(); |
6552
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2248 |
} |
d87268e08799
(svn r9754) -Codechange: make classes for all vehicle types, so we can make nicer/better maintainable code, i.e. virtual methods instead of switches.
rubidium
parents:
6550
diff
changeset
|
2249 |
|
7493
07944c9e005f
(svn r11004) -Codechange: some reworks of the saveload mechanism to be able to save and load private and protected variables in the vehicle struct.
rubidium
parents:
7492
diff
changeset
|
2250 |
SlObject(v, GetVehicleDescription(vtype)); |
7010
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2251 |
|
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2252 |
if (_cargo_count != 0 && IsPlayerBuildableVehicleType(v)) { |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2253 |
/* Don't construct the packet with station here, because that'll fail with old savegames */ |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2254 |
CargoPacket *cp = new CargoPacket(); |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2255 |
cp->source = _cargo_source; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2256 |
cp->source_xy = _cargo_source_xy; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2257 |
cp->count = _cargo_count; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2258 |
cp->days_in_transit = _cargo_days; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2259 |
cp->feeder_share = _cargo_feeder_share; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2260 |
cp->loaded_at_xy = _cargo_loaded_at_xy; |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2261 |
v->cargo.Append(cp); |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2262 |
} |
6f0d9f03180d
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents:
6998
diff
changeset
|
2263 |
|
2549 | 2264 |
/* Old savegames used 'last_station_visited = 0xFF' */ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2265 |
if (CheckSavegameVersion(5) && v->last_station_visited == 0xFF) |
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2467
diff
changeset
|
2266 |
v->last_station_visited = INVALID_STATION; |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2267 |
|
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2268 |
if (CheckSavegameVersion(5)) { |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2269 |
/* Convert the current_order.type (which is a mix of type and flags, because |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2270 |
* in those versions, they both were 4 bits big) to type and flags */ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
2271 |
v->current_order.flags = GB(v->current_order.type, 4, 4); |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8862
diff
changeset
|
2272 |
v->current_order.type &= 0x0F; |
956
dda0863632df
(svn r1448) -Fix: The current_order of a vehicle is now correctly saved (caused
truelight
parents:
941
diff
changeset
|
2273 |
} |
6643
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
2274 |
|
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
2275 |
/* Advanced vehicle lists got added */ |
f81bee57bc09
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents:
6641
diff
changeset
|
2276 |
if (CheckSavegameVersion(60)) v->group_id = DEFAULT_GROUP; |
0 | 2277 |
} |
2278 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2279 |
/* Check for shared order-lists (we now use pointers for that) */ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2681
diff
changeset
|
2280 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2281 |
FOR_ALL_VEHICLES(v) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2282 |
Vehicle *u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2283 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2284 |
FOR_ALL_VEHICLES_FROM(u, v->index + 1) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2285 |
/* If a vehicle has the same orders, add the link to eachother |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4544
diff
changeset
|
2286 |
* in both vehicles */ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2287 |
if (v->orders == u->orders) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2288 |
v->next_shared = u; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2289 |
u->prev_shared = v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2290 |
break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2291 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2292 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2293 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
956
diff
changeset
|
2294 |
} |
0 | 2295 |
} |
2296 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
2297 |
extern const ChunkHandler _veh_chunk_handlers[] = { |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1541
diff
changeset
|
2298 |
{ 'VEHS', Save_VEHS, Load_VEHS, CH_SPARSE_ARRAY | CH_LAST}, |
0 | 2299 |
}; |
5651
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2300 |
|
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2301 |
void Vehicle::BeginLoading() |
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2302 |
{ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6248
diff
changeset
|
2303 |
assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); |
6550
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2304 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
2305 |
if (this->current_order.IsType(OT_GOTO_STATION) && |
8840
332412c2e9c1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents:
8838
diff
changeset
|
2306 |
this->current_order.GetDestination() == this->last_station_visited) { |
8881
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8862
diff
changeset
|
2307 |
current_order.MakeLoading(true); |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8862
diff
changeset
|
2308 |
UpdateVehicleTimetable(this, true); |
ad608e8305ad
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium
parents:
8862
diff
changeset
|
2309 |
|
6550
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2310 |
/* Furthermore add the Non Stop flag to mark that this station |
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2311 |
* is the actual destination of the vehicle, which is (for example) |
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2312 |
* necessary to be known for HandleTrainLoading to determine |
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2313 |
* whether the train is lost or not; not marking a train lost |
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2314 |
* that arrives at random stations is bad. */ |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
2315 |
this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION); |
8843
45fdf630deaa
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents:
8840
diff
changeset
|
2316 |
|
6550
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2317 |
} else { |
8843
45fdf630deaa
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents:
8840
diff
changeset
|
2318 |
current_order.MakeLoading(false); |
6550
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2319 |
} |
8bdb954bba16
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium
parents:
6546
diff
changeset
|
2320 |
|
6500
f12678890222
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents:
6492
diff
changeset
|
2321 |
GetStation(this->last_station_visited)->loading_vehicles.push_back(this); |
6553
976a684212ad
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium
parents:
6552
diff
changeset
|
2322 |
|
6565
96ef0ede4b83
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents:
6562
diff
changeset
|
2323 |
VehiclePayment(this); |
96ef0ede4b83
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents:
6562
diff
changeset
|
2324 |
|
9043
eb4f06b99146
(svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz
parents:
9041
diff
changeset
|
2325 |
InvalidateWindow(GetWindowClassForVehicleType(this->type), this->owner); |
8350
8979cccdbed2
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents:
8317
diff
changeset
|
2326 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
6565
96ef0ede4b83
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents:
6562
diff
changeset
|
2327 |
InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
96ef0ede4b83
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents:
6562
diff
changeset
|
2328 |
InvalidateWindow(WC_STATION_VIEW, this->last_station_visited); |
96ef0ede4b83
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents:
6562
diff
changeset
|
2329 |
|
6823
1f2075619543
(svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents:
6817
diff
changeset
|
2330 |
GetStation(this->last_station_visited)->MarkTilesDirty(true); |
6565
96ef0ede4b83
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium
parents:
6562
diff
changeset
|
2331 |
this->MarkDirty(); |
5651
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2332 |
} |
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2333 |
|
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2334 |
void Vehicle::LeaveStation() |
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2335 |
{ |
8837
72125f871eb4
(svn r12585) -Fix (r12584): assumption that assertions were enabled during compilation/testing was flawed.
rubidium
parents:
8836
diff
changeset
|
2336 |
assert(current_order.IsType(OT_LOADING)); |
7076
0416a03dff7c
(svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents:
7070
diff
changeset
|
2337 |
|
0416a03dff7c
(svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents:
7070
diff
changeset
|
2338 |
/* Only update the timetable if the vehicle was supposed to stop here. */ |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
2339 |
if (current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false); |
7076
0416a03dff7c
(svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros
parents:
7070
diff
changeset
|
2340 |
|
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
2341 |
current_order.MakeLeaveStation(); |
9041
2e64f7dc7a48
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138
parents:
9009
diff
changeset
|
2342 |
Station *st = GetStation(this->last_station_visited); |
2e64f7dc7a48
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138
parents:
9009
diff
changeset
|
2343 |
st->loading_vehicles.remove(this); |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2344 |
|
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
2345 |
HideFillingPercent(this->fill_percent_te_id); |
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6980
diff
changeset
|
2346 |
this->fill_percent_te_id = INVALID_TE_ID; |
9041
2e64f7dc7a48
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138
parents:
9009
diff
changeset
|
2347 |
|
2e64f7dc7a48
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138
parents:
9009
diff
changeset
|
2348 |
/* Trigger station animation for trains only */ |
2e64f7dc7a48
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138
parents:
9009
diff
changeset
|
2349 |
if (this->type == VEH_TRAIN && IsTileType(this->tile, MP_STATION)) StationAnimationTrigger(st, this->tile, STAT_ANIM_TRAIN_DEPARTS); |
5651
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5609
diff
changeset
|
2350 |
} |
6558
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6553
diff
changeset
|
2351 |
|
c88e142f896e
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium
parents:
6553
diff
changeset
|
2352 |
|
6594
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2353 |
void Vehicle::HandleLoading(bool mode) |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2354 |
{ |
8836
f6f1ea3d7e93
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
8793
diff
changeset
|
2355 |
switch (this->current_order.GetType()) { |
6594
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2356 |
case OT_LOADING: { |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2357 |
uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0); |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6955
diff
changeset
|
2358 |
|
6616
0b3835bdd796
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium
parents:
6611
diff
changeset
|
2359 |
/* Not the first call for this tick, or still loading */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7923
diff
changeset
|
2360 |
if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9396
diff
changeset
|
2361 |
(_settings_game.order.timetabling && this->current_order_time < wait_time)) return; |
6594
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2362 |
|
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2363 |
this->PlayLeaveStationSound(); |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2364 |
|
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
2365 |
bool at_destination_station = this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE; |
6594
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2366 |
this->LeaveStation(); |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2367 |
|
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2368 |
/* If this was not the final order, don't remove it from the list. */ |
8848
635cb164edd4
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
8847
diff
changeset
|
2369 |
if (!at_destination_station) return; |
6594
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2370 |
break; |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2371 |
} |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2372 |
|
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2373 |
case OT_DUMMY: break; |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2374 |
|
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2375 |
default: return; |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2376 |
} |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2377 |
|
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2378 |
this->cur_order_index++; |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2379 |
InvalidateVehicleOrder(this); |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2380 |
} |
9673331eb174
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium
parents:
6585
diff
changeset
|
2381 |
|
8891
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2382 |
CommandCost Vehicle::SendToDepot(uint32 flags, DepotCommand command) |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2383 |
{ |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2384 |
if (!CheckOwnership(this->owner)) return CMD_ERROR; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2385 |
if (this->vehstatus & VS_CRASHED) return CMD_ERROR; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2386 |
if (this->IsInDepot()) return CMD_ERROR; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2387 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2388 |
if (this->current_order.IsType(OT_GOTO_DEPOT)) { |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2389 |
bool halt_in_depot = this->current_order.GetDepotActionType() & ODATFB_HALT; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2390 |
if (!!(command & DEPOT_SERVICE) == halt_in_depot) { |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2391 |
/* We called with a different DEPOT_SERVICE setting. |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2392 |
* Now we change the setting to apply the new one and let the vehicle head for the same depot. |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2393 |
* Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2394 |
if (flags & DC_EXEC) { |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2395 |
this->current_order.SetDepotOrderType(ODTF_MANUAL); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2396 |
this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2397 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2398 |
} |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2399 |
return CommandCost(); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2400 |
} |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2401 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2402 |
if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2403 |
if (flags & DC_EXEC) { |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2404 |
/* If the orders to 'goto depot' are in the orders list (forced servicing), |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2405 |
* then skip to the next order; effectively cancelling this forced service */ |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2406 |
if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->cur_order_index++; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2407 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2408 |
this->current_order.MakeDummy(); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2409 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2410 |
} |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2411 |
return CommandCost(); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2412 |
} |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2413 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2414 |
/* check if at a standstill (not stopped only) in a depot |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2415 |
* the check is down here to make it possible to alter stop/service for trains entering the depot */ |
8961
fb0848956387
(svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz
parents:
8954
diff
changeset
|
2416 |
if (this->type == VEH_TRAIN && IsRailDepotTile(this->tile) && this->cur_speed == 0) return CMD_ERROR; |
8891
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2417 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2418 |
TileIndex location; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2419 |
DestinationID destination; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2420 |
bool reverse; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2421 |
static const StringID no_depot[] = {STR_883A_UNABLE_TO_FIND_ROUTE_TO, STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT, STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT, STR_A012_CAN_T_SEND_AIRCRAFT_TO}; |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
2422 |
if (!this->FindClosestDepot(&location, &destination, &reverse)) return_cmd_error(no_depot[this->type]); |
8891
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2423 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2424 |
if (flags & DC_EXEC) { |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2425 |
if (this->current_order.IsType(OT_LOADING)) this->LeaveStation(); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2426 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2427 |
this->dest_tile = location; |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2428 |
this->current_order.MakeGoToDepot(destination, ODTF_MANUAL); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2429 |
if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2430 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2431 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2432 |
/* If there is no depot in front, reverse automatically (trains only) */ |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2433 |
if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2434 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2435 |
if (this->type == VEH_AIRCRAFT && this->u.air.state == FLYING && this->u.air.targetairport != destination) { |
8892
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
2436 |
/* The aircraft is now heading for a different hangar than the next in the orders */ |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
2437 |
extern void AircraftNextAirportPos_and_Order(Vehicle *v); |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
2438 |
AircraftNextAirportPos_and_Order(this); |
8401e1338665
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium
parents:
8891
diff
changeset
|
2439 |
} |
8891
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2440 |
} |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2441 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2442 |
return CommandCost(); |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2443 |
|
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2444 |
} |
1058c3b69b7f
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium
parents:
8881
diff
changeset
|
2445 |
|
7497
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2446 |
void Vehicle::SetNext(Vehicle *next) |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2447 |
{ |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2448 |
if (this->next != NULL) { |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2449 |
/* We had an old next vehicle. Update the first and previous pointers */ |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2450 |
for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2451 |
v->first = this->next; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2452 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2453 |
this->next->previous = NULL; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2454 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2455 |
|
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2456 |
this->next = next; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2457 |
|
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2458 |
if (this->next != NULL) { |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2459 |
/* A new next vehicle. Update the first and previous pointers */ |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2460 |
if (this->next->previous != NULL) this->next->previous->next = NULL; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2461 |
this->next->previous = this; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2462 |
for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2463 |
v->first = this->first; |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2464 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2465 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2466 |
} |
40e457c0a8ac
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium
parents:
7493
diff
changeset
|
2467 |
|
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2468 |
/** Backs up a chain of vehicles |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2469 |
* @param v The vehicle to back up |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2470 |
*/ |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2471 |
void BackuppedVehicle::BackupVehicle(Vehicle *v) |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2472 |
{ |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2473 |
int length = CountVehiclesInChain(v); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2474 |
|
9146
dbe2317185eb
(svn r13008) -Fix [FS#1997]: silence some MSVC x64 warnings
glx
parents:
9128
diff
changeset
|
2475 |
size_t cargo_packages_count = 1; |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2476 |
for (const Vehicle *v_count = v; v_count != NULL; v_count=v_count->Next()) { |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2477 |
/* Now we count how many cargo packets we need to store. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2478 |
* We started with an offset by one because we also need an end of array marker. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2479 |
cargo_packages_count += v_count->cargo.packets.size(); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2480 |
} |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2481 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2482 |
vehicles = MallocT<Vehicle>(length); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2483 |
cargo_packets = MallocT<CargoPacket>(cargo_packages_count); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2484 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2485 |
/* Now we make some pointers to iterate over the arrays. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2486 |
Vehicle *copy = vehicles; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2487 |
CargoPacket *cargo = cargo_packets; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2488 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2489 |
Vehicle *original = v; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2490 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2491 |
for (; 0 < length; original = original->Next(), copy++, length--) { |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2492 |
/* First we need to copy the vehicle itself. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2493 |
* However there is an issue as the cargo list isn't copied. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2494 |
* To avoid restoring invalid pointers we start by swapping the cargo list with an empty one. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2495 |
CargoList::List empty_packets; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2496 |
original->cargo.packets.swap(empty_packets); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2497 |
memcpy(copy, original, sizeof(Vehicle)); |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2498 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2499 |
/* No need to do anything else if the cargo list is empty. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2500 |
* It really doesn't matter if we swap an empty list with an empty list. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2501 |
if (original->cargo.Empty()) continue; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2502 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2503 |
/* And now we swap the cargo lists back. The vehicle now has it's cargo again. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2504 |
original->cargo.packets.swap(empty_packets); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2505 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2506 |
/* The vehicle contains some cargo so we will back up the cargo as well. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2507 |
* We only need to store the packets and not which vehicle they came from. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2508 |
* We will still be able to put them together with the right vehicle when restoring. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2509 |
const CargoList::List *packets = original->cargo.Packets(); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2510 |
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2511 |
memcpy(cargo, (*it), sizeof(CargoPacket)); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2512 |
cargo++; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2513 |
} |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2514 |
} |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2515 |
/* We should end with a 0 packet so restoring can detect the end of the array. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2516 |
memset(cargo, 0, sizeof(CargoPacket)); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2517 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2518 |
|
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2519 |
/** Restore a backed up row of vehicles |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2520 |
* @param *v The array of vehicles to restore |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2521 |
* @param *p The owner of the vehicle |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2522 |
*/ |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2523 |
Vehicle* BackuppedVehicle::RestoreBackupVehicle(Vehicle *v, Player *p) |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2524 |
{ |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2525 |
Vehicle *backup = v; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2526 |
CargoPacket *cargo = cargo_packets; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2527 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2528 |
assert(v->owner == p->index); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2529 |
|
9128
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2530 |
/* Cache the result of the vehicle type check since it will not change |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2531 |
* and we need this check once for every run though the loop. */ |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2532 |
bool is_road_veh = v->type == VEH_ROAD; |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2533 |
|
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2534 |
while (true) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2535 |
Vehicle *dest = GetVehicle(backup->index); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2536 |
/* The vehicle should be free since we are restoring something we just sold. */ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2537 |
assert(!dest->IsValid()); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2538 |
memcpy(dest, backup, sizeof(Vehicle)); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2539 |
|
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2540 |
/* We decreased the engine count when we sold the engines so we will increase it again. */ |
9259
6007531b4ae5
(svn r13125) -Fix [FS#2000](r12913): [autoreplace] failing replacement and restoring a vehicle will no longer decrease the vehicle count in groups
bjarni
parents:
9234
diff
changeset
|
2541 |
if (IsEngineCountable(backup)) { |
6007531b4ae5
(svn r13125) -Fix [FS#2000](r12913): [autoreplace] failing replacement and restoring a vehicle will no longer decrease the vehicle count in groups
bjarni
parents:
9234
diff
changeset
|
2542 |
p->num_engines[backup->engine_type]++; |
6007531b4ae5
(svn r13125) -Fix [FS#2000](r12913): [autoreplace] failing replacement and restoring a vehicle will no longer decrease the vehicle count in groups
bjarni
parents:
9234
diff
changeset
|
2543 |
if (IsValidGroupID(backup->group_id)) GetGroup(backup->group_id)->num_engines[backup->engine_type]++; |
6007531b4ae5
(svn r13125) -Fix [FS#2000](r12913): [autoreplace] failing replacement and restoring a vehicle will no longer decrease the vehicle count in groups
bjarni
parents:
9234
diff
changeset
|
2544 |
if (backup->IsPrimaryVehicle()) IncreaseGroupNumVehicle(backup->group_id); |
6007531b4ae5
(svn r13125) -Fix [FS#2000](r12913): [autoreplace] failing replacement and restoring a vehicle will no longer decrease the vehicle count in groups
bjarni
parents:
9234
diff
changeset
|
2545 |
} |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2546 |
|
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2547 |
/* Update hash. */ |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2548 |
Vehicle *dummy = dest; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2549 |
dest->old_new_hash = &dummy; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2550 |
dest->left_coord = INVALID_COORD; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2551 |
UpdateVehiclePosHash(dest, INVALID_COORD, 0); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2552 |
|
9128
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2553 |
if (is_road_veh) { |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2554 |
/* Removed the slot in the road vehicles as the slot is gone. |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2555 |
* We don't want a pointer to a slot that's gone. */ |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2556 |
dest->u.road.slot = NULL; |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2557 |
} |
f4b41e7c282e
(svn r12988) -Fix [FS#1992](r12913): [autoreplace] failing to replace a road vehicle could free it's slot without the vehicle knowing it (leading to assert)
bjarni
parents:
9111
diff
changeset
|
2558 |
|
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2559 |
if (!dest->cargo.Empty()) { |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2560 |
/* The vehicle in question contains some cargo. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2561 |
* However we lost the list so we will have to recreate it. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2562 |
* We know that the packets are stored in the same order as the vehicles so |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2563 |
* the one cargo_packets points to and maybe some following ones belongs to |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2564 |
* the current vehicle. |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2565 |
* Now all we have to do is to add the packets to a list and keep track of how |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2566 |
* much cargo we restore and once we reached the cached cargo hold we recovered |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2567 |
* everything for this vehicle. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2568 |
uint cargo_count = 0; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2569 |
for(; cargo_count < dest->cargo.Count(); cargo++) { |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2570 |
dest->cargo.packets.push_back(GetCargoPacket(cargo->index)); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2571 |
cargo_count += cargo->count; |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2572 |
} |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2573 |
/* This design should always end up with the right amount of cargo. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2574 |
assert(cargo_count == dest->cargo.Count()); |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2575 |
} |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2576 |
|
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2577 |
if (backup->Next() == NULL) break; |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2578 |
backup++; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2579 |
} |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2580 |
return GetVehicle(v->index); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2581 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2582 |
|
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2583 |
/** Restores a backed up vehicle |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2584 |
* @param *v A vehicle we should sell and take the windows from (NULL for not using this) |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2585 |
* @param *p The owner of the vehicle |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2586 |
* @return The vehicle we restored (front for trains) or v if we didn't have anything to restore |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2587 |
*/ |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2588 |
Vehicle *BackuppedVehicle::Restore(Vehicle *v, Player *p) |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2589 |
{ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2590 |
if (!ContainsBackup()) return v; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2591 |
if (v != NULL) { |
9280
8adb36dcebab
(svn r13146) -Codechange: vehicle_base.h doesn't need to be included in vehicle_gui.h.
rubidium
parents:
9274
diff
changeset
|
2592 |
ChangeVehicleViewWindow(v->index, INVALID_VEHICLE); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2593 |
DoCommand(0, v->index, 1, DC_EXEC, GetCmdSellVeh(v)); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2594 |
} |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2595 |
v = RestoreBackupVehicle(this->vehicles, p); |
9280
8adb36dcebab
(svn r13146) -Codechange: vehicle_base.h doesn't need to be included in vehicle_gui.h.
rubidium
parents:
9274
diff
changeset
|
2596 |
ChangeVehicleViewWindow(INVALID_VEHICLE, v->index); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2597 |
if (orders != NULL) RestoreVehicleOrdersBruteForce(v, orders); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2598 |
if (economy != NULL) economy->Restore(); |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2599 |
/* If we stored cargo as well then we should restore it. */ |
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2600 |
cargo_packets->RestoreBackup(); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2601 |
return v; |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2602 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2603 |
|
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2604 |
/** Backs up a vehicle |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2605 |
* This should never be called when the object already contains a backup |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2606 |
* @param v the vehicle to backup |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2607 |
* @param p If it's set to the vehicle's owner then economy is backed up. If NULL then economy backup will be skipped. |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2608 |
*/ |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2609 |
void BackuppedVehicle::Backup(Vehicle *v, Player *p) |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2610 |
{ |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2611 |
assert(!ContainsBackup()); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2612 |
if (p != NULL) { |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2613 |
assert(p->index == v->owner); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2614 |
economy = new PlayerMoneyBackup(p); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2615 |
} |
9081
38b6cc9fd473
(svn r12940) -Fix [FS#1974](r12913): [autoreplace] a vehicle backup should include the cargo packets in the vehicle as well
bjarni
parents:
9070
diff
changeset
|
2616 |
BackupVehicle(v); |
9061
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2617 |
if (orders != NULL) BackupVehicleOrders(v, orders); |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2618 |
} |
8ebd40e86171
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
bjarni
parents:
9057
diff
changeset
|
2619 |
|
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2620 |
void StopAllVehicles() |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2621 |
{ |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2622 |
Vehicle *v; |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2623 |
FOR_ALL_VEHICLES(v) { |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2624 |
/* Code ripped from CmdStartStopTrain. Can't call it, because of |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2625 |
* ownership problems, so we'll duplicate some code, for now */ |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2626 |
v->vehstatus |= VS_STOPPED; |
8350
8979cccdbed2
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz
parents:
8317
diff
changeset
|
2627 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2628 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2629 |
} |
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
2630 |
} |