author | glx |
Mon, 20 Aug 2007 15:17:24 +0000 | |
branch | 0.5 |
changeset 5536 | 11b3dd55f6f4 |
parent 5520 | 82988aae1562 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
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
|
3 |
#include "stdafx.h" |
3431 | 4 |
#include <limits.h> |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1793
diff
changeset
|
5 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
6 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
7 |
#include "functions.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3140
diff
changeset
|
8 |
#include "road_map.h" |
3959 | 9 |
#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
|
10 |
#include "station_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
11 |
#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
|
12 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
13 |
#include "tile.h" |
0 | 14 |
#include "vehicle.h" |
15 |
#include "engine.h" |
|
16 |
#include "command.h" |
|
17 |
#include "station.h" |
|
18 |
#include "news.h" |
|
19 |
#include "pathfind.h" |
|
1247 | 20 |
#include "npf.h" |
0 | 21 |
#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
|
22 |
#include "sound.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
23 |
#include "depot.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
|
24 |
#include "tunnel_map.h" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
25 |
#include "vehicle_gui.h" |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
26 |
#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
|
27 |
#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
|
28 |
#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
|
29 |
#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
|
30 |
#include "yapf/yapf.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4244
diff
changeset
|
31 |
#include "date.h" |
0 | 32 |
|
33 |
static const uint16 _roadveh_images[63] = { |
|
34 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
35 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
36 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
37 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
38 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
39 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
40 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
41 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
42 |
}; |
|
43 |
||
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
0, 0, 0, 8, 8, 8, 8 |
0 | 53 |
}; |
54 |
||
55 |
||
56 |
static const uint16 _road_veh_fp_ax_and[4] = { |
|
57 |
0x1009, 0x16, 0x520, 0x2A00 |
|
58 |
}; |
|
59 |
||
60 |
static const byte _road_reverse_table[4] = { |
|
61 |
6, 7, 14, 15 |
|
62 |
}; |
|
63 |
||
64 |
static const uint16 _road_pf_table_3[4] = { |
|
65 |
0x910, 0x1600, 0x2005, 0x2A |
|
66 |
}; |
|
67 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
68 |
int GetRoadVehImage(const Vehicle* v, Direction direction) |
0 | 69 |
{ |
70 |
int img = v->spritenum; |
|
71 |
int image; |
|
72 |
||
73 |
if (is_custom_sprite(img)) { |
|
74 |
image = GetCustomVehicleSprite(v, direction); |
|
2989 | 75 |
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
|
76 |
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index; |
0 | 77 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
78 |
|
0 | 79 |
image = direction + _roadveh_images[img]; |
2989 | 80 |
if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img]; |
0 | 81 |
return image; |
82 |
} |
|
83 |
||
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2464
diff
changeset
|
84 |
void DrawRoadVehEngine(int x, int y, EngineID engine, uint32 image_ormod) |
0 | 85 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
86 |
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
|
87 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
88 |
if (is_custom_sprite(spritenum)) { |
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
89 |
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
|
90 |
|
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
|
91 |
if (sprite != 0) { |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
92 |
DrawSprite(sprite | image_ormod, x, y); |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
93 |
return; |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
94 |
} |
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
|
95 |
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
|
96 |
} |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
97 |
DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y); |
0 | 98 |
} |
99 |
||
2817 | 100 |
static int32 EstimateRoadVehCost(EngineID engine_type) |
0 | 101 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
102 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 103 |
} |
104 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
105 |
/** 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
|
106 |
* @param tile tile of depot where road vehicle is built |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
107 |
* @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
|
108 |
* @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
|
109 |
*/ |
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
|
110 |
int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 111 |
{ |
112 |
int32 cost; |
|
113 |
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
|
114 |
UnitID unit_num; |
0 | 115 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
116 |
|
5215
439d5ca71311
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5211
diff
changeset
|
117 |
if (!IsEngineBuildable(p1, VEH_Road, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE); |
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
|
118 |
|
0 | 119 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
120 |
||
121 |
cost = EstimateRoadVehCost(p1); |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
122 |
if (flags & DC_QUERY_COST) return cost; |
0 | 123 |
|
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
|
124 |
/* 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
|
125 |
* 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
|
126 |
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
|
127 |
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
|
128 |
|
0 | 129 |
v = AllocateVehicle(); |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
130 |
if (v == NULL || IsOrderPoolFull()) |
0 | 131 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
132 |
||
133 |
/* find the first free roadveh id */ |
|
4095
55a5642143f1
(svn r5427) - Codechange: testing for "== true" is redundant.
peter1138
parents:
4077
diff
changeset
|
134 |
unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_Road); |
0 | 135 |
if (unit_num > _patches.max_roadveh) |
136 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
137 |
||
138 |
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
|
139 |
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
|
140 |
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
|
141 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
142 |
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
|
143 |
|
0 | 144 |
v->unitnumber = unit_num; |
145 |
v->direction = 0; |
|
146 |
v->owner = _current_player; |
|
147 |
||
148 |
v->tile = tile; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3630
diff
changeset
|
149 |
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3630
diff
changeset
|
150 |
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
0 | 151 |
v->x_pos = x; |
152 |
v->y_pos = y; |
|
153 |
v->z_pos = GetSlopeZ(x,y); |
|
154 |
v->z_height = 6; |
|
155 |
||
156 |
v->u.road.state = 254; |
|
157 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
158 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
v->cargo_cap = rvi->capacity; |
0 | 163 |
// v->cargo_count = 0; |
164 |
v->value = cost; |
|
165 |
// v->day_counter = 0; |
|
166 |
// v->next_order_param = v->next_order = 0; |
|
167 |
// v->load_unload_time_rem = 0; |
|
168 |
// v->progress = 0; |
|
169 |
||
170 |
// v->u.road.unk2 = 0; |
|
171 |
// v->u.road.overtaking = 0; |
|
172 |
||
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
173 |
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
|
174 |
v->max_speed = rvi->max_speed; |
0 | 175 |
v->engine_type = (byte)p1; |
176 |
||
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
177 |
e = GetEngine(p1); |
0 | 178 |
v->reliability = e->reliability; |
179 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
180 |
v->max_age = e->lifelength * 366; |
|
2564 | 181 |
_new_vehicle_id = v->index; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
182 |
|
0 | 183 |
v->string_id = STR_SV_ROADVEH_NAME; |
184 |
||
185 |
v->service_interval = _patches.servint_roadveh; |
|
186 |
||
187 |
v->date_of_last_service = _date; |
|
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
188 |
v->build_year = _cur_year; |
0 | 189 |
|
190 |
v->type = VEH_Road; |
|
191 |
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
|
192 |
v->random_bits = VehicleRandomBits(); |
0 | 193 |
|
194 |
VehiclePositionChanged(v); |
|
4574
497540b4a75f
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4559
diff
changeset
|
195 |
GetPlayer(_current_player)->num_engines[p1]++; |
0 | 196 |
|
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4725
diff
changeset
|
197 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
588 | 198 |
RebuildVehicleLists(); |
0 | 199 |
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
|
200 |
if (IsLocalPlayer()) |
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
201 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
0 | 202 |
} |
203 |
||
204 |
return cost; |
|
205 |
} |
|
206 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
207 |
/** 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
|
208 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
209 |
* @param p1 road vehicle ID to start/stop |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
210 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
211 |
*/ |
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
|
212 |
int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 213 |
{ |
214 |
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
|
215 |
uint16 callback; |
0 | 216 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
217 |
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
|
218 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
219 |
v = GetVehicle(p1); |
0 | 220 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
221 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 222 |
|
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
|
223 |
/* 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
|
224 |
* 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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
} |
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
|
230 |
|
0 | 231 |
if (flags & DC_EXEC) { |
3959 | 232 |
if (IsRoadVehInDepotStopped(v)) { |
3139
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
233 |
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
|
234 |
} |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
235 |
|
0 | 236 |
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
|
237 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 238 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
239 |
} |
|
240 |
||
241 |
return 0; |
|
242 |
} |
|
243 |
||
3123 | 244 |
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
|
245 |
{ |
3123 | 246 |
RoadStop *rs = v->u.road.slot; |
247 |
if (v->u.road.slot == NULL) return; |
|
248 |
||
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
|
249 |
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
|
250 |
v->u.road.slot_age = 0; |
3123 | 251 |
|
3431 | 252 |
assert(rs->num_vehicles != 0); |
253 |
rs->num_vehicles--; |
|
254 |
||
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
255 |
DEBUG(ms, 3) ("Multistop: 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
|
256 |
} |
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
|
257 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
258 |
/** 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
|
259 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
260 |
* @param p1 vehicle ID to be sold |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
261 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
262 |
*/ |
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
|
263 |
int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 264 |
{ |
265 |
Vehicle *v; |
|
266 |
||
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
267 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
268 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
269 |
v = GetVehicle(p1); |
0 | 270 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
271 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 272 |
|
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
|
273 |
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
|
274 |
|
3959 | 275 |
if (!IsRoadVehInDepotStopped(v)) { |
0 | 276 |
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
|
277 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
278 |
|
0 | 279 |
if (flags & DC_EXEC) { |
280 |
// Invalidate depot |
|
281 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 282 |
RebuildVehicleLists(); |
0 | 283 |
InvalidateWindow(WC_COMPANY, v->owner); |
284 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
3123 | 285 |
ClearSlot(v); |
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
|
286 |
DeleteDepotHighlightOfVehicle(v); |
0 | 287 |
DeleteVehicle(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
|
288 |
if (IsLocalPlayer()) InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); |
0 | 289 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
290 |
|
0 | 291 |
return -(int32)v->value; |
292 |
} |
|
293 |
||
294 |
typedef struct RoadFindDepotData { |
|
295 |
uint best_length; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
296 |
TileIndex tile; |
0 | 297 |
byte owner; |
298 |
} RoadFindDepotData; |
|
299 |
||
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
300 |
static const DiagDirection _road_pf_directions[] = { |
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
301 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, 255, 255, |
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
302 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, 255, 255 |
0 | 303 |
}; |
304 |
||
3137 | 305 |
static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, int track, uint length, byte* state) |
0 | 306 |
{ |
3137 | 307 |
RoadFindDepotData* rfdd = data; |
308 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
309 |
tile += TileOffsByDiagDir(_road_pf_directions[track]); |
0 | 310 |
|
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
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
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
|
316 |
rfdd->tile = tile; |
0 | 317 |
} |
318 |
return false; |
|
319 |
} |
|
320 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
321 |
static const Depot* FindClosestRoadDepot(const Vehicle* v) |
0 | 322 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
323 |
TileIndex tile = v->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
324 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
325 |
if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v); |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
326 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
} else if (_patches.new_pathfinding_all) { |
1247 | 331 |
NPFFoundTargetData ftd; |
332 |
/* See where we are now */ |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
333 |
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
|
334 |
|
5520
82988aae1562
(svn r10374) [0.5] -Backport from trunk (r10333, r10336, r10337, r10345, 10346, 10368):
rubidium
parents:
5430
diff
changeset
|
335 |
ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, v->tile, ReverseTrackdir(trackdir), TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE, 0); |
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
|
336 |
if (ftd.best_bird_dist == 0) { |
1247 | 337 |
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
|
338 |
} else { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
339 |
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
|
340 |
} |
1247 | 341 |
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ |
342 |
} else { |
|
343 |
RoadFindDepotData rfdd; |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
344 |
DiagDirection i; |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
345 |
|
1247 | 346 |
rfdd.owner = v->owner; |
347 |
rfdd.best_length = (uint)-1; |
|
0 | 348 |
|
1247 | 349 |
/* search in all directions */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
350 |
for (i = 0; i != 4; i++) { |
3137 | 351 |
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
|
352 |
} |
0 | 353 |
|
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
|
354 |
if (rfdd.best_length == (uint)-1) return NULL; |
0 | 355 |
|
1247 | 356 |
return GetDepotByTile(rfdd.tile); |
357 |
} |
|
0 | 358 |
} |
359 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
360 |
/** 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
|
361 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
362 |
* @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
|
363 |
* @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
|
364 |
* - 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
|
365 |
* - 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
|
366 |
*/ |
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
|
367 |
int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 368 |
{ |
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
|
369 |
Vehicle *v; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
370 |
const Depot *dep; |
0 | 371 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
372 |
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
|
373 |
/* 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
|
374 |
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
9345e0569655
(svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents:
4544
diff
changeset
|
375 |
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
|
376 |
} |
3a70624c40eb
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
377 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
378 |
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
|
379 |
|
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
380 |
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
|
381 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
382 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 383 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
384 |
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
|
385 |
|
4526 | 386 |
if (IsRoadVehInDepot(v)) return CMD_ERROR; |
387 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
388 |
/* If the current orders are already goto-depot */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
389 |
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
|
390 |
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
|
391 |
/* 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
|
392 |
* 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
|
393 |
* 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
|
394 |
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
|
395 |
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
|
396 |
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
|
397 |
} |
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
|
398 |
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
|
399 |
} |
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
|
400 |
|
4506
0d8fcc0a4e49
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
401 |
if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders |
0 | 402 |
if (flags & DC_EXEC) { |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
403 |
/* 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
|
404 |
* 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
|
405 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
0 | 406 |
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
|
407 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
408 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
409 |
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
|
410 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 411 |
} |
412 |
return 0; |
|
413 |
} |
|
414 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
415 |
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
|
416 |
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
0 | 417 |
|
418 |
if (flags & DC_EXEC) { |
|
3236 | 419 |
ClearSlot(v); |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
420 |
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
v->current_order.dest = dep->index; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
425 |
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
|
426 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 427 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
428 |
|
0 | 429 |
return 0; |
430 |
} |
|
431 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
432 |
/** 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
|
433 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
434 |
* @param p1 vehicle ID to turn |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
435 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
436 |
*/ |
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
|
437 |
int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 438 |
{ |
439 |
Vehicle *v; |
|
440 |
||
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
441 |
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
|
442 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
443 |
v = GetVehicle(p1); |
0 | 444 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
445 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 446 |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
447 |
if (v->vehstatus & (VS_HIDDEN | VS_STOPPED) || |
0 | 448 |
v->u.road.crashed_ctr != 0 || |
449 |
v->breakdown_ctr != 0 || |
|
450 |
v->u.road.overtaking != 0 || |
|
451 |
v->cur_speed < 5) { |
|
452 |
return CMD_ERROR; |
|
453 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
454 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
455 |
if (flags & DC_EXEC) v->u.road.reverse_ctr = 180; |
0 | 456 |
|
457 |
return 0; |
|
458 |
} |
|
459 |
||
460 |
||
461 |
static void MarkRoadVehDirty(Vehicle *v) |
|
462 |
{ |
|
463 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
464 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
465 |
} |
|
466 |
||
467 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
468 |
{ |
|
469 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
470 |
static const uint32 _delta_xy_table[8] = { |
|
471 |
MKIT(3, 3, -1, -1), |
|
472 |
MKIT(3, 7, -1, -3), |
|
473 |
MKIT(3, 3, -1, -1), |
|
474 |
MKIT(7, 3, -3, -1), |
|
475 |
MKIT(3, 3, -1, -1), |
|
476 |
MKIT(3, 7, -1, -3), |
|
477 |
MKIT(3, 3, -1, -1), |
|
478 |
MKIT(7, 3, -3, -1), |
|
479 |
}; |
|
480 |
#undef MKIT |
|
481 |
uint32 x = _delta_xy_table[v->direction]; |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
482 |
v->x_offs = GB(x, 0, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
483 |
v->y_offs = GB(x, 8, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
484 |
v->sprite_width = GB(x, 16, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
485 |
v->sprite_height = GB(x, 24, 8); |
0 | 486 |
} |
487 |
||
488 |
static void ClearCrashedStation(Vehicle *v) |
|
489 |
{ |
|
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
|
490 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 491 |
|
492 |
// mark station as not busy |
|
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
|
493 |
CLRBIT(rs->status, 7); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
494 |
|
0 | 495 |
// free parking bay |
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
|
496 |
SETBIT(rs->status, HASBIT(v->u.road.state, 1) ? 1 : 0); |
0 | 497 |
} |
498 |
||
499 |
static void RoadVehDelete(Vehicle *v) |
|
500 |
{ |
|
501 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
502 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
503 |
|
588 | 504 |
RebuildVehicleLists(); |
0 | 505 |
InvalidateWindow(WC_COMPANY, v->owner); |
506 |
||
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
|
507 |
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
|
508 |
|
0 | 509 |
BeginVehicleMove(v); |
510 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
511 |
|
3123 | 512 |
ClearSlot(v); |
0 | 513 |
DeleteVehicle(v); |
514 |
} |
|
515 |
||
516 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
517 |
{ |
|
518 |
byte new_z, old_z; |
|
519 |
||
520 |
// need this hint so it returns the right z coordinate on bridges. |
|
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
521 |
_get_z_hint = 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
|
522 |
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
|
523 |
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
|
524 |
new_z = GetSlopeZ(x, y); |
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
525 |
_get_z_hint = 0; |
0 | 526 |
|
527 |
old_z = v->z_pos; |
|
528 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
529 |
|
0 | 530 |
VehiclePositionChanged(v); |
531 |
EndVehicleMove(v); |
|
532 |
return old_z; |
|
533 |
} |
|
534 |
||
535 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
536 |
{ |
|
3160 | 537 |
static const DirDiff delta[] = { |
538 |
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
539 |
}; |
|
540 |
||
0 | 541 |
uint32 r = Random(); |
3160 | 542 |
|
543 |
v->direction = ChangeDir(v->direction, delta[r & 3]); |
|
0 | 544 |
BeginVehicleMove(v); |
545 |
UpdateRoadVehDeltaXY(v); |
|
546 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
547 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
548 |
} |
|
549 |
||
550 |
static void RoadVehIsCrashed(Vehicle *v) |
|
551 |
{ |
|
552 |
v->u.road.crashed_ctr++; |
|
553 |
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
|
554 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 555 |
} 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
|
556 |
if ((v->tick_counter & 7) == 0) RoadVehSetRandomDirection(v); |
0 | 557 |
} else if (v->u.road.crashed_ctr >= 2220) { |
558 |
RoadVehDelete(v); |
|
559 |
} |
|
560 |
} |
|
561 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
562 |
static void* EnumCheckRoadVehCrashTrain(Vehicle* v, void* data) |
0 | 563 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
564 |
const Vehicle* u = data; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
565 |
|
2989 | 566 |
return |
567 |
v->type == VEH_Train && |
|
568 |
myabs(v->z_pos - u->z_pos) <= 6 && |
|
569 |
myabs(v->x_pos - u->x_pos) <= 4 && |
|
570 |
myabs(v->y_pos - u->y_pos) <= 4 ? |
|
571 |
v : NULL; |
|
0 | 572 |
} |
573 |
||
574 |
static void RoadVehCrash(Vehicle *v) |
|
575 |
{ |
|
576 |
uint16 pass; |
|
577 |
||
578 |
v->u.road.crashed_ctr++; |
|
579 |
v->vehstatus |= VS_CRASHED; |
|
3236 | 580 |
ClearSlot(v); |
0 | 581 |
|
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
|
582 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 583 |
|
584 |
pass = 1; |
|
2989 | 585 |
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count; |
0 | 586 |
v->cargo_count = 0; |
2951 | 587 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
588 |
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
|
589 |
AddNewsItem( |
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
590 |
(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
|
591 |
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE, |
0 | 592 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
593 |
v->index, |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
594 |
0 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
595 |
); |
0 | 596 |
|
597 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 598 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 599 |
} |
600 |
||
601 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
602 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
603 |
TileIndex tile; |
0 | 604 |
|
2951 | 605 |
if (v->u.road.state == 255) return; |
0 | 606 |
|
607 |
tile = v->tile; |
|
608 |
||
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
|
609 |
if (!IsLevelCrossingTile(tile)) return; |
0 | 610 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
611 |
if (VehicleFromPos(tile, v, EnumCheckRoadVehCrashTrain) != NULL) |
0 | 612 |
RoadVehCrash(v); |
613 |
} |
|
614 |
||
615 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
616 |
{ |
|
617 |
if (v->breakdown_ctr != 1) { |
|
618 |
v->breakdown_ctr = 1; |
|
619 |
v->cur_speed = 0; |
|
620 |
||
621 |
if (v->breakdowns_since_last_service != 255) |
|
622 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
623 |
|
0 | 624 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
625 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
626 |
|
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
627 |
if (!PlayVehicleSound(v, VSE_BREAKDOWN)) { |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
628 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
629 |
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
|
630 |
} |
0 | 631 |
|
632 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
633 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
2989 | 634 |
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; |
0 | 635 |
} |
636 |
} |
|
637 |
||
2989 | 638 |
if ((v->tick_counter & 1) == 0) { |
639 |
if (--v->breakdown_delay == 0) { |
|
0 | 640 |
v->breakdown_ctr = 0; |
641 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
642 |
} |
|
643 |
} |
|
644 |
} |
|
645 |
||
646 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
647 |
{ |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
648 |
const Order *order; |
0 | 649 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
650 |
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
|
651 |
case OT_GOTO_DEPOT: |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
652 |
// Let a depot order in the orderlist interrupt. |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
653 |
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
|
654 |
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
|
655 |
!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
|
656 |
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
|
657 |
} |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
658 |
break; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
659 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
660 |
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
|
661 |
case OT_LEAVESTATION: |
0 | 662 |
return; |
4351
63ae31104f07
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4344
diff
changeset
|
663 |
|
63ae31104f07
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4344
diff
changeset
|
664 |
default: break; |
0 | 665 |
} |
666 |
||
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
667 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 668 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
669 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 670 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
671 |
if (order == NULL) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
672 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
673 |
v->current_order.flags = 0; |
0 | 674 |
v->dest_tile = 0; |
3123 | 675 |
ClearSlot(v); |
0 | 676 |
return; |
677 |
} |
|
678 |
||
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
|
679 |
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
|
680 |
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
|
681 |
order->dest == v->current_order.dest) { |
0 | 682 |
return; |
2951 | 683 |
} |
0 | 684 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
685 |
v->current_order = *order; |
0 | 686 |
|
4179 | 687 |
switch (order->type) { |
688 |
case OT_GOTO_STATION: { |
|
689 |
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
|
690 |
|
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
|
691 |
if (order->dest == v->last_station_visited) { |
4179 | 692 |
v->last_station_visited = INVALID_STATION; |
693 |
} |
|
694 |
||
695 |
rs = GetPrimaryRoadStop( |
|
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
|
696 |
GetStation(order->dest), |
4179 | 697 |
v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK |
698 |
); |
|
699 |
||
700 |
if (rs != NULL) { |
|
701 |
TileIndex dest = rs->xy; |
|
702 |
uint mindist = DistanceManhattan(v->tile, rs->xy); |
|
703 |
||
704 |
for (rs = rs->next; rs != NULL; rs = rs->next) { |
|
705 |
uint dist = DistanceManhattan(v->tile, rs->xy); |
|
706 |
||
707 |
if (dist < mindist) { |
|
708 |
mindist = dist; |
|
709 |
dest = rs->xy; |
|
710 |
} |
|
711 |
} |
|
712 |
v->dest_tile = dest; |
|
713 |
} else { |
|
714 |
// There is no stop left at the station, so don't even TRY to go there |
|
715 |
v->cur_order_index++; |
|
716 |
v->dest_tile = 0; |
|
717 |
} |
|
718 |
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
|
719 |
} |
1231
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
720 |
|
4179 | 721 |
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
|
722 |
v->dest_tile = GetDepot(order->dest)->xy; |
4179 | 723 |
break; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
724 |
|
4179 | 725 |
default: |
726 |
v->dest_tile = 0; |
|
727 |
break; |
|
0 | 728 |
} |
729 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
730 |
InvalidateVehicleOrder(v); |
0 | 731 |
} |
732 |
||
733 |
static void HandleRoadVehLoading(Vehicle *v) |
|
734 |
{ |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
735 |
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
|
736 |
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
|
737 |
Order b; |
0 | 738 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
739 |
if (--v->load_unload_time_rem != 0) return; |
0 | 740 |
|
5211
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
741 |
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD || |
651c9272ad22
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
742 |
(_patches.gradual_loading && !HASBIT(v->load_status, LS_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
|
743 |
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
|
744 |
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
|
745 |
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
|
746 |
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
|
747 |
} |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
748 |
return; |
0 | 749 |
} |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
750 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
751 |
b = v->current_order; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
752 |
v->current_order.type = OT_LEAVESTATION; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
753 |
v->current_order.flags = 0; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
754 |
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
|
755 |
break; |
0 | 756 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
757 |
|
3004
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_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
|
759 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
760 |
default: return; |
0 | 761 |
} |
762 |
||
763 |
v->cur_order_index++; |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
764 |
InvalidateVehicleOrder(v); |
0 | 765 |
} |
766 |
||
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
|
767 |
static void StartRoadVehSound(const Vehicle* v) |
0 | 768 |
{ |
4656
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
769 |
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
|
770 |
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
|
771 |
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
|
772 |
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
|
773 |
SndPlayVehicleFx(s, v); |
acffecd6f484
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
774 |
} |
0 | 775 |
} |
776 |
||
777 |
typedef 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
|
778 |
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
|
779 |
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
|
780 |
const Vehicle* veh; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
781 |
Direction dir; |
0 | 782 |
} RoadVehFindData; |
783 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
784 |
static void* EnumCheckRoadVehClose(Vehicle *v, void* data) |
0 | 785 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
786 |
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
|
787 |
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
|
788 |
|
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
789 |
const RoadVehFindData* rvf = data; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
790 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
791 |
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
|
792 |
short y_diff = v->y_pos - rvf->y; |
0 | 793 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
794 |
return |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
795 |
rvf->veh != v && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
796 |
v->type == VEH_Road && |
3959 | 797 |
!IsRoadVehInDepot(v) && |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
798 |
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
|
799 |
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
|
800 |
(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
|
801 |
(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
|
802 |
(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
|
803 |
(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
|
804 |
v : NULL; |
0 | 805 |
} |
806 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
807 |
static Vehicle* RoadVehFindCloseTo(Vehicle* v, int x, int y, Direction dir) |
0 | 808 |
{ |
809 |
RoadVehFindData rvf; |
|
810 |
Vehicle *u; |
|
811 |
||
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
|
812 |
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
|
813 |
|
0 | 814 |
rvf.x = x; |
815 |
rvf.y = y; |
|
816 |
rvf.dir = dir; |
|
817 |
rvf.veh = v; |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
818 |
u = VehicleFromPos(TileVirtXY(x, y), &rvf, EnumCheckRoadVehClose); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
819 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
820 |
// This code protects a roadvehicle from being blocked for ever |
826 | 821 |
// If more than 1480 / 74 days a road vehicle is blocked, it will |
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
822 |
// drive just through it. The ultimate backup-code of TTD. |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
823 |
// It can be disabled. |
0 | 824 |
if (u == NULL) { |
3009
c477ab0f00b3
(svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents:
3004
diff
changeset
|
825 |
v->u.road.blocked_ctr = 0; |
0 | 826 |
return NULL; |
827 |
} |
|
828 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
829 |
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
|
830 |
|
0 | 831 |
return u; |
832 |
} |
|
833 |
||
2630 | 834 |
static void RoadVehArrivesAt(const Vehicle* v, Station* st) |
0 | 835 |
{ |
2550
5e405f5b2836
(svn r3079) Determine the type of the "first arrival" message for road vehicles using the cargo type and not a magic engine number
tron
parents:
2549
diff
changeset
|
836 |
if (v->cargo_type == CT_PASSENGERS) { |
0 | 837 |
/* Check if station was ever visited before */ |
838 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
839 |
uint32 flags; |
|
840 |
||
841 |
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
|
842 |
SetDParam(0, st->index); |
0 | 843 |
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); |
844 |
AddNewsItem( |
|
845 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
846 |
flags, |
|
847 |
v->index, |
|
848 |
0); |
|
849 |
} |
|
850 |
} else { |
|
851 |
/* Check if station was ever visited before */ |
|
852 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
853 |
uint32 flags; |
|
854 |
||
855 |
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
|
856 |
SetDParam(0, st->index); |
0 | 857 |
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); |
858 |
AddNewsItem( |
|
859 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
860 |
flags, |
|
861 |
v->index, |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
862 |
0 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
863 |
); |
0 | 864 |
} |
865 |
} |
|
866 |
} |
|
867 |
||
868 |
static bool RoadVehAccelerate(Vehicle *v) |
|
869 |
{ |
|
2951 | 870 |
uint spd = v->cur_speed + 1 + (v->u.road.overtaking != 0 ? 1 : 0); |
0 | 871 |
byte t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
872 |
|
0 | 873 |
// Clamp |
874 |
spd = min(spd, v->max_speed); |
|
875 |
||
876 |
//updates statusbar only if speed have changed to save CPU time |
|
877 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
878 |
v->cur_speed = spd; |
2951 | 879 |
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
|
880 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
2951 | 881 |
} |
0 | 882 |
} |
883 |
||
884 |
// Decrease somewhat when turning |
|
2951 | 885 |
if (!(v->direction & 1)) spd = spd * 3 >> 2; |
0 | 886 |
|
2951 | 887 |
if (spd == 0) return false; |
0 | 888 |
|
2951 | 889 |
if ((byte)++spd == 0) return true; |
0 | 890 |
|
891 |
v->progress = (t = v->progress) - (byte)spd; |
|
892 |
||
893 |
return (t < v->progress); |
|
894 |
} |
|
895 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
896 |
static Direction RoadVehGetNewDirection(const Vehicle* v, int x, int y) |
0 | 897 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
898 |
static const Direction _roadveh_new_dir[] = { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
899 |
DIR_N , DIR_NW, DIR_W , 0, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
900 |
DIR_NE, DIR_N , DIR_SW, 0, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
901 |
DIR_E , DIR_SE, DIR_S |
0 | 902 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
903 |
|
0 | 904 |
x = x - v->x_pos + 1; |
905 |
y = y - v->y_pos + 1; |
|
906 |
||
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
|
907 |
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
|
908 |
return _roadveh_new_dir[y * 4 + x]; |
0 | 909 |
} |
910 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
911 |
static Direction RoadVehGetSlidingDirection(const Vehicle* v, int x, int y) |
0 | 912 |
{ |
3168
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
913 |
Direction new = RoadVehGetNewDirection(v, x, y); |
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
914 |
Direction old = 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
|
915 |
DirDiff delta; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
916 |
|
3168
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
917 |
if (new == old) return old; |
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
918 |
delta = (DirDifference(new, old) > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
919 |
return ChangeDir(old, delta); |
0 | 920 |
} |
921 |
||
922 |
typedef struct OvertakeData { |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
923 |
const Vehicle* u; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
924 |
const Vehicle* v; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
925 |
TileIndex tile; |
0 | 926 |
byte tilebits; |
927 |
} OvertakeData; |
|
928 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
929 |
static void* EnumFindVehToOvertake(Vehicle* v, void* data) |
0 | 930 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
931 |
const OvertakeData* od = data; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
932 |
|
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
|
933 |
return |
4170
1e4a024fd08b
(svn r5607) -Regression [r3597]: Let a road vehicle only overtake if there is no vehicle close except the two involved
tron
parents:
4095
diff
changeset
|
934 |
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
|
935 |
v : NULL; |
0 | 936 |
} |
937 |
||
938 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
939 |
{ |
|
940 |
uint32 bits; |
|
941 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
942 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD) & 0x3F; |
0 | 943 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
944 |
if (!(od->tilebits & bits) || (bits & 0x3C) || (bits & 0x3F3F0000)) |
0 | 945 |
return true; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
946 |
return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL; |
0 | 947 |
} |
948 |
||
949 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
950 |
{ |
|
951 |
OvertakeData od; |
|
952 |
byte tt; |
|
953 |
||
954 |
od.v = v; |
|
955 |
od.u = u; |
|
956 |
||
957 |
if (u->max_speed >= v->max_speed && |
|
3431 | 958 |
!(u->vehstatus & VS_STOPPED) && |
2951 | 959 |
u->cur_speed != 0) { |
960 |
return; |
|
961 |
} |
|
0 | 962 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
963 |
if (v->direction != u->direction || !(v->direction & 1)) return; |
0 | 964 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
965 |
if (v->u.road.state >= 32 || (v->u.road.state & 7) > 1) return; |
0 | 966 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
967 |
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F; |
2951 | 968 |
if ((tt & 3) == 0) return; |
969 |
if ((tt & 0x3C) != 0) return; |
|
0 | 970 |
|
2951 | 971 |
if (tt == 3) tt = (v->direction & 2) ? 2 : 1; |
0 | 972 |
od.tilebits = tt; |
973 |
||
974 |
od.tile = v->tile; |
|
2951 | 975 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 976 |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
977 |
od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction)); |
2951 | 978 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 979 |
|
3431 | 980 |
if (od.u->cur_speed == 0 || od.u->vehstatus& VS_STOPPED) { |
0 | 981 |
v->u.road.overtaking_ctr = 0x11; |
982 |
v->u.road.overtaking = 0x10; |
|
983 |
} else { |
|
2951 | 984 |
// if (FindRoadVehToOvertake(&od)) return; |
0 | 985 |
v->u.road.overtaking_ctr = 0; |
986 |
v->u.road.overtaking = 0x10; |
|
987 |
} |
|
988 |
} |
|
989 |
||
990 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
991 |
{ |
|
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
|
992 |
if (old_z == v->z_pos) return; |
0 | 993 |
|
994 |
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
|
995 |
v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10% |
0 | 996 |
} else { |
997 |
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
|
998 |
if (spd <= v->max_speed) v->cur_speed = spd; |
0 | 999 |
} |
1000 |
} |
|
1001 |
||
1002 |
static int PickRandomBit(uint bits) |
|
1003 |
{ |
|
1004 |
uint num = 0; |
|
1005 |
uint b = bits; |
|
1006 |
uint i; |
|
1007 |
||
1008 |
do { |
|
2951 | 1009 |
if (b & 1) num++; |
0 | 1010 |
} while (b >>= 1); |
1011 |
||
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
1012 |
num = RandomRange(num); |
0 | 1013 |
|
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
|
1014 |
for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {} |
0 | 1015 |
return i; |
1016 |
} |
|
1017 |
||
1018 |
typedef struct { |
|
1019 |
TileIndex dest; |
|
1020 |
uint maxtracklen; |
|
1021 |
uint mindist; |
|
1022 |
} FindRoadToChooseData; |
|
1023 |
||
3137 | 1024 |
static bool EnumRoadTrackFindDist(TileIndex tile, void* data, int track, uint length, byte* state) |
0 | 1025 |
{ |
3137 | 1026 |
FindRoadToChooseData* frd = 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
|
1027 |
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
|
1028 |
|
0 | 1029 |
if (dist <= frd->mindist) { |
1030 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
1031 |
frd->maxtracklen = length; |
|
1032 |
} |
|
1033 |
frd->mindist = dist; |
|
1034 |
} |
|
1035 |
return false; |
|
1036 |
} |
|
1037 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1038 |
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
|
1039 |
{ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1040 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1041 |
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
|
1042 |
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
|
1043 |
int t = NpfEndInterval(perf); |
3947
7ab994b0fe9c
(svn r5093) -CodeChange: [YAPF] min. debug level changed from 1 to 3 and 4 for frequent debug messages (performance stats)
KUDr
parents:
3937
diff
changeset
|
1044 |
DEBUG(yapf, 4)("[YAPF][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
|
1045 |
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
|
1046 |
} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1047 |
|
0 | 1048 |
// Returns direction to choose |
1049 |
// or -1 if the direction is currently blocked |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1050 |
static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir) |
0 | 1051 |
{ |
1052 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
1053 |
||
1054 |
uint16 signal; |
|
1055 |
uint bitmask; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1056 |
TileIndex desttile; |
0 | 1057 |
FindRoadToChooseData frd; |
1058 |
int best_track; |
|
1059 |
uint best_dist, best_maxlen; |
|
1060 |
uint i; |
|
1061 |
||
1062 |
{ |
|
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
|
1063 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
2484
8e0c88a833fb
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1064 |
signal = GB(r, 16, 16); |
8e0c88a833fb
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1065 |
bitmask = GB(r, 0, 16); |
0 | 1066 |
} |
1067 |
||
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
|
1068 |
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
|
1069 |
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
|
1070 |
/* Road depot owned by another player or with the wrong orientation */ |
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
|
1071 |
bitmask = 0; |
2549 | 1072 |
} |
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
|
1073 |
} else if (IsTileType(tile, MP_STATION) && IsRoadStopTile(tile)) { |
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
|
1074 |
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
|
1075 |
/* different station owner or wrong orientation */ |
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
|
1076 |
bitmask = 0; |
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
|
1077 |
} else { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1078 |
/* Our station */ |
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
|
1079 |
RoadStopType rstype = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1080 |
|
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
|
1081 |
if (GetRoadStopType(tile) != rstype) { |
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
|
1082 |
// wrong station type |
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
|
1083 |
bitmask = 0; |
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
|
1084 |
} else { |
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
|
1085 |
// proper station type, check if there is free loading bay |
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
|
1086 |
const RoadStop *rs = GetRoadStopByTile(tile, rstype); |
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
|
1087 |
if (rs == NULL || (!_patches.roadveh_queue && GB(rs->status, 0, 2) == 0)) { |
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
|
1088 |
// station is full and RV queuing is off |
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
|
1089 |
bitmask = 0; |
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
|
1090 |
} |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1091 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1092 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1093 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1094 |
/* 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
|
1095 |
* 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
|
1096 |
* 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
|
1097 |
*/ |
0 | 1098 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1099 |
/* remove unreachable tracks */ |
1247 | 1100 |
bitmask &= _road_veh_fp_ax_and[enterdir]; |
0 | 1101 |
if (bitmask == 0) { |
1247 | 1102 |
/* No reachable tracks, so we'll reverse */ |
1103 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1104 |
} |
1105 |
||
1106 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1107 |
/* What happens here?? */ |
0 | 1108 |
v->u.road.reverse_ctr = 0; |
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
1109 |
if (v->tile != tile) { |
1247 | 1110 |
return_track(_road_reverse_table[enterdir]); |
0 | 1111 |
} |
1112 |
} |
|
1113 |
||
1114 |
desttile = v->dest_tile; |
|
1115 |
if (desttile == 0) { |
|
1247 | 1116 |
// Pick a random track |
0 | 1117 |
return_track(PickRandomBit(bitmask)); |
1118 |
} |
|
1119 |
||
1247 | 1120 |
// Only one track to choose between? |
1121 |
if (!(KillFirstBit2x64(bitmask))) { |
|
0 | 1122 |
return_track(FindFirstBit2x64(bitmask)); |
1123 |
} |
|
1124 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1125 |
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
|
1126 |
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
|
1127 |
if (trackdir != INVALID_TRACKDIR) return_track(trackdir); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1128 |
return_track(PickRandomBit(bitmask)); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1129 |
} else if (_patches.new_pathfinding_all) { |
1247 | 1130 |
NPFFindStationOrTileData fstd; |
1131 |
NPFFoundTargetData ftd; |
|
1132 |
byte trackdir; |
|
1133 |
||
1134 |
NPFFillWithOrderData(&fstd, v); |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1135 |
trackdir = DiagdirToDiagTrackdir(enterdir); |
1247 | 1136 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1137 |
||
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1138 |
ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
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
|
1139 |
if (ftd.best_trackdir == 0xff) { |
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
|
1140 |
/* We are already at our target. Just do something */ |
1247 | 1141 |
//TODO: maybe display error? |
1142 |
//TODO: go straight ahead if possible? |
|
1143 |
return_track(FindFirstBit2x64(bitmask)); |
|
1144 |
} 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
|
1145 |
/* 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
|
1146 |
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
|
1147 |
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
|
1148 |
to the tile closest to our target. */ |
1247 | 1149 |
return_track(ftd.best_trackdir); |
1150 |
} |
|
1151 |
} else { |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1152 |
DiagDirection dir; |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1153 |
|
1247 | 1154 |
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
|
1155 |
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
|
1156 |
dir = GetRoadDepotDirection(desttile); |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1157 |
goto do_it; |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1158 |
} |
1247 | 1159 |
} else if (IsTileType(desttile, MP_STATION)) { |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1160 |
if (IsRoadStop(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
|
1161 |
dir = GetRoadStopDir(desttile); |
0 | 1162 |
do_it:; |
1247 | 1163 |
/* When we are heading for a depot or station, we just |
1164 |
* pretend we are heading for the tile in front, we'll |
|
1165 |
* see from there */ |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1166 |
desttile += TileOffsByDiagDir(dir); |
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1167 |
if (desttile == tile && bitmask & _road_pf_table_3[dir]) { |
1247 | 1168 |
/* If we are already in front of the |
1169 |
* station/depot and we can get in from here, |
|
1170 |
* we enter */ |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1171 |
return_track(FindFirstBit2x64(bitmask & _road_pf_table_3[dir])); |
1247 | 1172 |
} |
0 | 1173 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1174 |
} |
1247 | 1175 |
// do pathfind |
1176 |
frd.dest = desttile; |
|
0 | 1177 |
|
1247 | 1178 |
best_track = -1; |
1179 |
best_dist = (uint)-1; |
|
1180 |
best_maxlen = (uint)-1; |
|
1181 |
i = 0; |
|
1182 |
do { |
|
1183 |
if (bitmask & 1) { |
|
1184 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track |
|
1185 |
frd.maxtracklen = (uint)-1; |
|
1186 |
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
|
1187 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd); |
0 | 1188 |
|
1247 | 1189 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
1190 |
best_dist = frd.mindist; |
|
1191 |
best_maxlen = frd.maxtracklen; |
|
1192 |
best_track = i; |
|
1193 |
} |
|
0 | 1194 |
} |
1247 | 1195 |
} while (++i,(bitmask>>=1) != 0); |
1196 |
} |
|
0 | 1197 |
|
1198 |
found_best_track:; |
|
1199 |
||
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
|
1200 |
if (HASBIT(signal, best_track)) return -1; |
0 | 1201 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1202 |
return best_track; |
0 | 1203 |
} |
1204 |
||
3123 | 1205 |
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
|
1206 |
{ |
4271
1a86f0faa2cb
(svn r5899) - Fix [FS#242]: Multistop not working when using NPF (r5033) (mart3p)
Darkvater
parents:
4261
diff
changeset
|
1207 |
uint dist; |
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1208 |
if (_patches.yapf.road_use_yapf) { |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1209 |
// use YAPF |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1210 |
dist = YapfRoadVehDistanceToTile(v, tile); |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1211 |
} else { |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1212 |
// use NPF |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1213 |
NPFFindStationOrTileData fstd; |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1214 |
byte trackdir = GetVehicleTrackdir(v); |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1215 |
assert(trackdir != 0xFF); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1216 |
|
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1217 |
fstd.dest_coords = tile; |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1218 |
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
|
1219 |
|
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1220 |
dist = NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE).best_path_dist; |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1221 |
// change units from NPF_TILE_LENGTH to # of tiles |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1222 |
if (dist != UINT_MAX) |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1223 |
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
|
1224 |
} |
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1225 |
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
|
1226 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1227 |
|
0 | 1228 |
typedef struct RoadDriveEntry { |
1229 |
byte x,y; |
|
1230 |
} RoadDriveEntry; |
|
1231 |
||
1232 |
#include "table/roadveh.h" |
|
1233 |
||
1234 |
static const byte _road_veh_data_1[] = { |
|
1235 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1236 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1237 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1238 |
15, 15, 11, 11 |
|
1239 |
}; |
|
1240 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
1241 |
static const byte _roadveh_data_2[4] = { 0, 1, 8, 9 }; |
0 | 1242 |
|
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
|
1243 |
static void RoadVehController(Vehicle *v) |
0 | 1244 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1245 |
Direction new_dir; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1246 |
Direction old_dir; |
0 | 1247 |
RoadDriveEntry rd; |
1248 |
int x,y; |
|
1249 |
uint32 r; |
|
1250 |
||
1251 |
// decrease counters |
|
1252 |
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
|
1253 |
if (v->u.road.reverse_ctr != 0) v->u.road.reverse_ctr--; |
0 | 1254 |
|
1255 |
// handle crashed |
|
1256 |
if (v->u.road.crashed_ctr != 0) { |
|
1257 |
RoadVehIsCrashed(v); |
|
1258 |
return; |
|
1259 |
} |
|
1260 |
||
1261 |
RoadVehCheckTrainCrash(v); |
|
1262 |
||
1263 |
// road vehicle has broken down? |
|
1264 |
if (v->breakdown_ctr != 0) { |
|
1265 |
if (v->breakdown_ctr <= 2) { |
|
1266 |
HandleBrokenRoadVeh(v); |
|
1267 |
return; |
|
1268 |
} |
|
1269 |
v->breakdown_ctr--; |
|
1270 |
} |
|
1271 |
||
3431 | 1272 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 1273 |
|
1274 |
ProcessRoadVehOrder(v); |
|
1275 |
HandleRoadVehLoading(v); |
|
1276 |
||
2951 | 1277 |
if (v->current_order.type == OT_LOADING) return; |
0 | 1278 |
|
3959 | 1279 |
if (IsRoadVehInDepot(v)) { |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1280 |
DiagDirection dir; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1281 |
const RoadDriveEntry* rdp; |
0 | 1282 |
byte rd2; |
1283 |
||
1284 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1285 |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1286 |
dir = GetRoadDepotDirection(v->tile); |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1287 |
v->direction = DiagDirToDir(dir); |
0 | 1288 |
|
1289 |
rd2 = _roadveh_data_2[dir]; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1290 |
rdp = _road_drive_data[(_opt.road_side << 4) + rd2]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1291 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1292 |
x = TileX(v->tile) * TILE_SIZE + (rdp[6].x & 0xF); |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1293 |
y = TileY(v->tile) * TILE_SIZE + (rdp[6].y & 0xF); |
0 | 1294 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1295 |
if (RoadVehFindCloseTo(v, x, y, v->direction) != NULL) return; |
0 | 1296 |
|
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
|
1297 |
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
|
1298 |
|
0 | 1299 |
StartRoadVehSound(v); |
1300 |
||
1301 |
BeginVehicleMove(v); |
|
1302 |
||
1303 |
v->vehstatus &= ~VS_HIDDEN; |
|
1304 |
v->u.road.state = rd2; |
|
1305 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1306 |
|
0 | 1307 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1308 |
UpdateRoadVehDeltaXY(v); |
|
1309 |
SetRoadVehPosition(v,x,y); |
|
1310 |
||
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4725
diff
changeset
|
1311 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
0 | 1312 |
return; |
1313 |
} |
|
1314 |
||
2951 | 1315 |
if (!RoadVehAccelerate(v)) return; |
0 | 1316 |
|
1317 |
if (v->u.road.overtaking != 0) { |
|
1318 |
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
|
1319 |
/* 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
|
1320 |
* if the vehicle started a corner. To protect that, only allow an abort of |
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
|
1321 |
* overtake if we are on straight road, which are the 8 states below */ |
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
|
1322 |
if (v->u.road.state == 0 || v->u.road.state == 1 || |
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
|
1323 |
v->u.road.state == 8 || v->u.road.state == 9 || |
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
|
1324 |
v->u.road.state == 16 || v->u.road.state == 17 || |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1325 |
v->u.road.state == 24 || v->u.road.state == 25) { |
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
|
1326 |
v->u.road.overtaking = 0; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1327 |
} |
0 | 1328 |
} |
1329 |
||
1330 |
BeginVehicleMove(v); |
|
1331 |
||
1332 |
if (v->u.road.state == 255) { |
|
5430
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1333 |
const Vehicle *u; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1334 |
GetNewVehiclePosResult gp; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1335 |
|
0 | 1336 |
GetNewVehiclePos(v, &gp); |
1337 |
||
5430
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1338 |
u = RoadVehFindCloseTo(v, gp.x, gp.y, v->direction); |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1339 |
if (u != NULL && u->cur_speed < v->cur_speed) { |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1340 |
v->cur_speed = u->cur_speed; |
0 | 1341 |
return; |
1342 |
} |
|
1343 |
||
3977
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
1344 |
if (IsTunnelTile(gp.new_tile) && |
edb5b94e2094
(svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents:
3959
diff
changeset
|
1345 |
VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) { |
0 | 1346 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1347 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1348 |
UpdateRoadVehDeltaXY(v); |
|
1349 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1350 |
return; |
|
1351 |
} |
|
1352 |
||
1353 |
v->x_pos = gp.x; |
|
1354 |
v->y_pos = gp.y; |
|
1355 |
VehiclePositionChanged(v); |
|
1356 |
return; |
|
1357 |
} |
|
1358 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1359 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side << 4)) ^ v->u.road.overtaking][v->u.road.frame + 1]; |
0 | 1360 |
|
1361 |
// switch to another tile |
|
1362 |
if (rd.x & 0x80) { |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1363 |
TileIndex tile = v->tile + TileOffsByDiagDir(rd.x & 3); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1364 |
int dir = RoadFindPathToDest(v, tile, rd.x & 3); |
0 | 1365 |
uint32 r; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1366 |
Direction newdir; |
0 | 1367 |
const RoadDriveEntry *rdp; |
1368 |
||
1369 |
if (dir == -1) { |
|
1370 |
v->cur_speed = 0; |
|
1371 |
return; |
|
1372 |
} |
|
1373 |
||
1374 |
again: |
|
1375 |
if ((dir & 7) >= 6) { |
|
1247 | 1376 |
/* Turning around */ |
0 | 1377 |
tile = v->tile; |
1378 |
} |
|
1379 |
||
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
|
1380 |
rdp = _road_drive_data[(dir + (_opt.road_side << 4)) ^ v->u.road.overtaking]; |
0 | 1381 |
|
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1382 |
x = TileX(tile) * TILE_SIZE + rdp[0].x; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1383 |
y = TileY(tile) * TILE_SIZE + rdp[0].y; |
0 | 1384 |
|
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
|
1385 |
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
|
1386 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1387 |
|
1388 |
r = VehicleEnterTile(v, tile, x, y); |
|
1389 |
if (r & 8) { |
|
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
|
1390 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1391 |
v->cur_speed = 0; |
1392 |
return; |
|
1393 |
} |
|
1394 |
dir = _road_reverse_table[rd.x&3]; |
|
1395 |
goto again; |
|
1396 |
} |
|
1397 |
||
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
|
1398 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1399 |
if ((dir & 7) >= 6) { |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1400 |
v->cur_speed = 0; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1401 |
return; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1402 |
} |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1403 |
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
|
1404 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 1405 |
|
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1406 |
// reached a loading bay, mark it as used and clear the usage bit |
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1407 |
SETBIT(rs->status, v->u.road.state & 2 ? 1 : 0); // occupied bay |
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1408 |
CLRBIT(rs->status, 7); // usage bit |
0 | 1409 |
} |
1410 |
} |
|
1411 |
||
1412 |
if (!(r & 4)) { |
|
1413 |
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
|
1414 |
v->u.road.state = (byte)dir; |
0 | 1415 |
v->u.road.frame = 0; |
1416 |
} |
|
1417 |
if (newdir != v->direction) { |
|
1418 |
v->direction = newdir; |
|
1419 |
v->cur_speed -= v->cur_speed >> 2; |
|
1420 |
} |
|
1421 |
||
1422 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1423 |
UpdateRoadVehDeltaXY(v); |
|
1424 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1425 |
return; |
|
1426 |
} |
|
1427 |
||
1428 |
if (rd.x & 0x40) { |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4412
diff
changeset
|
1429 |
int dir = RoadFindPathToDest(v, v->tile, rd.x & 3); |
0 | 1430 |
uint32 r; |
1431 |
int tmp; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1432 |
Direction newdir; |
0 | 1433 |
const RoadDriveEntry *rdp; |
1434 |
||
1435 |
if (dir == -1) { |
|
1436 |
v->cur_speed = 0; |
|
1437 |
return; |
|
1438 |
} |
|
1439 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1440 |
tmp = (_opt.road_side << 4) + dir; |
0 | 1441 |
rdp = _road_drive_data[tmp]; |
1442 |
||
3421
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1443 |
x = TileX(v->tile) * TILE_SIZE + rdp[1].x; |
8ab76c47c72c
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1444 |
y = TileY(v->tile) * TILE_SIZE + rdp[1].y; |
0 | 1445 |
|
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
|
1446 |
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
|
1447 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1448 |
|
1449 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1450 |
if (r & 8) { |
|
1451 |
v->cur_speed = 0; |
|
1452 |
return; |
|
1453 |
} |
|
1454 |
||
1455 |
v->u.road.state = tmp & ~16; |
|
1456 |
v->u.road.frame = 1; |
|
1457 |
||
1458 |
if (newdir != v->direction) { |
|
1459 |
v->direction = newdir; |
|
1460 |
v->cur_speed -= v->cur_speed >> 2; |
|
1461 |
} |
|
1462 |
||
1463 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1464 |
UpdateRoadVehDeltaXY(v); |
|
1465 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1466 |
return; |
|
1467 |
} |
|
1468 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1469 |
x = (v->x_pos & ~15) + (rd.x & 15); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1470 |
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
|
1471 |
|
0 | 1472 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1473 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1474 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30)) { |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1475 |
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
|
1476 |
|
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1477 |
if (u != NULL) { |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1478 |
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
|
1479 |
return; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1480 |
} |
0 | 1481 |
} |
1482 |
||
1483 |
old_dir = v->direction; |
|
1484 |
if (new_dir != old_dir) { |
|
1485 |
v->direction = new_dir; |
|
1486 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1487 |
if (old_dir != v->u.road.state) { |
|
1488 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1489 |
UpdateRoadVehDeltaXY(v); |
|
1490 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1491 |
return; |
|
1492 |
} |
|
1493 |
} |
|
1494 |
||
1495 |
if (v->u.road.state >= 0x20 && |
|
1496 |
_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) { |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1497 |
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
|
1498 |
Station* st = GetStationByTile(v->tile); |
0 | 1499 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1500 |
if (v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1501 |
v->current_order.type != OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1502 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1503 |
|
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1504 |
CLRBIT(rs->status, 7); |
0 | 1505 |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1506 |
v->last_station_visited = GetStationIndex(v->tile); |
0 | 1507 |
|
1508 |
RoadVehArrivesAt(v, st); |
|
1509 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1510 |
old_order = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1511 |
v->current_order.type = OT_LOADING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1512 |
v->current_order.flags = 0; |
0 | 1513 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1514 |
if (old_order.type == OT_GOTO_STATION && |
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
|
1515 |
v->current_order.dest == v->last_station_visited) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1516 |
v->current_order.flags = |
1935
f43f062c9498
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1927
diff
changeset
|
1517 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP; |
0 | 1518 |
} |
1519 |
||
1520 |
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
|
1521 |
if (LoadUnloadVehicle(v, true)) { |
0 | 1522 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
1523 |
MarkRoadVehDirty(v); |
|
1524 |
} |
|
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
|
1525 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1526 |
return; |
1527 |
} |
|
1528 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1529 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1530 |
if (HASBIT(rs->status, 7)) { |
0 | 1531 |
v->cur_speed = 0; |
1532 |
return; |
|
1533 |
} |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1534 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1535 |
v->current_order.flags = 0; |
3123 | 1536 |
ClearSlot(v); |
0 | 1537 |
} |
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1538 |
SETBIT(rs->status, 7); |
0 | 1539 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1540 |
if (rs == v->u.road.slot) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1541 |
//we have arrived at the correct station |
3123 | 1542 |
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
|
1543 |
} else if (v->u.road.slot != NULL) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1544 |
//we have arrived at the wrong station |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1545 |
//XXX The question is .. what to do? Actually we shouldn't be here |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1546 |
//but I guess we need to clear the slot |
3123 | 1547 |
DEBUG(ms, 0) ("Multistop: 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
|
1548 |
if (v->tile != v->dest_tile) { |
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1549 |
DEBUG(ms, 0) ("Multistop: -- 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
|
1550 |
} |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1551 |
if (v->dest_tile != v->u.road.slot->xy) { |
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1552 |
DEBUG(ms, 0) ("Multistop: -- 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
|
1553 |
} |
3123 | 1554 |
if (v->current_order.type != OT_GOTO_STATION) { |
1555 |
DEBUG(ms, 0) ("Multistop: -- Current order type (%d) is not OT_GOTO_STATION.", v->current_order.type); |
|
1556 |
} 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
|
1557 |
if (v->current_order.dest != st->index) |
3123 | 1558 |
DEBUG(ms, 0) ("Multistop: -- 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
|
1559 |
st->index, v->current_order.dest); |
3123 | 1560 |
} |
1561 |
||
1562 |
DEBUG(ms, 0) (" -- Force a slot clearing."); |
|
1563 |
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
|
1564 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1565 |
|
0 | 1566 |
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
|
1567 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1568 |
} |
1569 |
||
1570 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1571 |
if (r & 8) { |
|
1572 |
v->cur_speed = 0; |
|
1573 |
return; |
|
1574 |
} |
|
1575 |
||
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
|
1576 |
if ((r & 4) == 0) v->u.road.frame++; |
0 | 1577 |
|
1578 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1579 |
UpdateRoadVehDeltaXY(v); |
|
1580 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1581 |
} |
|
1582 |
||
1583 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1584 |
{ |
|
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
|
1585 |
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
|
1586 |
if (v->cargo_days != 255) v->cargo_days++; |
0 | 1587 |
} |
1588 |
||
1589 |
void RoadVeh_Tick(Vehicle *v) |
|
1590 |
{ |
|
1591 |
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
|
1592 |
RoadVehController(v); |
0 | 1593 |
} |
1594 |
||
1595 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1596 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1597 |
const Depot* depot; |
0 | 1598 |
|
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
|
1599 |
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
|
1600 |
if (!VehicleNeedsService(v)) return; |
3431 | 1601 |
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
|
1602 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1603 |
|
0 | 1604 |
// Don't interfere with a depot visit scheduled by the user, or a |
1605 |
// depot visit by the order list. |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1606 |
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
|
1607 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 1608 |
return; |
1609 |
||
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
|
1610 |
// If we already got a slot at a stop, use that FIRST, and go to a depot later |
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
|
1611 |
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
|
1612 |
|
4529
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1613 |
if (IsRoadVehInDepot(v)) { |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1614 |
VehicleServiceInDepot(v); |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1615 |
return; |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1616 |
} |
2bfac24af02a
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1617 |
|
3612 | 1618 |
// 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
|
1619 |
depot = FindClosestRoadDepot(v); |
0 | 1620 |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1621 |
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
|
1622 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1623 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1624 |
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
|
1625 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1626 |
} |
1627 |
return; |
|
1628 |
} |
|
1629 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1630 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1631 |
v->current_order.flags & OF_NON_STOP && |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1632 |
!CHANCE16(1, 20)) { |
0 | 1633 |
return; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1634 |
} |
0 | 1635 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1636 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1637 |
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
|
1638 |
v->current_order.dest = depot->index; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1639 |
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
|
1640 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1641 |
} |
1642 |
||
1643 |
void OnNewDay_RoadVeh(Vehicle *v) |
|
1644 |
{ |
|
1645 |
int32 cost; |
|
1646 |
||
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
|
1647 |
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
|
1648 |
if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v); |
0 | 1649 |
|
1650 |
AgeVehicle(v); |
|
1651 |
CheckIfRoadVehNeedsService(v); |
|
1652 |
||
3140
69cb681c6d86
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1653 |
CheckOrders(v); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1654 |
|
3123 | 1655 |
//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
|
1656 |
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot != NULL && v->u.road.slot_age-- == 0) { |
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1657 |
DEBUG(ms, 2) ("Multistop: Slot expired for vehicle %d (index %d) at stop 0x%X", |
3431 | 1658 |
v->unitnumber, v->index, v->u.road.slot->xy); |
3123 | 1659 |
ClearSlot(v); |
1660 |
} |
|
1661 |
||
3236 | 1662 |
if (v->vehstatus & VS_STOPPED) return; |
1663 |
||
0 | 1664 |
/* update destination */ |
3431 | 1665 |
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
|
1666 |
Station* st = GetStation(v->current_order.dest); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1667 |
RoadStop* rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK); |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1668 |
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
|
1669 |
|
3123 | 1670 |
if (rs != NULL) { |
5430
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1671 |
/* We try to obtain a slot if: |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1672 |
* 1) we're reasonably close to the primary road stop |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1673 |
* or |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1674 |
* 2) we're somewhere close to the station rectangle |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1675 |
*/ |
526e40487347
(svn r8626) [0.5] -Backport from trunk (8294, 8296, 8536, 8540, 8609):
rubidium
parents:
5259
diff
changeset
|
1676 |
if (DistanceManhattan(v->tile, rs->xy) < 16 || PtInExtendedRect(&st->rect, TileX(v->tile), TileY(v->tile), 2)) { |
3431 | 1677 |
uint dist, badness; |
1678 |
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
|
1679 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1680 |
DEBUG(ms, 2) ( |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1681 |
"Multistop: Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)", |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1682 |
v->unitnumber, v->index, st->index, st->xy |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1683 |
); |
3123 | 1684 |
/* Now we find the nearest road stop that has a free slot */ |
3431 | 1685 |
for (; rs != NULL; rs = rs->next) { |
1686 |
dist = RoadFindPathToStop(v, rs->xy); |
|
1687 |
if (dist == UINT_MAX) { |
|
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1688 |
DEBUG(ms, 4) (" ---- stop 0x%X is not reachable, not treating further", rs->xy); |
3123 | 1689 |
continue; |
1690 |
} |
|
3915
281c7ebd27e0
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1691 |
badness = (rs->num_vehicles + 1) * (rs->num_vehicles + 1) + dist; |
3123 | 1692 |
|
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1693 |
DEBUG(ms, 4) (" ---- stop 0x%X has %d vehicle%s waiting", rs->xy, rs->num_vehicles, rs->num_vehicles == 1 ? "":"s"); |
3431 | 1694 |
DEBUG(ms, 4) (" ---- Distance is %u", dist); |
1695 |
DEBUG(ms, 4) (" -- Badness %u", badness); |
|
1696 |
||
1697 |
if (badness < minbadness) { |
|
1698 |
best = rs; |
|
1699 |
minbadness = badness; |
|
3123 | 1700 |
} |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1701 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1702 |
|
3431 | 1703 |
if (best != NULL) { |
1704 |
best->num_vehicles++; |
|
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1705 |
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
|
1706 |
|
3431 | 1707 |
v->u.road.slot = best; |
1708 |
v->dest_tile = best->xy; |
|
1709 |
v->u.road.slot_age = 14; |
|
3123 | 1710 |
} else { |
3431 | 1711 |
DEBUG(ms, 3) (" -- Could not find a suitable stop"); |
3123 | 1712 |
} |
1713 |
} else { |
|
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1714 |
DEBUG(ms, 5) ("Multistop: --- Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%X)", |
3123 | 1715 |
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
|
1716 |
} |
3123 | 1717 |
} else { |
3630
0f7828d892ae
(svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents:
3612
diff
changeset
|
1718 |
DEBUG(ms, 4) ("Multistop: No road stop for vehicle %d (index %d) at station %d (0x%X)", |
3123 | 1719 |
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
|
1720 |
} |
0 | 1721 |
} |
1722 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1723 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1724 |
|
1725 |
v->profit_this_year -= cost >> 8; |
|
1726 |
||
1727 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1728 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1729 |
||
1730 |
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
|
1731 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1732 |
} |
1733 |
||
1734 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1053
diff
changeset
|
1735 |
void RoadVehiclesYearlyLoop(void) |
0 | 1736 |
{ |
1737 |
Vehicle *v; |
|
1738 |
||
1739 |
FOR_ALL_VEHICLES(v) { |
|
1740 |
if (v->type == VEH_Road) { |
|
1741 |
v->profit_last_year = v->profit_this_year; |
|
1742 |
v->profit_this_year = 0; |
|
1743 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1744 |
} |
|
1745 |
} |
|
1746 |
} |
|
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1747 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1748 |
/** 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
|
1749 |
* @param tile unused |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1750 |
* @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
|
1751 |
* @param p2 Bitstuffed elements |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1752 |
* - 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
|
1753 |
* - p2 = (bit 8-15) - the new cargo subtype to refit to |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1754 |
*/ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1755 |
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
|
1756 |
{ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1757 |
Vehicle *v; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1758 |
int32 cost; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1759 |
CargoID new_cid = GB(p2, 0, 8); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1760 |
byte new_subtype = GB(p2, 8, 8); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1761 |
uint16 capacity = CALLBACK_FAILED; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1762 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1763 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1764 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1765 |
v = GetVehicle(p1); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1766 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1767 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1768 |
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
|
1769 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1770 |
if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1771 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1772 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1773 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1774 |
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
|
1775 |
/* Back up the cargo type */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1776 |
CargoID temp_cid = v->cargo_type; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1777 |
byte temp_subtype = v->cargo_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1778 |
v->cargo_type = new_cid; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1779 |
v->cargo_subtype = new_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1780 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1781 |
/* Check the refit capacity callback */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1782 |
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
|
1783 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1784 |
/* Restore the original cargo type */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1785 |
v->cargo_type = temp_cid; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1786 |
v->cargo_subtype = temp_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1787 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1788 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1789 |
if (capacity == CALLBACK_FAILED) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1790 |
/* callback failed or not used, use default capacity */ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1791 |
const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1792 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1793 |
CargoID old_cid = rvi->cargo_type; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1794 |
/* 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
|
1795 |
* 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
|
1796 |
* many passengers |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1797 |
*/ |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1798 |
capacity = rvi->capacity; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1799 |
switch (old_cid) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1800 |
case CT_PASSENGERS: break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1801 |
case CT_MAIL: |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1802 |
case CT_GOODS: capacity *= 2; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1803 |
default: capacity *= 4; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1804 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1805 |
switch (new_cid) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1806 |
case CT_PASSENGERS: break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1807 |
case CT_MAIL: |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1808 |
case CT_GOODS: capacity /= 2; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1809 |
default: capacity /= 4; break; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1810 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1811 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1812 |
_returned_refit_capacity = capacity; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1813 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1814 |
cost = 0; |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4739
diff
changeset
|
1815 |
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
|
1816 |
cost = GetRefitCost(v->engine_type); |
3990
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1817 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1818 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1819 |
if (flags & DC_EXEC) { |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1820 |
v->cargo_cap = capacity; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1821 |
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
|
1822 |
v->cargo_type = new_cid; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1823 |
v->cargo_subtype = new_subtype; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1824 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1825 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1826 |
RebuildVehicleLists(); |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1827 |
} |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1828 |
|
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1829 |
return cost; |
d3d23f3bcd34
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1830 |
} |