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