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