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