author | Celestar |
Tue, 08 Mar 2005 16:27:26 +0000 | |
changeset 1455 | d6772f61e1ce |
parent 1442 | a166ae688746 |
child 1467 | 6be9302390be |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
3 |
#include "debug.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
4 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
5 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
6 |
#include "tile.h" |
0 | 7 |
#include "vehicle.h" |
8 |
#include "engine.h" |
|
9 |
#include "command.h" |
|
10 |
#include "station.h" |
|
11 |
#include "news.h" |
|
12 |
#include "gfx.h" |
|
13 |
#include "pathfind.h" |
|
1247 | 14 |
#include "npf.h" |
0 | 15 |
#include "player.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
16 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
17 |
#include "depot.h" |
0 | 18 |
|
19 |
void ShowRoadVehViewWindow(Vehicle *v); |
|
20 |
||
21 |
static const uint16 _roadveh_images[63] = { |
|
22 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
23 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
24 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
25 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
26 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
27 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
28 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
29 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
30 |
}; |
|
31 |
||
32 |
static const uint16 _roadveh_full_adder[63] = { |
|
33 |
0, 88, 0, 0, 0, 0, 48, 48, |
|
34 |
48, 48, 0, 0, 64, 64, 0, 16, |
|
35 |
16, 0, 88, 0, 0, 0, 0, 48, |
|
36 |
48, 48, 48, 0, 0, 64, 64, 0, |
|
37 |
16, 16, 0, 88, 0, 0, 0, 0, |
|
38 |
48, 48, 48, 48, 0, 0, 64, 64, |
|
39 |
0, 16, 16, 0, 8, 8, 8, 8, |
|
40 |
0, 0, 0, 8, 8, 8, 8 |
|
41 |
}; |
|
42 |
||
43 |
||
44 |
static const uint16 _road_veh_fp_ax_or[4] = { |
|
45 |
0x100,0x200,1,2, |
|
46 |
}; |
|
47 |
||
48 |
static const uint16 _road_veh_fp_ax_and[4] = { |
|
49 |
0x1009, 0x16, 0x520, 0x2A00 |
|
50 |
}; |
|
51 |
||
52 |
static const byte _road_reverse_table[4] = { |
|
53 |
6, 7, 14, 15 |
|
54 |
}; |
|
55 |
||
56 |
static const uint16 _road_pf_table_3[4] = { |
|
57 |
0x910, 0x1600, 0x2005, 0x2A |
|
58 |
}; |
|
59 |
||
60 |
int GetRoadVehImage(Vehicle *v, byte direction) |
|
61 |
{ |
|
62 |
int img = v->spritenum; |
|
63 |
int image; |
|
64 |
||
65 |
if (is_custom_sprite(img)) { |
|
66 |
image = GetCustomVehicleSprite(v, direction); |
|
67 |
if (image) return image; |
|
68 |
img = _engine_original_sprites[v->engine_type]; |
|
69 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
70 |
|
0 | 71 |
image = direction + _roadveh_images[img]; |
72 |
if (v->cargo_count >= (v->cargo_cap >> 1)) |
|
73 |
image += _roadveh_full_adder[img]; |
|
74 |
return image; |
|
75 |
} |
|
76 |
||
77 |
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod) |
|
78 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
79 |
int spritenum = RoadVehInfo(engine)->image_index; |
378
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
80 |
|
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
81 |
if (is_custom_sprite(spritenum)) { |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
82 |
int sprite = GetCustomVehicleIcon(engine, 6); |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
83 |
|
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
84 |
if (sprite) { |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
85 |
DrawSprite(sprite | image_ormod, x, y); |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
86 |
return; |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
87 |
} |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
88 |
spritenum = _engine_original_sprites[engine]; |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
89 |
} |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
90 |
DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y); |
0 | 91 |
} |
92 |
||
93 |
void DrawRoadVehEngineInfo(int engine, int x, int y, int maxw) |
|
94 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
95 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine); |
0 | 96 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
97 |
SetDParam(0, ((_price.roadveh_base >> 3) * rvi->base_cost) >> 5); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
98 |
SetDParam(1, rvi->max_speed * 10 >> 5); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
99 |
SetDParam(2, rvi->running_cost * _price.roadveh_running >> 8); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
100 |
|
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
101 |
SetDParam(4, rvi->capacity); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
102 |
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
|
103 |
|
0 | 104 |
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw); |
105 |
} |
|
106 |
||
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
107 |
int32 EstimateRoadVehCost(byte engine_type) |
0 | 108 |
{ |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
109 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 110 |
} |
111 |
||
842 | 112 |
// p1 = engine_type |
113 |
// p2 not used |
|
0 | 114 |
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
115 |
{ |
|
116 |
int32 cost; |
|
117 |
Vehicle *v; |
|
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
118 |
UnitID unit_num; |
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
119 |
TileIndex tile = TILE_FROM_XY(x,y); |
0 | 120 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
121 |
|
1197 | 122 |
if (!IsEngineBuildable(p1, VEH_Road)) return CMD_ERROR; |
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
123 |
|
0 | 124 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
125 |
||
126 |
cost = EstimateRoadVehCost(p1); |
|
127 |
if (flags & DC_QUERY_COST) |
|
128 |
return cost; |
|
129 |
||
1442
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
130 |
/* The ai_new queries the vehicle cost before building the route, |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
131 |
* so we must check against cheaters no sooner than now. --pasky */ |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
132 |
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR; |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
133 |
if (_map_owner[tile] != _current_player) return CMD_ERROR; |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
134 |
|
0 | 135 |
v = AllocateVehicle(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
136 |
if (v == NULL || IsOrderPoolFull()) |
0 | 137 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
138 |
||
139 |
/* find the first free roadveh id */ |
|
140 |
unit_num = GetFreeUnitNumber(VEH_Road); |
|
141 |
if (unit_num > _patches.max_roadveh) |
|
142 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
143 |
||
144 |
if (flags & DC_EXEC) { |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
145 |
const RoadVehicleInfo *rvi = RoadVehInfo(p1); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
146 |
|
0 | 147 |
v->unitnumber = unit_num; |
148 |
v->direction = 0; |
|
149 |
v->owner = _current_player; |
|
150 |
||
151 |
v->tile = tile; |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
152 |
x = TileX(tile) * 16 + 8; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
153 |
y = TileY(tile) * 16 + 8; |
0 | 154 |
v->x_pos = x; |
155 |
v->y_pos = y; |
|
156 |
v->z_pos = GetSlopeZ(x,y); |
|
157 |
v->z_height = 6; |
|
158 |
||
159 |
v->u.road.state = 254; |
|
160 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
161 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
162 |
v->spritenum = rvi->image_index; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
163 |
v->cargo_type = rvi->cargo_type; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
164 |
v->cargo_cap = rvi->capacity; |
0 | 165 |
// v->cargo_count = 0; |
166 |
v->value = cost; |
|
167 |
// v->day_counter = 0; |
|
168 |
// v->next_order_param = v->next_order = 0; |
|
169 |
// v->load_unload_time_rem = 0; |
|
170 |
// v->progress = 0; |
|
171 |
||
172 |
// v->u.road.unk2 = 0; |
|
173 |
// v->u.road.overtaking = 0; |
|
174 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
175 |
v->u.road.slot = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
176 |
v->u.road.slotindex = 0; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
177 |
v->u.road.slot_age = 0; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
178 |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
179 |
v->last_station_visited = INVALID_STATION; |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
180 |
v->max_speed = rvi->max_speed; |
0 | 181 |
v->engine_type = (byte)p1; |
182 |
||
183 |
e = &_engines[p1]; |
|
184 |
v->reliability = e->reliability; |
|
185 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
186 |
v->max_age = e->lifelength * 366; |
|
187 |
_new_roadveh_id = v->index; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
188 |
|
0 | 189 |
v->string_id = STR_SV_ROADVEH_NAME; |
190 |
||
191 |
v->service_interval = _patches.servint_roadveh; |
|
192 |
||
193 |
v->date_of_last_service = _date; |
|
194 |
v->build_year = _cur_year; |
|
195 |
||
196 |
v->type = VEH_Road; |
|
197 |
v->cur_image = 0xC15; |
|
198 |
||
199 |
VehiclePositionChanged(v); |
|
200 |
||
201 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 202 |
RebuildVehicleLists(); |
0 | 203 |
InvalidateWindow(WC_COMPANY, v->owner); |
204 |
} |
|
205 |
||
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
206 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
207 |
|
0 | 208 |
return cost; |
209 |
} |
|
210 |
||
211 |
// p1 = vehicle |
|
212 |
int32 CmdStartStopRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
213 |
{ |
|
214 |
Vehicle *v; |
|
215 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
216 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
217 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
218 |
v = GetVehicle(p1); |
0 | 219 |
|
220 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
221 |
return CMD_ERROR; |
|
222 |
||
223 |
if (flags & DC_EXEC) { |
|
224 |
v->vehstatus ^= VS_STOPPED; |
|
755
80091de50044
(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
|
225 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 226 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
227 |
} |
|
228 |
||
229 |
return 0; |
|
230 |
} |
|
231 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
232 |
// p1 = vehicle index in GetVehicle() |
842 | 233 |
// p2 not used |
0 | 234 |
int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
235 |
{ |
|
236 |
Vehicle *v; |
|
237 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
238 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
239 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
240 |
v = GetVehicle(p1); |
0 | 241 |
|
242 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
243 |
return CMD_ERROR; |
|
244 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
245 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
246 |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
247 |
if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) |
0 | 248 |
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
|
249 |
|
0 | 250 |
if (flags & DC_EXEC) { |
251 |
// Invalidate depot |
|
252 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 253 |
RebuildVehicleLists(); |
0 | 254 |
InvalidateWindow(WC_COMPANY, v->owner); |
255 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
256 |
DeleteVehicle(v); |
|
257 |
} |
|
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
258 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
259 |
|
0 | 260 |
return -(int32)v->value; |
261 |
} |
|
262 |
||
263 |
typedef struct RoadFindDepotData { |
|
264 |
uint best_length; |
|
265 |
uint tile; |
|
266 |
byte owner; |
|
267 |
} RoadFindDepotData; |
|
268 |
||
269 |
static const byte _road_pf_directions[16] = { |
|
270 |
0, 1, 0, 1, 2, 1, 255, 255, |
|
271 |
2, 3, 3, 2, 3, 0, 255, 255, |
|
272 |
}; |
|
273 |
||
274 |
static bool EnumRoadSignalFindDepot(uint tile, RoadFindDepotData *rfdd, int track, uint length, byte *state) |
|
275 |
{ |
|
904
f659cda593cb
(svn r1390) Use TileOffsByDir() instead of home brewed table
tron
parents:
900
diff
changeset
|
276 |
tile += TileOffsByDir(_road_pf_directions[track]); |
0 | 277 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
278 |
if (IsTileType(tile, MP_STREET) && |
0 | 279 |
(_map5[tile] & 0xF0) == 0x20 && |
280 |
_map_owner[tile] == rfdd->owner) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
281 |
|
0 | 282 |
if (length < rfdd->best_length) { |
283 |
rfdd->best_length = length; |
|
284 |
rfdd->tile = tile; |
|
285 |
} |
|
286 |
} |
|
287 |
return false; |
|
288 |
} |
|
289 |
||
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
290 |
static Depot *FindClosestRoadDepot(Vehicle *v) |
0 | 291 |
{ |
292 |
uint tile = v->tile; |
|
293 |
int i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
294 |
|
0 | 295 |
if (v->u.road.state == 255) { tile = GetVehicleOutOfTunnelTile(v); } |
296 |
||
1247 | 297 |
if (_patches.new_pathfinding_all) { |
298 |
NPFFoundTargetData ftd; |
|
299 |
/* See where we are now */ |
|
300 |
byte trackdir = _dir_to_diag_trackdir[(v->direction>>1)&3]; |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
301 |
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner); |
1247 | 302 |
if (ftd.best_bird_dist == 0) |
303 |
return GetDepotByTile(ftd.node.tile); /* Target found */ |
|
304 |
else |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
305 |
return NULL; /* Target not found */ |
1247 | 306 |
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ |
307 |
} else { |
|
308 |
RoadFindDepotData rfdd; |
|
309 |
rfdd.owner = v->owner; |
|
310 |
rfdd.best_length = (uint)-1; |
|
0 | 311 |
|
1247 | 312 |
/* search in all directions */ |
313 |
for(i=0; i!=4; i++) |
|
314 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd); |
|
0 | 315 |
|
1247 | 316 |
if (rfdd.best_length == (uint)-1) |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
317 |
return NULL; |
0 | 318 |
|
1247 | 319 |
return GetDepotByTile(rfdd.tile); |
320 |
} |
|
0 | 321 |
} |
322 |
||
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
323 |
/* Send a road vehicle to the nearest depot |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
324 |
p1 = index of the road vehicle |
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
325 |
p2 = bit 0 = do not stop in depot |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
326 |
bit 1 = set v->set_for_replacement |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
327 |
bit 2 = clear v->set_for_replacement */ |
0 | 328 |
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
329 |
{ |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
330 |
Vehicle *v; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
331 |
Depot *depot; |
0 | 332 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
333 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
334 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
335 |
v = GetVehicle(p1); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
336 |
|
0 | 337 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
338 |
return CMD_ERROR; |
|
339 |
||
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
340 |
if (HASBIT(p2, 0)) v->set_for_replacement = true; |
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
341 |
if (HASBIT(p2, 2)) v->set_for_replacement = false; |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
342 |
|
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
343 |
if (HASBIT(p2, 1) || HASBIT(p2, 2)) return CMD_ERROR; // vehicle has a depot in schedule. It just needed to alter set_for_replacement |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
344 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
345 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 346 |
if (flags & DC_EXEC) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
347 |
if (v->current_order.flags & OF_UNLOAD) |
0 | 348 |
v->cur_order_index++; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
349 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
350 |
v->current_order.flags = 0; |
755
80091de50044
(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
|
351 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 352 |
} |
353 |
return 0; |
|
354 |
} |
|
355 |
||
356 |
depot = FindClosestRoadDepot(v); |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
357 |
if (depot == NULL) |
0 | 358 |
return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
359 |
||
360 |
if (flags & DC_EXEC) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
361 |
v->current_order.type = OT_GOTO_DEPOT; |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
362 |
v->current_order.flags = p2 == 0 ? OF_NON_STOP | OF_FULL_LOAD : 0; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
363 |
v->current_order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
364 |
v->dest_tile = depot->xy; |
755
80091de50044
(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
|
365 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 366 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
367 |
|
0 | 368 |
return 0; |
369 |
} |
|
370 |
||
371 |
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
372 |
{ |
|
373 |
Vehicle *v; |
|
374 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
375 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
376 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
377 |
v = GetVehicle(p1); |
0 | 378 |
|
379 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
380 |
return CMD_ERROR; |
|
381 |
||
382 |
if (v->vehstatus & (VS_HIDDEN|VS_STOPPED) || |
|
383 |
v->u.road.crashed_ctr != 0 || |
|
384 |
v->breakdown_ctr != 0 || |
|
385 |
v->u.road.overtaking != 0 || |
|
386 |
v->cur_speed < 5) { |
|
387 |
_error_message = STR_EMPTY; |
|
388 |
return CMD_ERROR; |
|
389 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
390 |
|
0 | 391 |
if (flags & DC_EXEC) { |
392 |
v->u.road.reverse_ctr = 180; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
393 |
} |
0 | 394 |
|
395 |
return 0; |
|
396 |
} |
|
397 |
||
398 |
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
399 |
{ |
|
400 |
Vehicle *v; |
|
401 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
402 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
403 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
404 |
v = GetVehicle(p1); |
0 | 405 |
|
406 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
407 |
return CMD_ERROR; |
|
408 |
||
409 |
if (flags & DC_EXEC) { |
|
410 |
v->service_interval = (uint16)p2; |
|
411 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
|
412 |
} |
|
413 |
||
414 |
return 0; |
|
415 |
} |
|
416 |
||
417 |
||
418 |
static void MarkRoadVehDirty(Vehicle *v) |
|
419 |
{ |
|
420 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
421 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
422 |
} |
|
423 |
||
424 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
425 |
{ |
|
426 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
427 |
static const uint32 _delta_xy_table[8] = { |
|
428 |
MKIT(3, 3, -1, -1), |
|
429 |
MKIT(3, 7, -1, -3), |
|
430 |
MKIT(3, 3, -1, -1), |
|
431 |
MKIT(7, 3, -3, -1), |
|
432 |
MKIT(3, 3, -1, -1), |
|
433 |
MKIT(3, 7, -1, -3), |
|
434 |
MKIT(3, 3, -1, -1), |
|
435 |
MKIT(7, 3, -3, -1), |
|
436 |
}; |
|
437 |
#undef MKIT |
|
438 |
uint32 x = _delta_xy_table[v->direction]; |
|
439 |
v->x_offs = (byte)x; |
|
440 |
v->y_offs = (byte)(x>>=8); |
|
441 |
v->sprite_width = (byte)(x>>=8); |
|
442 |
v->sprite_height = (byte)(x>>=8); |
|
443 |
} |
|
444 |
||
445 |
static void ClearCrashedStation(Vehicle *v) |
|
446 |
{ |
|
447 |
uint tile = v->tile; |
|
448 |
byte *b, bb; |
|
449 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
450 |
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
451 |
b = &rs->status; |
0 | 452 |
|
453 |
bb = *b; |
|
454 |
||
455 |
// mark station as not busy |
|
456 |
bb &= ~0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
457 |
|
0 | 458 |
// free parking bay |
459 |
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
|
460 |
|
0 | 461 |
*b = bb; |
462 |
} |
|
463 |
||
464 |
static void RoadVehDelete(Vehicle *v) |
|
465 |
{ |
|
466 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
467 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
468 |
|
588 | 469 |
RebuildVehicleLists(); |
0 | 470 |
InvalidateWindow(WC_COMPANY, v->owner); |
471 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
472 |
if (IsTileType(v->tile, MP_STATION)) |
0 | 473 |
ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
474 |
|
0 | 475 |
BeginVehicleMove(v); |
476 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
477 |
|
0 | 478 |
DeleteVehicle(v); |
479 |
} |
|
480 |
||
481 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
482 |
{ |
|
483 |
byte new_z, old_z; |
|
484 |
||
485 |
// need this hint so it returns the right z coordinate on bridges. |
|
486 |
_get_z_hint = v->z_pos; |
|
487 |
new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y); |
|
488 |
_get_z_hint = 0; |
|
489 |
||
490 |
old_z = v->z_pos; |
|
491 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
492 |
|
0 | 493 |
VehiclePositionChanged(v); |
494 |
EndVehicleMove(v); |
|
495 |
return old_z; |
|
496 |
} |
|
497 |
||
498 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
499 |
{ |
|
500 |
static const int8 _turn_prob[4] = { -1, 0, 0, 1 }; |
|
501 |
uint32 r = Random(); |
|
502 |
v->direction = (v->direction+_turn_prob[r&3])&7; |
|
503 |
BeginVehicleMove(v); |
|
504 |
UpdateRoadVehDeltaXY(v); |
|
505 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
506 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
507 |
} |
|
508 |
||
509 |
static void RoadVehIsCrashed(Vehicle *v) |
|
510 |
{ |
|
511 |
v->u.road.crashed_ctr++; |
|
512 |
if (v->u.road.crashed_ctr == 2) { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
513 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 514 |
} else if (v->u.road.crashed_ctr <= 45) { |
515 |
if ((v->tick_counter&7)==0) |
|
516 |
RoadVehSetRandomDirection(v); |
|
517 |
} else if (v->u.road.crashed_ctr >= 2220) { |
|
518 |
RoadVehDelete(v); |
|
519 |
} |
|
520 |
} |
|
521 |
||
522 |
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u) |
|
523 |
{ |
|
524 |
if (v->type != VEH_Train || |
|
525 |
myabs(v->z_pos - u->z_pos) > 6 || |
|
526 |
myabs(v->x_pos - u->x_pos) > 4 || |
|
527 |
myabs(v->y_pos - u->y_pos) > 4) |
|
528 |
return NULL; |
|
529 |
return v; |
|
530 |
} |
|
531 |
||
532 |
static void RoadVehCrash(Vehicle *v) |
|
533 |
{ |
|
534 |
uint16 pass; |
|
535 |
||
536 |
v->u.road.crashed_ctr++; |
|
537 |
v->vehstatus |= VS_CRASHED; |
|
538 |
||
755
80091de50044
(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
|
539 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 540 |
|
541 |
pass = 1; |
|
542 |
if (v->cargo_type == 0) |
|
543 |
pass += v->cargo_count; |
|
544 |
v->cargo_count = 0; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
545 |
SetDParam(0, pass); |
0 | 546 |
|
547 |
AddNewsItem(STR_9031_ROAD_VEHICLE_CRASH_DRIVER+(pass!=1), |
|
548 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
549 |
v->index, |
|
550 |
0); |
|
551 |
||
552 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 553 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 554 |
} |
555 |
||
556 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
557 |
{ |
|
558 |
uint tile; |
|
559 |
||
560 |
if (v->u.road.state == 255) |
|
561 |
return; |
|
562 |
||
563 |
tile = v->tile; |
|
564 |
||
565 |
// Make sure it's a road/rail crossing |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
566 |
if (!IsTileType(tile, MP_STREET) || |
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
567 |
(_map5[tile] & 0xF0) != 0x10) |
0 | 568 |
return; |
569 |
||
570 |
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL) |
|
571 |
RoadVehCrash(v); |
|
572 |
} |
|
573 |
||
574 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
575 |
{ |
|
576 |
if (v->breakdown_ctr != 1) { |
|
577 |
v->breakdown_ctr = 1; |
|
578 |
v->cur_speed = 0; |
|
579 |
||
580 |
if (v->breakdowns_since_last_service != 255) |
|
581 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
582 |
|
0 | 583 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
584 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
585 |
|
541 | 586 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
587 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
|
0 | 588 |
|
589 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
590 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
591 |
if (u) |
|
592 |
u->u.special.unk0 = v->breakdown_delay * 2; |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
if (!(v->tick_counter & 1)) { |
|
597 |
if (!--v->breakdown_delay) { |
|
598 |
v->breakdown_ctr = 0; |
|
599 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
600 |
} |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
605 |
{ |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
606 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
607 |
const Station *st; |
0 | 608 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
609 |
if (v->current_order.type >= OT_GOTO_DEPOT && v->current_order.type <= OT_LEAVESTATION) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
610 |
// Let a depot order in the orderlist interrupt. |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
611 |
if (v->current_order.type != OT_GOTO_DEPOT || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
612 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 613 |
return; |
614 |
} |
|
615 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
616 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
617 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
618 |
!VehicleNeedsService(v) && !v->set_for_replacement) { |
0 | 619 |
v->cur_order_index++; |
620 |
} |
|
621 |
||
622 |
if (v->cur_order_index >= v->num_orders) |
|
623 |
v->cur_order_index = 0; |
|
624 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
625 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 626 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
627 |
if (order == NULL) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
628 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
629 |
v->current_order.flags = 0; |
0 | 630 |
v->dest_tile = 0; |
631 |
return; |
|
632 |
} |
|
633 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
634 |
if (order->type == v->current_order.type && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
635 |
order->flags == v->current_order.flags && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
636 |
order->station == v->current_order.station) |
0 | 637 |
return; |
638 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
639 |
v->current_order = *order; |
0 | 640 |
|
641 |
v->dest_tile = 0; |
|
642 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
643 |
if (order->type == OT_GOTO_STATION) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
644 |
if (order->station == v->last_station_visited) |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
645 |
v->last_station_visited = INVALID_STATION; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
646 |
st = GetStation(order->station); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
647 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
648 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
649 |
int32 *dist; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
650 |
int32 mindist = 0xFFFFFFFF; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
651 |
int num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
652 |
RoadStopType type; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
653 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
654 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
655 |
type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
656 |
num = GetNumRoadStops(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
657 |
rs = GetPrimaryRoadStop(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
658 |
|
1231
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
659 |
if (rs == NULL) { |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
660 |
//There is no stop left at the station, so don't even TRY to go there |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
661 |
v->cur_order_index++; |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
662 |
InvalidateVehicleOrder(v); |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
663 |
|
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
664 |
return; |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
665 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
666 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
667 |
dist = malloc(num * sizeof(int32)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
668 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
669 |
do { |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
670 |
*dist = DistanceSquare(v->tile, rs->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
671 |
if (*dist < mindist) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
672 |
v->dest_tile = rs->xy; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
673 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
674 |
rs = rs->next; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
675 |
} while ( rs != NULL ); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
676 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
677 |
free(dist); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
678 |
dist = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
679 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
680 |
} else if (order->type == OT_GOTO_DEPOT) { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
681 |
v->dest_tile = GetDepot(order->station)->xy; |
0 | 682 |
} |
683 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
684 |
InvalidateVehicleOrder(v); |
0 | 685 |
} |
686 |
||
687 |
static void HandleRoadVehLoading(Vehicle *v) |
|
688 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
689 |
if (v->current_order.type == OT_NOTHING) |
0 | 690 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
691 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
692 |
if (v->current_order.type != OT_DUMMY) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
693 |
if (v->current_order.type != OT_LOADING) |
0 | 694 |
return; |
695 |
||
696 |
if (--v->load_unload_time_rem) |
|
697 |
return; |
|
698 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
699 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 700 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
701 |
if (LoadUnloadVehicle(v)) { |
|
702 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
703 |
MarkRoadVehDirty(v); |
|
704 |
} |
|
705 |
return; |
|
706 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
707 |
|
0 | 708 |
{ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
709 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
710 |
v->current_order.type = OT_LEAVESTATION; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
711 |
v->current_order.flags = 0; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
712 |
if (!(b.flags & OF_NON_STOP)) |
0 | 713 |
return; |
714 |
} |
|
715 |
} |
|
716 |
||
717 |
v->cur_order_index++; |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
718 |
InvalidateVehicleOrder(v); |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
719 |
|
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
720 |
if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
721 |
// only the vehicle owner needs to calculate the rest (locally) |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
722 |
if ((_autoreplace_array[v->engine_type] != v->engine_type) || |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
723 |
(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
724 |
byte flags = 1; |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
725 |
// the flags means, bit 0 = needs to go to depot, bit 1 = have depot in orders |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
726 |
if (VehicleHasDepotOrders(v)) SETBIT(flags, 1); |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
727 |
if (!(HASBIT(flags, 1) && v->set_for_replacement)) { |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
728 |
_current_player = _local_player; |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
729 |
DoCommandP(v->tile, v->index, flags, NULL, CMD_SEND_ROADVEH_TO_DEPOT | CMD_SHOW_NO_ERROR); |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
730 |
_current_player = OWNER_NONE; |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
731 |
} |
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
732 |
} else { // no need to go to a depot |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
733 |
if (v->set_for_replacement) { |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
734 |
// it seems that the user clicked "Stop replacing" |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
735 |
_current_player = _local_player; |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
736 |
DoCommandP(v->tile, v->index, 1 | (1 << 2), NULL, CMD_SEND_ROADVEH_TO_DEPOT | CMD_SHOW_NO_ERROR); |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
737 |
_current_player = OWNER_NONE; |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
738 |
} |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
739 |
} |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
740 |
} |
0 | 741 |
} |
742 |
||
743 |
static void StartRoadVehSound(Vehicle *v) |
|
744 |
{ |
|
541 | 745 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
746 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
|
747 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
|
0 | 748 |
SndPlayVehicleFx(s, v); |
749 |
} |
|
750 |
||
751 |
typedef struct RoadVehFindData { |
|
752 |
int x,y; |
|
753 |
Vehicle *veh; |
|
754 |
byte dir; |
|
755 |
} RoadVehFindData; |
|
756 |
||
1095 | 757 |
static void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf) |
0 | 758 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
759 |
static const short _dists[] = { |
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
760 |
-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
|
761 |
-4, -1, 4, 8, 4, 1, -4, -8, |
0 | 762 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
763 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
764 |
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
|
765 |
short y_diff = v->y_pos - rvf->y; |
0 | 766 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
767 |
if (rvf->veh == v || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
768 |
v->type != VEH_Road || |
0 | 769 |
v->u.road.state == 254 || |
770 |
myabs(v->z_pos - rvf->veh->z_pos) > 6 || |
|
771 |
v->direction != rvf->dir || |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
772 |
(_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
|
773 |
(_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
|
774 |
(_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
|
775 |
(_dists[v->direction+8] > 0 && (y_diff >= _dists[v->direction+8] || y_diff < 0))) |
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
776 |
return NULL; |
0 | 777 |
|
778 |
return v; |
|
779 |
} |
|
780 |
||
781 |
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir) |
|
782 |
{ |
|
783 |
RoadVehFindData rvf; |
|
784 |
Vehicle *u; |
|
785 |
||
786 |
if (v->u.road.reverse_ctr != 0) |
|
787 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
788 |
|
0 | 789 |
rvf.x = x; |
790 |
rvf.y = y; |
|
791 |
rvf.dir = dir; |
|
792 |
rvf.veh = v; |
|
793 |
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
|
794 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
795 |
// This code protects a roadvehicle from being blocked for ever |
826 | 796 |
// 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
|
797 |
// 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
|
798 |
// It can be disabled. |
0 | 799 |
if (u == NULL) { |
800 |
v->u.road.unk2 = 0; |
|
801 |
return NULL; |
|
802 |
} |
|
803 |
||
804 |
if (++v->u.road.unk2 > 1480) |
|
805 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
806 |
|
0 | 807 |
return u; |
808 |
} |
|
809 |
||
810 |
static void RoadVehArrivesAt(Vehicle *v, Station *st) |
|
811 |
{ |
|
812 |
if (v->engine_type < 123) { |
|
813 |
/* Check if station was ever visited before */ |
|
814 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
815 |
uint32 flags; |
|
816 |
||
817 |
st->had_vehicle_of_type |= HVOT_BUS; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
818 |
SetDParam(0, st->index); |
0 | 819 |
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); |
820 |
AddNewsItem( |
|
821 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
822 |
flags, |
|
823 |
v->index, |
|
824 |
0); |
|
825 |
} |
|
826 |
} else { |
|
827 |
/* Check if station was ever visited before */ |
|
828 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
829 |
uint32 flags; |
|
830 |
||
831 |
st->had_vehicle_of_type |= HVOT_TRUCK; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
832 |
SetDParam(0, st->index); |
0 | 833 |
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); |
834 |
AddNewsItem( |
|
835 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
836 |
flags, |
|
837 |
v->index, |
|
838 |
0); |
|
839 |
} |
|
840 |
} |
|
841 |
} |
|
842 |
||
843 |
static bool RoadVehAccelerate(Vehicle *v) |
|
844 |
{ |
|
845 |
uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0); |
|
846 |
byte t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
847 |
|
0 | 848 |
// Clamp |
849 |
spd = min(spd, v->max_speed); |
|
850 |
||
851 |
//updates statusbar only if speed have changed to save CPU time |
|
852 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
853 |
v->cur_speed = spd; |
0 | 854 |
if (_patches.vehicle_speed) |
755
80091de50044
(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
|
855 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 856 |
} |
857 |
||
858 |
// Decrease somewhat when turning |
|
859 |
if (!(v->direction&1)) |
|
860 |
spd = spd * 3 >> 2; |
|
861 |
||
862 |
if (spd == 0) |
|
863 |
return false; |
|
864 |
||
865 |
if ((byte)++spd == 0) |
|
866 |
return true; |
|
867 |
||
868 |
v->progress = (t = v->progress) - (byte)spd; |
|
869 |
||
870 |
return (t < v->progress); |
|
871 |
} |
|
872 |
||
873 |
static byte RoadVehGetNewDirection(Vehicle *v, int x, int y) |
|
874 |
{ |
|
875 |
static const byte _roadveh_new_dir[11] = { |
|
876 |
0, 7, 6, 0, |
|
877 |
1, 0, 5, 0, |
|
878 |
2, 3, 4 |
|
879 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
880 |
|
0 | 881 |
x = x - v->x_pos + 1; |
882 |
y = y - v->y_pos + 1; |
|
883 |
||
884 |
if ((uint)x > 2 || (uint)y > 2) |
|
885 |
return v->direction; |
|
886 |
return _roadveh_new_dir[y*4+x]; |
|
887 |
} |
|
888 |
||
889 |
static byte RoadVehGetSlidingDirection(Vehicle *v, int x, int y) |
|
890 |
{ |
|
891 |
byte b = RoadVehGetNewDirection(v,x,y); |
|
892 |
byte d = v->direction; |
|
893 |
if (b == d) return d; |
|
894 |
d = (d+1)&7; |
|
895 |
if (b==d) return d; |
|
896 |
d = (d-2)&7; |
|
897 |
if (b==d) return d; |
|
898 |
if (b==((d-1)&7)) return d; |
|
899 |
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
|
900 |
return (d+2)&7; |
0 | 901 |
} |
902 |
||
903 |
typedef struct OvertakeData { |
|
904 |
Vehicle *u, *v; |
|
905 |
uint tile; |
|
906 |
byte tilebits; |
|
907 |
} OvertakeData; |
|
908 |
||
1095 | 909 |
static void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od) |
0 | 910 |
{ |
911 |
if (v->tile != (TileIndex)od->tile || |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
912 |
v->type != VEH_Road || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
913 |
v == od->u || |
0 | 914 |
v == od->v) |
915 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
916 |
return v; |
0 | 917 |
} |
918 |
||
919 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
920 |
{ |
|
921 |
uint32 bits; |
|
922 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
923 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F; |
0 | 924 |
|
925 |
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000)) |
|
926 |
return true; |
|
927 |
return VehicleFromPos(od->tile, od, (VehicleFromPosProc*)EnumFindVehToOvertake) != NULL; |
|
928 |
} |
|
929 |
||
930 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
931 |
{ |
|
932 |
OvertakeData od; |
|
933 |
byte tt; |
|
934 |
||
935 |
od.v = v; |
|
936 |
od.u = u; |
|
937 |
||
938 |
if (u->max_speed >= v->max_speed && |
|
939 |
!(u->vehstatus&VS_STOPPED) && |
|
940 |
u->cur_speed != 0) |
|
941 |
return; |
|
942 |
||
943 |
if (v->direction != u->direction || !(v->direction&1)) |
|
944 |
return; |
|
945 |
||
946 |
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) |
|
947 |
return; |
|
948 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
949 |
tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F); |
0 | 950 |
if ((tt & 3) == 0) |
951 |
return; |
|
952 |
if ((tt & 0x3C) != 0) |
|
953 |
return; |
|
954 |
||
955 |
if (tt == 3) { |
|
956 |
tt = (v->direction&2)?2:1; |
|
957 |
} |
|
958 |
od.tilebits = tt; |
|
959 |
||
960 |
od.tile = v->tile; |
|
961 |
if (FindRoadVehToOvertake(&od)) |
|
962 |
return; |
|
963 |
||
900 | 964 |
od.tile = v->tile + TileOffsByDir(v->direction >> 1); |
0 | 965 |
if (FindRoadVehToOvertake(&od)) |
966 |
return; |
|
967 |
||
968 |
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) { |
|
969 |
v->u.road.overtaking_ctr = 0x11; |
|
970 |
v->u.road.overtaking = 0x10; |
|
971 |
} else { |
|
972 |
// if (FindRoadVehToOvertake(&od)) |
|
973 |
// return; |
|
974 |
v->u.road.overtaking_ctr = 0; |
|
975 |
v->u.road.overtaking = 0x10; |
|
976 |
} |
|
977 |
} |
|
978 |
||
979 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
980 |
{ |
|
981 |
if (old_z == v->z_pos) |
|
982 |
return; |
|
983 |
||
984 |
if (old_z < v->z_pos) { |
|
985 |
v->cur_speed = v->cur_speed * 232 >> 8; |
|
986 |
} else { |
|
987 |
uint16 spd = v->cur_speed + 2; |
|
988 |
if (spd <= v->max_speed) |
|
989 |
v->cur_speed = spd; |
|
990 |
} |
|
991 |
} |
|
992 |
||
993 |
static int PickRandomBit(uint bits) |
|
994 |
{ |
|
995 |
uint num = 0; |
|
996 |
uint b = bits; |
|
997 |
uint i; |
|
998 |
||
999 |
do { |
|
1000 |
if (b & 1) |
|
1001 |
num++; |
|
1002 |
} while (b >>= 1); |
|
1003 |
||
1004 |
num = ((uint16)Random() * num >> 16); |
|
1005 |
||
1006 |
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++); |
|
1007 |
return i; |
|
1008 |
} |
|
1009 |
||
1010 |
typedef struct { |
|
1011 |
TileIndex dest; |
|
1012 |
uint maxtracklen; |
|
1013 |
uint mindist; |
|
1014 |
} FindRoadToChooseData; |
|
1015 |
||
1016 |
static bool EnumRoadTrackFindDist(uint tile, FindRoadToChooseData *frd, int track, uint length, byte *state) |
|
1017 |
{ |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
1018 |
uint dist = DistanceManhattan(tile, frd->dest); |
0 | 1019 |
if (dist <= frd->mindist) { |
1020 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
1021 |
frd->maxtracklen = length; |
|
1022 |
} |
|
1023 |
frd->mindist = dist; |
|
1024 |
} |
|
1025 |
return false; |
|
1026 |
} |
|
1027 |
||
1028 |
// Returns direction to choose |
|
1029 |
// or -1 if the direction is currently blocked |
|
1247 | 1030 |
static int RoadFindPathToDest(Vehicle *v, uint tile, int enterdir) |
0 | 1031 |
{ |
1032 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
1033 |
||
1034 |
uint16 signal; |
|
1035 |
uint bitmask; |
|
1036 |
uint desttile; |
|
1037 |
FindRoadToChooseData frd; |
|
1038 |
int best_track; |
|
1039 |
uint best_dist, best_maxlen; |
|
1040 |
uint i; |
|
1041 |
byte m5; |
|
1042 |
||
1043 |
{ |
|
1044 |
uint32 r; |
|
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1045 |
r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 1046 |
signal = (uint16)(r >> 16); |
1047 |
bitmask = (uint16)r; |
|
1048 |
} |
|
1049 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1050 |
if (IsTileType(tile, MP_STREET)) { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1051 |
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
|
1052 |
/* Road crossing */ |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1053 |
bitmask |= _road_veh_fp_ax_or[_map5[tile]&3]; |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1054 |
} else if (IsTileType(tile, MP_STATION)) { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1055 |
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
|
1056 |
/* Our station */ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1057 |
Station *st = GetStation(_map2[tile]); |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1058 |
byte val = _map5[tile]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1059 |
if (v->cargo_type != CT_PASSENGERS) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1060 |
if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3)) |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1061 |
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
|
1062 |
} else { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1063 |
if (IS_BYTE_INSIDE(val, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stops->status&3)) |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1064 |
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
|
1065 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1066 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1067 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1068 |
/* 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
|
1069 |
* 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
|
1070 |
* 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
|
1071 |
*/ |
0 | 1072 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1073 |
/* remove unreachable tracks */ |
1247 | 1074 |
bitmask &= _road_veh_fp_ax_and[enterdir]; |
0 | 1075 |
if (bitmask == 0) { |
1247 | 1076 |
/* No reachable tracks, so we'll reverse */ |
1077 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1078 |
} |
1079 |
||
1080 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1081 |
/* What happens here?? */ |
0 | 1082 |
v->u.road.reverse_ctr = 0; |
1083 |
if (v->tile != (TileIndex)tile) { |
|
1247 | 1084 |
return_track(_road_reverse_table[enterdir]); |
0 | 1085 |
} |
1086 |
} |
|
1087 |
||
1088 |
desttile = v->dest_tile; |
|
1089 |
if (desttile == 0) { |
|
1247 | 1090 |
// Pick a random track |
0 | 1091 |
return_track(PickRandomBit(bitmask)); |
1092 |
} |
|
1093 |
||
1247 | 1094 |
// Only one track to choose between? |
1095 |
if (!(KillFirstBit2x64(bitmask))) { |
|
0 | 1096 |
return_track(FindFirstBit2x64(bitmask)); |
1097 |
} |
|
1098 |
||
1247 | 1099 |
if (_patches.new_pathfinding_all) { |
1100 |
NPFFindStationOrTileData fstd; |
|
1101 |
NPFFoundTargetData ftd; |
|
1102 |
byte trackdir; |
|
1103 |
||
1104 |
NPFFillWithOrderData(&fstd, v); |
|
1105 |
trackdir = _dir_to_diag_trackdir[enterdir]; |
|
1106 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
|
1107 |
||
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
1108 |
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner); |
1247 | 1109 |
if (ftd.best_bird_dist != 0 || ftd.best_trackdir == 0xff) { |
1110 |
/* Not found, just do something, or we are already there */ |
|
1111 |
//TODO: maybe display error? |
|
1112 |
//TODO: go straight ahead if possible? |
|
1113 |
return_track(FindFirstBit2x64(bitmask)); |
|
1114 |
} else { |
|
1115 |
return_track(ftd.best_trackdir); |
|
1116 |
} |
|
1117 |
} else { |
|
1118 |
if (IsTileType(desttile, MP_STREET)) { |
|
1119 |
m5 = _map5[desttile]; |
|
1120 |
if ((m5&0xF0) == 0x20) |
|
1121 |
/* We are heading for a Depot */ |
|
1122 |
goto do_it; |
|
1123 |
} else if (IsTileType(desttile, MP_STATION)) { |
|
1124 |
m5 = _map5[desttile]; |
|
1125 |
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
|
1126 |
/* We are heading for a station */ |
|
1127 |
m5 -= 0x43; |
|
0 | 1128 |
do_it:; |
1247 | 1129 |
/* When we are heading for a depot or station, we just |
1130 |
* pretend we are heading for the tile in front, we'll |
|
1131 |
* see from there */ |
|
1132 |
desttile += TileOffsByDir(m5 & 3); |
|
1133 |
if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) { |
|
1134 |
/* If we are already in front of the |
|
1135 |
* station/depot and we can get in from here, |
|
1136 |
* we enter */ |
|
1137 |
return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3])); |
|
1138 |
} |
|
0 | 1139 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1140 |
} |
1247 | 1141 |
// do pathfind |
1142 |
frd.dest = desttile; |
|
0 | 1143 |
|
1247 | 1144 |
best_track = -1; |
1145 |
best_dist = (uint)-1; |
|
1146 |
best_maxlen = (uint)-1; |
|
1147 |
i = 0; |
|
1148 |
do { |
|
1149 |
if (bitmask & 1) { |
|
1150 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track |
|
1151 |
frd.maxtracklen = (uint)-1; |
|
1152 |
frd.mindist = (uint)-1; |
|
1153 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
|
0 | 1154 |
|
1247 | 1155 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
1156 |
best_dist = frd.mindist; |
|
1157 |
best_maxlen = frd.maxtracklen; |
|
1158 |
best_track = i; |
|
1159 |
} |
|
0 | 1160 |
} |
1247 | 1161 |
} while (++i,(bitmask>>=1) != 0); |
1162 |
} |
|
0 | 1163 |
|
1164 |
found_best_track:; |
|
1165 |
||
1166 |
if (HASBIT(signal, best_track)) |
|
1167 |
return -1; |
|
1168 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1169 |
return best_track; |
0 | 1170 |
} |
1171 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1172 |
static int RoadFindPathToStation(const Vehicle *v, TileIndex tile) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1173 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1174 |
FindRoadToChooseData frd; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1175 |
int i, best_track = -1; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1176 |
uint best_dist = (uint) -1, best_maxlen = (uint) -1; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1177 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1178 |
frd.dest = tile; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1179 |
frd.maxtracklen = (uint) -1; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1180 |
frd.mindist = (uint) -1; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1181 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1182 |
for (i = 0; i < 4; i++) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1183 |
FollowTrack(v->tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1184 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1185 |
if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen )) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1186 |
best_dist = frd.mindist; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1187 |
best_maxlen = frd.maxtracklen; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1188 |
best_track = i; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1189 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1190 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1191 |
return best_maxlen; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1192 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1193 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1194 |
|
0 | 1195 |
typedef struct RoadDriveEntry { |
1196 |
byte x,y; |
|
1197 |
} RoadDriveEntry; |
|
1198 |
||
1199 |
#include "table/roadveh.h" |
|
1200 |
||
1201 |
static const byte _road_veh_data_1[] = { |
|
1202 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1203 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1204 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1205 |
15, 15, 11, 11 |
|
1206 |
}; |
|
1207 |
||
1208 |
static const byte _roadveh_data_2[4] = { 0,1,8,9 }; |
|
1209 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1210 |
static inline void ClearSlot(Vehicle *v, RoadStop *rs) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1211 |
{ |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1212 |
DEBUG(ms, 3) ("Multistop: Clearing slot %d at 0x%x", v->u.road.slotindex, rs->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1213 |
v->u.road.slot = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1214 |
v->u.road.slot_age = 0; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1215 |
rs->slot[v->u.road.slotindex] = INVALID_SLOT; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1216 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1217 |
|
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1218 |
static void RoadVehController(Vehicle *v) |
0 | 1219 |
{ |
1220 |
GetNewVehiclePosResult gp; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1221 |
byte new_dir, old_dir; |
0 | 1222 |
RoadDriveEntry rd; |
1223 |
int x,y; |
|
1224 |
Station *st; |
|
1225 |
uint32 r; |
|
1226 |
Vehicle *u; |
|
1227 |
||
1228 |
// decrease counters |
|
1229 |
v->tick_counter++; |
|
1230 |
if (v->u.road.reverse_ctr != 0) |
|
1231 |
v->u.road.reverse_ctr--; |
|
1232 |
||
1233 |
// handle crashed |
|
1234 |
if (v->u.road.crashed_ctr != 0) { |
|
1235 |
RoadVehIsCrashed(v); |
|
1236 |
return; |
|
1237 |
} |
|
1238 |
||
1239 |
RoadVehCheckTrainCrash(v); |
|
1240 |
||
1241 |
// road vehicle has broken down? |
|
1242 |
if (v->breakdown_ctr != 0) { |
|
1243 |
if (v->breakdown_ctr <= 2) { |
|
1244 |
HandleBrokenRoadVeh(v); |
|
1245 |
return; |
|
1246 |
} |
|
1247 |
v->breakdown_ctr--; |
|
1248 |
} |
|
1249 |
||
1250 |
// exit if vehicle is stopped |
|
1251 |
if (v->vehstatus & VS_STOPPED) |
|
1252 |
return; |
|
1253 |
||
1254 |
ProcessRoadVehOrder(v); |
|
1255 |
HandleRoadVehLoading(v); |
|
1256 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1257 |
if (v->current_order.type == OT_LOADING) |
0 | 1258 |
return; |
1259 |
||
1260 |
if (v->u.road.state == 254) { |
|
1261 |
int dir; |
|
1262 |
const RoadDriveEntry*rdp; |
|
1263 |
byte rd2; |
|
1264 |
||
1265 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1266 |
|
0 | 1267 |
dir = _map5[v->tile]&3; |
1268 |
v->direction = dir*2+1; |
|
1269 |
||
1270 |
rd2 = _roadveh_data_2[dir]; |
|
1271 |
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
|
1272 |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1273 |
x = TileX(v->tile) * 16 + (rdp[6].x & 0xF); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1274 |
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF); |
0 | 1275 |
|
1276 |
if (RoadVehFindCloseTo(v,x,y,v->direction)) |
|
1277 |
return; |
|
1278 |
||
578
1e66514eb621
(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
|
1279 |
VehicleServiceInDepot(v); |
1e66514eb621
(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
|
1280 |
|
0 | 1281 |
StartRoadVehSound(v); |
1282 |
||
1283 |
BeginVehicleMove(v); |
|
1284 |
||
1285 |
v->vehstatus &= ~VS_HIDDEN; |
|
1286 |
v->u.road.state = rd2; |
|
1287 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1288 |
|
0 | 1289 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1290 |
UpdateRoadVehDeltaXY(v); |
|
1291 |
SetRoadVehPosition(v,x,y); |
|
1292 |
||
1293 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1294 |
return; |
|
1295 |
} |
|
1296 |
||
1297 |
if (!RoadVehAccelerate(v)) |
|
1298 |
return; |
|
1299 |
||
1300 |
if (v->u.road.overtaking != 0) { |
|
1301 |
if (++v->u.road.overtaking_ctr >= 35) |
|
1302 |
v->u.road.overtaking = 0; |
|
1303 |
} |
|
1304 |
||
1305 |
BeginVehicleMove(v); |
|
1306 |
||
1307 |
if (v->u.road.state == 255) { |
|
1308 |
GetNewVehiclePos(v, &gp); |
|
1309 |
||
1310 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction)) { |
|
1311 |
v->cur_speed = 0; |
|
1312 |
return; |
|
1313 |
} |
|
1314 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1315 |
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && |
0 | 1316 |
(_map5[gp.new_tile]&0xF0) == 0 && |
1317 |
(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
|
1318 |
|
0 | 1319 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1320 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1321 |
UpdateRoadVehDeltaXY(v); |
|
1322 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1323 |
return; |
|
1324 |
} |
|
1325 |
||
1326 |
v->x_pos = gp.x; |
|
1327 |
v->y_pos = gp.y; |
|
1328 |
VehiclePositionChanged(v); |
|
1329 |
return; |
|
1330 |
} |
|
1331 |
||
1332 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1]; |
|
1333 |
||
1334 |
// switch to another tile |
|
1335 |
if (rd.x & 0x80) { |
|
900 | 1336 |
uint tile = v->tile + TileOffsByDir(rd.x & 3); |
0 | 1337 |
int dir = RoadFindPathToDest(v, tile, rd.x&3); |
1338 |
int tmp; |
|
1339 |
uint32 r; |
|
1340 |
byte newdir; |
|
1341 |
const RoadDriveEntry *rdp; |
|
1342 |
||
1343 |
if (dir == -1) { |
|
1344 |
v->cur_speed = 0; |
|
1345 |
return; |
|
1346 |
} |
|
1347 |
||
1348 |
again: |
|
1349 |
if ((dir & 7) >= 6) { |
|
1247 | 1350 |
/* Turning around */ |
0 | 1351 |
tile = v->tile; |
1352 |
} |
|
1353 |
||
1354 |
tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking; |
|
1355 |
rdp = _road_drive_data[tmp]; |
|
1356 |
||
1357 |
tmp &= ~0x10; |
|
1358 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1359 |
x = TileX(tile) * 16 + rdp[0].x; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1360 |
y = TileY(tile) * 16 + rdp[0].y; |
0 | 1361 |
|
1362 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1363 |
return; |
|
1364 |
||
1365 |
r = VehicleEnterTile(v, tile, x, y); |
|
1366 |
if (r & 8) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1367 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1368 |
v->cur_speed = 0; |
1369 |
return; |
|
1370 |
} |
|
1371 |
dir = _road_reverse_table[rd.x&3]; |
|
1372 |
goto again; |
|
1373 |
} |
|
1374 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1375 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
0 | 1376 |
if ((tmp&7) >= 6) { v->cur_speed = 0; return; } |
1377 |
if (IS_BYTE_INSIDE(_map5[v->tile], 0x43, 0x4B)) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1378 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1379 |
byte *b = &rs->status; |
0 | 1380 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1381 |
//we have reached a loading bay, mark it as used |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1382 |
//and clear the usage bit (0x80) of the stop |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1383 |
*b = (*b | ((v->u.road.state&2)?2:1)) & ~0x80; |
0 | 1384 |
} |
1385 |
} |
|
1386 |
||
1387 |
if (!(r & 4)) { |
|
1388 |
v->tile = tile; |
|
1389 |
v->u.road.state = (byte)tmp; |
|
1390 |
v->u.road.frame = 0; |
|
1391 |
} |
|
1392 |
if (newdir != v->direction) { |
|
1393 |
v->direction = newdir; |
|
1394 |
v->cur_speed -= v->cur_speed >> 2; |
|
1395 |
} |
|
1396 |
||
1397 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1398 |
UpdateRoadVehDeltaXY(v); |
|
1399 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1400 |
return; |
|
1401 |
} |
|
1402 |
||
1403 |
if (rd.x & 0x40) { |
|
1404 |
int dir = RoadFindPathToDest(v, v->tile, rd.x&3); |
|
1405 |
uint32 r; |
|
1406 |
int tmp; |
|
1407 |
byte newdir; |
|
1408 |
const RoadDriveEntry *rdp; |
|
1409 |
||
1410 |
if (dir == -1) { |
|
1411 |
v->cur_speed = 0; |
|
1412 |
return; |
|
1413 |
} |
|
1414 |
||
1415 |
tmp = (_opt.road_side<<4) + dir; |
|
1416 |
rdp = _road_drive_data[tmp]; |
|
1417 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1418 |
x = TileX(v->tile) * 16 + rdp[1].x; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1419 |
y = TileY(v->tile) * 16 + rdp[1].y; |
0 | 1420 |
|
1421 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1422 |
return; |
|
1423 |
||
1424 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1425 |
if (r & 8) { |
|
1426 |
v->cur_speed = 0; |
|
1427 |
return; |
|
1428 |
} |
|
1429 |
||
1430 |
v->u.road.state = tmp & ~16; |
|
1431 |
v->u.road.frame = 1; |
|
1432 |
||
1433 |
if (newdir != v->direction) { |
|
1434 |
v->direction = newdir; |
|
1435 |
v->cur_speed -= v->cur_speed >> 2; |
|
1436 |
} |
|
1437 |
||
1438 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1439 |
UpdateRoadVehDeltaXY(v); |
|
1440 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1441 |
return; |
|
1442 |
} |
|
1443 |
||
1444 |
x = (v->x_pos&~15)+(rd.x&15); |
|
1445 |
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
|
1446 |
|
0 | 1447 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1448 |
||
1449 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) { |
|
1450 |
if (v->u.road.overtaking == 0) |
|
1451 |
RoadVehCheckOvertake(v, u); |
|
1452 |
return; |
|
1453 |
} |
|
1454 |
||
1455 |
old_dir = v->direction; |
|
1456 |
if (new_dir != old_dir) { |
|
1457 |
v->direction = new_dir; |
|
1458 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1459 |
if (old_dir != v->u.road.state) { |
|
1460 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1461 |
UpdateRoadVehDeltaXY(v); |
|
1462 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1463 |
return; |
|
1464 |
} |
|
1465 |
} |
|
1466 |
||
1467 |
if (v->u.road.state >= 0x20 && |
|
1468 |
_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1469 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1470 |
byte *b = &rs->status; |
0 | 1471 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1472 |
st = GetStation(_map2[v->tile]); |
0 | 1473 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1474 |
if (v->current_order.type != OT_LEAVESTATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1475 |
v->current_order.type != OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1476 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1477 |
|
0 | 1478 |
*b &= ~0x80; |
1479 |
||
1480 |
v->last_station_visited = _map2[v->tile]; |
|
1481 |
||
1482 |
RoadVehArrivesAt(v, st); |
|
1483 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1484 |
old_order = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1485 |
v->current_order.type = OT_LOADING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1486 |
v->current_order.flags = 0; |
0 | 1487 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1488 |
if (old_order.type == OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1489 |
v->current_order.station == v->last_station_visited) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1490 |
v->current_order.flags = |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1491 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP; |
0 | 1492 |
} |
1493 |
||
1494 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
1495 |
if (LoadUnloadVehicle(v)) { |
|
1496 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1497 |
MarkRoadVehDirty(v); |
|
1498 |
} |
|
755
80091de50044
(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
|
1499 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1500 |
return; |
1501 |
} |
|
1502 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1503 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
0 | 1504 |
if (*b&0x80) { |
1505 |
v->cur_speed = 0; |
|
1506 |
return; |
|
1507 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1508 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1509 |
v->current_order.flags = 0; |
0 | 1510 |
} |
1511 |
*b |= 0x80; |
|
1512 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1513 |
if (rs == v->u.road.slot) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1514 |
//we have arrived at the correct station |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1515 |
ClearSlot(v, rs); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1516 |
} else if (v->u.road.slot != NULL) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1517 |
//we have arrived at the wrong station |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1518 |
//XXX The question is .. what to do? Actually we shouldn't be here |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1519 |
//but I guess we need to clear the slot |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1520 |
DEBUG(ms, 1) ("Multistop: Wrong station, force a slot clearing. Vehicle %d at 0x%x, should go to 0x%x of station %d (%x), destination 0x%x", v->unitnumber, v->tile, v->u.road.slot->xy, st->index, st->xy, v->dest_tile); |
1239
133586622b78
(svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents:
1237
diff
changeset
|
1521 |
ClearSlot(v, v->u.road.slot); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1522 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1523 |
|
0 | 1524 |
StartRoadVehSound(v); |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1525 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1526 |
} |
1527 |
||
1528 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1529 |
if (r & 8) { |
|
1530 |
v->cur_speed = 0; |
|
1531 |
return; |
|
1532 |
} |
|
1533 |
||
1534 |
if ((r & 4) == 0) { |
|
1535 |
v->u.road.frame++; |
|
1536 |
} |
|
1537 |
||
1538 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1539 |
UpdateRoadVehDeltaXY(v); |
|
1540 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1541 |
} |
|
1542 |
||
1543 |
void RoadVehEnterDepot(Vehicle *v) |
|
1544 |
{ |
|
1545 |
v->u.road.state = 254; |
|
1546 |
v->vehstatus |= VS_HIDDEN; |
|
1547 |
||
1548 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1549 |
||
842 | 1550 |
MaybeReplaceVehicle(v); |
0 | 1551 |
|
578
1e66514eb621
(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
|
1552 |
VehicleServiceInDepot(v); |
1e66514eb621
(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
|
1553 |
|
445
beafc0fb8f12
(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
|
1554 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1555 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1556 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1557 |
Order t; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1558 |
|
0 | 1559 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1560 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1561 |
t = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1562 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1563 |
v->current_order.flags = 0; |
0 | 1564 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1565 |
// Part of the orderlist? |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1566 |
if (t.flags & OF_UNLOAD) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1567 |
v->cur_order_index++; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1568 |
} else if (t.flags & OF_FULL_LOAD) { |
0 | 1569 |
v->vehstatus |= VS_STOPPED; |
1570 |
if (v->owner == _local_player) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1571 |
SetDParam(0, v->unitnumber); |
0 | 1572 |
AddNewsItem( |
1573 |
STR_9016_ROAD_VEHICLE_IS_WAITING, |
|
1574 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1575 |
v->index, |
|
1576 |
0); |
|
1577 |
} |
|
1578 |
} |
|
1579 |
} |
|
1580 |
||
1581 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
1582 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1583 |
} |
1584 |
||
1585 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1586 |
{ |
|
1587 |
if (_age_cargo_skip_counter != 0) |
|
1588 |
return; |
|
1589 |
if (v->cargo_days != 255) |
|
1590 |
v->cargo_days++; |
|
1591 |
} |
|
1592 |
||
1593 |
void RoadVeh_Tick(Vehicle *v) |
|
1594 |
{ |
|
1595 |
AgeRoadVehCargo(v); |
|
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1596 |
RoadVehController(v); |
0 | 1597 |
} |
1598 |
||
1599 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1600 |
{ |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1601 |
Depot *depot; |
0 | 1602 |
|
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1603 |
if (_patches.servint_roadveh == 0 && !v->set_for_replacement) |
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
|
1604 |
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
|
1605 |
|
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1606 |
if (!VehicleNeedsService(v) && !v->set_for_replacement) |
0 | 1607 |
return; |
1608 |
||
1609 |
if (v->vehstatus & VS_STOPPED) |
|
1610 |
return; |
|
1611 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1612 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) |
0 | 1613 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1614 |
|
0 | 1615 |
// Don't interfere with a depot visit scheduled by the user, or a |
1616 |
// depot visit by the order list. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1617 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1618 |
(v->current_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) != 0) |
0 | 1619 |
return; |
1620 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1621 |
//If we already got a slot at a stop, use that FIRST, and go to a depot later |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1622 |
if (v->u.road.slot != NULL) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1623 |
return; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1624 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1625 |
depot = FindClosestRoadDepot(v); |
0 | 1626 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1627 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1628 |
if (v->current_order.type == OT_GOTO_DEPOT && !( |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
1629 |
DistanceManhattan(v->tile, v->dest_tile) > 25 && v->set_for_replacement)) { |
1203
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1630 |
/* a vehicle needs a greater distance to a depot to loose it than to find it since |
1138851a6d45
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1631 |
they can circle forever othervise if they are in a loop with an unlucky distance */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1632 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1633 |
v->current_order.flags = 0; |
755
80091de50044
(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
|
1634 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1635 |
} |
1636 |
return; |
|
1637 |
} |
|
1638 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1639 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1640 |
v->current_order.flags & OF_NON_STOP && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1641 |
!CHANCE16(1,20)) |
0 | 1642 |
return; |
1643 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1644 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1645 |
v->current_order.flags = OF_NON_STOP; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1646 |
v->current_order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1647 |
v->dest_tile = depot->xy; |
755
80091de50044
(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
|
1648 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1649 |
} |
1650 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1651 |
int dist_compare(const void *a, const void *b) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1652 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1653 |
return ( *(const uint32 *)a) - ( *(const uint32 *) b); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1654 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1655 |
|
0 | 1656 |
void OnNewDay_RoadVeh(Vehicle *v) |
1657 |
{ |
|
1658 |
int32 cost; |
|
1659 |
Station *st; |
|
1660 |
||
1661 |
if ((++v->day_counter & 7) == 0) |
|
1662 |
DecreaseVehicleValue(v); |
|
1663 |
||
1664 |
if (v->u.road.unk2 == 0) |
|
1665 |
CheckVehicleBreakdown(v); |
|
1666 |
||
1667 |
AgeVehicle(v); |
|
1668 |
CheckIfRoadVehNeedsService(v); |
|
1669 |
||
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1035
diff
changeset
|
1670 |
CheckOrders(v->index, OC_INIT); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1671 |
|
0 | 1672 |
/* update destination */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1673 |
if (v->current_order.type == OT_GOTO_STATION) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1674 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1675 |
uint32 mindist = 0xFFFFFFFF; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1676 |
int num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1677 |
RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1678 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1679 |
typedef struct { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1680 |
uint32 dist; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1681 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1682 |
} StopStruct; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1683 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1684 |
StopStruct *stop, *firststop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1685 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1686 |
st = GetStation(v->current_order.station); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1687 |
rs = GetPrimaryRoadStop(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1688 |
num = GetNumRoadStops(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1689 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1690 |
firststop = stop = malloc(num * sizeof(StopStruct)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1691 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1692 |
//Current slot has expired |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1693 |
if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL)) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1694 |
ClearSlot(v, v->u.road.slot); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1695 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1696 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1697 |
//We do not have a slot, so make one |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1698 |
if (v->u.road.slot == NULL) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1699 |
//first we need to find out how far our stations are away. |
1455
d6772f61e1ce
(svn r1959) -Fix: Repaired two memleaks I have hacked :(
Celestar
parents:
1442
diff
changeset
|
1700 |
if ( rs == NULL ) { |
d6772f61e1ce
(svn r1959) -Fix: Repaired two memleaks I have hacked :(
Celestar
parents:
1442
diff
changeset
|
1701 |
free(firststop); |
d6772f61e1ce
(svn r1959) -Fix: Repaired two memleaks I have hacked :(
Celestar
parents:
1442
diff
changeset
|
1702 |
firststop = stop = NULL; |
1231
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
1703 |
goto no_stop; |
1455
d6772f61e1ce
(svn r1959) -Fix: Repaired two memleaks I have hacked :(
Celestar
parents:
1442
diff
changeset
|
1704 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1705 |
|
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1706 |
DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1707 |
do { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1708 |
stop->dist = 0xFFFFFFFF; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1709 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1710 |
//FIXME This doesn't fully work yet, as it only goes |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1711 |
//to one tile BEFORE the stop in question and doesn't |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1712 |
//regard the direction of the exit |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1713 |
stop->dist = RoadFindPathToStation(v, rs->xy); |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1714 |
DEBUG(ms, 3) ("Multistop: Distance to stop at 0x%x is %d", rs->xy, stop->dist); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1715 |
stop->rs = rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1716 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1717 |
if (stop->dist < mindist) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1718 |
mindist = stop->dist; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1719 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1720 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1721 |
stop++; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1722 |
rs = rs->next; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1723 |
} while (rs != NULL); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1724 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1725 |
if (mindist < 120) { //if we're reasonably close, get us a slot |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1726 |
int k; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1727 |
bubblesort(firststop, num, sizeof(StopStruct), dist_compare); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1728 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1729 |
stop = firststop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1730 |
for (k = 0; k < num; k++) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1731 |
int i; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1732 |
for (i = 0; i < NUM_SLOTS; i++) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1733 |
if ((stop->rs->slot[i] == INVALID_SLOT) && (stop->dist < 120)) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1734 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1735 |
//Hooray we found a free slot. Assign it |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1736 |
DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d", i, stop->rs->xy, v->unitnumber); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1737 |
stop->rs->slot[i] = v->index; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1738 |
v->u.road.slot = stop->rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1739 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1740 |
v->dest_tile = stop->rs->xy; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1741 |
v->u.road.slot_age = -30; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1742 |
v->u.road.slotindex = i; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1743 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1744 |
goto have_slot; //jump out of BOTH loops |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1745 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1746 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1747 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1748 |
stop++; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1749 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1750 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1751 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1752 |
have_slot: |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1753 |
//now we couldn't assign a slot for one reason or another. |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1754 |
//so we just go to the nearest station |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1755 |
if (v->u.road.slot == NULL) { |
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1756 |
DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber); |
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1757 |
v->dest_tile = firststop->rs->xy; |
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1758 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1759 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1760 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1761 |
free(firststop); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1762 |
firststop = stop = NULL; |
0 | 1763 |
} |
1764 |
||
1231
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
1765 |
no_stop: |
0 | 1766 |
if (v->vehstatus & VS_STOPPED) |
1767 |
return; |
|
1768 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1769 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1770 |
|
1771 |
v->profit_this_year -= cost >> 8; |
|
1772 |
||
1773 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1774 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1775 |
||
1776 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
1777 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1778 |
} |
1779 |
||
1780 |
void HandleClickOnRoadVeh(Vehicle *v) |
|
1781 |
{ |
|
1782 |
ShowRoadVehViewWindow(v); |
|
1783 |
} |
|
1784 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1053
diff
changeset
|
1785 |
void RoadVehiclesYearlyLoop(void) |
0 | 1786 |
{ |
1787 |
Vehicle *v; |
|
1788 |
||
1789 |
FOR_ALL_VEHICLES(v) { |
|
1790 |
if (v->type == VEH_Road) { |
|
1791 |
v->profit_last_year = v->profit_this_year; |
|
1792 |
v->profit_this_year = 0; |
|
1793 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1794 |
} |
|
1795 |
} |
|
1796 |
} |
|
1797 |