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