author | rubidium |
Sun, 29 Apr 2007 21:24:08 +0000 | |
changeset 7048 | 06b931095b26 |
parent 7046 | 5f11f759f74d |
child 7049 | 01825af2ce90 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
3 |
/** @file roadveh_cmd.cpp */ |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
4 |
|
3508
99974a14a81d
(svn r4359) MSV6 Release mode now compiles (problem of UINT_MAX. stdafx.h should be the first include). Thanks to KUDr for solution and testing
belugas
parents:
3491
diff
changeset
|
5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1793
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
7 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
8 |
#include "functions.h" |
6949
72d11a1e1e60
(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:
6903
diff
changeset
|
9 |
#include "landscape.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3140
diff
changeset
|
10 |
#include "road_map.h" |
3959 | 11 |
#include "roadveh.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
12 |
#include "station_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
13 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
14 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
15 |
#include "tile.h" |
0 | 16 |
#include "vehicle.h" |
17 |
#include "engine.h" |
|
18 |
#include "command.h" |
|
19 |
#include "station.h" |
|
20 |
#include "news.h" |
|
21 |
#include "pathfind.h" |
|
1247 | 22 |
#include "npf.h" |
0 | 23 |
#include "player.h" |
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
24 |
#include "sound.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
25 |
#include "depot.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
26 |
#include "bridge.h" |
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3169
diff
changeset
|
27 |
#include "tunnel_map.h" |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
28 |
#include "bridge_map.h" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
29 |
#include "vehicle_gui.h" |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
30 |
#include "newgrf_callbacks.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2954
diff
changeset
|
31 |
#include "newgrf_engine.h" |
4244
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
32 |
#include "newgrf_text.h" |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
33 |
#include "newgrf_sound.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
34 |
#include "yapf/yapf.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4244
diff
changeset
|
35 |
#include "date.h" |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
36 |
#include "cargotype.h" |
0 | 37 |
|
38 |
static const uint16 _roadveh_images[63] = { |
|
39 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
40 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
41 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
42 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
43 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
44 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
45 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
46 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
47 |
}; |
|
48 |
||
49 |
static const uint16 _roadveh_full_adder[63] = { |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
50 |
0, 88, 0, 0, 0, 0, 48, 48, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
51 |
48, 48, 0, 0, 64, 64, 0, 16, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
52 |
16, 0, 88, 0, 0, 0, 0, 48, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
53 |
48, 48, 48, 0, 0, 64, 64, 0, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
54 |
16, 16, 0, 88, 0, 0, 0, 0, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
55 |
48, 48, 48, 48, 0, 0, 64, 64, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
56 |
0, 16, 16, 0, 8, 8, 8, 8, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
57 |
0, 0, 0, 8, 8, 8, 8 |
0 | 58 |
}; |
59 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
60 |
/** 'Convert' the DiagDirection where a road vehicle enters to the trackdirs it can drive onto */ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
61 |
static const TrackdirBits _road_enter_dir_to_reachable_trackdirs[DIAGDIR_END] = { |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
62 |
TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_X_NE, // Enter from north east |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
63 |
TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_Y_SE, // Enter from south east |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
64 |
TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_X_SW | TRACKDIR_BIT_RIGHT_S, // Enter from south west |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
65 |
TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_Y_NW // Enter from north west |
0 | 66 |
}; |
67 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
68 |
static const Trackdir _road_reverse_table[DIAGDIR_END] = { |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
69 |
TRACKDIR_RVREV_NE, TRACKDIR_RVREV_SE, TRACKDIR_RVREV_SW, TRACKDIR_RVREV_NW |
0 | 70 |
}; |
71 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
72 |
/** 'Convert' the DiagDirection where a road vehicle should exit to |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
73 |
* the trackdirs it can use to drive to the exit direction*/ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
74 |
static const TrackdirBits _road_exit_dir_to_incoming_trackdirs[DIAGDIR_END] = { |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
75 |
TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_X_SW | TRACKDIR_BIT_LEFT_S, |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
76 |
TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_Y_NW, |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
77 |
TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_X_NE, |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
78 |
TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_Y_SE |
0 | 79 |
}; |
80 |
||
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
81 |
/** Converts the exit direction of a depot to trackdir the vehicle is going to drive to */ |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
82 |
static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = { |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
83 |
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
84 |
}; |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
85 |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
86 |
int GetRoadVehImage(const Vehicle* v, Direction direction) |
0 | 87 |
{ |
88 |
int img = v->spritenum; |
|
89 |
int image; |
|
90 |
||
91 |
if (is_custom_sprite(img)) { |
|
92 |
image = GetCustomVehicleSprite(v, direction); |
|
2989 | 93 |
if (image != 0) return image; |
2464
3dee59d241c0
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2260
diff
changeset
|
94 |
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index; |
0 | 95 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
96 |
|
0 | 97 |
image = direction + _roadveh_images[img]; |
2989 | 98 |
if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img]; |
0 | 99 |
return image; |
100 |
} |
|
101 |
||
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
102 |
void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal) |
0 | 103 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
104 |
int spritenum = RoadVehInfo(engine)->image_index; |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
105 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
106 |
if (is_custom_sprite(spritenum)) { |
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
107 |
int sprite = GetCustomVehicleIcon(engine, DIR_W); |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
108 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
109 |
if (sprite != 0) { |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
110 |
DrawSprite(sprite, pal, x, y); |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
111 |
return; |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
112 |
} |
2464
3dee59d241c0
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2260
diff
changeset
|
113 |
spritenum = orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index; |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
114 |
} |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5902
diff
changeset
|
115 |
DrawSprite(6 + _roadveh_images[spritenum], pal, x, y); |
0 | 116 |
} |
117 |
||
2817 | 118 |
static int32 EstimateRoadVehCost(EngineID engine_type) |
0 | 119 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
120 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 121 |
} |
122 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
123 |
/** Build a road vehicle. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
124 |
* @param tile tile of depot where road vehicle is built |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
125 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
126 |
* @param p1 bus/truck type being built (engine) |
3816
2cdb29b57c1f
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3793
diff
changeset
|
127 |
* @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
128 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
129 |
int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 130 |
{ |
131 |
int32 cost; |
|
132 |
Vehicle *v; |
|
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
133 |
UnitID unit_num; |
0 | 134 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
135 |
|
6903
0b3d43bd1fdb
(svn r9543) -Fix [FS#691]: Split up STR_ENGINE_NOT_BUILDABLE into four strings so it can be
maedhros
parents:
6889
diff
changeset
|
136 |
if (!IsEngineBuildable(p1, VEH_ROAD, _current_player)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE); |
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
137 |
|
0 | 138 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
139 |
||
140 |
cost = EstimateRoadVehCost(p1); |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
141 |
if (flags & DC_QUERY_COST) return cost; |
0 | 142 |
|
1442
3e0ac5f13ee2
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
143 |
/* The ai_new queries the vehicle cost before building the route, |
3e0ac5f13ee2
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
144 |
* so we must check against cheaters no sooner than now. --pasky */ |
3e0ac5f13ee2
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
145 |
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR; |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
146 |
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
1442
3e0ac5f13ee2
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
147 |
|
0 | 148 |
v = AllocateVehicle(); |
6173 | 149 |
if (v == NULL) return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
0 | 150 |
|
151 |
/* find the first free roadveh id */ |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
152 |
unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_ROAD); |
0 | 153 |
if (unit_num > _patches.max_roadveh) |
154 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
155 |
||
156 |
if (flags & DC_EXEC) { |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
157 |
int x; |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
158 |
int y; |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
159 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
160 |
const RoadVehicleInfo *rvi = RoadVehInfo(p1); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
161 |
|
0 | 162 |
v->unitnumber = unit_num; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
163 |
v->direction = INVALID_DIR; |
0 | 164 |
v->owner = _current_player; |
165 |
||
166 |
v->tile = tile; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3630
diff
changeset
|
167 |
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3630
diff
changeset
|
168 |
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
0 | 169 |
v->x_pos = x; |
170 |
v->y_pos = y; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6979
diff
changeset
|
171 |
v->z_pos = GetSlopeZ(x, y); |
0 | 172 |
v->z_height = 6; |
173 |
||
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
174 |
v->u.road.state = RVSB_IN_DEPOT; |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6979
diff
changeset
|
175 |
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
0 | 176 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
177 |
v->spritenum = rvi->image_index; |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
178 |
v->cargo_type = rvi->cargo_type; |
3870
766d7bd6c299
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
179 |
v->cargo_subtype = 0; |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
180 |
v->cargo_cap = rvi->capacity; |
0 | 181 |
// v->cargo_count = 0; |
182 |
v->value = cost; |
|
183 |
// v->day_counter = 0; |
|
184 |
// v->next_order_param = v->next_order = 0; |
|
185 |
// v->load_unload_time_rem = 0; |
|
186 |
// v->progress = 0; |
|
187 |
||
188 |
// v->u.road.unk2 = 0; |
|
189 |
// v->u.road.overtaking = 0; |
|
190 |
||
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
191 |
v->last_station_visited = INVALID_STATION; |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
192 |
v->max_speed = rvi->max_speed; |
0 | 193 |
v->engine_type = (byte)p1; |
194 |
||
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
195 |
e = GetEngine(p1); |
0 | 196 |
v->reliability = e->reliability; |
197 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
198 |
v->max_age = e->lifelength * 366; |
|
2564 | 199 |
_new_vehicle_id = v->index; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
200 |
|
0 | 201 |
v->string_id = STR_SV_ROADVEH_NAME; |
202 |
||
203 |
v->service_interval = _patches.servint_roadveh; |
|
204 |
||
205 |
v->date_of_last_service = _date; |
|
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
206 |
v->build_year = _cur_year; |
0 | 207 |
|
7048
06b931095b26
(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:
7046
diff
changeset
|
208 |
v = new (v) RoadVehicle(); |
0 | 209 |
v->cur_image = 0xC15; |
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2767
diff
changeset
|
210 |
v->random_bits = VehicleRandomBits(); |
0 | 211 |
|
6502
7ca154aca2b7
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6501
diff
changeset
|
212 |
v->vehicle_flags = 0; |
7ca154aca2b7
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6501
diff
changeset
|
213 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); |
7ca154aca2b7
(svn r8946) -Feature: [NewGRF] Add support for vehicle variables 0xFE and 0xFF bit 10,
maedhros
parents:
6501
diff
changeset
|
214 |
|
0 | 215 |
VehiclePositionChanged(v); |
216 |
||
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4725
diff
changeset
|
217 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
588 | 218 |
RebuildVehicleLists(); |
0 | 219 |
InvalidateWindow(WC_COMPANY, v->owner); |
2618
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
220 |
if (IsLocalPlayer()) |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
221 |
InvalidateAutoreplaceWindow(VEH_ROAD); // updates the replace Road window |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6194
diff
changeset
|
222 |
|
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6194
diff
changeset
|
223 |
GetPlayer(_current_player)->num_engines[p1]++; |
0 | 224 |
} |
225 |
||
226 |
return cost; |
|
227 |
} |
|
228 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
229 |
/** Start/Stop a road vehicle. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
230 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
231 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
232 |
* @param p1 road vehicle ID to start/stop |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
233 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
234 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
235 |
int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 236 |
{ |
237 |
Vehicle *v; |
|
4244
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
238 |
uint16 callback; |
0 | 239 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
240 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
241 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
242 |
v = GetVehicle(p1); |
0 | 243 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
244 |
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 245 |
|
4244
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
246 |
/* Check if this road veh can be started/stopped. The callback will fail or |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
247 |
* return 0xFF if it can. */ |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
248 |
callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
249 |
if (callback != CALLBACK_FAILED && callback != 0xFF) { |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
250 |
StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
251 |
return_cmd_error(error); |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
252 |
} |
44dcec623504
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
253 |
|
0 | 254 |
if (flags & DC_EXEC) { |
3959 | 255 |
if (IsRoadVehInDepotStopped(v)) { |
3139
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
256 |
DeleteVehicleNews(p1, STR_9016_ROAD_VEHICLE_IS_WAITING); |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
257 |
} |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
258 |
|
0 | 259 |
v->vehstatus ^= VS_STOPPED; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
260 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 261 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
262 |
} |
|
263 |
||
264 |
return 0; |
|
265 |
} |
|
266 |
||
3123 | 267 |
void ClearSlot(Vehicle *v) |
1664
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
268 |
{ |
3123 | 269 |
RoadStop *rs = v->u.road.slot; |
270 |
if (v->u.road.slot == NULL) return; |
|
271 |
||
1664
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
272 |
v->u.road.slot = NULL; |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
273 |
v->u.road.slot_age = 0; |
3123 | 274 |
|
3431 | 275 |
assert(rs->num_vehicles != 0); |
276 |
rs->num_vehicles--; |
|
277 |
||
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
278 |
DEBUG(ms, 3, "Clearing slot at 0x%X", rs->xy); |
1664
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
279 |
} |
000099fbae6e
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
280 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
281 |
/** Sell a road vehicle. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
282 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
283 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
284 |
* @param p1 vehicle ID to be sold |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
285 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
286 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
287 |
int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 288 |
{ |
289 |
Vehicle *v; |
|
290 |
||
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
291 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
292 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
293 |
v = GetVehicle(p1); |
0 | 294 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
295 |
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 296 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
297 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
298 |
|
3959 | 299 |
if (!IsRoadVehInDepotStopped(v)) { |
0 | 300 |
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
301 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
302 |
|
0 | 303 |
if (flags & DC_EXEC) { |
304 |
// Invalidate depot |
|
305 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 306 |
RebuildVehicleLists(); |
0 | 307 |
InvalidateWindow(WC_COMPANY, v->owner); |
308 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
5256
90226d8da8fb
(svn r7386) -Codechange r7385: moved deletion of the vehicle highlight from DeleteVehicle to the sell commands as they are not called as often
bjarni
parents:
5215
diff
changeset
|
309 |
DeleteDepotHighlightOfVehicle(v); |
0 | 310 |
DeleteVehicle(v); |
311 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
312 |
|
0 | 313 |
return -(int32)v->value; |
314 |
} |
|
315 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
316 |
struct RoadFindDepotData { |
0 | 317 |
uint best_length; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
318 |
TileIndex tile; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
319 |
OwnerByte owner; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
320 |
}; |
0 | 321 |
|
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
322 |
static const DiagDirection _road_pf_directions[] = { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
323 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, INVALID_DIAGDIR, INVALID_DIAGDIR, |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
324 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, INVALID_DIAGDIR, INVALID_DIAGDIR |
0 | 325 |
}; |
326 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
327 |
static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state) |
0 | 328 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
329 |
RoadFindDepotData* rfdd = (RoadFindDepotData*)data; |
3137 | 330 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
331 |
tile += TileOffsByDiagDir(_road_pf_directions[trackdir]); |
0 | 332 |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
333 |
if (IsTileType(tile, MP_STREET) && |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3645
diff
changeset
|
334 |
GetRoadTileType(tile) == ROAD_TILE_DEPOT && |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
335 |
IsTileOwner(tile, rfdd->owner) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
336 |
length < rfdd->best_length) { |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
337 |
rfdd->best_length = length; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
338 |
rfdd->tile = tile; |
0 | 339 |
} |
340 |
return false; |
|
341 |
} |
|
342 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
343 |
static const Depot* FindClosestRoadDepot(const Vehicle* v) |
0 | 344 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
345 |
TileIndex tile = v->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
346 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
347 |
if (_patches.yapf.road_use_yapf) { |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
348 |
Depot* ret = YapfFindNearestRoadDepot(v); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
349 |
return ret; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
350 |
} else if (_patches.new_pathfinding_all) { |
1247 | 351 |
NPFFoundTargetData ftd; |
352 |
/* See where we are now */ |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
353 |
Trackdir trackdir = GetVehicleTrackdir(v); |
1745
2dcc0a66d91d
(svn r2249) - Fix: [ 1187703 ] [NPF] Road vehicles cannot find a depot when in a roadstop
matthijs
parents:
1709
diff
changeset
|
354 |
|
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1998
diff
changeset
|
355 |
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
356 |
if (ftd.best_bird_dist == 0) { |
1247 | 357 |
return GetDepotByTile(ftd.node.tile); /* Target found */ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
358 |
} else { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
359 |
return NULL; /* Target not found */ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
360 |
} |
1247 | 361 |
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ |
362 |
} else { |
|
363 |
RoadFindDepotData rfdd; |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
364 |
|
1247 | 365 |
rfdd.owner = v->owner; |
366 |
rfdd.best_length = (uint)-1; |
|
0 | 367 |
|
1247 | 368 |
/* search in all directions */ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
369 |
for (DiagDirection i = DIAGDIR_BEGIN; i != DIAGDIR_END; i++) { |
3137 | 370 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, EnumRoadSignalFindDepot, NULL, &rfdd); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
371 |
} |
0 | 372 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
373 |
if (rfdd.best_length == (uint)-1) return NULL; |
0 | 374 |
|
1247 | 375 |
return GetDepotByTile(rfdd.tile); |
376 |
} |
|
0 | 377 |
} |
378 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
379 |
/** Send a road vehicle to the depot. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
380 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
381 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
382 |
* @param p1 vehicle ID to send to the depot |
4451
66603f0f732e
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4445
diff
changeset
|
383 |
* @param p2 various bitmasked elements |
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
384 |
* - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) |
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
385 |
* - p2 bit 8-10 - VLW flag (for mass goto depot) |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
386 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
387 |
int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 388 |
{ |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
389 |
Vehicle *v; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
390 |
const Depot *dep; |
0 | 391 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
392 |
if (p2 & DEPOT_MASS_SEND) { |
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
393 |
/* Mass goto depot requested */ |
4546
9345e0569655
(svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents:
4544
diff
changeset
|
394 |
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
395 |
return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1); |
4463
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
396 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
397 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
398 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
399 |
|
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
400 |
v = GetVehicle(p1); |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
401 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
402 |
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 403 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
404 |
if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
1757
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
405 |
|
4526 | 406 |
if (IsRoadVehInDepot(v)) return CMD_ERROR; |
407 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
408 |
/* If the current orders are already goto-depot */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
409 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
4519
1437b1e7416c
(svn r6304) -Codechange r6295: Use !! instead of (bool) in commands to send vehicles to depots
bjarni
parents:
4510
diff
changeset
|
410 |
if (!!(p2 & DEPOT_SERVICE) == HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT)) { |
4510
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
411 |
/* We called with a different DEPOT_SERVICE setting. |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
412 |
* Now we change the setting to apply the new one and let the vehicle head for the same depot. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
413 |
* Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
4510
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
414 |
if (flags & DC_EXEC) { |
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
415 |
TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); |
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
416 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
417 |
} |
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
418 |
return 0; |
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
419 |
} |
071bca98c577
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
420 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
421 |
if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders |
0 | 422 |
if (flags & DC_EXEC) { |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
423 |
/* If the orders to 'goto depot' are in the orders list (forced servicing), |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
424 |
* then skip to the next order; effectively cancelling this forced service */ |
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
425 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
0 | 426 |
v->cur_order_index++; |
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
427 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
428 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
429 |
v->current_order.flags = 0; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
430 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 431 |
} |
432 |
return 0; |
|
433 |
} |
|
434 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
435 |
dep = FindClosestRoadDepot(v); |
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
436 |
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
0 | 437 |
|
438 |
if (flags & DC_EXEC) { |
|
6998
403314de0154
(svn r9685) -Fix (r9683): Call v->LeaveStation() when a vehicle in a station is sent to a depot.
maedhros
parents:
6987
diff
changeset
|
439 |
if (v->current_order.type == OT_LOADING) v->LeaveStation(); |
403314de0154
(svn r9685) -Fix (r9683): Call v->LeaveStation() when a vehicle in a station is sent to a depot.
maedhros
parents:
6987
diff
changeset
|
440 |
|
3236 | 441 |
ClearSlot(v); |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
442 |
v->current_order.type = OT_GOTO_DEPOT; |
4412
945e8a9bb89a
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4389
diff
changeset
|
443 |
v->current_order.flags = OF_NON_STOP; |
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
444 |
if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); |
5259
08336337aae0
(svn r7389) -Fix: when forcing a vehicle to go to a depot, clear refit orders from current orders (caused refit error popup when not having no orders)
bjarni
parents:
5256
diff
changeset
|
445 |
v->current_order.refit_cargo = CT_INVALID; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
446 |
v->current_order.dest = dep->index; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
447 |
v->dest_tile = dep->xy; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
448 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 449 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
450 |
|
0 | 451 |
return 0; |
452 |
} |
|
453 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
454 |
/** Turn a roadvehicle around. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
455 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
456 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
457 |
* @param p1 vehicle ID to turn |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
458 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
459 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
460 |
int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 461 |
{ |
462 |
Vehicle *v; |
|
463 |
||
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
464 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
465 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
466 |
v = GetVehicle(p1); |
0 | 467 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
468 |
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 469 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
470 |
if (v->vehstatus & VS_STOPPED || |
0 | 471 |
v->u.road.crashed_ctr != 0 || |
472 |
v->breakdown_ctr != 0 || |
|
473 |
v->u.road.overtaking != 0 || |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
474 |
v->u.road.state == RVSB_WORMHOLE || |
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
475 |
IsRoadVehInDepot(v) || |
0 | 476 |
v->cur_speed < 5) { |
477 |
return CMD_ERROR; |
|
478 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
479 |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
480 |
if (IsTunnelTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelDirection(v->tile)) return CMD_ERROR; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
481 |
if (IsBridgeTile(v->tile) && DirToDiagDir(v->direction) == GetBridgeRampDirection(v->tile)) return CMD_ERROR; |
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
482 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
483 |
if (flags & DC_EXEC) v->u.road.reverse_ctr = 180; |
0 | 484 |
|
485 |
return 0; |
|
486 |
} |
|
487 |
||
488 |
||
489 |
static void MarkRoadVehDirty(Vehicle *v) |
|
490 |
{ |
|
491 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
492 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
493 |
} |
|
494 |
||
495 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
496 |
{ |
|
497 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
498 |
static const uint32 _delta_xy_table[8] = { |
|
499 |
MKIT(3, 3, -1, -1), |
|
500 |
MKIT(3, 7, -1, -3), |
|
501 |
MKIT(3, 3, -1, -1), |
|
502 |
MKIT(7, 3, -3, -1), |
|
503 |
MKIT(3, 3, -1, -1), |
|
504 |
MKIT(3, 7, -1, -3), |
|
505 |
MKIT(3, 3, -1, -1), |
|
506 |
MKIT(7, 3, -3, -1), |
|
507 |
}; |
|
508 |
#undef MKIT |
|
509 |
uint32 x = _delta_xy_table[v->direction]; |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
510 |
v->x_offs = GB(x, 0, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
511 |
v->y_offs = GB(x, 8, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
512 |
v->sprite_width = GB(x, 16, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
513 |
v->sprite_height = GB(x, 24, 8); |
0 | 514 |
} |
515 |
||
516 |
static void ClearCrashedStation(Vehicle *v) |
|
517 |
{ |
|
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
518 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 519 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6315
diff
changeset
|
520 |
/* Mark the station entrance as not busy */ |
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6315
diff
changeset
|
521 |
rs->SetEntranceBusy(false); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
522 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6315
diff
changeset
|
523 |
/* Free the parking bay */ |
6331
9bc486e6cd0d
(svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents:
6330
diff
changeset
|
524 |
rs->FreeBay(HASBIT(v->u.road.state, RVS_USING_SECOND_BAY)); |
0 | 525 |
} |
526 |
||
527 |
static void RoadVehDelete(Vehicle *v) |
|
528 |
{ |
|
529 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
530 |
|
588 | 531 |
RebuildVehicleLists(); |
0 | 532 |
InvalidateWindow(WC_COMPANY, v->owner); |
533 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
534 |
if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
535 |
|
0 | 536 |
BeginVehicleMove(v); |
537 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
538 |
|
0 | 539 |
DeleteVehicle(v); |
540 |
} |
|
541 |
||
542 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
543 |
{ |
|
544 |
byte new_z, old_z; |
|
545 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
546 |
/* need this hint so it returns the right z coordinate on bridges. */ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
547 |
v->x_pos = x; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
548 |
v->y_pos = y; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
549 |
new_z = GetSlopeZ(x, y); |
0 | 550 |
|
551 |
old_z = v->z_pos; |
|
552 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
553 |
|
0 | 554 |
VehiclePositionChanged(v); |
555 |
EndVehicleMove(v); |
|
556 |
return old_z; |
|
557 |
} |
|
558 |
||
559 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
560 |
{ |
|
3160 | 561 |
static const DirDiff delta[] = { |
562 |
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
563 |
}; |
|
564 |
||
0 | 565 |
uint32 r = Random(); |
3160 | 566 |
|
567 |
v->direction = ChangeDir(v->direction, delta[r & 3]); |
|
0 | 568 |
BeginVehicleMove(v); |
569 |
UpdateRoadVehDeltaXY(v); |
|
570 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
571 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
572 |
} |
|
573 |
||
574 |
static void RoadVehIsCrashed(Vehicle *v) |
|
575 |
{ |
|
576 |
v->u.road.crashed_ctr++; |
|
577 |
if (v->u.road.crashed_ctr == 2) { |
|
1359
8ba976aed634
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
578 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 579 |
} else if (v->u.road.crashed_ctr <= 45) { |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
580 |
if ((v->tick_counter & 7) == 0) RoadVehSetRandomDirection(v); |
0 | 581 |
} else if (v->u.road.crashed_ctr >= 2220) { |
582 |
RoadVehDelete(v); |
|
583 |
} |
|
584 |
} |
|
585 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
586 |
static void* EnumCheckRoadVehCrashTrain(Vehicle* v, void* data) |
0 | 587 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
588 |
const Vehicle* u = (Vehicle*)data; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
589 |
|
2989 | 590 |
return |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
591 |
v->type == VEH_TRAIN && |
2989 | 592 |
myabs(v->z_pos - u->z_pos) <= 6 && |
593 |
myabs(v->x_pos - u->x_pos) <= 4 && |
|
594 |
myabs(v->y_pos - u->y_pos) <= 4 ? |
|
595 |
v : NULL; |
|
0 | 596 |
} |
597 |
||
598 |
static void RoadVehCrash(Vehicle *v) |
|
599 |
{ |
|
600 |
uint16 pass; |
|
601 |
||
602 |
v->u.road.crashed_ctr++; |
|
603 |
v->vehstatus |= VS_CRASHED; |
|
3236 | 604 |
ClearSlot(v); |
0 | 605 |
|
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
606 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 607 |
|
608 |
pass = 1; |
|
6657
3bf9d9badb6b
(svn r9303) -Codechange: Use cargo class when counting passengers in a road vehicle crash, and when loading aircraft.
peter1138
parents:
6655
diff
changeset
|
609 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo_count; |
0 | 610 |
v->cargo_count = 0; |
2951 | 611 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
612 |
SetDParam(0, pass); |
2260
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
613 |
AddNewsItem( |
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
614 |
(pass == 1) ? |
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
615 |
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE, |
0 | 616 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
617 |
v->index, |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
618 |
0 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
619 |
); |
0 | 620 |
|
621 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 622 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 623 |
} |
624 |
||
625 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
626 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
627 |
TileIndex tile; |
0 | 628 |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
629 |
if (v->u.road.state == RVSB_WORMHOLE) return; |
0 | 630 |
|
631 |
tile = v->tile; |
|
632 |
||
3560
4389ae5ad967
(svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents:
3508
diff
changeset
|
633 |
if (!IsLevelCrossingTile(tile)) return; |
0 | 634 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
635 |
if (VehicleFromPos(tile, v, EnumCheckRoadVehCrashTrain) != NULL) |
0 | 636 |
RoadVehCrash(v); |
637 |
} |
|
638 |
||
639 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
640 |
{ |
|
641 |
if (v->breakdown_ctr != 1) { |
|
642 |
v->breakdown_ctr = 1; |
|
643 |
v->cur_speed = 0; |
|
644 |
||
645 |
if (v->breakdowns_since_last_service != 255) |
|
646 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
647 |
|
0 | 648 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
649 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
650 |
|
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
651 |
if (!PlayVehicleSound(v, VSE_BREAKDOWN)) { |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6657
diff
changeset
|
652 |
SndPlayVehicleFx((_opt.landscape != LT_TOYLAND) ? |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
653 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
654 |
} |
0 | 655 |
|
656 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
657 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
2989 | 658 |
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; |
0 | 659 |
} |
660 |
} |
|
661 |
||
2989 | 662 |
if ((v->tick_counter & 1) == 0) { |
663 |
if (--v->breakdown_delay == 0) { |
|
0 | 664 |
v->breakdown_ctr = 0; |
665 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
666 |
} |
|
667 |
} |
|
668 |
} |
|
669 |
||
670 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
671 |
{ |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
672 |
const Order *order; |
0 | 673 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
674 |
switch (v->current_order.type) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
675 |
case OT_GOTO_DEPOT: |
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
676 |
/* Let a depot order in the orderlist interrupt. */ |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
677 |
if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
678 |
if (v->current_order.flags & OF_SERVICE_IF_NEEDED && |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
679 |
!VehicleNeedsService(v)) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
680 |
v->cur_order_index++; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
681 |
} |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
682 |
break; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
683 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
684 |
case OT_LOADING: |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
685 |
case OT_LEAVESTATION: |
0 | 686 |
return; |
4351
63ae31104f07
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4344
diff
changeset
|
687 |
|
63ae31104f07
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4344
diff
changeset
|
688 |
default: break; |
0 | 689 |
} |
690 |
||
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
691 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 692 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
693 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 694 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
695 |
if (order == NULL) { |
6589
addf4b6946d0
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6585
diff
changeset
|
696 |
v->current_order.Free(); |
0 | 697 |
v->dest_tile = 0; |
3123 | 698 |
ClearSlot(v); |
0 | 699 |
return; |
700 |
} |
|
701 |
||
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
702 |
if (order->type == v->current_order.type && |
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
703 |
order->flags == v->current_order.flags && |
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
704 |
order->dest == v->current_order.dest) { |
0 | 705 |
return; |
2951 | 706 |
} |
0 | 707 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
708 |
v->current_order = *order; |
0 | 709 |
|
4179 | 710 |
switch (order->type) { |
711 |
case OT_GOTO_STATION: { |
|
712 |
const RoadStop* rs; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
713 |
|
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
714 |
if (order->dest == v->last_station_visited) { |
4179 | 715 |
v->last_station_visited = INVALID_STATION; |
716 |
} |
|
717 |
||
6127 | 718 |
rs = GetStation(order->dest)->GetPrimaryRoadStop( |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
719 |
IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK |
4179 | 720 |
); |
721 |
||
722 |
if (rs != NULL) { |
|
723 |
TileIndex dest = rs->xy; |
|
724 |
uint mindist = DistanceManhattan(v->tile, rs->xy); |
|
725 |
||
726 |
for (rs = rs->next; rs != NULL; rs = rs->next) { |
|
727 |
uint dist = DistanceManhattan(v->tile, rs->xy); |
|
728 |
||
729 |
if (dist < mindist) { |
|
730 |
mindist = dist; |
|
731 |
dest = rs->xy; |
|
732 |
} |
|
733 |
} |
|
734 |
v->dest_tile = dest; |
|
735 |
} else { |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
736 |
/* There is no stop left at the station, so don't even TRY to go there */ |
4179 | 737 |
v->cur_order_index++; |
738 |
v->dest_tile = 0; |
|
739 |
} |
|
740 |
break; |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
741 |
} |
1231
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
742 |
|
4179 | 743 |
case OT_GOTO_DEPOT: |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
744 |
v->dest_tile = GetDepot(order->dest)->xy; |
4179 | 745 |
break; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
746 |
|
4179 | 747 |
default: |
748 |
v->dest_tile = 0; |
|
749 |
break; |
|
0 | 750 |
} |
751 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
752 |
InvalidateVehicleOrder(v); |
0 | 753 |
} |
754 |
||
755 |
static void HandleRoadVehLoading(Vehicle *v) |
|
756 |
{ |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
757 |
switch (v->current_order.type) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
758 |
case OT_LOADING: { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
759 |
Order b; |
0 | 760 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
761 |
if (--v->load_unload_time_rem != 0) return; |
0 | 762 |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
763 |
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD || |
6501
1e95e8d993ff
(svn r8945) -Codechange: Rename v->load_status to v->vehicle_flags so it can be used for more than just the gradual loading status.
maedhros
parents:
6479
diff
changeset
|
764 |
(_patches.gradual_loading && !HASBIT(v->vehicle_flags, VF_LOADING_FINISHED)))) { |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
765 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
766 |
if (LoadUnloadVehicle(v, false)) { |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
767 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
768 |
MarkRoadVehDirty(v); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
769 |
} |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
770 |
return; |
0 | 771 |
} |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
772 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
773 |
b = v->current_order; |
5902
906fea1535ab
(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:
5838
diff
changeset
|
774 |
v->LeaveStation(); |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
775 |
if (!(b.flags & OF_NON_STOP)) return; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
776 |
break; |
0 | 777 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
778 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
779 |
case OT_DUMMY: break; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
780 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
781 |
default: return; |
0 | 782 |
} |
783 |
||
784 |
v->cur_order_index++; |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
785 |
InvalidateVehicleOrder(v); |
0 | 786 |
} |
787 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
788 |
static void StartRoadVehSound(const Vehicle* v) |
0 | 789 |
{ |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
790 |
if (!PlayVehicleSound(v, VSE_START)) { |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
791 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
792 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
793 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
794 |
SndPlayVehicleFx(s, v); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
795 |
} |
0 | 796 |
} |
797 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
798 |
struct RoadVehFindData { |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
799 |
int x; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
800 |
int y; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
801 |
const Vehicle* veh; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
802 |
Direction dir; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
803 |
}; |
0 | 804 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
805 |
static void* EnumCheckRoadVehClose(Vehicle *v, void* data) |
0 | 806 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
807 |
static const int8 dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 }; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
808 |
static const int8 dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 }; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
809 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
810 |
const RoadVehFindData* rvf = (RoadVehFindData*)data; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
811 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
812 |
short x_diff = v->x_pos - rvf->x; |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
813 |
short y_diff = v->y_pos - rvf->y; |
0 | 814 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
815 |
return |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
816 |
rvf->veh != v && |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
817 |
v->type == VEH_ROAD && |
3959 | 818 |
!IsRoadVehInDepot(v) && |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
819 |
myabs(v->z_pos - rvf->veh->z_pos) < 6 && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
820 |
v->direction == rvf->dir && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
821 |
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
822 |
(dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
823 |
(dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
824 |
(dist_y[v->direction] <= 0 || (y_diff < dist_y[v->direction] && y_diff >= 0)) ? |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
825 |
v : NULL; |
0 | 826 |
} |
827 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
828 |
static Vehicle* RoadVehFindCloseTo(Vehicle* v, int x, int y, Direction dir) |
0 | 829 |
{ |
830 |
RoadVehFindData rvf; |
|
831 |
Vehicle *u; |
|
832 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
833 |
if (v->u.road.reverse_ctr != 0) return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
834 |
|
0 | 835 |
rvf.x = x; |
836 |
rvf.y = y; |
|
837 |
rvf.dir = dir; |
|
838 |
rvf.veh = v; |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
839 |
u = (Vehicle*)VehicleFromPos(TileVirtXY(x, y), &rvf, EnumCheckRoadVehClose); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
840 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
841 |
/* This code protects a roadvehicle from being blocked for ever |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
842 |
* If more than 1480 / 74 days a road vehicle is blocked, it will |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
843 |
* drive just through it. The ultimate backup-code of TTD. |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
844 |
* It can be disabled. */ |
0 | 845 |
if (u == NULL) { |
3009
c477ab0f00b3
(svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents:
3004
diff
changeset
|
846 |
v->u.road.blocked_ctr = 0; |
0 | 847 |
return NULL; |
848 |
} |
|
849 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
850 |
if (++v->u.road.blocked_ctr > 1480) return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
851 |
|
0 | 852 |
return u; |
853 |
} |
|
854 |
||
2630 | 855 |
static void RoadVehArrivesAt(const Vehicle* v, Station* st) |
0 | 856 |
{ |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
857 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
0 | 858 |
/* Check if station was ever visited before */ |
859 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
860 |
uint32 flags; |
|
861 |
||
862 |
st->had_vehicle_of_type |= HVOT_BUS; |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
863 |
SetDParam(0, st->index); |
0 | 864 |
flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0); |
865 |
AddNewsItem( |
|
866 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
867 |
flags, |
|
868 |
v->index, |
|
869 |
0); |
|
870 |
} |
|
871 |
} else { |
|
872 |
/* Check if station was ever visited before */ |
|
873 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
874 |
uint32 flags; |
|
875 |
||
876 |
st->had_vehicle_of_type |= HVOT_TRUCK; |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
877 |
SetDParam(0, st->index); |
0 | 878 |
flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0); |
879 |
AddNewsItem( |
|
880 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
881 |
flags, |
|
882 |
v->index, |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
883 |
0 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
884 |
); |
0 | 885 |
} |
886 |
} |
|
887 |
} |
|
888 |
||
889 |
static bool RoadVehAccelerate(Vehicle *v) |
|
890 |
{ |
|
2951 | 891 |
uint spd = v->cur_speed + 1 + (v->u.road.overtaking != 0 ? 1 : 0); |
0 | 892 |
byte t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
893 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
894 |
/* Clamp */ |
0 | 895 |
spd = min(spd, v->max_speed); |
6467 | 896 |
if (v->u.road.state == RVSB_WORMHOLE && !(v->vehstatus & VS_HIDDEN)) { |
897 |
spd = min(spd, GetBridge(GetBridgeType(v->tile))->speed * 2); |
|
898 |
} |
|
0 | 899 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
900 |
/* updates statusbar only if speed have changed to save CPU time */ |
0 | 901 |
if (spd != v->cur_speed) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
902 |
v->cur_speed = spd; |
2951 | 903 |
if (_patches.vehicle_speed) { |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
904 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
2951 | 905 |
} |
0 | 906 |
} |
907 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
908 |
/* Decrease somewhat when turning */ |
2951 | 909 |
if (!(v->direction & 1)) spd = spd * 3 >> 2; |
0 | 910 |
|
2951 | 911 |
if (spd == 0) return false; |
0 | 912 |
|
2951 | 913 |
if ((byte)++spd == 0) return true; |
0 | 914 |
|
915 |
v->progress = (t = v->progress) - (byte)spd; |
|
916 |
||
917 |
return (t < v->progress); |
|
918 |
} |
|
919 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
920 |
static Direction RoadVehGetNewDirection(const Vehicle* v, int x, int y) |
0 | 921 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
922 |
static const Direction _roadveh_new_dir[] = { |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
923 |
DIR_N , DIR_NW, DIR_W , INVALID_DIR, |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
924 |
DIR_NE, DIR_N , DIR_SW, INVALID_DIR, |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
925 |
DIR_E , DIR_SE, DIR_S |
0 | 926 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
927 |
|
0 | 928 |
x = x - v->x_pos + 1; |
929 |
y = y - v->y_pos + 1; |
|
930 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
931 |
if ((uint)x > 2 || (uint)y > 2) return v->direction; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
932 |
return _roadveh_new_dir[y * 4 + x]; |
0 | 933 |
} |
934 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
935 |
static Direction RoadVehGetSlidingDirection(const Vehicle* v, int x, int y) |
0 | 936 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
937 |
Direction new_dir = RoadVehGetNewDirection(v, x, y); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
938 |
Direction old_dir = v->direction; |
3159
2abc21583259
(svn r3785) Replace some if-magic to determine the turning direction for road vehicles with the new DirDiff stuff
tron
parents:
3157
diff
changeset
|
939 |
DirDiff delta; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
940 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
941 |
if (new_dir == old_dir) return old_dir; |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
942 |
delta = (DirDifference(new_dir, old_dir) > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
943 |
return ChangeDir(old_dir, delta); |
0 | 944 |
} |
945 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
946 |
struct OvertakeData { |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
947 |
const Vehicle* u; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
948 |
const Vehicle* v; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
949 |
TileIndex tile; |
0 | 950 |
byte tilebits; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
951 |
}; |
0 | 952 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
953 |
static void* EnumFindVehToOvertake(Vehicle* v, void* data) |
0 | 954 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
955 |
const OvertakeData* od = (OvertakeData*)data; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
956 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
957 |
return |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
958 |
v->tile == od->tile && v->type == VEH_ROAD && v != od->u && v != od->v ? |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
959 |
v : NULL; |
0 | 960 |
} |
961 |
||
962 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
963 |
{ |
|
964 |
uint32 bits; |
|
965 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
966 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD) & 0x3F; |
0 | 967 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
968 |
if (!(od->tilebits & bits) || (bits & 0x3C) || (bits & 0x3F3F0000)) |
0 | 969 |
return true; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
970 |
return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL; |
0 | 971 |
} |
972 |
||
973 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
974 |
{ |
|
975 |
OvertakeData od; |
|
976 |
byte tt; |
|
977 |
||
978 |
od.v = v; |
|
979 |
od.u = u; |
|
980 |
||
981 |
if (u->max_speed >= v->max_speed && |
|
3431 | 982 |
!(u->vehstatus & VS_STOPPED) && |
2951 | 983 |
u->cur_speed != 0) { |
984 |
return; |
|
985 |
} |
|
0 | 986 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
987 |
if (v->direction != u->direction || !(v->direction & 1)) return; |
0 | 988 |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
989 |
/* Check if vehicle is in a road stop, depot, tunnel or bridge or not on a straight road */ |
6457
2c447a703ec6
(svn r8868) -Fix (r8715): road vehicles could not overtake anymore in some directions (mart3p).
rubidium
parents:
6338
diff
changeset
|
990 |
if (v->u.road.state >= RVSB_IN_ROAD_STOP || !IsStraightRoadTrackdir((Trackdir)(v->u.road.state & RVSB_TRACKDIR_MASK))) return; |
0 | 991 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
992 |
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F; |
2951 | 993 |
if ((tt & 3) == 0) return; |
994 |
if ((tt & 0x3C) != 0) return; |
|
0 | 995 |
|
2951 | 996 |
if (tt == 3) tt = (v->direction & 2) ? 2 : 1; |
0 | 997 |
od.tilebits = tt; |
998 |
||
999 |
od.tile = v->tile; |
|
2951 | 1000 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 1001 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1002 |
od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction)); |
2951 | 1003 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 1004 |
|
3431 | 1005 |
if (od.u->cur_speed == 0 || od.u->vehstatus& VS_STOPPED) { |
0 | 1006 |
v->u.road.overtaking_ctr = 0x11; |
1007 |
v->u.road.overtaking = 0x10; |
|
1008 |
} else { |
|
2951 | 1009 |
// if (FindRoadVehToOvertake(&od)) return; |
0 | 1010 |
v->u.road.overtaking_ctr = 0; |
1011 |
v->u.road.overtaking = 0x10; |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
1016 |
{ |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1017 |
if (old_z == v->z_pos) return; |
0 | 1018 |
|
1019 |
if (old_z < v->z_pos) { |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1020 |
v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10% |
0 | 1021 |
} else { |
1022 |
uint16 spd = v->cur_speed + 2; |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1023 |
if (spd <= v->max_speed) v->cur_speed = spd; |
0 | 1024 |
} |
1025 |
} |
|
1026 |
||
1027 |
static int PickRandomBit(uint bits) |
|
1028 |
{ |
|
1029 |
uint num = 0; |
|
1030 |
uint b = bits; |
|
1031 |
uint i; |
|
1032 |
||
1033 |
do { |
|
2951 | 1034 |
if (b & 1) num++; |
0 | 1035 |
} while (b >>= 1); |
1036 |
||
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
1037 |
num = RandomRange(num); |
0 | 1038 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1039 |
for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {} |
0 | 1040 |
return i; |
1041 |
} |
|
1042 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1043 |
struct FindRoadToChooseData { |
0 | 1044 |
TileIndex dest; |
1045 |
uint maxtracklen; |
|
1046 |
uint mindist; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1047 |
}; |
0 | 1048 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1049 |
static bool EnumRoadTrackFindDist(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state) |
0 | 1050 |
{ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1051 |
FindRoadToChooseData* frd = (FindRoadToChooseData*)data; |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
1052 |
uint dist = DistanceManhattan(tile, frd->dest); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1053 |
|
0 | 1054 |
if (dist <= frd->mindist) { |
1055 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
1056 |
frd->maxtracklen = length; |
|
1057 |
} |
|
1058 |
frd->mindist = dist; |
|
1059 |
} |
|
1060 |
return false; |
|
1061 |
} |
|
1062 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1063 |
static inline NPFFoundTargetData PerfNPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes) |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1064 |
{ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1065 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1066 |
void* perf = NpfBeginInterval(); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1067 |
NPFFoundTargetData ret = NPFRouteToStationOrTile(tile, trackdir, target, type, owner, railtypes); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1068 |
int t = NpfEndInterval(perf); |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1069 |
DEBUG(yapf, 4, "[NPFR] %d us - %d rounds - %d open - %d closed -- ", t, 0, _aystar_stats_open_size, _aystar_stats_closed_size); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1070 |
return ret; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1071 |
} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1072 |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1073 |
/** |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1074 |
* Returns direction to for a road vehicle to take or |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1075 |
* INVALID_TRACKDIR if the direction is currently blocked |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
1076 |
* @param v the Vehicle to do the pathfinding for |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1077 |
* @param tile the where to start the pathfinding |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1078 |
* @param enterdir the direction the vehicle enters the tile from |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
1079 |
* @return the Trackdir to take |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1080 |
*/ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1081 |
static Trackdir RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir) |
0 | 1082 |
{ |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1083 |
#define return_track(x) { best_track = (Trackdir)x; goto found_best_track; } |
0 | 1084 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1085 |
TileIndex desttile; |
0 | 1086 |
FindRoadToChooseData frd; |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1087 |
Trackdir best_track; |
0 | 1088 |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1089 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1090 |
TrackdirBits signal = (TrackdirBits)GB(r, 16, 16); |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1091 |
TrackdirBits trackdirs = (TrackdirBits)GB(r, 0, 16); |
0 | 1092 |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1093 |
if (IsTileType(tile, MP_STREET)) { |
4445
562232eef864
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1094 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT && (!IsTileOwner(tile, v->owner) || GetRoadDepotDirection(tile) == enterdir)) { |
562232eef864
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1095 |
/* Road depot owned by another player or with the wrong orientation */ |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1096 |
trackdirs = TRACKDIR_BIT_NONE; |
2549 | 1097 |
} |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1098 |
} else if (IsTileType(tile, MP_STATION) && IsStandardRoadStopTile(tile)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1099 |
/* Standard road stop (drive-through stops are treated as normal road) */ |
4445
562232eef864
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1100 |
if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir) { |
562232eef864
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1101 |
/* different station owner or wrong orientation */ |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1102 |
trackdirs = TRACKDIR_BIT_NONE; |
3937
60b89172e88e
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1103 |
} else { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1104 |
/* Our station */ |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
1105 |
RoadStop::Type rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1106 |
|
3937
60b89172e88e
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1107 |
if (GetRoadStopType(tile) != rstype) { |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1108 |
/* Wrong station type */ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1109 |
trackdirs = TRACKDIR_BIT_NONE; |
3937
60b89172e88e
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1110 |
} else { |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1111 |
/* Proper station type, check if there is free loading bay */ |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1112 |
if (!_patches.roadveh_queue && IsStandardRoadStopTile(tile) && |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6315
diff
changeset
|
1113 |
!GetRoadStopByTile(tile, rstype)->HasFreeBay()) { |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1114 |
/* Station is full and RV queuing is off */ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1115 |
trackdirs = TRACKDIR_BIT_NONE; |
3092
e790a2dbda83
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1116 |
} |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1117 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1118 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1119 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1120 |
/* The above lookups should be moved to GetTileTrackStatus in the |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1121 |
* future, but that requires more changes to the pathfinder and other |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1122 |
* stuff, probably even more arguments to GTTS. |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1123 |
*/ |
0 | 1124 |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1125 |
/* Remove tracks unreachable from the enter dir */ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1126 |
trackdirs &= _road_enter_dir_to_reachable_trackdirs[enterdir]; |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1127 |
if (trackdirs == TRACKDIR_BIT_NONE) { |
1247 | 1128 |
/* No reachable tracks, so we'll reverse */ |
1129 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1130 |
} |
1131 |
||
1132 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1133 |
/* What happens here?? */ |
0 | 1134 |
v->u.road.reverse_ctr = 0; |
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
1135 |
if (v->tile != tile) { |
1247 | 1136 |
return_track(_road_reverse_table[enterdir]); |
0 | 1137 |
} |
1138 |
} |
|
1139 |
||
1140 |
desttile = v->dest_tile; |
|
1141 |
if (desttile == 0) { |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1142 |
/* We've got no destination, pick a random track */ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1143 |
return_track(PickRandomBit(trackdirs)); |
0 | 1144 |
} |
1145 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1146 |
/* Only one track to choose between? */ |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1147 |
if (!(KillFirstBit2x64(trackdirs))) { |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1148 |
return_track(FindFirstBit2x64(trackdirs)); |
0 | 1149 |
} |
1150 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1151 |
if (_patches.yapf.road_use_yapf) { |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1152 |
Trackdir trackdir = YapfChooseRoadTrack(v, tile, enterdir); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1153 |
if (trackdir != INVALID_TRACKDIR) return_track(trackdir); |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1154 |
return_track(PickRandomBit(trackdirs)); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1155 |
} else if (_patches.new_pathfinding_all) { |
1247 | 1156 |
NPFFindStationOrTileData fstd; |
1157 |
NPFFoundTargetData ftd; |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1158 |
Trackdir trackdir; |
1247 | 1159 |
|
1160 |
NPFFillWithOrderData(&fstd, v); |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1161 |
trackdir = DiagdirToDiagTrackdir(enterdir); |
1247 | 1162 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1163 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1164 |
ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1165 |
if (ftd.best_trackdir == INVALID_TRACKDIR) { |
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1166 |
/* We are already at our target. Just do something |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1167 |
* @todo: maybe display error? |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1168 |
* @todo: go straight ahead if possible? */ |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1169 |
return_track(FindFirstBit2x64(trackdirs)); |
1247 | 1170 |
} else { |
1698
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1171 |
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains |
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1172 |
the direction we need to take to get there, if ftd.best_bird_dist is not 0, |
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1173 |
we did not find our target, but ftd.best_trackdir contains the direction leading |
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1174 |
to the tile closest to our target. */ |
1247 | 1175 |
return_track(ftd.best_trackdir); |
1176 |
} |
|
1177 |
} else { |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1178 |
DiagDirection dir; |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1179 |
|
1247 | 1180 |
if (IsTileType(desttile, MP_STREET)) { |
3793
33cdb5bf7b21
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3645
diff
changeset
|
1181 |
if (GetRoadTileType(desttile) == ROAD_TILE_DEPOT) { |
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1182 |
dir = GetRoadDepotDirection(desttile); |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1183 |
goto do_it; |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1184 |
} |
1247 | 1185 |
} else if (IsTileType(desttile, MP_STATION)) { |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1186 |
/* For drive-through stops we can head for the actual station tile */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1187 |
if (IsStandardRoadStopTile(desttile)) { |
3404
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3338
diff
changeset
|
1188 |
dir = GetRoadStopDir(desttile); |
0 | 1189 |
do_it:; |
1247 | 1190 |
/* When we are heading for a depot or station, we just |
1191 |
* pretend we are heading for the tile in front, we'll |
|
1192 |
* see from there */ |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1193 |
desttile += TileOffsByDiagDir(dir); |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1194 |
if (desttile == tile && trackdirs & _road_exit_dir_to_incoming_trackdirs[dir]) { |
1247 | 1195 |
/* If we are already in front of the |
1196 |
* station/depot and we can get in from here, |
|
1197 |
* we enter */ |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1198 |
return_track(FindFirstBit2x64(trackdirs & _road_exit_dir_to_incoming_trackdirs[dir])); |
1247 | 1199 |
} |
0 | 1200 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1201 |
} |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1202 |
/* Do some pathfinding */ |
1247 | 1203 |
frd.dest = desttile; |
0 | 1204 |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1205 |
best_track = INVALID_TRACKDIR; |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1206 |
uint best_dist = (uint)-1; |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1207 |
uint best_maxlen = (uint)-1; |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1208 |
uint bitmask = (uint)trackdirs; |
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1209 |
for (int i = 0; bitmask != 0; bitmask >>= 1, i++) { |
6330
9b6379040529
(svn r8725) -Fix (r8712): test the first bit of the bitmask, not the nth, as we are shifting the bitmask.
rubidium
parents:
6329
diff
changeset
|
1210 |
if (HASBIT(bitmask, 0)) { |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1211 |
if (best_track == INVALID_TRACKDIR) best_track = (Trackdir)i; // in case we don't find the path, just pick a track |
1247 | 1212 |
frd.maxtracklen = (uint)-1; |
1213 |
frd.mindist = (uint)-1; |
|
3611
5dd134f2cf25
(svn r4506) -Fix: (FS#95) Use the tile hash when pathfinding to a depot. Eats a tiny bit of performance, but the likelihood that the depot is found is greatly increased
celestar
parents:
3560
diff
changeset
|
1214 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd); |
0 | 1215 |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1216 |
if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen)) { |
1247 | 1217 |
best_dist = frd.mindist; |
1218 |
best_maxlen = frd.maxtracklen; |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1219 |
best_track = (Trackdir)i; |
1247 | 1220 |
} |
0 | 1221 |
} |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1222 |
} |
1247 | 1223 |
} |
0 | 1224 |
|
1225 |
found_best_track:; |
|
1226 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1227 |
if (HASBIT(signal, best_track)) return INVALID_TRACKDIR; |
0 | 1228 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1229 |
return best_track; |
0 | 1230 |
} |
1231 |
||
3123 | 1232 |
static uint RoadFindPathToStop(const Vehicle *v, TileIndex tile) |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1233 |
{ |
4271
1a86f0faa2cb
(svn r5899) - Fix [FS#242]: Multistop not working when using NPF (r5033) (mart3p)
Darkvater
parents:
4261
diff
changeset
|
1234 |
uint dist; |
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1235 |
if (_patches.yapf.road_use_yapf) { |
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1236 |
/* use YAPF */ |
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1237 |
dist = YapfRoadVehDistanceToTile(v, tile); |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1238 |
} else { |
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1239 |
/* use NPF */ |
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1240 |
NPFFindStationOrTileData fstd; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1241 |
Trackdir trackdir = GetVehicleTrackdir(v); |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1242 |
assert(trackdir != INVALID_TRACKDIR); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1243 |
|
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1244 |
fstd.dest_coords = tile; |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1245 |
fstd.station_index = INVALID_STATION; // indicates that the destination is a tile, not a station |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1246 |
|
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1247 |
dist = NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE).best_path_dist; |
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1248 |
/* change units from NPF_TILE_LENGTH to # of tiles */ |
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1249 |
if (dist != UINT_MAX) |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1250 |
dist = (dist + NPF_TILE_LENGTH - 1) / NPF_TILE_LENGTH; |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1251 |
} |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1252 |
return dist; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1253 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1254 |
|
6329
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1255 |
enum { |
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1256 |
RDE_NEXT_TILE = 0x80, |
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1257 |
RDE_TURNED = 0x40, |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1258 |
|
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1259 |
/* Start frames for when a vehicle enters a tile/changes its state. |
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1260 |
* The start frame is different for vehicles that turned around or |
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1261 |
* are leaving the depot as the do not start at the edge of the tile */ |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1262 |
RVC_DEFAULT_START_FRAME = 0, |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1263 |
RVC_TURN_AROUND_START_FRAME = 1, |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1264 |
RVC_DEPOT_START_FRAME = 6, |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1265 |
/* Stop frame for a vehicle in a drive-through stop */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1266 |
RVC_DRIVE_THROUGH_STOP_FRAME = 7 |
6329
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1267 |
}; |
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1268 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1269 |
struct RoadDriveEntry { |
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1270 |
byte x, y; |
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
1271 |
}; |
0 | 1272 |
|
1273 |
#include "table/roadveh.h" |
|
1274 |
||
1275 |
static const byte _road_veh_data_1[] = { |
|
1276 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1277 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1278 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1279 |
15, 15, 11, 11 |
|
1280 |
}; |
|
1281 |
||
1401
56d372a75b74
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1282 |
static void RoadVehController(Vehicle *v) |
0 | 1283 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1284 |
Direction new_dir; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1285 |
Direction old_dir; |
0 | 1286 |
RoadDriveEntry rd; |
1287 |
int x,y; |
|
1288 |
uint32 r; |
|
1289 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1290 |
/* decrease counters */ |
0 | 1291 |
v->tick_counter++; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1292 |
if (v->u.road.reverse_ctr != 0) v->u.road.reverse_ctr--; |
0 | 1293 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1294 |
/* handle crashed */ |
0 | 1295 |
if (v->u.road.crashed_ctr != 0) { |
1296 |
RoadVehIsCrashed(v); |
|
1297 |
return; |
|
1298 |
} |
|
1299 |
||
1300 |
RoadVehCheckTrainCrash(v); |
|
1301 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1302 |
/* road vehicle has broken down? */ |
0 | 1303 |
if (v->breakdown_ctr != 0) { |
1304 |
if (v->breakdown_ctr <= 2) { |
|
1305 |
HandleBrokenRoadVeh(v); |
|
1306 |
return; |
|
1307 |
} |
|
1308 |
v->breakdown_ctr--; |
|
1309 |
} |
|
1310 |
||
3431 | 1311 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 1312 |
|
1313 |
ProcessRoadVehOrder(v); |
|
1314 |
HandleRoadVehLoading(v); |
|
1315 |
||
2951 | 1316 |
if (v->current_order.type == OT_LOADING) return; |
0 | 1317 |
|
3959 | 1318 |
if (IsRoadVehInDepot(v)) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1319 |
/* Vehicle is about to leave a depot */ |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1320 |
DiagDirection dir; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1321 |
const RoadDriveEntry* rdp; |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1322 |
Trackdir tdir; |
0 | 1323 |
|
1324 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1325 |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1326 |
dir = GetRoadDepotDirection(v->tile); |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1327 |
v->direction = DiagDirToDir(dir); |
0 | 1328 |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1329 |
tdir = _roadveh_depot_exit_trackdir[dir]; |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1330 |
rdp = _road_drive_data[(_opt.road_side << RVS_DRIVE_SIDE) + tdir]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1331 |
|
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1332 |
x = TileX(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].x & 0xF); |
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1333 |
y = TileY(v->tile) * TILE_SIZE + (rdp[RVC_DEPOT_START_FRAME].y & 0xF); |
0 | 1334 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1335 |
if (RoadVehFindCloseTo(v, x, y, v->direction) != NULL) return; |
0 | 1336 |
|
578
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1337 |
VehicleServiceInDepot(v); |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1338 |
|
0 | 1339 |
StartRoadVehSound(v); |
1340 |
||
1341 |
BeginVehicleMove(v); |
|
1342 |
||
1343 |
v->vehstatus &= ~VS_HIDDEN; |
|
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1344 |
v->u.road.state = tdir; |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1345 |
v->u.road.frame = RVC_DEPOT_START_FRAME; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1346 |
|
0 | 1347 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1348 |
UpdateRoadVehDeltaXY(v); |
|
1349 |
SetRoadVehPosition(v,x,y); |
|
1350 |
||
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4725
diff
changeset
|
1351 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
0 | 1352 |
return; |
1353 |
} |
|
1354 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1355 |
/* Check if vehicle needs to proceed, return if it doesn't */ |
2951 | 1356 |
if (!RoadVehAccelerate(v)) return; |
0 | 1357 |
|
1358 |
if (v->u.road.overtaking != 0) { |
|
1359 |
if (++v->u.road.overtaking_ctr >= 35) |
|
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1360 |
/* If overtaking just aborts at a random moment, we can have a out-of-bound problem, |
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1361 |
* if the vehicle started a corner. To protect that, only allow an abort of |
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
1362 |
* overtake if we are on straight roads */ |
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
1363 |
if (v->u.road.state < RVSB_IN_ROAD_STOP && IsStraightRoadTrackdir((Trackdir)v->u.road.state)) { |
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1364 |
v->u.road.overtaking = 0; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1365 |
} |
0 | 1366 |
} |
1367 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1368 |
/* Save old vehicle position to use at end of move to set viewport area dirty */ |
0 | 1369 |
BeginVehicleMove(v); |
1370 |
||
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
1371 |
if (v->u.road.state == RVSB_WORMHOLE) { |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1372 |
/* Vehicle is entering a depot or is on a bridge or in a tunnel */ |
6479 | 1373 |
GetNewVehiclePosResult gp = GetNewVehiclePos(v); |
0 | 1374 |
|
6194
3d84c2b85f3d
(svn r8609) -Fix: a road vehicle that is very close after another (slower) road vehicle gets its speed reset to 0 when entering a tunnel, which causes a traffic jam outside of the tunnel.
rubidium
parents:
6173
diff
changeset
|
1375 |
const Vehicle *u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction); |
3d84c2b85f3d
(svn r8609) -Fix: a road vehicle that is very close after another (slower) road vehicle gets its speed reset to 0 when entering a tunnel, which causes a traffic jam outside of the tunnel.
rubidium
parents:
6173
diff
changeset
|
1376 |
if (u != NULL && u->cur_speed < v->cur_speed) { |
3d84c2b85f3d
(svn r8609) -Fix: a road vehicle that is very close after another (slower) road vehicle gets its speed reset to 0 when entering a tunnel, which causes a traffic jam outside of the tunnel.
rubidium
parents:
6173
diff
changeset
|
1377 |
v->cur_speed = u->cur_speed; |
0 | 1378 |
return; |
1379 |
} |
|
1380 |
||
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
1381 |
if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1382 |
/* Vehicle has just entered a bridge or tunnel */ |
0 | 1383 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1384 |
UpdateRoadVehDeltaXY(v); |
|
1385 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1386 |
return; |
|
1387 |
} |
|
1388 |
||
1389 |
v->x_pos = gp.x; |
|
1390 |
v->y_pos = gp.y; |
|
1391 |
VehiclePositionChanged(v); |
|
5573
afa6f92a71fd
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5568
diff
changeset
|
1392 |
if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v); |
0 | 1393 |
return; |
1394 |
} |
|
1395 |
||
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1396 |
/* Get move position data for next frame. |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1397 |
* For a drive-through road stop use 'straight road' move data. |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1398 |
* In this case v->u.road.state is masked to give the road stop entry direction. */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1399 |
rd = _road_drive_data[( |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1400 |
(HASBIT(v->u.road.state, RVS_IN_DT_ROAD_STOP) ? v->u.road.state & RVSB_ROAD_STOP_TRACKDIR_MASK : v->u.road.state) + |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1401 |
(_opt.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking][v->u.road.frame + 1]; |
0 | 1402 |
|
6329
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1403 |
if (rd.x & RDE_NEXT_TILE) { |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1404 |
TileIndex tile = v->tile + TileOffsByDiagDir(rd.x & 3); |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1405 |
Trackdir dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3)); |
0 | 1406 |
uint32 r; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1407 |
Direction newdir; |
0 | 1408 |
const RoadDriveEntry *rdp; |
1409 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1410 |
if (dir == INVALID_TRACKDIR) { |
0 | 1411 |
v->cur_speed = 0; |
1412 |
return; |
|
1413 |
} |
|
1414 |
||
1415 |
again: |
|
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
1416 |
if (IsReversingRoadTrackdir(dir)) { |
1247 | 1417 |
/* Turning around */ |
0 | 1418 |
tile = v->tile; |
1419 |
} |
|
1420 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1421 |
/* Get position data for first frame on the new tile */ |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1422 |
rdp = _road_drive_data[(dir + (_opt.road_side << RVS_DRIVE_SIDE)) ^ v->u.road.overtaking]; |
0 | 1423 |
|
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1424 |
x = TileX(tile) * TILE_SIZE + rdp[RVC_DEFAULT_START_FRAME].x; |
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1425 |
y = TileY(tile) * TILE_SIZE + rdp[RVC_DEFAULT_START_FRAME].y; |
0 | 1426 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1427 |
newdir = RoadVehGetSlidingDirection(v, x, y); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1428 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1429 |
|
1430 |
r = VehicleEnterTile(v, tile, x, y); |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
1431 |
if (HASBIT(r, VETS_CANNOT_ENTER)) { |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1432 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1433 |
v->cur_speed = 0; |
1434 |
return; |
|
1435 |
} |
|
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1436 |
/* Try an about turn to re-enter the previous tile */ |
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
1437 |
dir = _road_reverse_table[rd.x & 3]; |
0 | 1438 |
goto again; |
1439 |
} |
|
1440 |
||
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1441 |
if (IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) && IsTileType(v->tile, MP_STATION)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1442 |
if (IsReversingRoadTrackdir(dir) && IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1443 |
/* New direction is trying to turn vehicle around. |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1444 |
* We can't turn at the exit of a road stop so wait.*/ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1445 |
v->cur_speed = 0; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1446 |
return; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1447 |
} |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1448 |
if (IsRoadStop(v->tile)) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1449 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 1450 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1451 |
/* Vehicle is leaving a road stop tile, mark bay as free |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1452 |
* For drive-through stops, only do it if the vehicle stopped here */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1453 |
if (IsStandardRoadStopTile(v->tile) || HASBIT(v->u.road.state, RVS_IS_STOPPING)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1454 |
rs->FreeBay(HASBIT(v->u.road.state, RVS_USING_SECOND_BAY)); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1455 |
CLRBIT(v->u.road.state, RVS_IS_STOPPING); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1456 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1457 |
if (IsStandardRoadStopTile(v->tile)) rs->SetEntranceBusy(false); |
0 | 1458 |
} |
1459 |
} |
|
1460 |
||
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
1461 |
if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) { |
0 | 1462 |
v->tile = tile; |
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1463 |
v->u.road.state = (byte)dir; |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1464 |
v->u.road.frame = RVC_DEFAULT_START_FRAME; |
0 | 1465 |
} |
1466 |
if (newdir != v->direction) { |
|
1467 |
v->direction = newdir; |
|
1468 |
v->cur_speed -= v->cur_speed >> 2; |
|
1469 |
} |
|
1470 |
||
1471 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1472 |
UpdateRoadVehDeltaXY(v); |
|
1473 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1474 |
return; |
|
1475 |
} |
|
1476 |
||
6329
13ccf5062387
(svn r8723) -Codechange: replace yet another couple of magic numbers with enums.
rubidium
parents:
6328
diff
changeset
|
1477 |
if (rd.x & RDE_TURNED) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1478 |
/* Vehicle has finished turning around, it will now head back onto the same tile */ |
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1479 |
Trackdir dir = RoadFindPathToDest(v, v->tile, (DiagDirection)(rd.x & 3)); |
0 | 1480 |
uint32 r; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1481 |
Direction newdir; |
0 | 1482 |
const RoadDriveEntry *rdp; |
1483 |
||
6325
f03f94f4d8fc
(svn r8712) -Codechange/cleanup: replace 'magic' constants with enums, use proper types instead of byte, uint etc., give variables more descriptive names and add some comments.
rubidium
parents:
6317
diff
changeset
|
1484 |
if (dir == INVALID_TRACKDIR) { |
0 | 1485 |
v->cur_speed = 0; |
1486 |
return; |
|
1487 |
} |
|
1488 |
||
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1489 |
rdp = _road_drive_data[(_opt.road_side << RVS_DRIVE_SIDE) + dir]; |
0 | 1490 |
|
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1491 |
x = TileX(v->tile) * TILE_SIZE + rdp[RVC_TURN_AROUND_START_FRAME].x; |
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1492 |
y = TileY(v->tile) * TILE_SIZE + rdp[RVC_TURN_AROUND_START_FRAME].y; |
0 | 1493 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1494 |
newdir = RoadVehGetSlidingDirection(v, x, y); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1495 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1496 |
|
1497 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
1498 |
if (HASBIT(r, VETS_CANNOT_ENTER)) { |
0 | 1499 |
v->cur_speed = 0; |
1500 |
return; |
|
1501 |
} |
|
1502 |
||
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1503 |
v->u.road.state = dir; |
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1504 |
v->u.road.frame = RVC_TURN_AROUND_START_FRAME; |
0 | 1505 |
|
1506 |
if (newdir != v->direction) { |
|
1507 |
v->direction = newdir; |
|
1508 |
v->cur_speed -= v->cur_speed >> 2; |
|
1509 |
} |
|
1510 |
||
1511 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1512 |
UpdateRoadVehDeltaXY(v); |
|
1513 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1514 |
return; |
|
1515 |
} |
|
1516 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1517 |
/* Calculate new position for the vehicle */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1518 |
x = (v->x_pos & ~15) + (rd.x & 15); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1519 |
y = (v->y_pos & ~15) + (rd.y & 15); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1520 |
|
0 | 1521 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1522 |
||
6326
c904c7ea1c8d
(svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents:
6325
diff
changeset
|
1523 |
if (!IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END)) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1524 |
/* Vehicle is not in a road stop. |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1525 |
* Check for another vehicle to overtake */ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1526 |
Vehicle* u = RoadVehFindCloseTo(v, x, y, new_dir); |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1527 |
|
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1528 |
if (u != NULL) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1529 |
/* There is a vehicle in front overtake it if possible */ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1530 |
if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u); |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1531 |
return; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1532 |
} |
0 | 1533 |
} |
1534 |
||
1535 |
old_dir = v->direction; |
|
1536 |
if (new_dir != old_dir) { |
|
1537 |
v->direction = new_dir; |
|
1538 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1539 |
if (old_dir != v->u.road.state) { |
|
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1540 |
/* The vehicle is in a road stop */ |
0 | 1541 |
v->cur_image = GetRoadVehImage(v, new_dir); |
1542 |
UpdateRoadVehDeltaXY(v); |
|
1543 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1544 |
/* Note, return here means that the frame counter is not incremented |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1545 |
* for vehicles changing direction in a road stop. This causes frames to |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1546 |
* be repeated. (XXX) Is this intended? */ |
0 | 1547 |
return; |
1548 |
} |
|
1549 |
} |
|
1550 |
||
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1551 |
/* If the vehicle is in a normal road stop and the frame equals the stop frame OR |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1552 |
* if the vehicle is in a drive-through road stop and this is the destination station |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1553 |
* and it's the correct type of stop (bus or truck) and the frame equals the stop frame... |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1554 |
* (the station test and stop type test ensure that other vehicles, using the road stop as |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1555 |
* a through route, do not stop) */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1556 |
if ((IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) && |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1557 |
_road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_opt.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) || |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1558 |
(IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) && |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1559 |
v->current_order.dest == GetStationIndex(v->tile) && |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
1560 |
GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) && |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1561 |
v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1562 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1563 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1564 |
Station* st = GetStationByTile(v->tile); |
0 | 1565 |
|
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1566 |
/* Vehicle is at the stop position (at a bay) in a road stop. |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1567 |
* Note, if vehicle is loading/unloading it has already been handled, |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1568 |
* so if we get here the vehicle has just arrived or is just ready to leave. */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1569 |
if (v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1570 |
v->current_order.type != OT_GOTO_DEPOT) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1571 |
/* Vehicle has arrived at a bay in a road stop */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1572 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1573 |
if (IsDriveThroughStopTile(v->tile)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1574 |
TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction)); |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
1575 |
RoadStop::Type type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1576 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1577 |
/* Check if next inline bay is free */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1578 |
if (IsDriveThroughStopTile(next_tile) && (GetRoadStopType(next_tile) == type)) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1579 |
RoadStop *rs_n = GetRoadStopByTile(next_tile, type); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1580 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1581 |
if (rs_n->IsFreeBay(HASBIT(v->u.road.state, RVS_USING_SECOND_BAY))) { |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1582 |
/* Bay in next stop along is free - use it */ |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1583 |
ClearSlot(v); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1584 |
rs_n->num_vehicles++; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1585 |
v->u.road.slot = rs_n; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1586 |
v->dest_tile = rs_n->xy; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1587 |
v->u.road.slot_age = 14; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1588 |
|
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1589 |
v->u.road.frame++; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1590 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1591 |
return; |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1592 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1593 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1594 |
} |
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1595 |
|
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6315
diff
changeset
|
1596 |
rs->SetEntranceBusy(false); |
0 | 1597 |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1598 |
v->last_station_visited = GetStationIndex(v->tile); |
0 | 1599 |
|
1600 |
RoadVehArrivesAt(v, st); |
|
1601 |
||
5902
906fea1535ab
(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:
5838
diff
changeset
|
1602 |
v->BeginLoading(); |
0 | 1603 |
|
1604 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
1605 |
if (LoadUnloadVehicle(v, true)) { |
0 | 1606 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
1607 |
MarkRoadVehDirty(v); |
|
1608 |
} |
|
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1609 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1610 |
return; |
1611 |
} |
|
1612 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1613 |
/* Vehicle is ready to leave a bay in a road stop */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1614 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
6316
6ba1efc2b7fc
(svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents:
6315
diff
changeset
|
1615 |
if (rs->IsEntranceBusy()) { |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1616 |
/* Road stop entrance is busy, so wait as there is nowhere else to go */ |
0 | 1617 |
v->cur_speed = 0; |
1618 |
return; |
|
1619 |
} |
|
6589
addf4b6946d0
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6585
diff
changeset
|
1620 |
v->current_order.Free(); |
3123 | 1621 |
ClearSlot(v); |
0 | 1622 |
} |
6335
0c3dc188f099
(svn r8730) -Codechange: more replacements of magic numbers by enums and removal of some (by now) redundant comments.
rubidium
parents:
6331
diff
changeset
|
1623 |
|
6338
0fb4f452873c
(svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents:
6335
diff
changeset
|
1624 |
if (IsStandardRoadStopTile(v->tile)) rs->SetEntranceBusy(true); |
0 | 1625 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1626 |
if (rs == v->u.road.slot) { |
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1627 |
/* We are leaving the correct station */ |
3123 | 1628 |
ClearSlot(v); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1629 |
} else if (v->u.road.slot != NULL) { |
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1630 |
/* We are leaving the wrong station |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1631 |
* XXX The question is .. what to do? Actually we shouldn't be here |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1632 |
* but I guess we need to clear the slot */ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1633 |
DEBUG(ms, 0, "Vehicle %d (index %d) arrived at wrong stop", v->unitnumber, v->index); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1634 |
if (v->tile != v->dest_tile) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1635 |
DEBUG(ms, 2, " current tile 0x%X is not destination tile 0x%X. Route problem", v->tile, v->dest_tile); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1636 |
} |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1637 |
if (v->dest_tile != v->u.road.slot->xy) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1638 |
DEBUG(ms, 2, " stop tile 0x%X is not destination tile 0x%X. Multistop desync", v->u.road.slot->xy, v->dest_tile); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1639 |
} |
3123 | 1640 |
if (v->current_order.type != OT_GOTO_STATION) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1641 |
DEBUG(ms, 2, " current order type (%d) is not OT_GOTO_STATION", v->current_order.type); |
3123 | 1642 |
} else { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1643 |
if (v->current_order.dest != st->index) |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1644 |
DEBUG(ms, 2, " current station %d is not target station in current_order.station (%d)", |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1645 |
st->index, v->current_order.dest); |
3123 | 1646 |
} |
1647 |
||
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1648 |
DEBUG(ms, 2, " force a slot clearing"); |
3123 | 1649 |
ClearSlot(v); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1650 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1651 |
|
0 | 1652 |
StartRoadVehSound(v); |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1653 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1654 |
} |
1655 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1656 |
/* Check tile position conditions - i.e. stop position in depot, |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1657 |
* entry onto bridge or into tunnel */ |
0 | 1658 |
r = VehicleEnterTile(v, v->tile, x, y); |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
1659 |
if (HASBIT(r, VETS_CANNOT_ENTER)) { |
0 | 1660 |
v->cur_speed = 0; |
1661 |
return; |
|
1662 |
} |
|
1663 |
||
6315
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1664 |
/* Move to next frame unless vehicle arrived at a stop position |
0f38464910a1
(svn r8692) -Cleanup: add comments to RoadVehController. Patch by mart3p.
rubidium
parents:
6195
diff
changeset
|
1665 |
* in a depot or entered a tunnel/bridge */ |
6317
c73bda71ac16
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents:
6316
diff
changeset
|
1666 |
if (!HASBIT(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++; |
0 | 1667 |
|
1668 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1669 |
UpdateRoadVehDeltaXY(v); |
|
1670 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1671 |
} |
|
1672 |
||
1673 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1674 |
{ |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1675 |
if (_age_cargo_skip_counter != 0) return; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1676 |
if (v->cargo_days != 255) v->cargo_days++; |
0 | 1677 |
} |
1678 |
||
1679 |
void RoadVeh_Tick(Vehicle *v) |
|
1680 |
{ |
|
1681 |
AgeRoadVehCargo(v); |
|
1401
56d372a75b74
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1682 |
RoadVehController(v); |
0 | 1683 |
} |
1684 |
||
1685 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1686 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1687 |
const Depot* depot; |
0 | 1688 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1689 |
if (_patches.servint_roadveh == 0) return; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1690 |
if (!VehicleNeedsService(v)) return; |
3431 | 1691 |
if (v->vehstatus & VS_STOPPED) return; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1692 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1693 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1694 |
/* Don't interfere with a depot visit scheduled by the user, or a |
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1695 |
* depot visit by the order list. */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1696 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1697 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 1698 |
return; |
1699 |
||
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1700 |
/* If we already got a slot at a stop, use that FIRST, and go to a depot later */ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1701 |
if (v->u.road.slot != NULL) return; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1702 |
|
4529
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1703 |
if (IsRoadVehInDepot(v)) { |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1704 |
VehicleServiceInDepot(v); |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1705 |
return; |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1706 |
} |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1707 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1708 |
/* XXX If we already have a depot order, WHY do we search over and over? */ |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1709 |
depot = FindClosestRoadDepot(v); |
0 | 1710 |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1711 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
1520
c85dc79795e0
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1712 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1713 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1714 |
v->current_order.flags = 0; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1715 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1716 |
} |
1717 |
return; |
|
1718 |
} |
|
1719 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1720 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1721 |
v->current_order.flags & OF_NON_STOP && |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1722 |
!CHANCE16(1, 20)) { |
0 | 1723 |
return; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1724 |
} |
0 | 1725 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1726 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1727 |
v->current_order.flags = OF_NON_STOP; |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1728 |
v->current_order.dest = depot->index; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1729 |
v->dest_tile = depot->xy; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1730 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1731 |
} |
1732 |
||
1733 |
void OnNewDay_RoadVeh(Vehicle *v) |
|
1734 |
{ |
|
1735 |
int32 cost; |
|
1736 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1737 |
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1738 |
if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v); |
0 | 1739 |
|
1740 |
AgeVehicle(v); |
|
1741 |
CheckIfRoadVehNeedsService(v); |
|
1742 |
||
3140
69cb681c6d86
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1743 |
CheckOrders(v); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1744 |
|
6889
f7f6d9cb07a0
(svn r9523) -Cleanup: doxygen changes. Time to take care of "R"
belugas
parents:
6683
diff
changeset
|
1745 |
/* Current slot has expired */ |
3481
5425ba1d135a
(svn r4326) Only reduce the slot age of a vehicle if it has a slot assigned
tron
parents:
3431
diff
changeset
|
1746 |
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot != NULL && v->u.road.slot_age-- == 0) { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1747 |
DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X", |
3431 | 1748 |
v->unitnumber, v->index, v->u.road.slot->xy); |
3123 | 1749 |
ClearSlot(v); |
1750 |
} |
|
1751 |
||
3236 | 1752 |
if (v->vehstatus & VS_STOPPED) return; |
1753 |
||
0 | 1754 |
/* update destination */ |
3431 | 1755 |
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) { |
4527
b18634a31a4a
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1756 |
Station* st = GetStation(v->current_order.dest); |
6655
951b0ba32eb1
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6642
diff
changeset
|
1757 |
RoadStop* rs = st->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1758 |
RoadStop* best = NULL; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1759 |
|
3123 | 1760 |
if (rs != NULL) { |
6161
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1761 |
/* We try to obtain a slot if: |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1762 |
* 1) we're reasonably close to the primary road stop |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1763 |
* or |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1764 |
* 2) we're somewhere close to the station rectangle (to make sure we do assign |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1765 |
* slots even if the station and its road stops are incredibly spread out) |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1766 |
*/ |
754debc55207
(svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents:
6127
diff
changeset
|
1767 |
if (DistanceManhattan(v->tile, rs->xy) < 16 || st->rect.PtInExtendedRect(TileX(v->tile), TileY(v->tile), 2)) { |
3431 | 1768 |
uint dist, badness; |
1769 |
uint minbadness = UINT_MAX; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1770 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1771 |
DEBUG(ms, 2, "Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)", |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1772 |
v->unitnumber, v->index, st->index, st->xy |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1773 |
); |
3123 | 1774 |
/* Now we find the nearest road stop that has a free slot */ |
3431 | 1775 |
for (; rs != NULL; rs = rs->next) { |
1776 |
dist = RoadFindPathToStop(v, rs->xy); |
|
1777 |
if (dist == UINT_MAX) { |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1778 |
DEBUG(ms, 4, " stop 0x%X is unreachable, not treating further", rs->xy); |
3123 | 1779 |
continue; |
1780 |
} |
|
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1781 |
badness = (rs->num_vehicles + 1) * (rs->num_vehicles + 1) + dist; |
3123 | 1782 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1783 |
DEBUG(ms, 4, " stop 0x%X has %d vehicle%s waiting", rs->xy, rs->num_vehicles, rs->num_vehicles == 1 ? "":"s"); |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1784 |
DEBUG(ms, 4, " distance is %u", dist); |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1785 |
DEBUG(ms, 4, " badness %u", badness); |
3431 | 1786 |
|
1787 |
if (badness < minbadness) { |
|
1788 |
best = rs; |
|
1789 |
minbadness = badness; |
|
3123 | 1790 |
} |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1791 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1792 |
|
3431 | 1793 |
if (best != NULL) { |
1794 |
best->num_vehicles++; |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1795 |
DEBUG(ms, 3, "Assigned to stop 0x%X", best->xy); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1796 |
|
3431 | 1797 |
v->u.road.slot = best; |
1798 |
v->dest_tile = best->xy; |
|
1799 |
v->u.road.slot_age = 14; |
|
3123 | 1800 |
} else { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1801 |
DEBUG(ms, 3, "Could not find a suitable stop"); |
3123 | 1802 |
} |
1803 |
} else { |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1804 |
DEBUG(ms, 5, "Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%X)", |
3123 | 1805 |
v->unitnumber, v->index, st->index, st->xy); |
1295
5dc810674581
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1806 |
} |
3123 | 1807 |
} else { |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1808 |
DEBUG(ms, 4, "No road stop for vehicle %d (index %d) at station %d (0x%X)", |
3123 | 1809 |
v->unitnumber, v->index, st->index, st->xy); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1810 |
} |
0 | 1811 |
} |
1812 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1813 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1814 |
|
1815 |
v->profit_this_year -= cost >> 8; |
|
1816 |
||
1817 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1818 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1819 |
||
1820 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1151
614cbcb5b9fe
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
1821 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1822 |
} |
1823 |
||
1824 |
||
6573 | 1825 |
void RoadVehiclesYearlyLoop() |
0 | 1826 |
{ |
1827 |
Vehicle *v; |
|
1828 |
||
1829 |
FOR_ALL_VEHICLES(v) { |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1830 |
if (v->type == VEH_ROAD) { |
0 | 1831 |
v->profit_last_year = v->profit_this_year; |
1832 |
v->profit_this_year = 0; |
|
1833 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1834 |
} |
|
1835 |
} |
|
1836 |
} |
|
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1837 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1838 |
/** Refit a road vehicle to the specified cargo type |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1839 |
* @param tile unused |
6979
d194d25020e7
(svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents:
6949
diff
changeset
|
1840 |
* @param flags operation to perform |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1841 |
* @param p1 Vehicle ID of the vehicle to refit |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1842 |
* @param p2 Bitstuffed elements |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1843 |
* - p2 = (bit 0-7) - the new cargo type to refit to |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1844 |
* - p2 = (bit 8-15) - the new cargo subtype to refit to |
7042
d841fb0d8e9a
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
7040
diff
changeset
|
1845 |
* - p2 = (bit 16) - refit only this vehicle (ignored) |
d841fb0d8e9a
(svn r9742) -Fix (r9689) [FS#739]: Fix cloning with refit costs again, hopefully for good this time.
maedhros
parents:
7040
diff
changeset
|
1846 |
* @return cost of refit or error |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1847 |
*/ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1848 |
int32 CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1849 |
{ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1850 |
Vehicle *v; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1851 |
int32 cost; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1852 |
CargoID new_cid = GB(p2, 0, 8); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1853 |
byte new_subtype = GB(p2, 8, 8); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1854 |
uint16 capacity = CALLBACK_FAILED; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1855 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1856 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1857 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1858 |
v = GetVehicle(p1); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1859 |
|
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6574
diff
changeset
|
1860 |
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1861 |
if (!IsRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1862 |
|
6642
2e690e6fdc03
(svn r9259) -Codechange: NUM_CARGO isn't a valid cargo type...
peter1138
parents:
6589
diff
changeset
|
1863 |
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1864 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1865 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1866 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1867 |
if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1868 |
/* Back up the cargo type */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1869 |
CargoID temp_cid = v->cargo_type; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1870 |
byte temp_subtype = v->cargo_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1871 |
v->cargo_type = new_cid; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1872 |
v->cargo_subtype = new_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1873 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1874 |
/* Check the refit capacity callback */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1875 |
capacity = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1876 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1877 |
/* Restore the original cargo type */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1878 |
v->cargo_type = temp_cid; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1879 |
v->cargo_subtype = temp_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1880 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1881 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1882 |
if (capacity == CALLBACK_FAILED) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1883 |
/* callback failed or not used, use default capacity */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1884 |
const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1885 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1886 |
CargoID old_cid = rvi->cargo_type; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1887 |
/* normally, the capacity depends on the cargo type, a vehicle can |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1888 |
* carry twice as much mail/goods as normal cargo, and four times as |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1889 |
* many passengers |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1890 |
*/ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1891 |
capacity = rvi->capacity; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1892 |
switch (old_cid) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1893 |
case CT_PASSENGERS: break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1894 |
case CT_MAIL: |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1895 |
case CT_GOODS: capacity *= 2; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1896 |
default: capacity *= 4; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1897 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1898 |
switch (new_cid) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1899 |
case CT_PASSENGERS: break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1900 |
case CT_MAIL: |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1901 |
case CT_GOODS: capacity /= 2; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1902 |
default: capacity /= 4; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1903 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1904 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1905 |
_returned_refit_capacity = capacity; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1906 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1907 |
cost = 0; |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4739
diff
changeset
|
1908 |
if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) { |
4544
b2d5ad597e4d
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4529
diff
changeset
|
1909 |
cost = GetRefitCost(v->engine_type); |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1910 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1911 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1912 |
if (flags & DC_EXEC) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1913 |
v->cargo_cap = capacity; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1914 |
v->cargo_count = (v->cargo_type == new_cid) ? min(capacity, v->cargo_count) : 0; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1915 |
v->cargo_type = new_cid; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1916 |
v->cargo_subtype = new_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1917 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1918 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1919 |
RebuildVehicleLists(); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1920 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1921 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1922 |
return cost; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1923 |
} |