author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1530 | 2b46869fc0d4 |
child 1664 | 1f909247678d |
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 |
||
323 |
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
324 |
{ |
|
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
|
325 |
Vehicle *v; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
326 |
Depot *depot; |
0 | 327 |
|
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
|
328 |
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
|
329 |
|
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 |
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
|
331 |
|
0 | 332 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
333 |
return CMD_ERROR; |
|
334 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
335 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 336 |
if (flags & DC_EXEC) { |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
337 |
|
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
338 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
0 | 339 |
v->cur_order_index++; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
340 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
341 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
342 |
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
|
343 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 344 |
} |
345 |
return 0; |
|
346 |
} |
|
347 |
||
348 |
depot = FindClosestRoadDepot(v); |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
349 |
if (depot == NULL) |
0 | 350 |
return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
351 |
||
352 |
if (flags & DC_EXEC) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
353 |
v->current_order.type = OT_GOTO_DEPOT; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
354 |
v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
355 |
v->current_order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
356 |
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
|
357 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 358 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
359 |
|
0 | 360 |
return 0; |
361 |
} |
|
362 |
||
363 |
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
364 |
{ |
|
365 |
Vehicle *v; |
|
366 |
||
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
|
367 |
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
|
368 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
369 |
v = GetVehicle(p1); |
0 | 370 |
|
371 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
372 |
return CMD_ERROR; |
|
373 |
||
374 |
if (v->vehstatus & (VS_HIDDEN|VS_STOPPED) || |
|
375 |
v->u.road.crashed_ctr != 0 || |
|
376 |
v->breakdown_ctr != 0 || |
|
377 |
v->u.road.overtaking != 0 || |
|
378 |
v->cur_speed < 5) { |
|
379 |
_error_message = STR_EMPTY; |
|
380 |
return CMD_ERROR; |
|
381 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
382 |
|
0 | 383 |
if (flags & DC_EXEC) { |
384 |
v->u.road.reverse_ctr = 180; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
385 |
} |
0 | 386 |
|
387 |
return 0; |
|
388 |
} |
|
389 |
||
390 |
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
391 |
{ |
|
392 |
Vehicle *v; |
|
393 |
||
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
|
394 |
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
|
395 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
396 |
v = GetVehicle(p1); |
0 | 397 |
|
398 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
399 |
return CMD_ERROR; |
|
400 |
||
401 |
if (flags & DC_EXEC) { |
|
402 |
v->service_interval = (uint16)p2; |
|
403 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
|
404 |
} |
|
405 |
||
406 |
return 0; |
|
407 |
} |
|
408 |
||
409 |
||
410 |
static void MarkRoadVehDirty(Vehicle *v) |
|
411 |
{ |
|
412 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
413 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
414 |
} |
|
415 |
||
416 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
417 |
{ |
|
418 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
419 |
static const uint32 _delta_xy_table[8] = { |
|
420 |
MKIT(3, 3, -1, -1), |
|
421 |
MKIT(3, 7, -1, -3), |
|
422 |
MKIT(3, 3, -1, -1), |
|
423 |
MKIT(7, 3, -3, -1), |
|
424 |
MKIT(3, 3, -1, -1), |
|
425 |
MKIT(3, 7, -1, -3), |
|
426 |
MKIT(3, 3, -1, -1), |
|
427 |
MKIT(7, 3, -3, -1), |
|
428 |
}; |
|
429 |
#undef MKIT |
|
430 |
uint32 x = _delta_xy_table[v->direction]; |
|
431 |
v->x_offs = (byte)x; |
|
432 |
v->y_offs = (byte)(x>>=8); |
|
433 |
v->sprite_width = (byte)(x>>=8); |
|
434 |
v->sprite_height = (byte)(x>>=8); |
|
435 |
} |
|
436 |
||
437 |
static void ClearCrashedStation(Vehicle *v) |
|
438 |
{ |
|
439 |
uint tile = v->tile; |
|
440 |
byte *b, bb; |
|
441 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
442 |
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
|
443 |
b = &rs->status; |
0 | 444 |
|
445 |
bb = *b; |
|
446 |
||
447 |
// mark station as not busy |
|
448 |
bb &= ~0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
449 |
|
0 | 450 |
// free parking bay |
451 |
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
|
452 |
|
0 | 453 |
*b = bb; |
454 |
} |
|
455 |
||
456 |
static void RoadVehDelete(Vehicle *v) |
|
457 |
{ |
|
458 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
459 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
460 |
|
588 | 461 |
RebuildVehicleLists(); |
0 | 462 |
InvalidateWindow(WC_COMPANY, v->owner); |
463 |
||
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
|
464 |
if (IsTileType(v->tile, MP_STATION)) |
0 | 465 |
ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
466 |
|
0 | 467 |
BeginVehicleMove(v); |
468 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
469 |
|
0 | 470 |
DeleteVehicle(v); |
471 |
} |
|
472 |
||
473 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
474 |
{ |
|
475 |
byte new_z, old_z; |
|
476 |
||
477 |
// need this hint so it returns the right z coordinate on bridges. |
|
478 |
_get_z_hint = v->z_pos; |
|
479 |
new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y); |
|
480 |
_get_z_hint = 0; |
|
481 |
||
482 |
old_z = v->z_pos; |
|
483 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
484 |
|
0 | 485 |
VehiclePositionChanged(v); |
486 |
EndVehicleMove(v); |
|
487 |
return old_z; |
|
488 |
} |
|
489 |
||
490 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
491 |
{ |
|
492 |
static const int8 _turn_prob[4] = { -1, 0, 0, 1 }; |
|
493 |
uint32 r = Random(); |
|
494 |
v->direction = (v->direction+_turn_prob[r&3])&7; |
|
495 |
BeginVehicleMove(v); |
|
496 |
UpdateRoadVehDeltaXY(v); |
|
497 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
498 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
499 |
} |
|
500 |
||
501 |
static void RoadVehIsCrashed(Vehicle *v) |
|
502 |
{ |
|
503 |
v->u.road.crashed_ctr++; |
|
504 |
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
|
505 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 506 |
} else if (v->u.road.crashed_ctr <= 45) { |
507 |
if ((v->tick_counter&7)==0) |
|
508 |
RoadVehSetRandomDirection(v); |
|
509 |
} else if (v->u.road.crashed_ctr >= 2220) { |
|
510 |
RoadVehDelete(v); |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u) |
|
515 |
{ |
|
516 |
if (v->type != VEH_Train || |
|
517 |
myabs(v->z_pos - u->z_pos) > 6 || |
|
518 |
myabs(v->x_pos - u->x_pos) > 4 || |
|
519 |
myabs(v->y_pos - u->y_pos) > 4) |
|
520 |
return NULL; |
|
521 |
return v; |
|
522 |
} |
|
523 |
||
524 |
static void RoadVehCrash(Vehicle *v) |
|
525 |
{ |
|
526 |
uint16 pass; |
|
527 |
||
528 |
v->u.road.crashed_ctr++; |
|
529 |
v->vehstatus |= VS_CRASHED; |
|
530 |
||
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
|
531 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 532 |
|
533 |
pass = 1; |
|
534 |
if (v->cargo_type == 0) |
|
535 |
pass += v->cargo_count; |
|
536 |
v->cargo_count = 0; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
537 |
SetDParam(0, pass); |
0 | 538 |
|
539 |
AddNewsItem(STR_9031_ROAD_VEHICLE_CRASH_DRIVER+(pass!=1), |
|
540 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
541 |
v->index, |
|
542 |
0); |
|
543 |
||
544 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 545 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 546 |
} |
547 |
||
548 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
549 |
{ |
|
550 |
uint tile; |
|
551 |
||
552 |
if (v->u.road.state == 255) |
|
553 |
return; |
|
554 |
||
555 |
tile = v->tile; |
|
556 |
||
557 |
// 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
|
558 |
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
|
559 |
(_map5[tile] & 0xF0) != 0x10) |
0 | 560 |
return; |
561 |
||
562 |
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL) |
|
563 |
RoadVehCrash(v); |
|
564 |
} |
|
565 |
||
566 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
567 |
{ |
|
568 |
if (v->breakdown_ctr != 1) { |
|
569 |
v->breakdown_ctr = 1; |
|
570 |
v->cur_speed = 0; |
|
571 |
||
572 |
if (v->breakdowns_since_last_service != 255) |
|
573 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
574 |
|
0 | 575 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
576 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
577 |
|
541 | 578 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
579 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
|
0 | 580 |
|
581 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
582 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
583 |
if (u) |
|
584 |
u->u.special.unk0 = v->breakdown_delay * 2; |
|
585 |
} |
|
586 |
} |
|
587 |
||
588 |
if (!(v->tick_counter & 1)) { |
|
589 |
if (!--v->breakdown_delay) { |
|
590 |
v->breakdown_ctr = 0; |
|
591 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
592 |
} |
|
593 |
} |
|
594 |
} |
|
595 |
||
596 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
597 |
{ |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
598 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
599 |
const Station *st; |
0 | 600 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
601 |
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
|
602 |
// Let a depot order in the orderlist interrupt. |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
603 |
if (v->current_order.type != OT_GOTO_DEPOT || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
604 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 605 |
return; |
606 |
} |
|
607 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
608 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
609 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
610 |
!VehicleNeedsService(v)) { |
0 | 611 |
v->cur_order_index++; |
612 |
} |
|
613 |
||
614 |
if (v->cur_order_index >= v->num_orders) |
|
615 |
v->cur_order_index = 0; |
|
616 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
617 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 618 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
619 |
if (order == NULL) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
620 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
621 |
v->current_order.flags = 0; |
0 | 622 |
v->dest_tile = 0; |
623 |
return; |
|
624 |
} |
|
625 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
626 |
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
|
627 |
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
|
628 |
order->station == v->current_order.station) |
0 | 629 |
return; |
630 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
631 |
v->current_order = *order; |
0 | 632 |
|
633 |
v->dest_tile = 0; |
|
634 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
635 |
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
|
636 |
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
|
637 |
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
|
638 |
st = GetStation(order->station); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
639 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
640 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
641 |
int32 *dist; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
642 |
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
|
643 |
int num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
644 |
RoadStopType type; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
645 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
646 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
647 |
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
|
648 |
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
|
649 |
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
|
650 |
|
1231
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
651 |
if (rs == NULL) { |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
652 |
//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
|
653 |
v->cur_order_index++; |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
654 |
InvalidateVehicleOrder(v); |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
655 |
|
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
656 |
return; |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
657 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
658 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
659 |
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
|
660 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
661 |
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
|
662 |
*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
|
663 |
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
|
664 |
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
|
665 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
666 |
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
|
667 |
} 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
|
668 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
669 |
free(dist); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
670 |
dist = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
671 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
672 |
} else if (order->type == OT_GOTO_DEPOT) { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
673 |
v->dest_tile = GetDepot(order->station)->xy; |
0 | 674 |
} |
675 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
676 |
InvalidateVehicleOrder(v); |
0 | 677 |
} |
678 |
||
679 |
static void HandleRoadVehLoading(Vehicle *v) |
|
680 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
681 |
if (v->current_order.type == OT_NOTHING) |
0 | 682 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
683 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
684 |
if (v->current_order.type != OT_DUMMY) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
685 |
if (v->current_order.type != OT_LOADING) |
0 | 686 |
return; |
687 |
||
688 |
if (--v->load_unload_time_rem) |
|
689 |
return; |
|
690 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
691 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 692 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
693 |
if (LoadUnloadVehicle(v)) { |
|
694 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
695 |
MarkRoadVehDirty(v); |
|
696 |
} |
|
697 |
return; |
|
698 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
699 |
|
0 | 700 |
{ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
701 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
702 |
v->current_order.type = OT_LEAVESTATION; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
703 |
v->current_order.flags = 0; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
704 |
if (!(b.flags & OF_NON_STOP)) |
0 | 705 |
return; |
706 |
} |
|
707 |
} |
|
708 |
||
709 |
v->cur_order_index++; |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
710 |
InvalidateVehicleOrder(v); |
0 | 711 |
} |
712 |
||
713 |
static void StartRoadVehSound(Vehicle *v) |
|
714 |
{ |
|
541 | 715 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
716 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
|
717 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
|
0 | 718 |
SndPlayVehicleFx(s, v); |
719 |
} |
|
720 |
||
721 |
typedef struct RoadVehFindData { |
|
722 |
int x,y; |
|
723 |
Vehicle *veh; |
|
724 |
byte dir; |
|
725 |
} RoadVehFindData; |
|
726 |
||
1095 | 727 |
static void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf) |
0 | 728 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
729 |
static const short _dists[] = { |
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
730 |
-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
|
731 |
-4, -1, 4, 8, 4, 1, -4, -8, |
0 | 732 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
733 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
734 |
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
|
735 |
short y_diff = v->y_pos - rvf->y; |
0 | 736 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
737 |
if (rvf->veh == v || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
738 |
v->type != VEH_Road || |
0 | 739 |
v->u.road.state == 254 || |
740 |
myabs(v->z_pos - rvf->veh->z_pos) > 6 || |
|
741 |
v->direction != rvf->dir || |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
742 |
(_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
|
743 |
(_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
|
744 |
(_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
|
745 |
(_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
|
746 |
return NULL; |
0 | 747 |
|
748 |
return v; |
|
749 |
} |
|
750 |
||
751 |
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir) |
|
752 |
{ |
|
753 |
RoadVehFindData rvf; |
|
754 |
Vehicle *u; |
|
755 |
||
756 |
if (v->u.road.reverse_ctr != 0) |
|
757 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
758 |
|
0 | 759 |
rvf.x = x; |
760 |
rvf.y = y; |
|
761 |
rvf.dir = dir; |
|
762 |
rvf.veh = v; |
|
763 |
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
|
764 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
765 |
// This code protects a roadvehicle from being blocked for ever |
826 | 766 |
// 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
|
767 |
// 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
|
768 |
// It can be disabled. |
0 | 769 |
if (u == NULL) { |
770 |
v->u.road.unk2 = 0; |
|
771 |
return NULL; |
|
772 |
} |
|
773 |
||
774 |
if (++v->u.road.unk2 > 1480) |
|
775 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
776 |
|
0 | 777 |
return u; |
778 |
} |
|
779 |
||
780 |
static void RoadVehArrivesAt(Vehicle *v, Station *st) |
|
781 |
{ |
|
782 |
if (v->engine_type < 123) { |
|
783 |
/* Check if station was ever visited before */ |
|
784 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
785 |
uint32 flags; |
|
786 |
||
787 |
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
|
788 |
SetDParam(0, st->index); |
0 | 789 |
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); |
790 |
AddNewsItem( |
|
791 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
792 |
flags, |
|
793 |
v->index, |
|
794 |
0); |
|
795 |
} |
|
796 |
} else { |
|
797 |
/* Check if station was ever visited before */ |
|
798 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
799 |
uint32 flags; |
|
800 |
||
801 |
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
|
802 |
SetDParam(0, st->index); |
0 | 803 |
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); |
804 |
AddNewsItem( |
|
805 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
806 |
flags, |
|
807 |
v->index, |
|
808 |
0); |
|
809 |
} |
|
810 |
} |
|
811 |
} |
|
812 |
||
813 |
static bool RoadVehAccelerate(Vehicle *v) |
|
814 |
{ |
|
815 |
uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0); |
|
816 |
byte t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
817 |
|
0 | 818 |
// Clamp |
819 |
spd = min(spd, v->max_speed); |
|
820 |
||
821 |
//updates statusbar only if speed have changed to save CPU time |
|
822 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
823 |
v->cur_speed = spd; |
0 | 824 |
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
|
825 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 826 |
} |
827 |
||
828 |
// Decrease somewhat when turning |
|
829 |
if (!(v->direction&1)) |
|
830 |
spd = spd * 3 >> 2; |
|
831 |
||
832 |
if (spd == 0) |
|
833 |
return false; |
|
834 |
||
835 |
if ((byte)++spd == 0) |
|
836 |
return true; |
|
837 |
||
838 |
v->progress = (t = v->progress) - (byte)spd; |
|
839 |
||
840 |
return (t < v->progress); |
|
841 |
} |
|
842 |
||
843 |
static byte RoadVehGetNewDirection(Vehicle *v, int x, int y) |
|
844 |
{ |
|
845 |
static const byte _roadveh_new_dir[11] = { |
|
846 |
0, 7, 6, 0, |
|
847 |
1, 0, 5, 0, |
|
848 |
2, 3, 4 |
|
849 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
850 |
|
0 | 851 |
x = x - v->x_pos + 1; |
852 |
y = y - v->y_pos + 1; |
|
853 |
||
854 |
if ((uint)x > 2 || (uint)y > 2) |
|
855 |
return v->direction; |
|
856 |
return _roadveh_new_dir[y*4+x]; |
|
857 |
} |
|
858 |
||
859 |
static byte RoadVehGetSlidingDirection(Vehicle *v, int x, int y) |
|
860 |
{ |
|
861 |
byte b = RoadVehGetNewDirection(v,x,y); |
|
862 |
byte d = v->direction; |
|
863 |
if (b == d) return d; |
|
864 |
d = (d+1)&7; |
|
865 |
if (b==d) return d; |
|
866 |
d = (d-2)&7; |
|
867 |
if (b==d) return d; |
|
868 |
if (b==((d-1)&7)) return d; |
|
869 |
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
|
870 |
return (d+2)&7; |
0 | 871 |
} |
872 |
||
873 |
typedef struct OvertakeData { |
|
874 |
Vehicle *u, *v; |
|
875 |
uint tile; |
|
876 |
byte tilebits; |
|
877 |
} OvertakeData; |
|
878 |
||
1095 | 879 |
static void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od) |
0 | 880 |
{ |
881 |
if (v->tile != (TileIndex)od->tile || |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
882 |
v->type != VEH_Road || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
883 |
v == od->u || |
0 | 884 |
v == od->v) |
885 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
886 |
return v; |
0 | 887 |
} |
888 |
||
889 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
890 |
{ |
|
891 |
uint32 bits; |
|
892 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
893 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F; |
0 | 894 |
|
895 |
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000)) |
|
896 |
return true; |
|
897 |
return VehicleFromPos(od->tile, od, (VehicleFromPosProc*)EnumFindVehToOvertake) != NULL; |
|
898 |
} |
|
899 |
||
900 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
901 |
{ |
|
902 |
OvertakeData od; |
|
903 |
byte tt; |
|
904 |
||
905 |
od.v = v; |
|
906 |
od.u = u; |
|
907 |
||
908 |
if (u->max_speed >= v->max_speed && |
|
909 |
!(u->vehstatus&VS_STOPPED) && |
|
910 |
u->cur_speed != 0) |
|
911 |
return; |
|
912 |
||
913 |
if (v->direction != u->direction || !(v->direction&1)) |
|
914 |
return; |
|
915 |
||
916 |
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) |
|
917 |
return; |
|
918 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
919 |
tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F); |
0 | 920 |
if ((tt & 3) == 0) |
921 |
return; |
|
922 |
if ((tt & 0x3C) != 0) |
|
923 |
return; |
|
924 |
||
925 |
if (tt == 3) { |
|
926 |
tt = (v->direction&2)?2:1; |
|
927 |
} |
|
928 |
od.tilebits = tt; |
|
929 |
||
930 |
od.tile = v->tile; |
|
931 |
if (FindRoadVehToOvertake(&od)) |
|
932 |
return; |
|
933 |
||
900 | 934 |
od.tile = v->tile + TileOffsByDir(v->direction >> 1); |
0 | 935 |
if (FindRoadVehToOvertake(&od)) |
936 |
return; |
|
937 |
||
938 |
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) { |
|
939 |
v->u.road.overtaking_ctr = 0x11; |
|
940 |
v->u.road.overtaking = 0x10; |
|
941 |
} else { |
|
942 |
// if (FindRoadVehToOvertake(&od)) |
|
943 |
// return; |
|
944 |
v->u.road.overtaking_ctr = 0; |
|
945 |
v->u.road.overtaking = 0x10; |
|
946 |
} |
|
947 |
} |
|
948 |
||
949 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
950 |
{ |
|
951 |
if (old_z == v->z_pos) |
|
952 |
return; |
|
953 |
||
954 |
if (old_z < v->z_pos) { |
|
955 |
v->cur_speed = v->cur_speed * 232 >> 8; |
|
956 |
} else { |
|
957 |
uint16 spd = v->cur_speed + 2; |
|
958 |
if (spd <= v->max_speed) |
|
959 |
v->cur_speed = spd; |
|
960 |
} |
|
961 |
} |
|
962 |
||
963 |
static int PickRandomBit(uint bits) |
|
964 |
{ |
|
965 |
uint num = 0; |
|
966 |
uint b = bits; |
|
967 |
uint i; |
|
968 |
||
969 |
do { |
|
970 |
if (b & 1) |
|
971 |
num++; |
|
972 |
} while (b >>= 1); |
|
973 |
||
974 |
num = ((uint16)Random() * num >> 16); |
|
975 |
||
976 |
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++); |
|
977 |
return i; |
|
978 |
} |
|
979 |
||
980 |
typedef struct { |
|
981 |
TileIndex dest; |
|
982 |
uint maxtracklen; |
|
983 |
uint mindist; |
|
984 |
} FindRoadToChooseData; |
|
985 |
||
986 |
static bool EnumRoadTrackFindDist(uint tile, FindRoadToChooseData *frd, int track, uint length, byte *state) |
|
987 |
{ |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
988 |
uint dist = DistanceManhattan(tile, frd->dest); |
0 | 989 |
if (dist <= frd->mindist) { |
990 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
991 |
frd->maxtracklen = length; |
|
992 |
} |
|
993 |
frd->mindist = dist; |
|
994 |
} |
|
995 |
return false; |
|
996 |
} |
|
997 |
||
998 |
// Returns direction to choose |
|
999 |
// or -1 if the direction is currently blocked |
|
1247 | 1000 |
static int RoadFindPathToDest(Vehicle *v, uint tile, int enterdir) |
0 | 1001 |
{ |
1002 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
1003 |
||
1004 |
uint16 signal; |
|
1005 |
uint bitmask; |
|
1006 |
uint desttile; |
|
1007 |
FindRoadToChooseData frd; |
|
1008 |
int best_track; |
|
1009 |
uint best_dist, best_maxlen; |
|
1010 |
uint i; |
|
1011 |
byte m5; |
|
1012 |
||
1013 |
{ |
|
1014 |
uint32 r; |
|
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1015 |
r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 1016 |
signal = (uint16)(r >> 16); |
1017 |
bitmask = (uint16)r; |
|
1018 |
} |
|
1019 |
||
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
|
1020 |
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
|
1021 |
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
|
1022 |
/* Road crossing */ |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1023 |
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
|
1024 |
} 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
|
1025 |
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
|
1026 |
/* Our station */ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1027 |
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
|
1028 |
byte val = _map5[tile]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1029 |
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
|
1030 |
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
|
1031 |
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
|
1032 |
} else { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1033 |
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
|
1034 |
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
|
1035 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1036 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1037 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1038 |
/* 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
|
1039 |
* 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
|
1040 |
* 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
|
1041 |
*/ |
0 | 1042 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1043 |
/* remove unreachable tracks */ |
1247 | 1044 |
bitmask &= _road_veh_fp_ax_and[enterdir]; |
0 | 1045 |
if (bitmask == 0) { |
1247 | 1046 |
/* No reachable tracks, so we'll reverse */ |
1047 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1048 |
} |
1049 |
||
1050 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1051 |
/* What happens here?? */ |
0 | 1052 |
v->u.road.reverse_ctr = 0; |
1053 |
if (v->tile != (TileIndex)tile) { |
|
1247 | 1054 |
return_track(_road_reverse_table[enterdir]); |
0 | 1055 |
} |
1056 |
} |
|
1057 |
||
1058 |
desttile = v->dest_tile; |
|
1059 |
if (desttile == 0) { |
|
1247 | 1060 |
// Pick a random track |
0 | 1061 |
return_track(PickRandomBit(bitmask)); |
1062 |
} |
|
1063 |
||
1247 | 1064 |
// Only one track to choose between? |
1065 |
if (!(KillFirstBit2x64(bitmask))) { |
|
0 | 1066 |
return_track(FindFirstBit2x64(bitmask)); |
1067 |
} |
|
1068 |
||
1247 | 1069 |
if (_patches.new_pathfinding_all) { |
1070 |
NPFFindStationOrTileData fstd; |
|
1071 |
NPFFoundTargetData ftd; |
|
1072 |
byte trackdir; |
|
1073 |
||
1074 |
NPFFillWithOrderData(&fstd, v); |
|
1075 |
trackdir = _dir_to_diag_trackdir[enterdir]; |
|
1076 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
|
1077 |
||
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
|
1078 |
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner); |
1247 | 1079 |
if (ftd.best_bird_dist != 0 || ftd.best_trackdir == 0xff) { |
1080 |
/* Not found, just do something, or we are already there */ |
|
1081 |
//TODO: maybe display error? |
|
1082 |
//TODO: go straight ahead if possible? |
|
1083 |
return_track(FindFirstBit2x64(bitmask)); |
|
1084 |
} else { |
|
1085 |
return_track(ftd.best_trackdir); |
|
1086 |
} |
|
1087 |
} else { |
|
1088 |
if (IsTileType(desttile, MP_STREET)) { |
|
1089 |
m5 = _map5[desttile]; |
|
1090 |
if ((m5&0xF0) == 0x20) |
|
1091 |
/* We are heading for a Depot */ |
|
1092 |
goto do_it; |
|
1093 |
} else if (IsTileType(desttile, MP_STATION)) { |
|
1094 |
m5 = _map5[desttile]; |
|
1095 |
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
|
1096 |
/* We are heading for a station */ |
|
1097 |
m5 -= 0x43; |
|
0 | 1098 |
do_it:; |
1247 | 1099 |
/* When we are heading for a depot or station, we just |
1100 |
* pretend we are heading for the tile in front, we'll |
|
1101 |
* see from there */ |
|
1102 |
desttile += TileOffsByDir(m5 & 3); |
|
1103 |
if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) { |
|
1104 |
/* If we are already in front of the |
|
1105 |
* station/depot and we can get in from here, |
|
1106 |
* we enter */ |
|
1107 |
return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3])); |
|
1108 |
} |
|
0 | 1109 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1110 |
} |
1247 | 1111 |
// do pathfind |
1112 |
frd.dest = desttile; |
|
0 | 1113 |
|
1247 | 1114 |
best_track = -1; |
1115 |
best_dist = (uint)-1; |
|
1116 |
best_maxlen = (uint)-1; |
|
1117 |
i = 0; |
|
1118 |
do { |
|
1119 |
if (bitmask & 1) { |
|
1120 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track |
|
1121 |
frd.maxtracklen = (uint)-1; |
|
1122 |
frd.mindist = (uint)-1; |
|
1123 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
|
0 | 1124 |
|
1247 | 1125 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
1126 |
best_dist = frd.mindist; |
|
1127 |
best_maxlen = frd.maxtracklen; |
|
1128 |
best_track = i; |
|
1129 |
} |
|
0 | 1130 |
} |
1247 | 1131 |
} while (++i,(bitmask>>=1) != 0); |
1132 |
} |
|
0 | 1133 |
|
1134 |
found_best_track:; |
|
1135 |
||
1136 |
if (HASBIT(signal, best_track)) |
|
1137 |
return -1; |
|
1138 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1139 |
return best_track; |
0 | 1140 |
} |
1141 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1142 |
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
|
1143 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1144 |
FindRoadToChooseData frd; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1145 |
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
|
1146 |
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
|
1147 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1148 |
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
|
1149 |
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
|
1150 |
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
|
1151 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1152 |
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
|
1153 |
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
|
1154 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1155 |
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
|
1156 |
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
|
1157 |
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
|
1158 |
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
|
1159 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1160 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1161 |
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
|
1162 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1163 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1164 |
|
0 | 1165 |
typedef struct RoadDriveEntry { |
1166 |
byte x,y; |
|
1167 |
} RoadDriveEntry; |
|
1168 |
||
1169 |
#include "table/roadveh.h" |
|
1170 |
||
1171 |
static const byte _road_veh_data_1[] = { |
|
1172 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1173 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1174 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1175 |
15, 15, 11, 11 |
|
1176 |
}; |
|
1177 |
||
1178 |
static const byte _roadveh_data_2[4] = { 0,1,8,9 }; |
|
1179 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1180 |
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
|
1181 |
{ |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1182 |
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
|
1183 |
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
|
1184 |
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
|
1185 |
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
|
1186 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1187 |
|
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
|
1188 |
static void RoadVehController(Vehicle *v) |
0 | 1189 |
{ |
1190 |
GetNewVehiclePosResult gp; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1191 |
byte new_dir, old_dir; |
0 | 1192 |
RoadDriveEntry rd; |
1193 |
int x,y; |
|
1194 |
Station *st; |
|
1195 |
uint32 r; |
|
1196 |
Vehicle *u; |
|
1197 |
||
1198 |
// decrease counters |
|
1199 |
v->tick_counter++; |
|
1200 |
if (v->u.road.reverse_ctr != 0) |
|
1201 |
v->u.road.reverse_ctr--; |
|
1202 |
||
1203 |
// handle crashed |
|
1204 |
if (v->u.road.crashed_ctr != 0) { |
|
1205 |
RoadVehIsCrashed(v); |
|
1206 |
return; |
|
1207 |
} |
|
1208 |
||
1209 |
RoadVehCheckTrainCrash(v); |
|
1210 |
||
1211 |
// road vehicle has broken down? |
|
1212 |
if (v->breakdown_ctr != 0) { |
|
1213 |
if (v->breakdown_ctr <= 2) { |
|
1214 |
HandleBrokenRoadVeh(v); |
|
1215 |
return; |
|
1216 |
} |
|
1217 |
v->breakdown_ctr--; |
|
1218 |
} |
|
1219 |
||
1220 |
// exit if vehicle is stopped |
|
1221 |
if (v->vehstatus & VS_STOPPED) |
|
1222 |
return; |
|
1223 |
||
1224 |
ProcessRoadVehOrder(v); |
|
1225 |
HandleRoadVehLoading(v); |
|
1226 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1227 |
if (v->current_order.type == OT_LOADING) |
0 | 1228 |
return; |
1229 |
||
1230 |
if (v->u.road.state == 254) { |
|
1231 |
int dir; |
|
1232 |
const RoadDriveEntry*rdp; |
|
1233 |
byte rd2; |
|
1234 |
||
1235 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1236 |
|
0 | 1237 |
dir = _map5[v->tile]&3; |
1238 |
v->direction = dir*2+1; |
|
1239 |
||
1240 |
rd2 = _roadveh_data_2[dir]; |
|
1241 |
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
|
1242 |
|
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
|
1243 |
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
|
1244 |
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF); |
0 | 1245 |
|
1246 |
if (RoadVehFindCloseTo(v,x,y,v->direction)) |
|
1247 |
return; |
|
1248 |
||
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
|
1249 |
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
|
1250 |
|
0 | 1251 |
StartRoadVehSound(v); |
1252 |
||
1253 |
BeginVehicleMove(v); |
|
1254 |
||
1255 |
v->vehstatus &= ~VS_HIDDEN; |
|
1256 |
v->u.road.state = rd2; |
|
1257 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1258 |
|
0 | 1259 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1260 |
UpdateRoadVehDeltaXY(v); |
|
1261 |
SetRoadVehPosition(v,x,y); |
|
1262 |
||
1263 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1264 |
return; |
|
1265 |
} |
|
1266 |
||
1267 |
if (!RoadVehAccelerate(v)) |
|
1268 |
return; |
|
1269 |
||
1270 |
if (v->u.road.overtaking != 0) { |
|
1271 |
if (++v->u.road.overtaking_ctr >= 35) |
|
1272 |
v->u.road.overtaking = 0; |
|
1273 |
} |
|
1274 |
||
1275 |
BeginVehicleMove(v); |
|
1276 |
||
1277 |
if (v->u.road.state == 255) { |
|
1278 |
GetNewVehiclePos(v, &gp); |
|
1279 |
||
1280 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction)) { |
|
1281 |
v->cur_speed = 0; |
|
1282 |
return; |
|
1283 |
} |
|
1284 |
||
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
|
1285 |
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && |
0 | 1286 |
(_map5[gp.new_tile]&0xF0) == 0 && |
1287 |
(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
|
1288 |
|
0 | 1289 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1290 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1291 |
UpdateRoadVehDeltaXY(v); |
|
1292 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1293 |
return; |
|
1294 |
} |
|
1295 |
||
1296 |
v->x_pos = gp.x; |
|
1297 |
v->y_pos = gp.y; |
|
1298 |
VehiclePositionChanged(v); |
|
1299 |
return; |
|
1300 |
} |
|
1301 |
||
1302 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1]; |
|
1303 |
||
1304 |
// switch to another tile |
|
1305 |
if (rd.x & 0x80) { |
|
900 | 1306 |
uint tile = v->tile + TileOffsByDir(rd.x & 3); |
0 | 1307 |
int dir = RoadFindPathToDest(v, tile, rd.x&3); |
1308 |
int tmp; |
|
1309 |
uint32 r; |
|
1310 |
byte newdir; |
|
1311 |
const RoadDriveEntry *rdp; |
|
1312 |
||
1313 |
if (dir == -1) { |
|
1314 |
v->cur_speed = 0; |
|
1315 |
return; |
|
1316 |
} |
|
1317 |
||
1318 |
again: |
|
1319 |
if ((dir & 7) >= 6) { |
|
1247 | 1320 |
/* Turning around */ |
0 | 1321 |
tile = v->tile; |
1322 |
} |
|
1323 |
||
1324 |
tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking; |
|
1325 |
rdp = _road_drive_data[tmp]; |
|
1326 |
||
1327 |
tmp &= ~0x10; |
|
1328 |
||
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
|
1329 |
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
|
1330 |
y = TileY(tile) * 16 + rdp[0].y; |
0 | 1331 |
|
1332 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1333 |
return; |
|
1334 |
||
1335 |
r = VehicleEnterTile(v, tile, x, y); |
|
1336 |
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
|
1337 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1338 |
v->cur_speed = 0; |
1339 |
return; |
|
1340 |
} |
|
1341 |
dir = _road_reverse_table[rd.x&3]; |
|
1342 |
goto again; |
|
1343 |
} |
|
1344 |
||
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
|
1345 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
0 | 1346 |
if ((tmp&7) >= 6) { v->cur_speed = 0; return; } |
1347 |
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
|
1348 |
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
|
1349 |
byte *b = &rs->status; |
0 | 1350 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1351 |
//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
|
1352 |
//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
|
1353 |
*b = (*b | ((v->u.road.state&2)?2:1)) & ~0x80; |
0 | 1354 |
} |
1355 |
} |
|
1356 |
||
1357 |
if (!(r & 4)) { |
|
1358 |
v->tile = tile; |
|
1359 |
v->u.road.state = (byte)tmp; |
|
1360 |
v->u.road.frame = 0; |
|
1361 |
} |
|
1362 |
if (newdir != v->direction) { |
|
1363 |
v->direction = newdir; |
|
1364 |
v->cur_speed -= v->cur_speed >> 2; |
|
1365 |
} |
|
1366 |
||
1367 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1368 |
UpdateRoadVehDeltaXY(v); |
|
1369 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1370 |
return; |
|
1371 |
} |
|
1372 |
||
1373 |
if (rd.x & 0x40) { |
|
1374 |
int dir = RoadFindPathToDest(v, v->tile, rd.x&3); |
|
1375 |
uint32 r; |
|
1376 |
int tmp; |
|
1377 |
byte newdir; |
|
1378 |
const RoadDriveEntry *rdp; |
|
1379 |
||
1380 |
if (dir == -1) { |
|
1381 |
v->cur_speed = 0; |
|
1382 |
return; |
|
1383 |
} |
|
1384 |
||
1385 |
tmp = (_opt.road_side<<4) + dir; |
|
1386 |
rdp = _road_drive_data[tmp]; |
|
1387 |
||
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
|
1388 |
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
|
1389 |
y = TileY(v->tile) * 16 + rdp[1].y; |
0 | 1390 |
|
1391 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1392 |
return; |
|
1393 |
||
1394 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1395 |
if (r & 8) { |
|
1396 |
v->cur_speed = 0; |
|
1397 |
return; |
|
1398 |
} |
|
1399 |
||
1400 |
v->u.road.state = tmp & ~16; |
|
1401 |
v->u.road.frame = 1; |
|
1402 |
||
1403 |
if (newdir != v->direction) { |
|
1404 |
v->direction = newdir; |
|
1405 |
v->cur_speed -= v->cur_speed >> 2; |
|
1406 |
} |
|
1407 |
||
1408 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1409 |
UpdateRoadVehDeltaXY(v); |
|
1410 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1411 |
return; |
|
1412 |
} |
|
1413 |
||
1414 |
x = (v->x_pos&~15)+(rd.x&15); |
|
1415 |
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
|
1416 |
|
0 | 1417 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1418 |
||
1419 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) { |
|
1420 |
if (v->u.road.overtaking == 0) |
|
1421 |
RoadVehCheckOvertake(v, u); |
|
1422 |
return; |
|
1423 |
} |
|
1424 |
||
1425 |
old_dir = v->direction; |
|
1426 |
if (new_dir != old_dir) { |
|
1427 |
v->direction = new_dir; |
|
1428 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1429 |
if (old_dir != v->u.road.state) { |
|
1430 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1431 |
UpdateRoadVehDeltaXY(v); |
|
1432 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1433 |
return; |
|
1434 |
} |
|
1435 |
} |
|
1436 |
||
1437 |
if (v->u.road.state >= 0x20 && |
|
1438 |
_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
|
1439 |
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
|
1440 |
byte *b = &rs->status; |
0 | 1441 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1442 |
st = GetStation(_map2[v->tile]); |
0 | 1443 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1444 |
if (v->current_order.type != OT_LEAVESTATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1445 |
v->current_order.type != OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1446 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1447 |
|
0 | 1448 |
*b &= ~0x80; |
1449 |
||
1450 |
v->last_station_visited = _map2[v->tile]; |
|
1451 |
||
1452 |
RoadVehArrivesAt(v, st); |
|
1453 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1454 |
old_order = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1455 |
v->current_order.type = OT_LOADING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1456 |
v->current_order.flags = 0; |
0 | 1457 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1458 |
if (old_order.type == OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1459 |
v->current_order.station == v->last_station_visited) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1460 |
v->current_order.flags = |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1461 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP; |
0 | 1462 |
} |
1463 |
||
1464 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
1465 |
if (LoadUnloadVehicle(v)) { |
|
1466 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1467 |
MarkRoadVehDirty(v); |
|
1468 |
} |
|
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
|
1469 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1470 |
return; |
1471 |
} |
|
1472 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1473 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
0 | 1474 |
if (*b&0x80) { |
1475 |
v->cur_speed = 0; |
|
1476 |
return; |
|
1477 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1478 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1479 |
v->current_order.flags = 0; |
0 | 1480 |
} |
1481 |
*b |= 0x80; |
|
1482 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1483 |
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
|
1484 |
//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
|
1485 |
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
|
1486 |
} 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
|
1487 |
//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
|
1488 |
//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
|
1489 |
//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
|
1490 |
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
|
1491 |
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
|
1492 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1493 |
|
0 | 1494 |
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
|
1495 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1496 |
} |
1497 |
||
1498 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1499 |
if (r & 8) { |
|
1500 |
v->cur_speed = 0; |
|
1501 |
return; |
|
1502 |
} |
|
1503 |
||
1504 |
if ((r & 4) == 0) { |
|
1505 |
v->u.road.frame++; |
|
1506 |
} |
|
1507 |
||
1508 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1509 |
UpdateRoadVehDeltaXY(v); |
|
1510 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1511 |
} |
|
1512 |
||
1513 |
void RoadVehEnterDepot(Vehicle *v) |
|
1514 |
{ |
|
1515 |
v->u.road.state = 254; |
|
1516 |
v->vehstatus |= VS_HIDDEN; |
|
1517 |
||
1518 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1519 |
||
842 | 1520 |
MaybeReplaceVehicle(v); |
0 | 1521 |
|
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
|
1522 |
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
|
1523 |
|
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
|
1524 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1525 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1526 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1527 |
Order t; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1528 |
|
0 | 1529 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1530 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1531 |
t = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1532 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1533 |
v->current_order.flags = 0; |
0 | 1534 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1535 |
// Part of the orderlist? |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1536 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1537 |
v->cur_order_index++; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1538 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { |
0 | 1539 |
v->vehstatus |= VS_STOPPED; |
1540 |
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
|
1541 |
SetDParam(0, v->unitnumber); |
0 | 1542 |
AddNewsItem( |
1543 |
STR_9016_ROAD_VEHICLE_IS_WAITING, |
|
1544 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1545 |
v->index, |
|
1546 |
0); |
|
1547 |
} |
|
1548 |
} |
|
1549 |
} |
|
1550 |
||
1551 |
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
|
1552 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1553 |
} |
1554 |
||
1555 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1556 |
{ |
|
1557 |
if (_age_cargo_skip_counter != 0) |
|
1558 |
return; |
|
1559 |
if (v->cargo_days != 255) |
|
1560 |
v->cargo_days++; |
|
1561 |
} |
|
1562 |
||
1563 |
void RoadVeh_Tick(Vehicle *v) |
|
1564 |
{ |
|
1565 |
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
|
1566 |
RoadVehController(v); |
0 | 1567 |
} |
1568 |
||
1569 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1570 |
{ |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1571 |
Depot *depot; |
0 | 1572 |
|
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1573 |
if (_patches.servint_roadveh == 0) |
11
836bc4b37b5b
(svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents:
0
diff
changeset
|
1574 |
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
|
1575 |
|
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1576 |
if (!VehicleNeedsService(v)) |
0 | 1577 |
return; |
1578 |
||
1579 |
if (v->vehstatus & VS_STOPPED) |
|
1580 |
return; |
|
1581 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1582 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) |
0 | 1583 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1584 |
|
0 | 1585 |
// Don't interfere with a depot visit scheduled by the user, or a |
1586 |
// depot visit by the order list. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1587 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1588 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 1589 |
return; |
1590 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1591 |
//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
|
1592 |
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
|
1593 |
return; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1594 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1595 |
depot = FindClosestRoadDepot(v); |
0 | 1596 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1597 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1598 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1599 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1600 |
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
|
1601 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1602 |
} |
1603 |
return; |
|
1604 |
} |
|
1605 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1606 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1607 |
v->current_order.flags & OF_NON_STOP && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1608 |
!CHANCE16(1,20)) |
0 | 1609 |
return; |
1610 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1611 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1612 |
v->current_order.flags = OF_NON_STOP; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1613 |
v->current_order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1614 |
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
|
1615 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1616 |
} |
1617 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1618 |
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
|
1619 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1620 |
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
|
1621 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1622 |
|
0 | 1623 |
void OnNewDay_RoadVeh(Vehicle *v) |
1624 |
{ |
|
1625 |
int32 cost; |
|
1626 |
Station *st; |
|
1627 |
||
1628 |
if ((++v->day_counter & 7) == 0) |
|
1629 |
DecreaseVehicleValue(v); |
|
1630 |
||
1631 |
if (v->u.road.unk2 == 0) |
|
1632 |
CheckVehicleBreakdown(v); |
|
1633 |
||
1634 |
AgeVehicle(v); |
|
1635 |
CheckIfRoadVehNeedsService(v); |
|
1636 |
||
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1035
diff
changeset
|
1637 |
CheckOrders(v->index, OC_INIT); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1638 |
|
0 | 1639 |
/* update destination */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1640 |
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
|
1641 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1642 |
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
|
1643 |
int num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1644 |
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
|
1645 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1646 |
typedef struct { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1647 |
uint32 dist; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1648 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1649 |
} StopStruct; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1650 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1651 |
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
|
1652 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1653 |
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
|
1654 |
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
|
1655 |
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
|
1656 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1657 |
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
|
1658 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1659 |
//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
|
1660 |
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
|
1661 |
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
|
1662 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1663 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1664 |
//We do not have a slot, so make one |
1467
6be9302390be
(svn r1971) -Codechange: Got rid of two ugly gotos and replaced them by one elegant and one ugly non-goto. Credits for 1959 go to Darkvater. Sorry
celestar
parents:
1455
diff
changeset
|
1665 |
if (v->u.road.slot == NULL && rs != NULL) { |
6be9302390be
(svn r1971) -Codechange: Got rid of two ugly gotos and replaced them by one elegant and one ugly non-goto. Credits for 1959 go to Darkvater. Sorry
celestar
parents:
1455
diff
changeset
|
1666 |
//first we need to find out how far our stations are away. |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1667 |
|
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1668 |
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
|
1669 |
do { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1670 |
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
|
1671 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1672 |
//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
|
1673 |
//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
|
1674 |
//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
|
1675 |
stop->dist = RoadFindPathToStation(v, rs->xy); |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1676 |
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
|
1677 |
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
|
1678 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1679 |
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
|
1680 |
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
|
1681 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1682 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1683 |
stop++; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1684 |
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
|
1685 |
} 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
|
1686 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1687 |
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
|
1688 |
int k; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1689 |
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
|
1690 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1691 |
stop = firststop; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1692 |
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
|
1693 |
int i; |
1467
6be9302390be
(svn r1971) -Codechange: Got rid of two ugly gotos and replaced them by one elegant and one ugly non-goto. Credits for 1959 go to Darkvater. Sorry
celestar
parents:
1455
diff
changeset
|
1694 |
bool br = false; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1695 |
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
|
1696 |
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
|
1697 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1698 |
//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
|
1699 |
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
|
1700 |
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
|
1701 |
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
|
1702 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1703 |
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
|
1704 |
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
|
1705 |
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
|
1706 |
|
1467
6be9302390be
(svn r1971) -Codechange: Got rid of two ugly gotos and replaced them by one elegant and one ugly non-goto. Credits for 1959 go to Darkvater. Sorry
celestar
parents:
1455
diff
changeset
|
1707 |
br = true; |
6be9302390be
(svn r1971) -Codechange: Got rid of two ugly gotos and replaced them by one elegant and one ugly non-goto. Credits for 1959 go to Darkvater. Sorry
celestar
parents:
1455
diff
changeset
|
1708 |
break; |
1217
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 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1711 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1712 |
stop++; |
1467
6be9302390be
(svn r1971) -Codechange: Got rid of two ugly gotos and replaced them by one elegant and one ugly non-goto. Credits for 1959 go to Darkvater. Sorry
celestar
parents:
1455
diff
changeset
|
1713 |
if (br) break; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1714 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1715 |
} |
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 |
//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
|
1718 |
//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
|
1719 |
if (v->u.road.slot == NULL) { |
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1720 |
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
|
1721 |
v->dest_tile = firststop->rs->xy; |
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1722 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1723 |
} |
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 |
free(firststop); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1726 |
firststop = stop = NULL; |
0 | 1727 |
} |
1728 |
||
1729 |
if (v->vehstatus & VS_STOPPED) |
|
1730 |
return; |
|
1731 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1732 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1733 |
|
1734 |
v->profit_this_year -= cost >> 8; |
|
1735 |
||
1736 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1737 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1738 |
||
1739 |
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
|
1740 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1741 |
} |
1742 |
||
1743 |
void HandleClickOnRoadVeh(Vehicle *v) |
|
1744 |
{ |
|
1745 |
ShowRoadVehViewWindow(v); |
|
1746 |
} |
|
1747 |
||
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
|
1748 |
void RoadVehiclesYearlyLoop(void) |
0 | 1749 |
{ |
1750 |
Vehicle *v; |
|
1751 |
||
1752 |
FOR_ALL_VEHICLES(v) { |
|
1753 |
if (v->type == VEH_Road) { |
|
1754 |
v->profit_last_year = v->profit_this_year; |
|
1755 |
v->profit_this_year = 0; |
|
1756 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1757 |
} |
|
1758 |
} |
|
1759 |
} |
|
1760 |