author | ludde |
Sun, 17 Jul 2005 12:29:33 +0000 | |
changeset 2089 | 32846ac9e841 |
parent 2049 | 538e73c53f54 |
child 2093 | 8c3e6f5b92e1 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1793
diff
changeset
|
2 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
3 |
#include "debug.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
4 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
5 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
6 |
#include "tile.h" |
0 | 7 |
#include "vehicle.h" |
8 |
#include "engine.h" |
|
9 |
#include "command.h" |
|
10 |
#include "station.h" |
|
11 |
#include "news.h" |
|
12 |
#include "pathfind.h" |
|
1247 | 13 |
#include "npf.h" |
0 | 14 |
#include "player.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
15 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
16 |
#include "depot.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
17 |
#include "vehicle_gui.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 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
60 |
int GetRoadVehImage(const Vehicle *v, byte direction) |
0 | 61 |
{ |
62 |
int img = v->spritenum; |
|
63 |
int image; |
|
64 |
||
65 |
if (is_custom_sprite(img)) { |
|
66 |
image = GetCustomVehicleSprite(v, direction); |
|
67 |
if (image) return image; |
|
68 |
img = _engine_original_sprites[v->engine_type]; |
|
69 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
70 |
|
0 | 71 |
image = direction + _roadveh_images[img]; |
72 |
if (v->cargo_count >= (v->cargo_cap >> 1)) |
|
73 |
image += _roadveh_full_adder[img]; |
|
74 |
return image; |
|
75 |
} |
|
76 |
||
77 |
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod) |
|
78 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
79 |
int spritenum = RoadVehInfo(engine)->image_index; |
378
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
80 |
|
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
81 |
if (is_custom_sprite(spritenum)) { |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
82 |
int sprite = GetCustomVehicleIcon(engine, 6); |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
83 |
|
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
84 |
if (sprite) { |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
85 |
DrawSprite(sprite | image_ormod, x, y); |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
86 |
return; |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
87 |
} |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
88 |
spritenum = _engine_original_sprites[engine]; |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
89 |
} |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
90 |
DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y); |
0 | 91 |
} |
92 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
93 |
int32 EstimateRoadVehCost(EngineID engine_type) |
0 | 94 |
{ |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
95 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 96 |
} |
97 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
98 |
/** Build a road vehicle. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
99 |
* @param x,y tile coordinates of depot where road vehicle is built |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
100 |
* @param p1 bus/truck type being built (engine) |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
101 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
102 |
*/ |
0 | 103 |
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
104 |
{ |
|
105 |
int32 cost; |
|
106 |
Vehicle *v; |
|
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
107 |
UnitID unit_num; |
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
108 |
TileIndex tile = TileVirtXY(x, y); |
0 | 109 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
110 |
|
1197 | 111 |
if (!IsEngineBuildable(p1, VEH_Road)) return CMD_ERROR; |
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
112 |
|
0 | 113 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
114 |
||
115 |
cost = EstimateRoadVehCost(p1); |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
116 |
if (flags & DC_QUERY_COST) return cost; |
0 | 117 |
|
1442
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
118 |
/* The ai_new queries the vehicle cost before building the route, |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
119 |
* so we must check against cheaters no sooner than now. --pasky */ |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
120 |
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR; |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
121 |
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
1442
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
122 |
|
0 | 123 |
v = AllocateVehicle(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
124 |
if (v == NULL || IsOrderPoolFull()) |
0 | 125 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
126 |
||
127 |
/* find the first free roadveh id */ |
|
128 |
unit_num = GetFreeUnitNumber(VEH_Road); |
|
129 |
if (unit_num > _patches.max_roadveh) |
|
130 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
131 |
||
132 |
if (flags & DC_EXEC) { |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
133 |
const RoadVehicleInfo *rvi = RoadVehInfo(p1); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
134 |
|
0 | 135 |
v->unitnumber = unit_num; |
136 |
v->direction = 0; |
|
137 |
v->owner = _current_player; |
|
138 |
||
139 |
v->tile = tile; |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
140 |
x = TileX(tile) * 16 + 8; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
141 |
y = TileY(tile) * 16 + 8; |
0 | 142 |
v->x_pos = x; |
143 |
v->y_pos = y; |
|
144 |
v->z_pos = GetSlopeZ(x,y); |
|
145 |
v->z_height = 6; |
|
146 |
||
147 |
v->u.road.state = 254; |
|
148 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
149 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
150 |
v->spritenum = rvi->image_index; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
151 |
v->cargo_type = rvi->cargo_type; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
152 |
v->cargo_cap = rvi->capacity; |
0 | 153 |
// v->cargo_count = 0; |
154 |
v->value = cost; |
|
155 |
// v->day_counter = 0; |
|
156 |
// v->next_order_param = v->next_order = 0; |
|
157 |
// v->load_unload_time_rem = 0; |
|
158 |
// v->progress = 0; |
|
159 |
||
160 |
// v->u.road.unk2 = 0; |
|
161 |
// v->u.road.overtaking = 0; |
|
162 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
163 |
v->u.road.slot = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
164 |
v->u.road.slotindex = 0; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
165 |
v->u.road.slot_age = 0; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
166 |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
167 |
v->last_station_visited = INVALID_STATION; |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
168 |
v->max_speed = rvi->max_speed; |
0 | 169 |
v->engine_type = (byte)p1; |
170 |
||
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
171 |
e = GetEngine(p1); |
0 | 172 |
v->reliability = e->reliability; |
173 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
174 |
v->max_age = e->lifelength * 366; |
|
175 |
_new_roadveh_id = v->index; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
176 |
|
0 | 177 |
v->string_id = STR_SV_ROADVEH_NAME; |
178 |
||
179 |
v->service_interval = _patches.servint_roadveh; |
|
180 |
||
181 |
v->date_of_last_service = _date; |
|
182 |
v->build_year = _cur_year; |
|
183 |
||
184 |
v->type = VEH_Road; |
|
185 |
v->cur_image = 0xC15; |
|
186 |
||
187 |
VehiclePositionChanged(v); |
|
188 |
||
189 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 190 |
RebuildVehicleLists(); |
0 | 191 |
InvalidateWindow(WC_COMPANY, v->owner); |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
192 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
0 | 193 |
} |
194 |
||
195 |
return cost; |
|
196 |
} |
|
197 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
198 |
/** Start/Stop a road vehicle. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
199 |
* @param x,y unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
200 |
* @param p1 road vehicle ID to start/stop |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
201 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
202 |
*/ |
0 | 203 |
int32 CmdStartStopRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
204 |
{ |
|
205 |
Vehicle *v; |
|
206 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
207 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
208 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
209 |
v = GetVehicle(p1); |
0 | 210 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
211 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 212 |
|
213 |
if (flags & DC_EXEC) { |
|
214 |
v->vehstatus ^= VS_STOPPED; |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
215 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 216 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
217 |
} |
|
218 |
||
219 |
return 0; |
|
220 |
} |
|
221 |
||
1680
2d69b69f7b17
(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
|
222 |
void ClearSlot(Vehicle *v, RoadStop *rs) |
1664
1f909247678d
(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
|
223 |
{ |
1f909247678d
(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
|
224 |
DEBUG(ms, 3) ("Multistop: Clearing slot %d at 0x%x", v->u.road.slotindex, rs->xy); |
1f909247678d
(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
|
225 |
v->u.road.slot = NULL; |
1f909247678d
(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
|
226 |
v->u.road.slot_age = 0; |
1680
2d69b69f7b17
(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
|
227 |
if (rs != NULL) { |
2d69b69f7b17
(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
|
228 |
// check that the slot is indeed assigned to the same vehicle |
2d69b69f7b17
(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
|
229 |
assert(rs->slot[v->u.road.slotindex] == v->index); |
1664
1f909247678d
(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
|
230 |
rs->slot[v->u.road.slotindex] = INVALID_SLOT; |
1680
2d69b69f7b17
(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
|
231 |
} |
1664
1f909247678d
(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
|
232 |
} |
1f909247678d
(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 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
234 |
/** Sell a road vehicle. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
235 |
* @param x,y unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
236 |
* @param p1 vehicle ID to be sold |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
237 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
238 |
*/ |
0 | 239 |
int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
240 |
{ |
|
241 |
Vehicle *v; |
|
242 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
243 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
244 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
245 |
v = GetVehicle(p1); |
0 | 246 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
247 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 248 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
249 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
250 |
|
1330
5d76a0522a11
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
251 |
if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) |
0 | 252 |
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
|
253 |
|
0 | 254 |
if (flags & DC_EXEC) { |
255 |
// Invalidate depot |
|
256 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 257 |
RebuildVehicleLists(); |
0 | 258 |
InvalidateWindow(WC_COMPANY, v->owner); |
259 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
1664
1f909247678d
(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
|
260 |
ClearSlot(v, v->u.road.slot); |
0 | 261 |
DeleteVehicle(v); |
262 |
} |
|
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
263 |
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
|
264 |
|
0 | 265 |
return -(int32)v->value; |
266 |
} |
|
267 |
||
268 |
typedef struct RoadFindDepotData { |
|
269 |
uint best_length; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
270 |
TileIndex tile; |
0 | 271 |
byte owner; |
272 |
} RoadFindDepotData; |
|
273 |
||
274 |
static const byte _road_pf_directions[16] = { |
|
275 |
0, 1, 0, 1, 2, 1, 255, 255, |
|
276 |
2, 3, 3, 2, 3, 0, 255, 255, |
|
277 |
}; |
|
278 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
279 |
static bool EnumRoadSignalFindDepot(TileIndex tile, RoadFindDepotData *rfdd, int track, uint length, byte *state) |
0 | 280 |
{ |
904
f659cda593cb
(svn r1390) Use TileOffsByDir() instead of home brewed table
tron
parents:
900
diff
changeset
|
281 |
tile += TileOffsByDir(_road_pf_directions[track]); |
0 | 282 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
283 |
if (IsTileType(tile, MP_STREET) && |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
284 |
(_m[tile].m5 & 0xF0) == 0x20 && |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
285 |
IsTileOwner(tile, rfdd->owner)) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
286 |
|
0 | 287 |
if (length < rfdd->best_length) { |
288 |
rfdd->best_length = length; |
|
289 |
rfdd->tile = tile; |
|
290 |
} |
|
291 |
} |
|
292 |
return false; |
|
293 |
} |
|
294 |
||
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
295 |
static Depot *FindClosestRoadDepot(Vehicle *v) |
0 | 296 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
297 |
TileIndex tile = v->tile; |
0 | 298 |
int i; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
299 |
|
0 | 300 |
if (v->u.road.state == 255) { tile = GetVehicleOutOfTunnelTile(v); } |
301 |
||
1247 | 302 |
if (_patches.new_pathfinding_all) { |
303 |
NPFFoundTargetData ftd; |
|
304 |
/* See where we are now */ |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
305 |
Trackdir trackdir = GetVehicleTrackdir(v); |
1745
1113e1272ca2
(svn r2249) - Fix: [ 1187703 ] [NPF] Road vehicles cannot find a depot when in a roadstop
matthijs
parents:
1709
diff
changeset
|
306 |
|
2006
9d5d7fd428c2
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1998
diff
changeset
|
307 |
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
1247 | 308 |
if (ftd.best_bird_dist == 0) |
309 |
return GetDepotByTile(ftd.node.tile); /* Target found */ |
|
310 |
else |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
311 |
return NULL; /* Target not found */ |
1247 | 312 |
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ |
313 |
} else { |
|
314 |
RoadFindDepotData rfdd; |
|
315 |
rfdd.owner = v->owner; |
|
316 |
rfdd.best_length = (uint)-1; |
|
0 | 317 |
|
1247 | 318 |
/* search in all directions */ |
319 |
for(i=0; i!=4; i++) |
|
320 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd); |
|
0 | 321 |
|
1247 | 322 |
if (rfdd.best_length == (uint)-1) |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
323 |
return NULL; |
0 | 324 |
|
1247 | 325 |
return GetDepotByTile(rfdd.tile); |
326 |
} |
|
0 | 327 |
} |
328 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
329 |
/** Send a road vehicle to the depot. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
330 |
* @param x,y unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
331 |
* @param p1 vehicle ID to send to the depot |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
332 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
333 |
*/ |
0 | 334 |
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
335 |
{ |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
336 |
Vehicle *v; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
337 |
const Depot *dep; |
0 | 338 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
339 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
340 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
341 |
v = GetVehicle(p1); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
342 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
343 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 344 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
345 |
if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
1757
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
346 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
347 |
/* If the current orders are already goto-depot */ |
555
02df8a1b7f33
(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) { |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
350 |
/* If the orders to 'goto depot' are in the orders list (forced servicing), |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
351 |
* then skip to the next order; effectively cancelling this forced service */ |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
352 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
0 | 353 |
v->cur_order_index++; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
354 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
355 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
356 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
357 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 358 |
} |
359 |
return 0; |
|
360 |
} |
|
361 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
362 |
dep = FindClosestRoadDepot(v); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
363 |
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
0 | 364 |
|
365 |
if (flags & DC_EXEC) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
366 |
v->current_order.type = OT_GOTO_DEPOT; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
367 |
v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
368 |
v->current_order.station = dep->index; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
369 |
v->dest_tile = dep->xy; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
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 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
376 |
/** Turn a roadvehicle around. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
377 |
* @param x,y unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
378 |
* @param p1 vehicle ID to turn |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
379 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
380 |
*/ |
0 | 381 |
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
382 |
{ |
|
383 |
Vehicle *v; |
|
384 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
385 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
386 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
387 |
v = GetVehicle(p1); |
0 | 388 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
389 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 390 |
|
391 |
if (v->vehstatus & (VS_HIDDEN|VS_STOPPED) || |
|
392 |
v->u.road.crashed_ctr != 0 || |
|
393 |
v->breakdown_ctr != 0 || |
|
394 |
v->u.road.overtaking != 0 || |
|
395 |
v->cur_speed < 5) { |
|
396 |
return CMD_ERROR; |
|
397 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
398 |
|
0 | 399 |
if (flags & DC_EXEC) { |
400 |
v->u.road.reverse_ctr = 180; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
401 |
} |
0 | 402 |
|
403 |
return 0; |
|
404 |
} |
|
405 |
||
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
406 |
/** Change the service interval for road vehicles. |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
407 |
* @param x,y unused |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
408 |
* @param p1 vehicle ID that is being service-interval-changed |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
409 |
* @param p2 new service interval |
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
410 |
*/ |
0 | 411 |
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
412 |
{ |
|
413 |
Vehicle *v; |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
414 |
uint16 serv_int = GetServiceIntervalClamped(p2); /* Double check the service interval from the user-input */ |
0 | 415 |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
416 |
if (serv_int != p2 || !IsVehicleIndex(p1)) return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
417 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
418 |
v = GetVehicle(p1); |
0 | 419 |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
420 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 421 |
|
422 |
if (flags & DC_EXEC) { |
|
1790
47963a0cfca3
(svn r2294) - CodeChange: check the service interval settings when changing of all vehicle-types. To simplify things introduce GetServiceIntervalClamped() that returns the same or clamped value of the new service interval. There were some inconsistencies in the gui files so I had to change those, and const correctness kicked in, so it's a bit messy at certain points.
Darkvater
parents:
1769
diff
changeset
|
423 |
v->service_interval = serv_int; |
0 | 424 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
425 |
} |
|
426 |
||
427 |
return 0; |
|
428 |
} |
|
429 |
||
430 |
||
431 |
static void MarkRoadVehDirty(Vehicle *v) |
|
432 |
{ |
|
433 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
434 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
435 |
} |
|
436 |
||
437 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
438 |
{ |
|
439 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
440 |
static const uint32 _delta_xy_table[8] = { |
|
441 |
MKIT(3, 3, -1, -1), |
|
442 |
MKIT(3, 7, -1, -3), |
|
443 |
MKIT(3, 3, -1, -1), |
|
444 |
MKIT(7, 3, -3, -1), |
|
445 |
MKIT(3, 3, -1, -1), |
|
446 |
MKIT(3, 7, -1, -3), |
|
447 |
MKIT(3, 3, -1, -1), |
|
448 |
MKIT(7, 3, -3, -1), |
|
449 |
}; |
|
450 |
#undef MKIT |
|
451 |
uint32 x = _delta_xy_table[v->direction]; |
|
452 |
v->x_offs = (byte)x; |
|
453 |
v->y_offs = (byte)(x>>=8); |
|
454 |
v->sprite_width = (byte)(x>>=8); |
|
455 |
v->sprite_height = (byte)(x>>=8); |
|
456 |
} |
|
457 |
||
458 |
static void ClearCrashedStation(Vehicle *v) |
|
459 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
460 |
TileIndex tile = v->tile; |
0 | 461 |
byte *b, bb; |
462 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
463 |
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
464 |
b = &rs->status; |
0 | 465 |
|
466 |
bb = *b; |
|
467 |
||
468 |
// mark station as not busy |
|
469 |
bb &= ~0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
470 |
|
0 | 471 |
// free parking bay |
472 |
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
|
473 |
|
0 | 474 |
*b = bb; |
475 |
} |
|
476 |
||
477 |
static void RoadVehDelete(Vehicle *v) |
|
478 |
{ |
|
479 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
480 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
481 |
|
588 | 482 |
RebuildVehicleLists(); |
0 | 483 |
InvalidateWindow(WC_COMPANY, v->owner); |
484 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
485 |
if (IsTileType(v->tile, MP_STATION)) |
0 | 486 |
ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
487 |
|
0 | 488 |
BeginVehicleMove(v); |
489 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
490 |
|
1665
ad61a6a27fca
(svn r2169) -Fix: Doing the slot clearing also for crashed road vehicles (c.f. previous commit)
celestar
parents:
1664
diff
changeset
|
491 |
ClearSlot(v, v->u.road.slot); |
0 | 492 |
DeleteVehicle(v); |
493 |
} |
|
494 |
||
495 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
496 |
{ |
|
497 |
byte new_z, old_z; |
|
498 |
||
499 |
// need this hint so it returns the right z coordinate on bridges. |
|
500 |
_get_z_hint = v->z_pos; |
|
501 |
new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y); |
|
502 |
_get_z_hint = 0; |
|
503 |
||
504 |
old_z = v->z_pos; |
|
505 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
506 |
|
0 | 507 |
VehiclePositionChanged(v); |
508 |
EndVehicleMove(v); |
|
509 |
return old_z; |
|
510 |
} |
|
511 |
||
512 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
513 |
{ |
|
514 |
static const int8 _turn_prob[4] = { -1, 0, 0, 1 }; |
|
515 |
uint32 r = Random(); |
|
516 |
v->direction = (v->direction+_turn_prob[r&3])&7; |
|
517 |
BeginVehicleMove(v); |
|
518 |
UpdateRoadVehDeltaXY(v); |
|
519 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
520 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
521 |
} |
|
522 |
||
523 |
static void RoadVehIsCrashed(Vehicle *v) |
|
524 |
{ |
|
525 |
v->u.road.crashed_ctr++; |
|
526 |
if (v->u.road.crashed_ctr == 2) { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
527 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 528 |
} else if (v->u.road.crashed_ctr <= 45) { |
529 |
if ((v->tick_counter&7)==0) |
|
530 |
RoadVehSetRandomDirection(v); |
|
531 |
} else if (v->u.road.crashed_ctr >= 2220) { |
|
532 |
RoadVehDelete(v); |
|
533 |
} |
|
534 |
} |
|
535 |
||
536 |
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u) |
|
537 |
{ |
|
538 |
if (v->type != VEH_Train || |
|
539 |
myabs(v->z_pos - u->z_pos) > 6 || |
|
540 |
myabs(v->x_pos - u->x_pos) > 4 || |
|
541 |
myabs(v->y_pos - u->y_pos) > 4) |
|
542 |
return NULL; |
|
543 |
return v; |
|
544 |
} |
|
545 |
||
546 |
static void RoadVehCrash(Vehicle *v) |
|
547 |
{ |
|
548 |
uint16 pass; |
|
549 |
||
550 |
v->u.road.crashed_ctr++; |
|
551 |
v->vehstatus |= VS_CRASHED; |
|
552 |
||
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
553 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 554 |
|
555 |
pass = 1; |
|
556 |
if (v->cargo_type == 0) |
|
557 |
pass += v->cargo_count; |
|
558 |
v->cargo_count = 0; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
559 |
SetDParam(0, pass); |
0 | 560 |
|
561 |
AddNewsItem(STR_9031_ROAD_VEHICLE_CRASH_DRIVER+(pass!=1), |
|
562 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
563 |
v->index, |
|
564 |
0); |
|
565 |
||
566 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 567 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 568 |
} |
569 |
||
570 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
571 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
572 |
TileIndex tile; |
0 | 573 |
|
574 |
if (v->u.road.state == 255) |
|
575 |
return; |
|
576 |
||
577 |
tile = v->tile; |
|
578 |
||
579 |
// Make sure it's a road/rail crossing |
|
1927
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1926
diff
changeset
|
580 |
if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile)) |
1181e7652e2f
(svn r2433) - CodeChange: unmagicify all road/train crossings with IsLevelCrossing() function (peter1138)
Darkvater
parents:
1926
diff
changeset
|
581 |
return; |
0 | 582 |
|
583 |
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL) |
|
584 |
RoadVehCrash(v); |
|
585 |
} |
|
586 |
||
587 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
588 |
{ |
|
589 |
if (v->breakdown_ctr != 1) { |
|
590 |
v->breakdown_ctr = 1; |
|
591 |
v->cur_speed = 0; |
|
592 |
||
593 |
if (v->breakdowns_since_last_service != 255) |
|
594 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
595 |
|
0 | 596 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
597 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
598 |
|
541 | 599 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
600 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
|
0 | 601 |
|
602 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
603 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
604 |
if (u) |
|
605 |
u->u.special.unk0 = v->breakdown_delay * 2; |
|
606 |
} |
|
607 |
} |
|
608 |
||
609 |
if (!(v->tick_counter & 1)) { |
|
610 |
if (!--v->breakdown_delay) { |
|
611 |
v->breakdown_ctr = 0; |
|
612 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
613 |
} |
|
614 |
} |
|
615 |
} |
|
616 |
||
617 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
618 |
{ |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
619 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
620 |
const Station *st; |
0 | 621 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
622 |
if (v->current_order.type >= OT_GOTO_DEPOT && v->current_order.type <= OT_LEAVESTATION) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
623 |
// Let a depot order in the orderlist interrupt. |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
624 |
if (v->current_order.type != OT_GOTO_DEPOT || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
625 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 626 |
return; |
627 |
} |
|
628 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
629 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
630 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
631 |
!VehicleNeedsService(v)) { |
0 | 632 |
v->cur_order_index++; |
633 |
} |
|
634 |
||
635 |
if (v->cur_order_index >= v->num_orders) |
|
636 |
v->cur_order_index = 0; |
|
637 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
638 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 639 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
640 |
if (order == NULL) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
641 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
642 |
v->current_order.flags = 0; |
0 | 643 |
v->dest_tile = 0; |
644 |
return; |
|
645 |
} |
|
646 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
647 |
if (order->type == v->current_order.type && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
648 |
order->flags == v->current_order.flags && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
649 |
order->station == v->current_order.station) |
0 | 650 |
return; |
651 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
652 |
v->current_order = *order; |
0 | 653 |
|
654 |
v->dest_tile = 0; |
|
655 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
656 |
if (order->type == OT_GOTO_STATION) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
657 |
if (order->station == v->last_station_visited) |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
658 |
v->last_station_visited = INVALID_STATION; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
659 |
st = GetStation(order->station); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
660 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
661 |
{ |
1709
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
662 |
uint mindist = 0xFFFFFFFF; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
663 |
int num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
664 |
RoadStopType type; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
665 |
RoadStop *rs; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
666 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
667 |
type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
668 |
num = GetNumRoadStops(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
669 |
rs = GetPrimaryRoadStop(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
670 |
|
1231
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
671 |
if (rs == NULL) { |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
672 |
//There is no stop left at the station, so don't even TRY to go there |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
673 |
v->cur_order_index++; |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
674 |
InvalidateVehicleOrder(v); |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
675 |
|
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
676 |
return; |
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
677 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
678 |
|
1709
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
679 |
for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) { |
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
680 |
if (DistanceManhattan(v->tile, rs->xy) < mindist) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
681 |
v->dest_tile = rs->xy; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
682 |
} |
1709
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
683 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
684 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
685 |
} |
1024
5e446b5b3ec5
(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
f1013ec3d318
(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
5e446b5b3ec5
(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
02df8a1b7f33
(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
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
698 |
if (v->current_order.type != OT_DUMMY) { |
02df8a1b7f33
(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
02df8a1b7f33
(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
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
715 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
716 |
v->current_order.type = OT_LEAVESTATION; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
717 |
v->current_order.flags = 0; |
02df8a1b7f33
(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
5e446b5b3ec5
(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
06c115ce7b7a
(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; |
|
1980
6c5917cfcb78
(svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents:
1977
diff
changeset
|
777 |
u = VehicleFromPos(TileVirtXY(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
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
802 |
SetDParam(0, st->index); |
0 | 803 |
flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0); |
804 |
AddNewsItem( |
|
805 |
STR_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
306bc86eb23e
(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
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
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; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
889 |
TileIndex tile; |
0 | 890 |
byte tilebits; |
891 |
} OvertakeData; |
|
892 |
||
1095 | 893 |
static void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od) |
0 | 894 |
{ |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
895 |
if (v->tile != od->tile || v->type != VEH_Road || v == od->u || v == od->v) |
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
896 |
return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
897 |
return v; |
0 | 898 |
} |
899 |
||
900 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
901 |
{ |
|
902 |
uint32 bits; |
|
903 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
904 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F; |
0 | 905 |
|
906 |
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000)) |
|
907 |
return true; |
|
908 |
return VehicleFromPos(od->tile, od, (VehicleFromPosProc*)EnumFindVehToOvertake) != NULL; |
|
909 |
} |
|
910 |
||
911 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
912 |
{ |
|
913 |
OvertakeData od; |
|
914 |
byte tt; |
|
915 |
||
916 |
od.v = v; |
|
917 |
od.u = u; |
|
918 |
||
919 |
if (u->max_speed >= v->max_speed && |
|
920 |
!(u->vehstatus&VS_STOPPED) && |
|
921 |
u->cur_speed != 0) |
|
922 |
return; |
|
923 |
||
924 |
if (v->direction != u->direction || !(v->direction&1)) |
|
925 |
return; |
|
926 |
||
927 |
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) |
|
928 |
return; |
|
929 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
930 |
tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F); |
0 | 931 |
if ((tt & 3) == 0) |
932 |
return; |
|
933 |
if ((tt & 0x3C) != 0) |
|
934 |
return; |
|
935 |
||
936 |
if (tt == 3) { |
|
937 |
tt = (v->direction&2)?2:1; |
|
938 |
} |
|
939 |
od.tilebits = tt; |
|
940 |
||
941 |
od.tile = v->tile; |
|
942 |
if (FindRoadVehToOvertake(&od)) |
|
943 |
return; |
|
944 |
||
900 | 945 |
od.tile = v->tile + TileOffsByDir(v->direction >> 1); |
0 | 946 |
if (FindRoadVehToOvertake(&od)) |
947 |
return; |
|
948 |
||
949 |
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) { |
|
950 |
v->u.road.overtaking_ctr = 0x11; |
|
951 |
v->u.road.overtaking = 0x10; |
|
952 |
} else { |
|
953 |
// if (FindRoadVehToOvertake(&od)) |
|
954 |
// return; |
|
955 |
v->u.road.overtaking_ctr = 0; |
|
956 |
v->u.road.overtaking = 0x10; |
|
957 |
} |
|
958 |
} |
|
959 |
||
960 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
961 |
{ |
|
962 |
if (old_z == v->z_pos) |
|
963 |
return; |
|
964 |
||
965 |
if (old_z < v->z_pos) { |
|
966 |
v->cur_speed = v->cur_speed * 232 >> 8; |
|
967 |
} else { |
|
968 |
uint16 spd = v->cur_speed + 2; |
|
969 |
if (spd <= v->max_speed) |
|
970 |
v->cur_speed = spd; |
|
971 |
} |
|
972 |
} |
|
973 |
||
974 |
static int PickRandomBit(uint bits) |
|
975 |
{ |
|
976 |
uint num = 0; |
|
977 |
uint b = bits; |
|
978 |
uint i; |
|
979 |
||
980 |
do { |
|
981 |
if (b & 1) |
|
982 |
num++; |
|
983 |
} while (b >>= 1); |
|
984 |
||
985 |
num = ((uint16)Random() * num >> 16); |
|
986 |
||
987 |
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++); |
|
988 |
return i; |
|
989 |
} |
|
990 |
||
991 |
typedef struct { |
|
992 |
TileIndex dest; |
|
993 |
uint maxtracklen; |
|
994 |
uint mindist; |
|
995 |
} FindRoadToChooseData; |
|
996 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
997 |
static bool EnumRoadTrackFindDist(TileIndex tile, FindRoadToChooseData *frd, int track, uint length, byte *state) |
0 | 998 |
{ |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
999 |
uint dist = DistanceManhattan(tile, frd->dest); |
0 | 1000 |
if (dist <= frd->mindist) { |
1001 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
1002 |
frd->maxtracklen = length; |
|
1003 |
} |
|
1004 |
frd->mindist = dist; |
|
1005 |
} |
|
1006 |
return false; |
|
1007 |
} |
|
1008 |
||
1009 |
// Returns direction to choose |
|
1010 |
// or -1 if the direction is currently blocked |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1011 |
static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir) |
0 | 1012 |
{ |
1013 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
1014 |
||
1015 |
uint16 signal; |
|
1016 |
uint bitmask; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1017 |
TileIndex desttile; |
0 | 1018 |
FindRoadToChooseData frd; |
1019 |
int best_track; |
|
1020 |
uint best_dist, best_maxlen; |
|
1021 |
uint i; |
|
1022 |
byte m5; |
|
1023 |
||
1024 |
{ |
|
1025 |
uint32 r; |
|
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1026 |
r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 1027 |
signal = (uint16)(r >> 16); |
1028 |
bitmask = (uint16)r; |
|
1029 |
} |
|
1030 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1031 |
if (IsTileType(tile, MP_STREET)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1032 |
if ((_m[tile].m5&0xF0) == 0x20 && IsTileOwner(tile, v->owner)) |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1033 |
/* Road crossing */ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1034 |
bitmask |= _road_veh_fp_ax_or[_m[tile].m5&3]; |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1035 |
} else if (IsTileType(tile, MP_STATION)) { |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1036 |
if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1037 |
/* Our station */ |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1038 |
Station *st = GetStation(_m[tile].m2); |
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1039 |
byte val = _m[tile].m5; |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1040 |
if (v->cargo_type != CT_PASSENGERS) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1041 |
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
|
1042 |
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
|
1043 |
} else { |
1217
59c024cfaf54
(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, 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
|
1045 |
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
|
1046 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1047 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1048 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1049 |
/* 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
|
1050 |
* 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
|
1051 |
* 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
|
1052 |
*/ |
0 | 1053 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1054 |
/* remove unreachable tracks */ |
1247 | 1055 |
bitmask &= _road_veh_fp_ax_and[enterdir]; |
0 | 1056 |
if (bitmask == 0) { |
1247 | 1057 |
/* No reachable tracks, so we'll reverse */ |
1058 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1059 |
} |
1060 |
||
1061 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1062 |
/* What happens here?? */ |
0 | 1063 |
v->u.road.reverse_ctr = 0; |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
1064 |
if (v->tile != tile) { |
1247 | 1065 |
return_track(_road_reverse_table[enterdir]); |
0 | 1066 |
} |
1067 |
} |
|
1068 |
||
1069 |
desttile = v->dest_tile; |
|
1070 |
if (desttile == 0) { |
|
1247 | 1071 |
// Pick a random track |
0 | 1072 |
return_track(PickRandomBit(bitmask)); |
1073 |
} |
|
1074 |
||
1247 | 1075 |
// Only one track to choose between? |
1076 |
if (!(KillFirstBit2x64(bitmask))) { |
|
0 | 1077 |
return_track(FindFirstBit2x64(bitmask)); |
1078 |
} |
|
1079 |
||
1247 | 1080 |
if (_patches.new_pathfinding_all) { |
1081 |
NPFFindStationOrTileData fstd; |
|
1082 |
NPFFoundTargetData ftd; |
|
1083 |
byte trackdir; |
|
1084 |
||
1085 |
NPFFillWithOrderData(&fstd, v); |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1086 |
trackdir = DiagdirToDiagTrackdir(enterdir); |
1247 | 1087 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1088 |
||
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1089 |
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE, PBS_MODE_NONE); |
1698
3f979f9ecf6c
(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
|
1090 |
if (ftd.best_trackdir == 0xff) { |
3f979f9ecf6c
(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
|
1091 |
/* We are already at our target. Just do something */ |
1247 | 1092 |
//TODO: maybe display error? |
1093 |
//TODO: go straight ahead if possible? |
|
1094 |
return_track(FindFirstBit2x64(bitmask)); |
|
1095 |
} else { |
|
1698
3f979f9ecf6c
(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
|
1096 |
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains |
3f979f9ecf6c
(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
|
1097 |
the direction we need to take to get there, if ftd.best_bird_dist is not 0, |
3f979f9ecf6c
(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
|
1098 |
we did not find our target, but ftd.best_trackdir contains the direction leading |
3f979f9ecf6c
(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 |
to the tile closest to our target. */ |
1247 | 1100 |
return_track(ftd.best_trackdir); |
1101 |
} |
|
1102 |
} else { |
|
1103 |
if (IsTileType(desttile, MP_STREET)) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1104 |
m5 = _m[desttile].m5; |
1247 | 1105 |
if ((m5&0xF0) == 0x20) |
1106 |
/* We are heading for a Depot */ |
|
1107 |
goto do_it; |
|
1108 |
} else if (IsTileType(desttile, MP_STATION)) { |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1109 |
m5 = _m[desttile].m5; |
1247 | 1110 |
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
1111 |
/* We are heading for a station */ |
|
1112 |
m5 -= 0x43; |
|
0 | 1113 |
do_it:; |
1247 | 1114 |
/* When we are heading for a depot or station, we just |
1115 |
* pretend we are heading for the tile in front, we'll |
|
1116 |
* see from there */ |
|
1117 |
desttile += TileOffsByDir(m5 & 3); |
|
1118 |
if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) { |
|
1119 |
/* If we are already in front of the |
|
1120 |
* station/depot and we can get in from here, |
|
1121 |
* we enter */ |
|
1122 |
return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3])); |
|
1123 |
} |
|
0 | 1124 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1125 |
} |
1247 | 1126 |
// do pathfind |
1127 |
frd.dest = desttile; |
|
0 | 1128 |
|
1247 | 1129 |
best_track = -1; |
1130 |
best_dist = (uint)-1; |
|
1131 |
best_maxlen = (uint)-1; |
|
1132 |
i = 0; |
|
1133 |
do { |
|
1134 |
if (bitmask & 1) { |
|
1135 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track |
|
1136 |
frd.maxtracklen = (uint)-1; |
|
1137 |
frd.mindist = (uint)-1; |
|
1138 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
|
0 | 1139 |
|
1247 | 1140 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
1141 |
best_dist = frd.mindist; |
|
1142 |
best_maxlen = frd.maxtracklen; |
|
1143 |
best_track = i; |
|
1144 |
} |
|
0 | 1145 |
} |
1247 | 1146 |
} while (++i,(bitmask>>=1) != 0); |
1147 |
} |
|
0 | 1148 |
|
1149 |
found_best_track:; |
|
1150 |
||
1151 |
if (HASBIT(signal, best_track)) |
|
1152 |
return -1; |
|
1153 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1154 |
return best_track; |
0 | 1155 |
} |
1156 |
||
1709
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
1157 |
static uint RoadFindPathToStation(const Vehicle *v, TileIndex tile) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1158 |
{ |
1709
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
1159 |
NPFFindStationOrTileData fstd; |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
1160 |
byte trackdir = GetVehicleTrackdir(v); |
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
1161 |
assert(trackdir != 0xFF); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1162 |
|
1709
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
1163 |
fstd.dest_coords = tile; |
4407b7f5f607
(svn r2213) -Fix/Feature/Codechange: [ Multistop ] Changed the algo so that it uses NPF. This fixes the problem of RVs attempting to go to unreachable stops [ 1161610 ], and should greatly reduce the wrong stop problem. Cleaned parts of the code
celestar
parents:
1698
diff
changeset
|
1164 |
fstd.station_index = -1; // indicates that the destination is a tile, not a station |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1165 |
|
2008
cdb444f6d43c
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
2006
diff
changeset
|
1166 |
return NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE, PBS_MODE_NONE).best_path_dist; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1167 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1168 |
|
0 | 1169 |
typedef struct RoadDriveEntry { |
1170 |
byte x,y; |
|
1171 |
} RoadDriveEntry; |
|
1172 |
||
1173 |
#include "table/roadveh.h" |
|
1174 |
||
1175 |
static const byte _road_veh_data_1[] = { |
|
1176 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1177 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1178 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1179 |
15, 15, 11, 11 |
|
1180 |
}; |
|
1181 |
||
1182 |
static const byte _roadveh_data_2[4] = { 0,1,8,9 }; |
|
1183 |
||
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1184 |
static void RoadVehController(Vehicle *v) |
0 | 1185 |
{ |
1186 |
GetNewVehiclePosResult gp; |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1187 |
byte new_dir, old_dir; |
0 | 1188 |
RoadDriveEntry rd; |
1189 |
int x,y; |
|
1190 |
Station *st; |
|
1191 |
uint32 r; |
|
1192 |
Vehicle *u; |
|
1193 |
||
1194 |
// decrease counters |
|
1195 |
v->tick_counter++; |
|
1196 |
if (v->u.road.reverse_ctr != 0) |
|
1197 |
v->u.road.reverse_ctr--; |
|
1198 |
||
1199 |
// handle crashed |
|
1200 |
if (v->u.road.crashed_ctr != 0) { |
|
1201 |
RoadVehIsCrashed(v); |
|
1202 |
return; |
|
1203 |
} |
|
1204 |
||
1205 |
RoadVehCheckTrainCrash(v); |
|
1206 |
||
1207 |
// road vehicle has broken down? |
|
1208 |
if (v->breakdown_ctr != 0) { |
|
1209 |
if (v->breakdown_ctr <= 2) { |
|
1210 |
HandleBrokenRoadVeh(v); |
|
1211 |
return; |
|
1212 |
} |
|
1213 |
v->breakdown_ctr--; |
|
1214 |
} |
|
1215 |
||
1216 |
// exit if vehicle is stopped |
|
1217 |
if (v->vehstatus & VS_STOPPED) |
|
1218 |
return; |
|
1219 |
||
1220 |
ProcessRoadVehOrder(v); |
|
1221 |
HandleRoadVehLoading(v); |
|
1222 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1223 |
if (v->current_order.type == OT_LOADING) |
0 | 1224 |
return; |
1225 |
||
1226 |
if (v->u.road.state == 254) { |
|
1227 |
int dir; |
|
1228 |
const RoadDriveEntry*rdp; |
|
1229 |
byte rd2; |
|
1230 |
||
1231 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1232 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1233 |
dir = _m[v->tile].m5&3; |
0 | 1234 |
v->direction = dir*2+1; |
1235 |
||
1236 |
rd2 = _roadveh_data_2[dir]; |
|
1237 |
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
|
1238 |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1239 |
x = TileX(v->tile) * 16 + (rdp[6].x & 0xF); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1240 |
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF); |
0 | 1241 |
|
1242 |
if (RoadVehFindCloseTo(v,x,y,v->direction)) |
|
1243 |
return; |
|
1244 |
||
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1245 |
VehicleServiceInDepot(v); |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1246 |
|
0 | 1247 |
StartRoadVehSound(v); |
1248 |
||
1249 |
BeginVehicleMove(v); |
|
1250 |
||
1251 |
v->vehstatus &= ~VS_HIDDEN; |
|
1252 |
v->u.road.state = rd2; |
|
1253 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1254 |
|
0 | 1255 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1256 |
UpdateRoadVehDeltaXY(v); |
|
1257 |
SetRoadVehPosition(v,x,y); |
|
1258 |
||
1259 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1260 |
return; |
|
1261 |
} |
|
1262 |
||
1263 |
if (!RoadVehAccelerate(v)) |
|
1264 |
return; |
|
1265 |
||
1266 |
if (v->u.road.overtaking != 0) { |
|
1267 |
if (++v->u.road.overtaking_ctr >= 35) |
|
1268 |
v->u.road.overtaking = 0; |
|
1269 |
} |
|
1270 |
||
1271 |
BeginVehicleMove(v); |
|
1272 |
||
1273 |
if (v->u.road.state == 255) { |
|
1274 |
GetNewVehiclePos(v, &gp); |
|
1275 |
||
1276 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction)) { |
|
1277 |
v->cur_speed = 0; |
|
1278 |
return; |
|
1279 |
} |
|
1280 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1281 |
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1282 |
(_m[gp.new_tile].m5&0xF0) == 0 && |
0 | 1283 |
(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
|
1284 |
|
0 | 1285 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1286 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1287 |
UpdateRoadVehDeltaXY(v); |
|
1288 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1289 |
return; |
|
1290 |
} |
|
1291 |
||
1292 |
v->x_pos = gp.x; |
|
1293 |
v->y_pos = gp.y; |
|
1294 |
VehiclePositionChanged(v); |
|
1295 |
return; |
|
1296 |
} |
|
1297 |
||
1298 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1]; |
|
1299 |
||
1300 |
// switch to another tile |
|
1301 |
if (rd.x & 0x80) { |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1302 |
TileIndex tile = v->tile + TileOffsByDir(rd.x & 3); |
0 | 1303 |
int dir = RoadFindPathToDest(v, tile, rd.x&3); |
1304 |
int tmp; |
|
1305 |
uint32 r; |
|
1306 |
byte newdir; |
|
1307 |
const RoadDriveEntry *rdp; |
|
1308 |
||
1309 |
if (dir == -1) { |
|
1310 |
v->cur_speed = 0; |
|
1311 |
return; |
|
1312 |
} |
|
1313 |
||
1314 |
again: |
|
1315 |
if ((dir & 7) >= 6) { |
|
1247 | 1316 |
/* Turning around */ |
0 | 1317 |
tile = v->tile; |
1318 |
} |
|
1319 |
||
1320 |
tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking; |
|
1321 |
rdp = _road_drive_data[tmp]; |
|
1322 |
||
1323 |
tmp &= ~0x10; |
|
1324 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1325 |
x = TileX(tile) * 16 + rdp[0].x; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1326 |
y = TileY(tile) * 16 + rdp[0].y; |
0 | 1327 |
|
1328 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1329 |
return; |
|
1330 |
||
1331 |
r = VehicleEnterTile(v, tile, x, y); |
|
1332 |
if (r & 8) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1333 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1334 |
v->cur_speed = 0; |
1335 |
return; |
|
1336 |
} |
|
1337 |
dir = _road_reverse_table[rd.x&3]; |
|
1338 |
goto again; |
|
1339 |
} |
|
1340 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1341 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
0 | 1342 |
if ((tmp&7) >= 6) { v->cur_speed = 0; return; } |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1343 |
if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1344 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1345 |
byte *b = &rs->status; |
0 | 1346 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1347 |
//we have reached a loading bay, mark it as used |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1348 |
//and clear the usage bit (0x80) of the stop |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1349 |
*b = (*b | ((v->u.road.state&2)?2:1)) & ~0x80; |
0 | 1350 |
} |
1351 |
} |
|
1352 |
||
1353 |
if (!(r & 4)) { |
|
1354 |
v->tile = tile; |
|
1355 |
v->u.road.state = (byte)tmp; |
|
1356 |
v->u.road.frame = 0; |
|
1357 |
} |
|
1358 |
if (newdir != v->direction) { |
|
1359 |
v->direction = newdir; |
|
1360 |
v->cur_speed -= v->cur_speed >> 2; |
|
1361 |
} |
|
1362 |
||
1363 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1364 |
UpdateRoadVehDeltaXY(v); |
|
1365 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1366 |
return; |
|
1367 |
} |
|
1368 |
||
1369 |
if (rd.x & 0x40) { |
|
1370 |
int dir = RoadFindPathToDest(v, v->tile, rd.x&3); |
|
1371 |
uint32 r; |
|
1372 |
int tmp; |
|
1373 |
byte newdir; |
|
1374 |
const RoadDriveEntry *rdp; |
|
1375 |
||
1376 |
if (dir == -1) { |
|
1377 |
v->cur_speed = 0; |
|
1378 |
return; |
|
1379 |
} |
|
1380 |
||
1381 |
tmp = (_opt.road_side<<4) + dir; |
|
1382 |
rdp = _road_drive_data[tmp]; |
|
1383 |
||
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1384 |
x = TileX(v->tile) * 16 + rdp[1].x; |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1385 |
y = TileY(v->tile) * 16 + rdp[1].y; |
0 | 1386 |
|
1387 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1388 |
return; |
|
1389 |
||
1390 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1391 |
if (r & 8) { |
|
1392 |
v->cur_speed = 0; |
|
1393 |
return; |
|
1394 |
} |
|
1395 |
||
1396 |
v->u.road.state = tmp & ~16; |
|
1397 |
v->u.road.frame = 1; |
|
1398 |
||
1399 |
if (newdir != v->direction) { |
|
1400 |
v->direction = newdir; |
|
1401 |
v->cur_speed -= v->cur_speed >> 2; |
|
1402 |
} |
|
1403 |
||
1404 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1405 |
UpdateRoadVehDeltaXY(v); |
|
1406 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1407 |
return; |
|
1408 |
} |
|
1409 |
||
1410 |
x = (v->x_pos&~15)+(rd.x&15); |
|
1411 |
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
|
1412 |
|
0 | 1413 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1414 |
||
1415 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) { |
|
1416 |
if (v->u.road.overtaking == 0) |
|
1417 |
RoadVehCheckOvertake(v, u); |
|
1418 |
return; |
|
1419 |
} |
|
1420 |
||
1421 |
old_dir = v->direction; |
|
1422 |
if (new_dir != old_dir) { |
|
1423 |
v->direction = new_dir; |
|
1424 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1425 |
if (old_dir != v->u.road.state) { |
|
1426 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1427 |
UpdateRoadVehDeltaXY(v); |
|
1428 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1429 |
return; |
|
1430 |
} |
|
1431 |
} |
|
1432 |
||
1433 |
if (v->u.road.state >= 0x20 && |
|
1434 |
_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1435 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1436 |
byte *b = &rs->status; |
0 | 1437 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1438 |
st = GetStation(_m[v->tile].m2); |
0 | 1439 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1440 |
if (v->current_order.type != OT_LEAVESTATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1441 |
v->current_order.type != OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1442 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1443 |
|
0 | 1444 |
*b &= ~0x80; |
1445 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2008
diff
changeset
|
1446 |
v->last_station_visited = _m[v->tile].m2; |
0 | 1447 |
|
1448 |
RoadVehArrivesAt(v, st); |
|
1449 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1450 |
old_order = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1451 |
v->current_order.type = OT_LOADING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1452 |
v->current_order.flags = 0; |
0 | 1453 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1454 |
if (old_order.type == OT_GOTO_STATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1455 |
v->current_order.station == v->last_station_visited) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1456 |
v->current_order.flags = |
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1927
diff
changeset
|
1457 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP; |
0 | 1458 |
} |
1459 |
||
1460 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
1461 |
if (LoadUnloadVehicle(v)) { |
|
1462 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1463 |
MarkRoadVehDirty(v); |
|
1464 |
} |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1465 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1466 |
return; |
1467 |
} |
|
1468 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1469 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
0 | 1470 |
if (*b&0x80) { |
1471 |
v->cur_speed = 0; |
|
1472 |
return; |
|
1473 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1474 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1475 |
v->current_order.flags = 0; |
0 | 1476 |
} |
1477 |
*b |= 0x80; |
|
1478 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1479 |
if (rs == v->u.road.slot) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1480 |
//we have arrived at the correct station |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1481 |
ClearSlot(v, rs); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1482 |
} else if (v->u.road.slot != NULL) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1483 |
//we have arrived at the wrong station |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1484 |
//XXX The question is .. what to do? Actually we shouldn't be here |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1485 |
//but I guess we need to clear the slot |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1486 |
DEBUG(ms, 1) ("Multistop: Wrong station, force a slot clearing. Vehicle %d at 0x%x, should go to 0x%x of station %d (%x), destination 0x%x", v->unitnumber, v->tile, v->u.road.slot->xy, st->index, st->xy, v->dest_tile); |
1239
133586622b78
(svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents:
1237
diff
changeset
|
1487 |
ClearSlot(v, v->u.road.slot); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1488 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1489 |
|
0 | 1490 |
StartRoadVehSound(v); |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1491 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1492 |
} |
1493 |
||
1494 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1495 |
if (r & 8) { |
|
1496 |
v->cur_speed = 0; |
|
1497 |
return; |
|
1498 |
} |
|
1499 |
||
1500 |
if ((r & 4) == 0) { |
|
1501 |
v->u.road.frame++; |
|
1502 |
} |
|
1503 |
||
1504 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1505 |
UpdateRoadVehDeltaXY(v); |
|
1506 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1507 |
} |
|
1508 |
||
1509 |
void RoadVehEnterDepot(Vehicle *v) |
|
1510 |
{ |
|
1511 |
v->u.road.state = 254; |
|
1512 |
v->vehstatus |= VS_HIDDEN; |
|
1513 |
||
1514 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1515 |
||
842 | 1516 |
MaybeReplaceVehicle(v); |
0 | 1517 |
|
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1518 |
VehicleServiceInDepot(v); |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1519 |
|
445
beafc0fb8f12
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
378
diff
changeset
|
1520 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1521 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1522 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1523 |
Order t; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1524 |
|
0 | 1525 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1526 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1527 |
t = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1528 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1529 |
v->current_order.flags = 0; |
0 | 1530 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1531 |
// Part of the orderlist? |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1532 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1533 |
v->cur_order_index++; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1534 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { |
0 | 1535 |
v->vehstatus |= VS_STOPPED; |
1536 |
if (v->owner == _local_player) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1537 |
SetDParam(0, v->unitnumber); |
0 | 1538 |
AddNewsItem( |
1539 |
STR_9016_ROAD_VEHICLE_IS_WAITING, |
|
1540 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1541 |
v->index, |
|
1542 |
0); |
|
1543 |
} |
|
1544 |
} |
|
1545 |
} |
|
1546 |
||
1547 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
1548 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1549 |
} |
1550 |
||
1551 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1552 |
{ |
|
1553 |
if (_age_cargo_skip_counter != 0) |
|
1554 |
return; |
|
1555 |
if (v->cargo_days != 255) |
|
1556 |
v->cargo_days++; |
|
1557 |
} |
|
1558 |
||
1559 |
void RoadVeh_Tick(Vehicle *v) |
|
1560 |
{ |
|
1561 |
AgeRoadVehCargo(v); |
|
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1562 |
RoadVehController(v); |
0 | 1563 |
} |
1564 |
||
1565 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1566 |
{ |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1567 |
Depot *depot; |
0 | 1568 |
|
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1569 |
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
|
1570 |
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
|
1571 |
|
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1572 |
if (!VehicleNeedsService(v)) |
0 | 1573 |
return; |
1574 |
||
1575 |
if (v->vehstatus & VS_STOPPED) |
|
1576 |
return; |
|
1577 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1578 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) |
0 | 1579 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1580 |
|
0 | 1581 |
// Don't interfere with a depot visit scheduled by the user, or a |
1582 |
// depot visit by the order list. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1583 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1584 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 1585 |
return; |
1586 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1587 |
//If we already got a slot at a stop, use that FIRST, and go to a depot later |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1588 |
if (v->u.road.slot != NULL) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1589 |
return; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1590 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1591 |
depot = FindClosestRoadDepot(v); |
0 | 1592 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1593 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1594 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1595 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1596 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1597 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1598 |
} |
1599 |
return; |
|
1600 |
} |
|
1601 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1602 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1603 |
v->current_order.flags & OF_NON_STOP && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1604 |
!CHANCE16(1,20)) |
0 | 1605 |
return; |
1606 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1607 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1608 |
v->current_order.flags = OF_NON_STOP; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1609 |
v->current_order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1610 |
v->dest_tile = depot->xy; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1611 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1612 |
} |
1613 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1614 |
int dist_compare(const void *a, const void *b) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1615 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1616 |
return ( *(const uint32 *)a) - ( *(const uint32 *) b); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1617 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1618 |
|
0 | 1619 |
void OnNewDay_RoadVeh(Vehicle *v) |
1620 |
{ |
|
1621 |
int32 cost; |
|
1622 |
Station *st; |
|
1623 |
||
1624 |
if ((++v->day_counter & 7) == 0) |
|
1625 |
DecreaseVehicleValue(v); |
|
1626 |
||
1627 |
if (v->u.road.unk2 == 0) |
|
1628 |
CheckVehicleBreakdown(v); |
|
1629 |
||
1630 |
AgeVehicle(v); |
|
1631 |
CheckIfRoadVehNeedsService(v); |
|
1632 |
||
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1035
diff
changeset
|
1633 |
CheckOrders(v->index, OC_INIT); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1634 |
|
0 | 1635 |
/* update destination */ |
1769
8d9f801f1731
(svn r2273) -Fix: Road vehicles no longer try to obtain a slot when they have crashed. (peter1138)
celestar
parents:
1758
diff
changeset
|
1636 |
if (v->current_order.type == OT_GOTO_STATION && !(v->vehstatus & VS_CRASHED)) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1637 |
int num; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1638 |
RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1639 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1640 |
st = GetStation(v->current_order.station); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1641 |
num = GetNumRoadStops(st, type); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1642 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1643 |
//Current slot has expired |
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1644 |
if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL)) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1645 |
ClearSlot(v, v->u.road.slot); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1646 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1647 |
//We do not have a slot, so make one |
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1648 |
if (v->u.road.slot == NULL) { |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1649 |
RoadStop *rs = GetPrimaryRoadStop(st, type); |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1650 |
RoadStop *first_stop = rs; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1651 |
RoadStop *best_stop = NULL; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1652 |
uint32 mindist = 120, dist; // 120 is threshold distance. |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1653 |
|
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1654 |
//first we need to find out how far our stations are away. |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1655 |
DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy); |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1656 |
for(; rs != NULL; rs = rs->next) { |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1657 |
// Only consider those with at least a free slot. |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1658 |
if (!(rs->slot[0] == INVALID_SLOT || rs->slot[1] == INVALID_SLOT)) |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1659 |
continue; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1660 |
|
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1661 |
// Previously the NPF pathfinder was used here even if NPF is OFF.. WTF? |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1662 |
assert(NUM_SLOTS == 2); |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1663 |
dist = DistanceManhattan(v->tile, rs->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1664 |
|
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1665 |
// Remember the one with the shortest distance |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1666 |
if (dist < mindist) { |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1667 |
mindist = dist; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1668 |
best_stop = rs; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1669 |
} |
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1670 |
DEBUG(ms, 3) ("Multistop: Distance to stop at 0x%x is %d", rs->xy, dist); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1671 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1672 |
|
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1673 |
// best_stop now contains the best stop we found. |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1674 |
if (best_stop) { |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1675 |
int slot; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1676 |
// Find a free slot in this stop. We know that at least one is free. |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1677 |
assert(best_stop->slot[0] == INVALID_SLOT || best_stop->slot[1] == INVALID_SLOT); |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1678 |
slot = (best_stop->slot[0] == INVALID_SLOT) ? 0 : 1; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1679 |
best_stop->slot[slot] = v->index; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1680 |
v->u.road.slot = best_stop; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1681 |
v->dest_tile = best_stop->xy; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1682 |
v->u.road.slot_age = -30; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1683 |
v->u.road.slotindex = slot; |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1684 |
DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d", slot, best_stop->xy, v->unitnumber); |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1685 |
} else if (first_stop) { |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1686 |
//now we couldn't assign a slot for one reason or another. |
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1687 |
//so we just go towards the first station |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1688 |
DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber); |
2089
32846ac9e841
(svn r2599) Fix: Road vehicle multistop handling used NPF even if NPF was off????
ludde
parents:
2049
diff
changeset
|
1689 |
v->dest_tile = first_stop->xy; |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1690 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1691 |
} |
0 | 1692 |
} |
1693 |
||
1694 |
if (v->vehstatus & VS_STOPPED) |
|
1695 |
return; |
|
1696 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1697 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1698 |
|
1699 |
v->profit_this_year -= cost >> 8; |
|
1700 |
||
1701 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1702 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1703 |
||
1704 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
1705 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1706 |
} |
1707 |
||
1708 |
void HandleClickOnRoadVeh(Vehicle *v) |
|
1709 |
{ |
|
1710 |
ShowRoadVehViewWindow(v); |
|
1711 |
} |
|
1712 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1053
diff
changeset
|
1713 |
void RoadVehiclesYearlyLoop(void) |
0 | 1714 |
{ |
1715 |
Vehicle *v; |
|
1716 |
||
1717 |
FOR_ALL_VEHICLES(v) { |
|
1718 |
if (v->type == VEH_Road) { |
|
1719 |
v->profit_last_year = v->profit_this_year; |
|
1720 |
v->profit_this_year = 0; |
|
1721 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1722 |
} |
|
1723 |
} |
|
1724 |
} |