author | truelight |
Tue, 28 Dec 2004 11:51:31 +0000 | |
changeset 817 | 4f9377b7fd2b |
parent 812 | 79c99885ad00 |
child 826 | 0e2b569b737b |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
3 |
#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
|
4 |
#include "map.h" |
0 | 5 |
#include "vehicle.h" |
6 |
#include "engine.h" |
|
7 |
#include "command.h" |
|
8 |
#include "station.h" |
|
9 |
#include "news.h" |
|
10 |
#include "gfx.h" |
|
11 |
#include "pathfind.h" |
|
12 |
#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
|
13 |
#include "sound.h" |
0 | 14 |
|
15 |
void ShowRoadVehViewWindow(Vehicle *v); |
|
16 |
||
17 |
static const uint16 _roadveh_images[63] = { |
|
18 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
19 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
20 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
21 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
22 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
23 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
24 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
25 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
26 |
}; |
|
27 |
||
28 |
static const uint16 _roadveh_full_adder[63] = { |
|
29 |
0, 88, 0, 0, 0, 0, 48, 48, |
|
30 |
48, 48, 0, 0, 64, 64, 0, 16, |
|
31 |
16, 0, 88, 0, 0, 0, 0, 48, |
|
32 |
48, 48, 48, 0, 0, 64, 64, 0, |
|
33 |
16, 16, 0, 88, 0, 0, 0, 0, |
|
34 |
48, 48, 48, 48, 0, 0, 64, 64, |
|
35 |
0, 16, 16, 0, 8, 8, 8, 8, |
|
36 |
0, 0, 0, 8, 8, 8, 8 |
|
37 |
}; |
|
38 |
||
39 |
||
40 |
static const uint16 _road_veh_fp_ax_or[4] = { |
|
41 |
0x100,0x200,1,2, |
|
42 |
}; |
|
43 |
||
44 |
static const uint16 _road_veh_fp_ax_and[4] = { |
|
45 |
0x1009, 0x16, 0x520, 0x2A00 |
|
46 |
}; |
|
47 |
||
48 |
static const byte _road_reverse_table[4] = { |
|
49 |
6, 7, 14, 15 |
|
50 |
}; |
|
51 |
||
52 |
static const uint16 _road_pf_table_3[4] = { |
|
53 |
0x910, 0x1600, 0x2005, 0x2A |
|
54 |
}; |
|
55 |
||
56 |
int GetRoadVehImage(Vehicle *v, byte direction) |
|
57 |
{ |
|
58 |
int img = v->spritenum; |
|
59 |
int image; |
|
60 |
||
61 |
if (is_custom_sprite(img)) { |
|
62 |
image = GetCustomVehicleSprite(v, direction); |
|
63 |
if (image) return image; |
|
64 |
img = _engine_original_sprites[v->engine_type]; |
|
65 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
66 |
|
0 | 67 |
image = direction + _roadveh_images[img]; |
68 |
if (v->cargo_count >= (v->cargo_cap >> 1)) |
|
69 |
image += _roadveh_full_adder[img]; |
|
70 |
return image; |
|
71 |
} |
|
72 |
||
73 |
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod) |
|
74 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
75 |
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
|
76 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
77 |
if (is_custom_sprite(spritenum)) { |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
78 |
int sprite = GetCustomVehicleIcon(engine, 6); |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
79 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
80 |
if (sprite) { |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
81 |
DrawSprite(sprite | image_ormod, x, y); |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
82 |
return; |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
83 |
} |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
84 |
spritenum = _engine_original_sprites[engine]; |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
85 |
} |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
86 |
DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y); |
0 | 87 |
} |
88 |
||
89 |
void DrawRoadVehEngineInfo(int engine, int x, int y, int maxw) |
|
90 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
91 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine); |
0 | 92 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
93 |
SetDParam(0, ((_price.roadveh_base >> 3) * rvi->base_cost) >> 5); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
94 |
SetDParam(1, rvi->max_speed * 10 >> 5); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
95 |
SetDParam(2, rvi->running_cost * _price.roadveh_running >> 8); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
96 |
|
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
97 |
SetDParam(4, rvi->capacity); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
98 |
SetDParam(3, _cargoc.names_long_p[rvi->cargo_type]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
99 |
|
0 | 100 |
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw); |
101 |
} |
|
102 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
103 |
int32 EstimateRoadVehCost(byte engine_type) |
0 | 104 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
105 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 106 |
} |
107 |
||
108 |
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
109 |
{ |
|
110 |
int32 cost; |
|
111 |
Vehicle *v; |
|
112 |
byte unit_num; |
|
113 |
uint tile = TILE_FROM_XY(x,y); |
|
114 |
Engine *e; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
115 |
|
0 | 116 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
117 |
||
118 |
cost = EstimateRoadVehCost(p1); |
|
119 |
if (flags & DC_QUERY_COST) |
|
120 |
return cost; |
|
121 |
||
122 |
v = AllocateVehicle(); |
|
123 |
if (v == NULL || _ptr_to_next_order >= endof(_order_array)) |
|
124 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
125 |
||
126 |
/* find the first free roadveh id */ |
|
127 |
unit_num = GetFreeUnitNumber(VEH_Road); |
|
128 |
if (unit_num > _patches.max_roadveh) |
|
129 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
130 |
||
131 |
if (flags & DC_EXEC) { |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
132 |
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
|
133 |
|
0 | 134 |
v->unitnumber = unit_num; |
135 |
v->direction = 0; |
|
136 |
v->owner = _current_player; |
|
137 |
||
138 |
v->tile = tile; |
|
139 |
x = GET_TILE_X(tile)*16 + 8; |
|
140 |
y = GET_TILE_Y(tile)*16 + 8; |
|
141 |
v->x_pos = x; |
|
142 |
v->y_pos = y; |
|
143 |
v->z_pos = GetSlopeZ(x,y); |
|
144 |
v->z_height = 6; |
|
145 |
||
146 |
v->u.road.state = 254; |
|
147 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
148 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
149 |
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
|
150 |
v->cargo_type = rvi->cargo_type; |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
151 |
v->cargo_cap = rvi->capacity; |
0 | 152 |
// v->cargo_count = 0; |
153 |
v->value = cost; |
|
154 |
// v->day_counter = 0; |
|
155 |
// v->next_order_param = v->next_order = 0; |
|
156 |
// v->load_unload_time_rem = 0; |
|
157 |
// v->progress = 0; |
|
158 |
||
159 |
// v->u.road.unk2 = 0; |
|
160 |
// v->u.road.overtaking = 0; |
|
161 |
||
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
162 |
v->last_station_visited = 0xFFFF; |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
163 |
v->max_speed = rvi->max_speed; |
0 | 164 |
v->engine_type = (byte)p1; |
165 |
||
166 |
e = &_engines[p1]; |
|
167 |
v->reliability = e->reliability; |
|
168 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
169 |
v->max_age = e->lifelength * 366; |
|
170 |
_new_roadveh_id = v->index; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
171 |
|
0 | 172 |
v->string_id = STR_SV_ROADVEH_NAME; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
173 |
_ptr_to_next_order->type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
174 |
_ptr_to_next_order->flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
175 |
v->schedule_ptr = _ptr_to_next_order++; |
0 | 176 |
|
177 |
v->service_interval = _patches.servint_roadveh; |
|
178 |
||
179 |
v->date_of_last_service = _date; |
|
180 |
v->build_year = _cur_year; |
|
181 |
||
182 |
v->type = VEH_Road; |
|
183 |
v->cur_image = 0xC15; |
|
184 |
||
185 |
VehiclePositionChanged(v); |
|
186 |
||
187 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 188 |
RebuildVehicleLists(); |
0 | 189 |
InvalidateWindow(WC_COMPANY, v->owner); |
190 |
} |
|
191 |
||
192 |
return cost; |
|
193 |
} |
|
194 |
||
195 |
// p1 = vehicle |
|
196 |
int32 CmdStartStopRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
197 |
{ |
|
198 |
Vehicle *v; |
|
199 |
||
200 |
v = &_vehicles[p1]; |
|
201 |
||
202 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
203 |
return CMD_ERROR; |
|
204 |
||
205 |
if (flags & DC_EXEC) { |
|
206 |
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
|
207 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 208 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
209 |
} |
|
210 |
||
211 |
return 0; |
|
212 |
} |
|
213 |
||
214 |
int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
215 |
{ |
|
216 |
Vehicle *v; |
|
217 |
||
218 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
219 |
|
0 | 220 |
v = &_vehicles[p1]; |
221 |
||
222 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
223 |
return CMD_ERROR; |
|
224 |
||
225 |
if (!IsRoadDepotTile(v->tile) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) |
|
226 |
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
227 |
|
0 | 228 |
if (flags & DC_EXEC) { |
229 |
// Invalidate depot |
|
230 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 231 |
RebuildVehicleLists(); |
0 | 232 |
InvalidateWindow(WC_COMPANY, v->owner); |
233 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
234 |
DeleteVehicle(v); |
|
235 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
236 |
|
0 | 237 |
return -(int32)v->value; |
238 |
} |
|
239 |
||
240 |
typedef struct RoadFindDepotData { |
|
241 |
uint best_length; |
|
242 |
uint tile; |
|
243 |
byte owner; |
|
244 |
} RoadFindDepotData; |
|
245 |
||
246 |
||
247 |
static const TileIndexDiff _road_find_sig_dir_mod[4] = { |
|
248 |
TILE_XY(-1,0), |
|
249 |
TILE_XY(0,1), |
|
250 |
TILE_XY(1,0), |
|
251 |
TILE_XY(0,-1), |
|
252 |
}; |
|
253 |
||
254 |
static const byte _road_pf_directions[16] = { |
|
255 |
0, 1, 0, 1, 2, 1, 255, 255, |
|
256 |
2, 3, 3, 2, 3, 0, 255, 255, |
|
257 |
}; |
|
258 |
||
259 |
static bool EnumRoadSignalFindDepot(uint tile, RoadFindDepotData *rfdd, int track, uint length, byte *state) |
|
260 |
{ |
|
261 |
tile += _road_find_sig_dir_mod[_road_pf_directions[track]]; |
|
262 |
||
263 |
if (IS_TILETYPE(tile, MP_STREET) && |
|
264 |
(_map5[tile] & 0xF0) == 0x20 && |
|
265 |
_map_owner[tile] == rfdd->owner) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
266 |
|
0 | 267 |
if (length < rfdd->best_length) { |
268 |
rfdd->best_length = length; |
|
269 |
rfdd->tile = tile; |
|
270 |
} |
|
271 |
} |
|
272 |
return false; |
|
273 |
} |
|
274 |
||
275 |
static int FindClosestRoadDepot(Vehicle *v) |
|
276 |
{ |
|
277 |
uint tile = v->tile; |
|
278 |
int i; |
|
279 |
RoadFindDepotData rfdd; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
280 |
|
0 | 281 |
if (v->u.road.state == 255) { tile = GetVehicleOutOfTunnelTile(v); } |
282 |
||
283 |
rfdd.owner = v->owner; |
|
284 |
rfdd.best_length = (uint)-1; |
|
285 |
||
286 |
/* search in all directions */ |
|
287 |
for(i=0; i!=4; i++) |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
288 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd); |
0 | 289 |
|
290 |
if (rfdd.best_length == (uint)-1) |
|
291 |
return -1; |
|
292 |
||
293 |
return GetDepotByTile(rfdd.tile); |
|
294 |
} |
|
295 |
||
296 |
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
297 |
{ |
|
298 |
Vehicle *v = &_vehicles[p1]; |
|
299 |
int depot; |
|
300 |
||
301 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
302 |
return CMD_ERROR; |
|
303 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
304 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 305 |
if (flags & DC_EXEC) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
306 |
if (v->current_order.flags & OF_UNLOAD) |
0 | 307 |
v->cur_order_index++; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
308 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
309 |
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
|
310 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 311 |
} |
312 |
return 0; |
|
313 |
} |
|
314 |
||
315 |
depot = FindClosestRoadDepot(v); |
|
316 |
if (depot < 0) |
|
317 |
return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
|
318 |
||
319 |
if (flags & DC_EXEC) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
320 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
321 |
v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
322 |
v->current_order.station = (byte)depot; |
0 | 323 |
v->dest_tile = _depots[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
|
324 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 325 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
326 |
|
0 | 327 |
return 0; |
328 |
} |
|
329 |
||
330 |
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
331 |
{ |
|
332 |
Vehicle *v; |
|
333 |
||
334 |
v = &_vehicles[p1]; |
|
335 |
||
336 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
337 |
return CMD_ERROR; |
|
338 |
||
339 |
if (v->vehstatus & (VS_HIDDEN|VS_STOPPED) || |
|
340 |
v->u.road.crashed_ctr != 0 || |
|
341 |
v->breakdown_ctr != 0 || |
|
342 |
v->u.road.overtaking != 0 || |
|
343 |
v->cur_speed < 5) { |
|
344 |
_error_message = STR_EMPTY; |
|
345 |
return CMD_ERROR; |
|
346 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
347 |
|
0 | 348 |
if (flags & DC_EXEC) { |
349 |
v->u.road.reverse_ctr = 180; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
350 |
} |
0 | 351 |
|
352 |
return 0; |
|
353 |
} |
|
354 |
||
355 |
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
356 |
{ |
|
357 |
Vehicle *v; |
|
358 |
||
359 |
v = &_vehicles[p1]; |
|
360 |
||
361 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
362 |
return CMD_ERROR; |
|
363 |
||
364 |
if (flags & DC_EXEC) { |
|
365 |
v->service_interval = (uint16)p2; |
|
366 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
|
367 |
} |
|
368 |
||
369 |
return 0; |
|
370 |
} |
|
371 |
||
372 |
||
373 |
static void MarkRoadVehDirty(Vehicle *v) |
|
374 |
{ |
|
375 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
376 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
377 |
} |
|
378 |
||
379 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
380 |
{ |
|
381 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
382 |
static const uint32 _delta_xy_table[8] = { |
|
383 |
MKIT(3, 3, -1, -1), |
|
384 |
MKIT(3, 7, -1, -3), |
|
385 |
MKIT(3, 3, -1, -1), |
|
386 |
MKIT(7, 3, -3, -1), |
|
387 |
MKIT(3, 3, -1, -1), |
|
388 |
MKIT(3, 7, -1, -3), |
|
389 |
MKIT(3, 3, -1, -1), |
|
390 |
MKIT(7, 3, -3, -1), |
|
391 |
}; |
|
392 |
#undef MKIT |
|
393 |
uint32 x = _delta_xy_table[v->direction]; |
|
394 |
v->x_offs = (byte)x; |
|
395 |
v->y_offs = (byte)(x>>=8); |
|
396 |
v->sprite_width = (byte)(x>>=8); |
|
397 |
v->sprite_height = (byte)(x>>=8); |
|
398 |
} |
|
399 |
||
400 |
static void ClearCrashedStation(Vehicle *v) |
|
401 |
{ |
|
402 |
uint tile = v->tile; |
|
403 |
Station *st = DEREF_STATION(_map2[tile]); |
|
404 |
byte *b, bb; |
|
405 |
||
406 |
b = (_map5[tile] >= 0x47) ? &st->bus_stop_status : &st->truck_stop_status; |
|
407 |
||
408 |
bb = *b; |
|
409 |
||
410 |
// mark station as not busy |
|
411 |
bb &= ~0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
412 |
|
0 | 413 |
// free parking bay |
414 |
bb |= (v->u.road.state&0x02)?2:1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
415 |
|
0 | 416 |
*b = bb; |
417 |
} |
|
418 |
||
419 |
static void RoadVehDelete(Vehicle *v) |
|
420 |
{ |
|
421 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
422 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
423 |
|
588 | 424 |
RebuildVehicleLists(); |
0 | 425 |
InvalidateWindow(WC_COMPANY, v->owner); |
426 |
||
427 |
if(IS_TILETYPE(v->tile, MP_STATION)) |
|
428 |
ClearCrashedStation(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
429 |
|
0 | 430 |
BeginVehicleMove(v); |
431 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
432 |
|
0 | 433 |
DeleteVehicle(v); |
434 |
} |
|
435 |
||
436 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
437 |
{ |
|
438 |
byte new_z, old_z; |
|
439 |
||
440 |
// need this hint so it returns the right z coordinate on bridges. |
|
441 |
_get_z_hint = v->z_pos; |
|
442 |
new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y); |
|
443 |
_get_z_hint = 0; |
|
444 |
||
445 |
old_z = v->z_pos; |
|
446 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
447 |
|
0 | 448 |
VehiclePositionChanged(v); |
449 |
EndVehicleMove(v); |
|
450 |
return old_z; |
|
451 |
} |
|
452 |
||
453 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
454 |
{ |
|
455 |
static const int8 _turn_prob[4] = { -1, 0, 0, 1 }; |
|
456 |
uint32 r = Random(); |
|
457 |
v->direction = (v->direction+_turn_prob[r&3])&7; |
|
458 |
BeginVehicleMove(v); |
|
459 |
UpdateRoadVehDeltaXY(v); |
|
460 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
461 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
462 |
} |
|
463 |
||
464 |
static void RoadVehIsCrashed(Vehicle *v) |
|
465 |
{ |
|
466 |
v->u.road.crashed_ctr++; |
|
467 |
if (v->u.road.crashed_ctr == 2) { |
|
468 |
CreateEffectVehicleRel(v,4,4,8,EV_CRASHED_SMOKE); |
|
469 |
} else if (v->u.road.crashed_ctr <= 45) { |
|
470 |
if ((v->tick_counter&7)==0) |
|
471 |
RoadVehSetRandomDirection(v); |
|
472 |
} else if (v->u.road.crashed_ctr >= 2220) { |
|
473 |
RoadVehDelete(v); |
|
474 |
} |
|
475 |
} |
|
476 |
||
477 |
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u) |
|
478 |
{ |
|
479 |
if (v->type != VEH_Train || |
|
480 |
myabs(v->z_pos - u->z_pos) > 6 || |
|
481 |
myabs(v->x_pos - u->x_pos) > 4 || |
|
482 |
myabs(v->y_pos - u->y_pos) > 4) |
|
483 |
return NULL; |
|
484 |
return v; |
|
485 |
} |
|
486 |
||
487 |
static void RoadVehCrash(Vehicle *v) |
|
488 |
{ |
|
489 |
uint16 pass; |
|
490 |
||
491 |
v->u.road.crashed_ctr++; |
|
492 |
v->vehstatus |= VS_CRASHED; |
|
493 |
||
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
|
494 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 495 |
|
496 |
pass = 1; |
|
497 |
if (v->cargo_type == 0) |
|
498 |
pass += v->cargo_count; |
|
499 |
v->cargo_count = 0; |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
500 |
SetDParam(0, pass); |
0 | 501 |
|
502 |
AddNewsItem(STR_9031_ROAD_VEHICLE_CRASH_DRIVER+(pass!=1), |
|
503 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
504 |
v->index, |
|
505 |
0); |
|
506 |
||
507 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 508 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 509 |
} |
510 |
||
511 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
512 |
{ |
|
513 |
uint tile; |
|
514 |
||
515 |
if (v->u.road.state == 255) |
|
516 |
return; |
|
517 |
||
518 |
tile = v->tile; |
|
519 |
||
520 |
// Make sure it's a road/rail crossing |
|
521 |
if (!IS_TILETYPE(tile, MP_STREET) || |
|
522 |
(_map5[tile] & 0xF0) != 0x10) |
|
523 |
return; |
|
524 |
||
525 |
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL) |
|
526 |
RoadVehCrash(v); |
|
527 |
} |
|
528 |
||
529 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
530 |
{ |
|
531 |
if (v->breakdown_ctr != 1) { |
|
532 |
v->breakdown_ctr = 1; |
|
533 |
v->cur_speed = 0; |
|
534 |
||
535 |
if (v->breakdowns_since_last_service != 255) |
|
536 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
537 |
|
0 | 538 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
539 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
540 |
|
541 | 541 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
542 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
|
0 | 543 |
|
544 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
545 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
546 |
if (u) |
|
547 |
u->u.special.unk0 = v->breakdown_delay * 2; |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
if (!(v->tick_counter & 1)) { |
|
552 |
if (!--v->breakdown_delay) { |
|
553 |
v->breakdown_ctr = 0; |
|
554 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
555 |
} |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
560 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
561 |
Order order; |
0 | 562 |
Station *st; |
563 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
564 |
if (v->current_order.type >= OT_GOTO_DEPOT && v->current_order.type <= OT_LEAVESTATION) { |
0 | 565 |
// Let a depot order in the schedule interrupt. |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
566 |
if (v->current_order.type != OT_GOTO_DEPOT || |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
567 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 568 |
return; |
569 |
} |
|
570 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
571 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
572 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
593 | 573 |
!VehicleNeedsService(v)) { |
0 | 574 |
v->cur_order_index++; |
575 |
} |
|
576 |
||
577 |
if (v->cur_order_index >= v->num_orders) |
|
578 |
v->cur_order_index = 0; |
|
579 |
||
580 |
order = v->schedule_ptr[v->cur_order_index]; |
|
581 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
582 |
if (order.type == OT_NOTHING) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
583 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
584 |
v->current_order.flags = 0; |
0 | 585 |
v->dest_tile = 0; |
586 |
return; |
|
587 |
} |
|
588 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
589 |
if (order.type == v->current_order.type && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
590 |
order.flags == v->current_order.flags && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
591 |
order.station == v->current_order.station) |
0 | 592 |
return; |
593 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
594 |
v->current_order = order; |
0 | 595 |
|
596 |
v->dest_tile = 0; |
|
597 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
598 |
if (order.type == OT_GOTO_STATION) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
599 |
if (order.station == v->last_station_visited) |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
600 |
v->last_station_visited = 0xFFFF; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
601 |
st = DEREF_STATION(order.station); |
0 | 602 |
v->dest_tile = v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
603 |
} else if (order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
604 |
v->dest_tile = _depots[order.station].xy; |
0 | 605 |
} |
606 |
||
607 |
InvalidateVehicleOrderWidget(v); |
|
608 |
} |
|
609 |
||
610 |
static void HandleRoadVehLoading(Vehicle *v) |
|
611 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
612 |
if (v->current_order.type == OT_NOTHING) |
0 | 613 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
614 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
615 |
if (v->current_order.type != OT_DUMMY) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
616 |
if (v->current_order.type != OT_LOADING) |
0 | 617 |
return; |
618 |
||
619 |
if (--v->load_unload_time_rem) |
|
620 |
return; |
|
621 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
622 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 623 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
624 |
if (LoadUnloadVehicle(v)) { |
|
625 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
626 |
MarkRoadVehDirty(v); |
|
627 |
} |
|
628 |
return; |
|
629 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
630 |
|
0 | 631 |
{ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
632 |
Order b = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
633 |
v->current_order.type = OT_LEAVESTATION; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
634 |
v->current_order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
635 |
if (!(b.flags & OF_NON_STOP)) |
0 | 636 |
return; |
637 |
} |
|
638 |
} |
|
639 |
||
640 |
v->cur_order_index++; |
|
641 |
InvalidateVehicleOrderWidget(v); |
|
642 |
} |
|
643 |
||
644 |
static void StartRoadVehSound(Vehicle *v) |
|
645 |
{ |
|
541 | 646 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
647 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
|
648 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
|
0 | 649 |
SndPlayVehicleFx(s, v); |
650 |
} |
|
651 |
||
652 |
typedef struct RoadVehFindData { |
|
653 |
int x,y; |
|
654 |
Vehicle *veh; |
|
655 |
byte dir; |
|
656 |
} RoadVehFindData; |
|
657 |
||
658 |
void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf) |
|
659 |
{ |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
660 |
static const short _dists[] = { |
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
661 |
-4, -8, -4, -1, 4, 8, 4, 1, |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
662 |
-4, -1, 4, 8, 4, 1, -4, -8, |
0 | 663 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
664 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
665 |
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
|
666 |
short y_diff = v->y_pos - rvf->y; |
0 | 667 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
668 |
if (rvf->veh == v || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
669 |
v->type != VEH_Road || |
0 | 670 |
v->u.road.state == 254 || |
671 |
myabs(v->z_pos - rvf->veh->z_pos) > 6 || |
|
672 |
v->direction != rvf->dir || |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
673 |
(_dists[v->direction] < 0 && (x_diff <= _dists[v->direction] || x_diff > 0)) || |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
674 |
(_dists[v->direction] > 0 && (x_diff >= _dists[v->direction] || x_diff < 0)) || |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
675 |
(_dists[v->direction+8] < 0 && (y_diff <= _dists[v->direction+8] || y_diff > 0)) || |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
676 |
(_dists[v->direction+8] > 0 && (y_diff >= _dists[v->direction+8] || y_diff < 0))) |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
677 |
return NULL; |
0 | 678 |
|
679 |
return v; |
|
680 |
} |
|
681 |
||
682 |
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir) |
|
683 |
{ |
|
684 |
RoadVehFindData rvf; |
|
685 |
Vehicle *u; |
|
686 |
||
687 |
if (v->u.road.reverse_ctr != 0) |
|
688 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
689 |
|
0 | 690 |
rvf.x = x; |
691 |
rvf.y = y; |
|
692 |
rvf.dir = dir; |
|
693 |
rvf.veh = v; |
|
694 |
u = VehicleFromPos(TILE_FROM_XY(x,y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
695 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
696 |
// This code protects a roadvehicle from being blocked for ever |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
697 |
// If more then 1480 / 74 days a road vehicle is blocked, it will |
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
698 |
// 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
|
699 |
// It can be disabled. |
0 | 700 |
if (u == NULL) { |
701 |
v->u.road.unk2 = 0; |
|
702 |
return NULL; |
|
703 |
} |
|
704 |
||
705 |
if (++v->u.road.unk2 > 1480) |
|
706 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
707 |
|
0 | 708 |
return u; |
709 |
} |
|
710 |
||
711 |
static void RoadVehArrivesAt(Vehicle *v, Station *st) |
|
712 |
{ |
|
713 |
if (v->engine_type < 123) { |
|
714 |
/* Check if station was ever visited before */ |
|
715 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
716 |
uint32 flags; |
|
717 |
||
718 |
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
|
719 |
SetDParam(0, st->index); |
0 | 720 |
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); |
721 |
AddNewsItem( |
|
722 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
723 |
flags, |
|
724 |
v->index, |
|
725 |
0); |
|
726 |
} |
|
727 |
} else { |
|
728 |
/* Check if station was ever visited before */ |
|
729 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
730 |
uint32 flags; |
|
731 |
||
732 |
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
|
733 |
SetDParam(0, st->index); |
0 | 734 |
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); |
735 |
AddNewsItem( |
|
736 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
737 |
flags, |
|
738 |
v->index, |
|
739 |
0); |
|
740 |
} |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
static bool RoadVehAccelerate(Vehicle *v) |
|
745 |
{ |
|
746 |
uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0); |
|
747 |
byte t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
748 |
|
0 | 749 |
// Clamp |
750 |
spd = min(spd, v->max_speed); |
|
751 |
||
752 |
//updates statusbar only if speed have changed to save CPU time |
|
753 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
754 |
v->cur_speed = spd; |
0 | 755 |
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
|
756 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 757 |
} |
758 |
||
759 |
// Decrease somewhat when turning |
|
760 |
if (!(v->direction&1)) |
|
761 |
spd = spd * 3 >> 2; |
|
762 |
||
763 |
if (spd == 0) |
|
764 |
return false; |
|
765 |
||
766 |
if ((byte)++spd == 0) |
|
767 |
return true; |
|
768 |
||
769 |
v->progress = (t = v->progress) - (byte)spd; |
|
770 |
||
771 |
return (t < v->progress); |
|
772 |
} |
|
773 |
||
774 |
static byte RoadVehGetNewDirection(Vehicle *v, int x, int y) |
|
775 |
{ |
|
776 |
static const byte _roadveh_new_dir[11] = { |
|
777 |
0, 7, 6, 0, |
|
778 |
1, 0, 5, 0, |
|
779 |
2, 3, 4 |
|
780 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
781 |
|
0 | 782 |
x = x - v->x_pos + 1; |
783 |
y = y - v->y_pos + 1; |
|
784 |
||
785 |
if ((uint)x > 2 || (uint)y > 2) |
|
786 |
return v->direction; |
|
787 |
return _roadveh_new_dir[y*4+x]; |
|
788 |
} |
|
789 |
||
790 |
static byte RoadVehGetSlidingDirection(Vehicle *v, int x, int y) |
|
791 |
{ |
|
792 |
byte b = RoadVehGetNewDirection(v,x,y); |
|
793 |
byte d = v->direction; |
|
794 |
if (b == d) return d; |
|
795 |
d = (d+1)&7; |
|
796 |
if (b==d) return d; |
|
797 |
d = (d-2)&7; |
|
798 |
if (b==d) return d; |
|
799 |
if (b==((d-1)&7)) return d; |
|
800 |
if (b==((d-2)&7)) return d; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
801 |
return (d+2)&7; |
0 | 802 |
} |
803 |
||
804 |
typedef struct OvertakeData { |
|
805 |
Vehicle *u, *v; |
|
806 |
uint tile; |
|
807 |
byte tilebits; |
|
808 |
} OvertakeData; |
|
809 |
||
810 |
void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od) |
|
811 |
{ |
|
812 |
if (v->tile != (TileIndex)od->tile || |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
813 |
v->type != VEH_Road || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
814 |
v == od->u || |
0 | 815 |
v == od->v) |
816 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
817 |
return v; |
0 | 818 |
} |
819 |
||
820 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
821 |
{ |
|
822 |
uint32 bits; |
|
823 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
824 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F; |
0 | 825 |
|
826 |
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000)) |
|
827 |
return true; |
|
828 |
return VehicleFromPos(od->tile, od, (VehicleFromPosProc*)EnumFindVehToOvertake) != NULL; |
|
829 |
} |
|
830 |
||
831 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
832 |
{ |
|
833 |
OvertakeData od; |
|
834 |
byte tt; |
|
835 |
||
836 |
od.v = v; |
|
837 |
od.u = u; |
|
838 |
||
839 |
if (u->max_speed >= v->max_speed && |
|
840 |
!(u->vehstatus&VS_STOPPED) && |
|
841 |
u->cur_speed != 0) |
|
842 |
return; |
|
843 |
||
844 |
if (v->direction != u->direction || !(v->direction&1)) |
|
845 |
return; |
|
846 |
||
847 |
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) |
|
848 |
return; |
|
849 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
850 |
tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F); |
0 | 851 |
if ((tt & 3) == 0) |
852 |
return; |
|
853 |
if ((tt & 0x3C) != 0) |
|
854 |
return; |
|
855 |
||
856 |
if (tt == 3) { |
|
857 |
tt = (v->direction&2)?2:1; |
|
858 |
} |
|
859 |
od.tilebits = tt; |
|
860 |
||
861 |
od.tile = v->tile; |
|
862 |
if (FindRoadVehToOvertake(&od)) |
|
863 |
return; |
|
864 |
||
865 |
od.tile = v->tile + _tileoffs_by_dir[v->direction>>1]; |
|
866 |
if (FindRoadVehToOvertake(&od)) |
|
867 |
return; |
|
868 |
||
869 |
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) { |
|
870 |
v->u.road.overtaking_ctr = 0x11; |
|
871 |
v->u.road.overtaking = 0x10; |
|
872 |
} else { |
|
873 |
// if (FindRoadVehToOvertake(&od)) |
|
874 |
// return; |
|
875 |
v->u.road.overtaking_ctr = 0; |
|
876 |
v->u.road.overtaking = 0x10; |
|
877 |
} |
|
878 |
} |
|
879 |
||
880 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
881 |
{ |
|
882 |
if (old_z == v->z_pos) |
|
883 |
return; |
|
884 |
||
885 |
if (old_z < v->z_pos) { |
|
886 |
v->cur_speed = v->cur_speed * 232 >> 8; |
|
887 |
} else { |
|
888 |
uint16 spd = v->cur_speed + 2; |
|
889 |
if (spd <= v->max_speed) |
|
890 |
v->cur_speed = spd; |
|
891 |
} |
|
892 |
} |
|
893 |
||
894 |
static int PickRandomBit(uint bits) |
|
895 |
{ |
|
896 |
uint num = 0; |
|
897 |
uint b = bits; |
|
898 |
uint i; |
|
899 |
||
900 |
do { |
|
901 |
if (b & 1) |
|
902 |
num++; |
|
903 |
} while (b >>= 1); |
|
904 |
||
905 |
num = ((uint16)Random() * num >> 16); |
|
906 |
||
907 |
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++); |
|
908 |
return i; |
|
909 |
} |
|
910 |
||
911 |
typedef struct { |
|
912 |
TileIndex dest; |
|
913 |
uint maxtracklen; |
|
914 |
uint mindist; |
|
915 |
} FindRoadToChooseData; |
|
916 |
||
917 |
static bool EnumRoadTrackFindDist(uint tile, FindRoadToChooseData *frd, int track, uint length, byte *state) |
|
918 |
{ |
|
919 |
uint dist = GetTileDist(tile, frd->dest); |
|
920 |
if (dist <= frd->mindist) { |
|
921 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
922 |
frd->maxtracklen = length; |
|
923 |
} |
|
924 |
frd->mindist = dist; |
|
925 |
} |
|
926 |
return false; |
|
927 |
} |
|
928 |
||
929 |
// Returns direction to choose |
|
930 |
// or -1 if the direction is currently blocked |
|
931 |
static int RoadFindPathToDest(Vehicle *v, uint tile, int direction) |
|
932 |
{ |
|
933 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
934 |
||
935 |
uint16 signal; |
|
936 |
uint bitmask; |
|
937 |
uint desttile; |
|
938 |
FindRoadToChooseData frd; |
|
939 |
int best_track; |
|
940 |
uint best_dist, best_maxlen; |
|
941 |
uint i; |
|
942 |
byte m5; |
|
943 |
||
944 |
{ |
|
945 |
uint32 r; |
|
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
946 |
r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 947 |
signal = (uint16)(r >> 16); |
948 |
bitmask = (uint16)r; |
|
949 |
} |
|
950 |
||
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
951 |
if (IS_TILETYPE(tile, MP_STREET)) { |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
952 |
if ((_map5[tile]&0xF0) == 0x20 && v->owner == _map_owner[tile]) |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
953 |
/* Road crossing */ |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
954 |
bitmask |= _road_veh_fp_ax_or[_map5[tile]&3]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
955 |
} else if (IS_TILETYPE(tile, MP_STATION)) { |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
956 |
if (_map_owner[tile] == OWNER_NONE || _map_owner[tile] == v->owner) { |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
957 |
/* Our station */ |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
958 |
Station *st = DEREF_STATION(_map2[tile]); |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
959 |
byte val = _map5[tile]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
960 |
if (v->cargo_type != CT_PASSENGERS) { |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
961 |
if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stop_status&3)) |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
962 |
bitmask |= _road_veh_fp_ax_or[(val-0x43)&3]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
963 |
} else { |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
964 |
if (IS_BYTE_INSIDE(val, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stop_status&3)) |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
965 |
bitmask |= _road_veh_fp_ax_or[(val-0x47)&3]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
966 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
967 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
968 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
969 |
/* 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
|
970 |
* 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
|
971 |
* 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
|
972 |
*/ |
0 | 973 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
974 |
/* remove unreachable tracks */ |
0 | 975 |
bitmask &= _road_veh_fp_ax_and[direction]; |
976 |
if (bitmask == 0) { |
|
977 |
// reverse |
|
978 |
return_track(_road_reverse_table[direction]); |
|
979 |
} |
|
980 |
||
981 |
if (v->u.road.reverse_ctr != 0) { |
|
982 |
v->u.road.reverse_ctr = 0; |
|
983 |
if (v->tile != (TileIndex)tile) { |
|
984 |
return_track(_road_reverse_table[direction]); |
|
985 |
} |
|
986 |
} |
|
987 |
||
988 |
desttile = v->dest_tile; |
|
989 |
if (desttile == 0) { |
|
990 |
// Pick a random direction |
|
991 |
return_track(PickRandomBit(bitmask)); |
|
992 |
} |
|
993 |
||
994 |
// Only one direction to choose between? |
|
995 |
if (!(bitmask & (bitmask - 1))) { |
|
996 |
return_track(FindFirstBit2x64(bitmask)); |
|
997 |
} |
|
998 |
||
999 |
if (IS_TILETYPE(desttile, MP_STREET)) { |
|
1000 |
m5 = _map5[desttile]; |
|
1001 |
if ((m5&0xF0) == 0x20) |
|
1002 |
goto do_it; |
|
1003 |
} else if (IS_TILETYPE(desttile, MP_STATION)) { |
|
1004 |
m5 = _map5[desttile]; |
|
1005 |
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
|
1006 |
m5 -= 0x43; |
|
1007 |
do_it:; |
|
1008 |
desttile += _tileoffs_by_dir[m5&3]; |
|
1009 |
if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) { |
|
1010 |
return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3])); |
|
1011 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1012 |
} |
0 | 1013 |
} |
1014 |
// do pathfind |
|
1015 |
frd.dest = desttile; |
|
1016 |
||
1017 |
best_track = -1; |
|
1018 |
best_dist = (uint)-1; |
|
1019 |
best_maxlen = (uint)-1; |
|
1020 |
i = 0; |
|
1021 |
do { |
|
1022 |
if (bitmask & 1) { |
|
1023 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a direction |
|
1024 |
frd.maxtracklen = (uint)-1; |
|
1025 |
frd.mindist = (uint)-1; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1026 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
0 | 1027 |
|
1028 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
|
1029 |
best_dist = frd.mindist; |
|
1030 |
best_maxlen = frd.maxtracklen; |
|
1031 |
best_track = i; |
|
1032 |
} |
|
1033 |
} |
|
1034 |
} while (++i,(bitmask>>=1) != 0); |
|
1035 |
||
1036 |
found_best_track:; |
|
1037 |
||
1038 |
if (HASBIT(signal, best_track)) |
|
1039 |
return -1; |
|
1040 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1041 |
return best_track; |
0 | 1042 |
} |
1043 |
||
1044 |
typedef struct RoadDriveEntry { |
|
1045 |
byte x,y; |
|
1046 |
} RoadDriveEntry; |
|
1047 |
||
1048 |
#include "table/roadveh.h" |
|
1049 |
||
1050 |
static const byte _road_veh_data_1[] = { |
|
1051 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1052 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1053 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1054 |
15, 15, 11, 11 |
|
1055 |
}; |
|
1056 |
||
1057 |
static const byte _roadveh_data_2[4] = { 0,1,8,9 }; |
|
1058 |
||
1059 |
static void RoadVehEventHandler(Vehicle *v) |
|
1060 |
{ |
|
1061 |
GetNewVehiclePosResult gp; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1062 |
byte new_dir, old_dir; |
0 | 1063 |
RoadDriveEntry rd; |
1064 |
int x,y; |
|
1065 |
Station *st; |
|
1066 |
uint32 r; |
|
1067 |
Vehicle *u; |
|
1068 |
||
1069 |
// decrease counters |
|
1070 |
v->tick_counter++; |
|
1071 |
if (v->u.road.reverse_ctr != 0) |
|
1072 |
v->u.road.reverse_ctr--; |
|
1073 |
||
1074 |
// handle crashed |
|
1075 |
if (v->u.road.crashed_ctr != 0) { |
|
1076 |
RoadVehIsCrashed(v); |
|
1077 |
return; |
|
1078 |
} |
|
1079 |
||
1080 |
RoadVehCheckTrainCrash(v); |
|
1081 |
||
1082 |
// road vehicle has broken down? |
|
1083 |
if (v->breakdown_ctr != 0) { |
|
1084 |
if (v->breakdown_ctr <= 2) { |
|
1085 |
HandleBrokenRoadVeh(v); |
|
1086 |
return; |
|
1087 |
} |
|
1088 |
v->breakdown_ctr--; |
|
1089 |
} |
|
1090 |
||
1091 |
// exit if vehicle is stopped |
|
1092 |
if (v->vehstatus & VS_STOPPED) |
|
1093 |
return; |
|
1094 |
||
1095 |
ProcessRoadVehOrder(v); |
|
1096 |
HandleRoadVehLoading(v); |
|
1097 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1098 |
if (v->current_order.type == OT_LOADING) |
0 | 1099 |
return; |
1100 |
||
1101 |
if (v->u.road.state == 254) { |
|
1102 |
int dir; |
|
1103 |
const RoadDriveEntry*rdp; |
|
1104 |
byte rd2; |
|
1105 |
||
1106 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1107 |
|
0 | 1108 |
dir = _map5[v->tile]&3; |
1109 |
v->direction = dir*2+1; |
|
1110 |
||
1111 |
rd2 = _roadveh_data_2[dir]; |
|
1112 |
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
|
1113 |
|
0 | 1114 |
x = GET_TILE_X(v->tile)*16 + (rdp[6].x&0xF); |
1115 |
y = GET_TILE_Y(v->tile)*16 + (rdp[6].y&0xF); |
|
1116 |
||
1117 |
if (RoadVehFindCloseTo(v,x,y,v->direction)) |
|
1118 |
return; |
|
1119 |
||
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
|
1120 |
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
|
1121 |
|
0 | 1122 |
StartRoadVehSound(v); |
1123 |
||
1124 |
BeginVehicleMove(v); |
|
1125 |
||
1126 |
v->vehstatus &= ~VS_HIDDEN; |
|
1127 |
v->u.road.state = rd2; |
|
1128 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1129 |
|
0 | 1130 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1131 |
UpdateRoadVehDeltaXY(v); |
|
1132 |
SetRoadVehPosition(v,x,y); |
|
1133 |
||
1134 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1135 |
return; |
|
1136 |
} |
|
1137 |
||
1138 |
if (!RoadVehAccelerate(v)) |
|
1139 |
return; |
|
1140 |
||
1141 |
if (v->u.road.overtaking != 0) { |
|
1142 |
if (++v->u.road.overtaking_ctr >= 35) |
|
1143 |
v->u.road.overtaking = 0; |
|
1144 |
} |
|
1145 |
||
1146 |
BeginVehicleMove(v); |
|
1147 |
||
1148 |
if (v->u.road.state == 255) { |
|
1149 |
GetNewVehiclePos(v, &gp); |
|
1150 |
||
1151 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction)) { |
|
1152 |
v->cur_speed = 0; |
|
1153 |
return; |
|
1154 |
} |
|
1155 |
||
1156 |
if (IS_TILETYPE(gp.new_tile, MP_TUNNELBRIDGE) && |
|
1157 |
(_map5[gp.new_tile]&0xF0) == 0 && |
|
1158 |
(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&4)) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1159 |
|
0 | 1160 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1161 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1162 |
UpdateRoadVehDeltaXY(v); |
|
1163 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1164 |
return; |
|
1165 |
} |
|
1166 |
||
1167 |
v->x_pos = gp.x; |
|
1168 |
v->y_pos = gp.y; |
|
1169 |
VehiclePositionChanged(v); |
|
1170 |
return; |
|
1171 |
} |
|
1172 |
||
1173 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1]; |
|
1174 |
||
1175 |
// switch to another tile |
|
1176 |
if (rd.x & 0x80) { |
|
1177 |
uint tile = v->tile + _tileoffs_by_dir[rd.x&3]; |
|
1178 |
int dir = RoadFindPathToDest(v, tile, rd.x&3); |
|
1179 |
int tmp; |
|
1180 |
uint32 r; |
|
1181 |
byte newdir; |
|
1182 |
const RoadDriveEntry *rdp; |
|
1183 |
||
1184 |
if (dir == -1) { |
|
1185 |
v->cur_speed = 0; |
|
1186 |
return; |
|
1187 |
} |
|
1188 |
||
1189 |
again: |
|
1190 |
if ((dir & 7) >= 6) { |
|
1191 |
tile = v->tile; |
|
1192 |
} |
|
1193 |
||
1194 |
tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking; |
|
1195 |
rdp = _road_drive_data[tmp]; |
|
1196 |
||
1197 |
tmp &= ~0x10; |
|
1198 |
||
1199 |
x = GET_TILE_X(tile)*16 + rdp[0].x; |
|
1200 |
y = GET_TILE_Y(tile)*16 + rdp[0].y; |
|
1201 |
||
1202 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1203 |
return; |
|
1204 |
||
1205 |
r = VehicleEnterTile(v, tile, x, y); |
|
1206 |
if (r & 8) { |
|
1207 |
if (!IS_TILETYPE(tile, MP_TUNNELBRIDGE)) { |
|
1208 |
v->cur_speed = 0; |
|
1209 |
return; |
|
1210 |
} |
|
1211 |
dir = _road_reverse_table[rd.x&3]; |
|
1212 |
goto again; |
|
1213 |
} |
|
1214 |
||
1215 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IS_TILETYPE(v->tile, MP_STATION)) { |
|
1216 |
if ((tmp&7) >= 6) { v->cur_speed = 0; return; } |
|
1217 |
if (IS_BYTE_INSIDE(_map5[v->tile], 0x43, 0x4B)) { |
|
1218 |
Station *st = DEREF_STATION(_map2[v->tile]); |
|
1219 |
byte *b; |
|
1220 |
||
1221 |
if (_map5[v->tile] >= 0x47) { |
|
1222 |
b = &st->bus_stop_status; |
|
1223 |
} else { |
|
1224 |
b = &st->truck_stop_status; |
|
1225 |
} |
|
1226 |
*b = (*b | ((v->u.road.state&2)?2:1)) & 0x7F; |
|
1227 |
} |
|
1228 |
} |
|
1229 |
||
1230 |
if (!(r & 4)) { |
|
1231 |
v->tile = tile; |
|
1232 |
v->u.road.state = (byte)tmp; |
|
1233 |
v->u.road.frame = 0; |
|
1234 |
} |
|
1235 |
if (newdir != v->direction) { |
|
1236 |
v->direction = newdir; |
|
1237 |
v->cur_speed -= v->cur_speed >> 2; |
|
1238 |
} |
|
1239 |
||
1240 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1241 |
UpdateRoadVehDeltaXY(v); |
|
1242 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1243 |
return; |
|
1244 |
} |
|
1245 |
||
1246 |
if (rd.x & 0x40) { |
|
1247 |
int dir = RoadFindPathToDest(v, v->tile, rd.x&3); |
|
1248 |
uint32 r; |
|
1249 |
int tmp; |
|
1250 |
byte newdir; |
|
1251 |
const RoadDriveEntry *rdp; |
|
1252 |
||
1253 |
if (dir == -1) { |
|
1254 |
v->cur_speed = 0; |
|
1255 |
return; |
|
1256 |
} |
|
1257 |
||
1258 |
tmp = (_opt.road_side<<4) + dir; |
|
1259 |
rdp = _road_drive_data[tmp]; |
|
1260 |
||
1261 |
x = GET_TILE_X(v->tile)*16 + rdp[1].x; |
|
1262 |
y = GET_TILE_Y(v->tile)*16 + rdp[1].y; |
|
1263 |
||
1264 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1265 |
return; |
|
1266 |
||
1267 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1268 |
if (r & 8) { |
|
1269 |
v->cur_speed = 0; |
|
1270 |
return; |
|
1271 |
} |
|
1272 |
||
1273 |
v->u.road.state = tmp & ~16; |
|
1274 |
v->u.road.frame = 1; |
|
1275 |
||
1276 |
if (newdir != v->direction) { |
|
1277 |
v->direction = newdir; |
|
1278 |
v->cur_speed -= v->cur_speed >> 2; |
|
1279 |
} |
|
1280 |
||
1281 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1282 |
UpdateRoadVehDeltaXY(v); |
|
1283 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1284 |
return; |
|
1285 |
} |
|
1286 |
||
1287 |
x = (v->x_pos&~15)+(rd.x&15); |
|
1288 |
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
|
1289 |
|
0 | 1290 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1291 |
||
1292 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) { |
|
1293 |
if (v->u.road.overtaking == 0) |
|
1294 |
RoadVehCheckOvertake(v, u); |
|
1295 |
return; |
|
1296 |
} |
|
1297 |
||
1298 |
old_dir = v->direction; |
|
1299 |
if (new_dir != old_dir) { |
|
1300 |
v->direction = new_dir; |
|
1301 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1302 |
if (old_dir != v->u.road.state) { |
|
1303 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1304 |
UpdateRoadVehDeltaXY(v); |
|
1305 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1306 |
return; |
|
1307 |
} |
|
1308 |
} |
|
1309 |
||
1310 |
if (v->u.road.state >= 0x20 && |
|
1311 |
_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) { |
|
1312 |
byte *b; |
|
1313 |
||
1314 |
st = DEREF_STATION(_map2[v->tile]); |
|
1315 |
b = IS_BYTE_INSIDE(_map5[v->tile], 0x43, 0x47) ? &st->truck_stop_status : &st->bus_stop_status; |
|
1316 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1317 |
if (v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1318 |
v->current_order.type != OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1319 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1320 |
|
0 | 1321 |
*b &= ~0x80; |
1322 |
||
1323 |
v->last_station_visited = _map2[v->tile]; |
|
1324 |
||
1325 |
RoadVehArrivesAt(v, st); |
|
1326 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1327 |
old_order = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1328 |
v->current_order.type = OT_LOADING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1329 |
v->current_order.flags = 0; |
0 | 1330 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1331 |
if (old_order.type == OT_GOTO_STATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1332 |
v->current_order.station == v->last_station_visited) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1333 |
v->current_order.flags = |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1334 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP; |
0 | 1335 |
} |
1336 |
||
1337 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
1338 |
if (LoadUnloadVehicle(v)) { |
|
1339 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1340 |
MarkRoadVehDirty(v); |
|
1341 |
} |
|
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
|
1342 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1343 |
return; |
1344 |
} |
|
1345 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1346 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
0 | 1347 |
if (*b&0x80) { |
1348 |
v->cur_speed = 0; |
|
1349 |
return; |
|
1350 |
} |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1351 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1352 |
v->current_order.flags = 0; |
0 | 1353 |
} |
1354 |
*b |= 0x80; |
|
1355 |
||
1356 |
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
|
1357 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1358 |
} |
1359 |
||
1360 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1361 |
if (r & 8) { |
|
1362 |
v->cur_speed = 0; |
|
1363 |
return; |
|
1364 |
} |
|
1365 |
||
1366 |
if ((r & 4) == 0) { |
|
1367 |
v->u.road.frame++; |
|
1368 |
} |
|
1369 |
||
1370 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1371 |
UpdateRoadVehDeltaXY(v); |
|
1372 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1373 |
} |
|
1374 |
||
1375 |
void RoadVehEnterDepot(Vehicle *v) |
|
1376 |
{ |
|
1377 |
v->u.road.state = 254; |
|
1378 |
v->vehstatus |= VS_HIDDEN; |
|
1379 |
||
1380 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1381 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
1382 |
MaybeRenewVehicle(v); |
0 | 1383 |
|
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
|
1384 |
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
|
1385 |
|
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
|
1386 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1387 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1388 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1389 |
Order t; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1390 |
|
0 | 1391 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1392 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1393 |
t = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1394 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1395 |
v->current_order.flags = 0; |
0 | 1396 |
|
1397 |
// Part of the schedule? |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1398 |
if (t.flags & OF_UNLOAD) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1399 |
v->cur_order_index++; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1400 |
} else if (t.flags & OF_FULL_LOAD) { |
0 | 1401 |
v->vehstatus |= VS_STOPPED; |
1402 |
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
|
1403 |
SetDParam(0, v->unitnumber); |
0 | 1404 |
AddNewsItem( |
1405 |
STR_9016_ROAD_VEHICLE_IS_WAITING, |
|
1406 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1407 |
v->index, |
|
1408 |
0); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
} |
|
1412 |
||
1413 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1414 |
} |
|
1415 |
||
1416 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1417 |
{ |
|
1418 |
if (_age_cargo_skip_counter != 0) |
|
1419 |
return; |
|
1420 |
if (v->cargo_days != 255) |
|
1421 |
v->cargo_days++; |
|
1422 |
} |
|
1423 |
||
1424 |
void RoadVeh_Tick(Vehicle *v) |
|
1425 |
{ |
|
1426 |
AgeRoadVehCargo(v); |
|
1427 |
RoadVehEventHandler(v); |
|
1428 |
} |
|
1429 |
||
1430 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1431 |
{ |
|
1432 |
int i; |
|
1433 |
||
76
30511cbc5188
(svn r77) -Fix: [1010788] AI service interval bug (tnx truesatan)
truelight
parents:
63
diff
changeset
|
1434 |
if (_patches.servint_roadveh == 0) |
11
836bc4b37b5b
(svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents:
0
diff
changeset
|
1435 |
return; |
836bc4b37b5b
(svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents:
0
diff
changeset
|
1436 |
|
593 | 1437 |
if (!VehicleNeedsService(v)) |
0 | 1438 |
return; |
1439 |
||
1440 |
if (v->vehstatus & VS_STOPPED) |
|
1441 |
return; |
|
1442 |
||
76
30511cbc5188
(svn r77) -Fix: [1010788] AI service interval bug (tnx truesatan)
truelight
parents:
63
diff
changeset
|
1443 |
if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr)) |
0 | 1444 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1445 |
|
0 | 1446 |
// Don't interfere with a depot visit scheduled by the user, or a |
1447 |
// depot visit by the order list. |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1448 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1449 |
(v->current_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) != 0) |
0 | 1450 |
return; |
1451 |
||
1452 |
i = FindClosestRoadDepot(v); |
|
1453 |
||
1454 |
if (i < 0 || GetTileDist(v->tile, (&_depots[i])->xy) > 12) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1455 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1456 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1457 |
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
|
1458 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1459 |
} |
1460 |
return; |
|
1461 |
} |
|
1462 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1463 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1464 |
v->current_order.flags & OF_NON_STOP && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1465 |
!CHANCE16(1,20)) |
0 | 1466 |
return; |
1467 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1468 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1469 |
v->current_order.flags = OF_NON_STOP; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1470 |
v->current_order.station = (byte)i; |
0 | 1471 |
v->dest_tile = (&_depots[i])->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
|
1472 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1473 |
} |
1474 |
||
1475 |
void OnNewDay_RoadVeh(Vehicle *v) |
|
1476 |
{ |
|
1477 |
int32 cost; |
|
1478 |
Station *st; |
|
1479 |
uint tile; |
|
1480 |
||
1481 |
if ((++v->day_counter & 7) == 0) |
|
1482 |
DecreaseVehicleValue(v); |
|
1483 |
||
1484 |
if (v->u.road.unk2 == 0) |
|
1485 |
CheckVehicleBreakdown(v); |
|
1486 |
||
1487 |
AgeVehicle(v); |
|
1488 |
CheckIfRoadVehNeedsService(v); |
|
1489 |
||
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1490 |
CheckOrders(v); |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1491 |
|
0 | 1492 |
/* update destination */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1493 |
if (v->current_order.type == OT_GOTO_STATION) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1494 |
st = DEREF_STATION(v->current_order.station); |
0 | 1495 |
if ((tile=(v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile)) != 0) |
1496 |
v->dest_tile = tile; |
|
1497 |
} |
|
1498 |
||
1499 |
if (v->vehstatus & VS_STOPPED) |
|
1500 |
return; |
|
1501 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1502 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1503 |
|
1504 |
v->profit_this_year -= cost >> 8; |
|
1505 |
||
1506 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1507 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1508 |
||
1509 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1510 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1511 |
} |
|
1512 |
||
1513 |
void HandleClickOnRoadVeh(Vehicle *v) |
|
1514 |
{ |
|
1515 |
ShowRoadVehViewWindow(v); |
|
1516 |
} |
|
1517 |
||
1518 |
void RoadVehiclesYearlyLoop() |
|
1519 |
{ |
|
1520 |
Vehicle *v; |
|
1521 |
||
1522 |
FOR_ALL_VEHICLES(v) { |
|
1523 |
if (v->type == VEH_Road) { |
|
1524 |
v->profit_last_year = v->profit_this_year; |
|
1525 |
v->profit_this_year = 0; |
|
1526 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1527 |
} |
|
1528 |
} |
|
1529 |
} |
|
1530 |