author | Darkvater |
Fri, 31 Mar 2006 21:22:41 +0000 | |
changeset 3408 | 313f35564673 |
parent 3404 | 3ac4f7fedfb5 |
child 3421 | 8ab76c47c72c |
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" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3140
diff
changeset
|
7 |
#include "road_map.h" |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
8 |
#include "station_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
9 |
#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
|
10 |
#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
|
11 |
#include "tile.h" |
0 | 12 |
#include "vehicle.h" |
13 |
#include "engine.h" |
|
14 |
#include "command.h" |
|
15 |
#include "station.h" |
|
16 |
#include "news.h" |
|
17 |
#include "pathfind.h" |
|
1247 | 18 |
#include "npf.h" |
0 | 19 |
#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
|
20 |
#include "sound.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
21 |
#include "depot.h" |
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3169
diff
changeset
|
22 |
#include "tunnel_map.h" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
23 |
#include "vehicle_gui.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2954
diff
changeset
|
24 |
#include "newgrf_engine.h" |
0 | 25 |
|
26 |
static const uint16 _roadveh_images[63] = { |
|
27 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
28 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
29 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
30 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
31 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
32 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
33 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
34 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
35 |
}; |
|
36 |
||
37 |
static const uint16 _roadveh_full_adder[63] = { |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
38 |
0, 88, 0, 0, 0, 0, 48, 48, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
39 |
48, 48, 0, 0, 64, 64, 0, 16, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
40 |
16, 0, 88, 0, 0, 0, 0, 48, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
41 |
48, 48, 48, 0, 0, 64, 64, 0, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
42 |
16, 16, 0, 88, 0, 0, 0, 0, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
43 |
48, 48, 48, 48, 0, 0, 64, 64, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
44 |
0, 16, 16, 0, 8, 8, 8, 8, |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
45 |
0, 0, 0, 8, 8, 8, 8 |
0 | 46 |
}; |
47 |
||
48 |
||
49 |
static const uint16 _road_veh_fp_ax_or[4] = { |
|
50 |
0x100,0x200,1,2, |
|
51 |
}; |
|
52 |
||
53 |
static const uint16 _road_veh_fp_ax_and[4] = { |
|
54 |
0x1009, 0x16, 0x520, 0x2A00 |
|
55 |
}; |
|
56 |
||
57 |
static const byte _road_reverse_table[4] = { |
|
58 |
6, 7, 14, 15 |
|
59 |
}; |
|
60 |
||
61 |
static const uint16 _road_pf_table_3[4] = { |
|
62 |
0x910, 0x1600, 0x2005, 0x2A |
|
63 |
}; |
|
64 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
65 |
int GetRoadVehImage(const Vehicle* v, Direction direction) |
0 | 66 |
{ |
67 |
int img = v->spritenum; |
|
68 |
int image; |
|
69 |
||
70 |
if (is_custom_sprite(img)) { |
|
71 |
image = GetCustomVehicleSprite(v, direction); |
|
2989 | 72 |
if (image != 0) return image; |
2464
3dee59d241c0
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2260
diff
changeset
|
73 |
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index; |
0 | 74 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
75 |
|
0 | 76 |
image = direction + _roadveh_images[img]; |
2989 | 77 |
if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img]; |
0 | 78 |
return image; |
79 |
} |
|
80 |
||
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2464
diff
changeset
|
81 |
void DrawRoadVehEngine(int x, int y, EngineID engine, uint32 image_ormod) |
0 | 82 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
83 |
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
|
84 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
85 |
if (is_custom_sprite(spritenum)) { |
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
86 |
int sprite = GetCustomVehicleIcon(engine, DIR_W); |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
87 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
88 |
if (sprite != 0) { |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
89 |
DrawSprite(sprite | image_ormod, x, y); |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
90 |
return; |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
91 |
} |
2464
3dee59d241c0
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2260
diff
changeset
|
92 |
spritenum = orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index; |
378
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
93 |
} |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
94 |
DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y); |
0 | 95 |
} |
96 |
||
2817 | 97 |
static int32 EstimateRoadVehCost(EngineID engine_type) |
0 | 98 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
99 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 100 |
} |
101 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
102 |
/** Build a road vehicle. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
103 |
* @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
|
104 |
* @param p1 bus/truck type being built (engine) |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
105 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
106 |
*/ |
0 | 107 |
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
108 |
{ |
|
109 |
int32 cost; |
|
110 |
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
|
111 |
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
|
112 |
TileIndex tile = TileVirtXY(x, y); |
0 | 113 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
114 |
|
2854
6b85a5f4b65f
(svn r3402) -Fix: [building/cloning] added a string telling if build failed due to not being able to build a vehicle. Triggered when cloning a retired design
bjarni
parents:
2823
diff
changeset
|
115 |
if (!IsEngineBuildable(p1, VEH_Road)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE); |
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
|
116 |
|
0 | 117 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
118 |
||
119 |
cost = EstimateRoadVehCost(p1); |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
120 |
if (flags & DC_QUERY_COST) return cost; |
0 | 121 |
|
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
|
122 |
/* 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
|
123 |
* 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
|
124 |
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
|
125 |
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
|
126 |
|
0 | 127 |
v = AllocateVehicle(); |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
128 |
if (v == NULL || IsOrderPoolFull()) |
0 | 129 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
130 |
||
131 |
/* find the first free roadveh id */ |
|
132 |
unit_num = GetFreeUnitNumber(VEH_Road); |
|
133 |
if (unit_num > _patches.max_roadveh) |
|
134 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
135 |
||
136 |
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
|
137 |
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
|
138 |
|
0 | 139 |
v->unitnumber = unit_num; |
140 |
v->direction = 0; |
|
141 |
v->owner = _current_player; |
|
142 |
||
143 |
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
|
144 |
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
|
145 |
y = TileY(tile) * 16 + 8; |
0 | 146 |
v->x_pos = x; |
147 |
v->y_pos = y; |
|
148 |
v->z_pos = GetSlopeZ(x,y); |
|
149 |
v->z_height = 6; |
|
150 |
||
151 |
v->u.road.state = 254; |
|
152 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
153 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
v->cargo_cap = rvi->capacity; |
0 | 157 |
// v->cargo_count = 0; |
158 |
v->value = cost; |
|
159 |
// v->day_counter = 0; |
|
160 |
// v->next_order_param = v->next_order = 0; |
|
161 |
// v->load_unload_time_rem = 0; |
|
162 |
// v->progress = 0; |
|
163 |
||
164 |
// v->u.road.unk2 = 0; |
|
165 |
// v->u.road.overtaking = 0; |
|
166 |
||
1217
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.slot = NULL; |
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.slotindex = 0; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
169 |
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
|
170 |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
171 |
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
|
172 |
v->max_speed = rvi->max_speed; |
0 | 173 |
v->engine_type = (byte)p1; |
174 |
||
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
175 |
e = GetEngine(p1); |
0 | 176 |
v->reliability = e->reliability; |
177 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
178 |
v->max_age = e->lifelength * 366; |
|
179 |
_new_roadveh_id = v->index; |
|
2564 | 180 |
_new_vehicle_id = v->index; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
181 |
|
0 | 182 |
v->string_id = STR_SV_ROADVEH_NAME; |
183 |
||
184 |
v->service_interval = _patches.servint_roadveh; |
|
185 |
||
186 |
v->date_of_last_service = _date; |
|
187 |
v->build_year = _cur_year; |
|
188 |
||
189 |
v->type = VEH_Road; |
|
190 |
v->cur_image = 0xC15; |
|
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2767
diff
changeset
|
191 |
v->random_bits = VehicleRandomBits(); |
0 | 192 |
|
193 |
VehiclePositionChanged(v); |
|
194 |
||
195 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 196 |
RebuildVehicleLists(); |
0 | 197 |
InvalidateWindow(WC_COMPANY, v->owner); |
2618
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
198 |
if (IsLocalPlayer()) |
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
199 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
0 | 200 |
} |
201 |
||
202 |
return cost; |
|
203 |
} |
|
204 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
205 |
/** Start/Stop a road vehicle. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
206 |
* @param x,y unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
207 |
* @param p1 road vehicle ID to start/stop |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
208 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
209 |
*/ |
0 | 210 |
int32 CmdStartStopRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
211 |
{ |
|
212 |
Vehicle *v; |
|
213 |
||
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
|
214 |
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
|
215 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
216 |
v = GetVehicle(p1); |
0 | 217 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
218 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 219 |
|
220 |
if (flags & DC_EXEC) { |
|
3139
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
221 |
if (v->vehstatus & VS_STOPPED && v->u.road.state == 254) { |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
222 |
DeleteVehicleNews(p1, STR_9016_ROAD_VEHICLE_IS_WAITING); |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
223 |
} |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
224 |
|
0 | 225 |
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
|
226 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 227 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
228 |
} |
|
229 |
||
230 |
return 0; |
|
231 |
} |
|
232 |
||
3123 | 233 |
void ClearSlot(Vehicle *v) |
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
|
234 |
{ |
3123 | 235 |
RoadStop *rs = v->u.road.slot; |
236 |
if (v->u.road.slot == NULL) return; |
|
237 |
||
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
|
238 |
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
|
239 |
v->u.road.slot_age = 0; |
3123 | 240 |
|
241 |
// check that the slot is indeed assigned to the same vehicle |
|
242 |
assert(rs->slot[v->u.road.slotindex] == v->index); |
|
243 |
rs->slot[v->u.road.slotindex] = INVALID_VEHICLE; |
|
244 |
DEBUG(ms, 3) ("Multistop: Clearing slot %d at 0x%x", v->u.road.slotindex, rs->xy); |
|
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
|
245 |
} |
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
|
246 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
247 |
/** Sell a road vehicle. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
248 |
* @param x,y unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
249 |
* @param p1 vehicle ID to be sold |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
250 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
251 |
*/ |
0 | 252 |
int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
253 |
{ |
|
254 |
Vehicle *v; |
|
255 |
||
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
|
256 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
257 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
258 |
v = GetVehicle(p1); |
0 | 259 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
260 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 261 |
|
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
|
262 |
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
|
263 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
264 |
if (!IsTileDepotType(v->tile, TRANSPORT_ROAD) || |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
265 |
v->u.road.state != 254 || |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
266 |
!(v->vehstatus & VS_STOPPED)) { |
0 | 267 |
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
268 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
269 |
|
0 | 270 |
if (flags & DC_EXEC) { |
271 |
// Invalidate depot |
|
272 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 273 |
RebuildVehicleLists(); |
0 | 274 |
InvalidateWindow(WC_COMPANY, v->owner); |
275 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
3123 | 276 |
ClearSlot(v); |
0 | 277 |
DeleteVehicle(v); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
278 |
if (IsLocalPlayer()) InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); |
0 | 279 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
280 |
|
0 | 281 |
return -(int32)v->value; |
282 |
} |
|
283 |
||
284 |
typedef struct RoadFindDepotData { |
|
285 |
uint best_length; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
286 |
TileIndex tile; |
0 | 287 |
byte owner; |
288 |
} RoadFindDepotData; |
|
289 |
||
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
290 |
static const DiagDirection _road_pf_directions[] = { |
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
291 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, 255, 255, |
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
292 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, 255, 255 |
0 | 293 |
}; |
294 |
||
3137 | 295 |
static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, int track, uint length, byte* state) |
0 | 296 |
{ |
3137 | 297 |
RoadFindDepotData* rfdd = data; |
298 |
||
904
bff808a1c7f0
(svn r1390) Use TileOffsByDir() instead of home brewed table
tron
parents:
900
diff
changeset
|
299 |
tile += TileOffsByDir(_road_pf_directions[track]); |
0 | 300 |
|
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
|
301 |
if (IsTileType(tile, MP_STREET) && |
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3054
diff
changeset
|
302 |
GetRoadType(tile) == ROAD_DEPOT && |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
303 |
IsTileOwner(tile, rfdd->owner) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
304 |
length < rfdd->best_length) { |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
305 |
rfdd->best_length = length; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
306 |
rfdd->tile = tile; |
0 | 307 |
} |
308 |
return false; |
|
309 |
} |
|
310 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
311 |
static const Depot* FindClosestRoadDepot(const Vehicle* v) |
0 | 312 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
313 |
TileIndex tile = v->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
314 |
|
2549 | 315 |
if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v); |
0 | 316 |
|
1247 | 317 |
if (_patches.new_pathfinding_all) { |
318 |
NPFFoundTargetData ftd; |
|
319 |
/* See where we are now */ |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
320 |
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
|
321 |
|
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1998
diff
changeset
|
322 |
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
323 |
if (ftd.best_bird_dist == 0) { |
1247 | 324 |
return GetDepotByTile(ftd.node.tile); /* Target found */ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
325 |
} else { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
326 |
return NULL; /* Target not found */ |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
327 |
} |
1247 | 328 |
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ |
329 |
} else { |
|
330 |
RoadFindDepotData rfdd; |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
331 |
DiagDirection i; |
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
332 |
|
1247 | 333 |
rfdd.owner = v->owner; |
334 |
rfdd.best_length = (uint)-1; |
|
0 | 335 |
|
1247 | 336 |
/* search in all directions */ |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
337 |
for (i = 0; i != 4; i++) { |
3137 | 338 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, EnumRoadSignalFindDepot, NULL, &rfdd); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
339 |
} |
0 | 340 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
341 |
if (rfdd.best_length == (uint)-1) return NULL; |
0 | 342 |
|
1247 | 343 |
return GetDepotByTile(rfdd.tile); |
344 |
} |
|
0 | 345 |
} |
346 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
347 |
/** Send a road vehicle to the depot. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
348 |
* @param x,y unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
349 |
* @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
|
350 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
351 |
*/ |
0 | 352 |
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
353 |
{ |
|
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
|
354 |
Vehicle *v; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
355 |
const Depot *dep; |
0 | 356 |
|
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
|
357 |
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
|
358 |
|
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
359 |
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
|
360 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
361 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 362 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
363 |
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
|
364 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
365 |
/* If the current orders are already goto-depot */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
366 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 367 |
if (flags & DC_EXEC) { |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
368 |
/* 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
|
369 |
* 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
|
370 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
0 | 371 |
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
|
372 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
373 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
374 |
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
|
375 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 376 |
} |
377 |
return 0; |
|
378 |
} |
|
379 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
380 |
dep = FindClosestRoadDepot(v); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
381 |
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
0 | 382 |
|
383 |
if (flags & DC_EXEC) { |
|
3236 | 384 |
ClearSlot(v); |
385 |
v->vehstatus &= ~VS_WAIT_FOR_SLOT; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
v->current_order.station = dep->index; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
389 |
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
|
390 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 391 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
392 |
|
0 | 393 |
return 0; |
394 |
} |
|
395 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
396 |
/** Turn a roadvehicle around. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
397 |
* @param x,y unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
398 |
* @param p1 vehicle ID to turn |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
399 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
400 |
*/ |
0 | 401 |
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
402 |
{ |
|
403 |
Vehicle *v; |
|
404 |
||
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
|
405 |
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
|
406 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
407 |
v = GetVehicle(p1); |
0 | 408 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
409 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 410 |
|
3236 | 411 |
if (v->vehstatus & (VS_HIDDEN | VS_STOPPED | VS_WAIT_FOR_SLOT) || |
0 | 412 |
v->u.road.crashed_ctr != 0 || |
413 |
v->breakdown_ctr != 0 || |
|
414 |
v->u.road.overtaking != 0 || |
|
415 |
v->cur_speed < 5) { |
|
416 |
return CMD_ERROR; |
|
417 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
418 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
419 |
if (flags & DC_EXEC) v->u.road.reverse_ctr = 180; |
0 | 420 |
|
421 |
return 0; |
|
422 |
} |
|
423 |
||
424 |
||
425 |
static void MarkRoadVehDirty(Vehicle *v) |
|
426 |
{ |
|
427 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
428 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
429 |
} |
|
430 |
||
431 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
432 |
{ |
|
433 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
434 |
static const uint32 _delta_xy_table[8] = { |
|
435 |
MKIT(3, 3, -1, -1), |
|
436 |
MKIT(3, 7, -1, -3), |
|
437 |
MKIT(3, 3, -1, -1), |
|
438 |
MKIT(7, 3, -3, -1), |
|
439 |
MKIT(3, 3, -1, -1), |
|
440 |
MKIT(3, 7, -1, -3), |
|
441 |
MKIT(3, 3, -1, -1), |
|
442 |
MKIT(7, 3, -3, -1), |
|
443 |
}; |
|
444 |
#undef MKIT |
|
445 |
uint32 x = _delta_xy_table[v->direction]; |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
446 |
v->x_offs = GB(x, 0, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
447 |
v->y_offs = GB(x, 8, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
448 |
v->sprite_width = GB(x, 16, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
449 |
v->sprite_height = GB(x, 24, 8); |
0 | 450 |
} |
451 |
||
452 |
static void ClearCrashedStation(Vehicle *v) |
|
453 |
{ |
|
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
454 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 455 |
|
456 |
// mark station as not busy |
|
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
457 |
CLRBIT(rs->status, 7); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
458 |
|
0 | 459 |
// free parking bay |
2671
457c6cdbf9e7
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
460 |
SETBIT(rs->status, HASBIT(v->u.road.state, 1) ? 1 : 0); |
0 | 461 |
} |
462 |
||
463 |
static void RoadVehDelete(Vehicle *v) |
|
464 |
{ |
|
465 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
466 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
467 |
|
588 | 468 |
RebuildVehicleLists(); |
0 | 469 |
InvalidateWindow(WC_COMPANY, v->owner); |
470 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
471 |
if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
472 |
|
0 | 473 |
BeginVehicleMove(v); |
474 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
475 |
|
3123 | 476 |
ClearSlot(v); |
0 | 477 |
DeleteVehicle(v); |
478 |
} |
|
479 |
||
480 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
481 |
{ |
|
482 |
byte new_z, old_z; |
|
483 |
||
484 |
// need this hint so it returns the right z coordinate on bridges. |
|
485 |
_get_z_hint = v->z_pos; |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
486 |
v->x_pos = x; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
487 |
v->y_pos = y; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
488 |
new_z = GetSlopeZ(x, y); |
0 | 489 |
_get_z_hint = 0; |
490 |
||
491 |
old_z = v->z_pos; |
|
492 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
493 |
|
0 | 494 |
VehiclePositionChanged(v); |
495 |
EndVehicleMove(v); |
|
496 |
return old_z; |
|
497 |
} |
|
498 |
||
499 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
500 |
{ |
|
3160 | 501 |
static const DirDiff delta[] = { |
502 |
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
503 |
}; |
|
504 |
||
0 | 505 |
uint32 r = Random(); |
3160 | 506 |
|
507 |
v->direction = ChangeDir(v->direction, delta[r & 3]); |
|
0 | 508 |
BeginVehicleMove(v); |
509 |
UpdateRoadVehDeltaXY(v); |
|
510 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
511 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
512 |
} |
|
513 |
||
514 |
static void RoadVehIsCrashed(Vehicle *v) |
|
515 |
{ |
|
516 |
v->u.road.crashed_ctr++; |
|
517 |
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
|
518 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 519 |
} else if (v->u.road.crashed_ctr <= 45) { |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
520 |
if ((v->tick_counter & 7) == 0) RoadVehSetRandomDirection(v); |
0 | 521 |
} else if (v->u.road.crashed_ctr >= 2220) { |
522 |
RoadVehDelete(v); |
|
523 |
} |
|
524 |
} |
|
525 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
526 |
static void* EnumCheckRoadVehCrashTrain(Vehicle* v, void* data) |
0 | 527 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
528 |
const Vehicle* u = data; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
529 |
|
2989 | 530 |
return |
531 |
v->type == VEH_Train && |
|
532 |
myabs(v->z_pos - u->z_pos) <= 6 && |
|
533 |
myabs(v->x_pos - u->x_pos) <= 4 && |
|
534 |
myabs(v->y_pos - u->y_pos) <= 4 ? |
|
535 |
v : NULL; |
|
0 | 536 |
} |
537 |
||
538 |
static void RoadVehCrash(Vehicle *v) |
|
539 |
{ |
|
540 |
uint16 pass; |
|
541 |
||
542 |
v->u.road.crashed_ctr++; |
|
543 |
v->vehstatus |= VS_CRASHED; |
|
3236 | 544 |
ClearSlot(v); |
0 | 545 |
|
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
|
546 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 547 |
|
548 |
pass = 1; |
|
2989 | 549 |
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count; |
0 | 550 |
v->cargo_count = 0; |
2951 | 551 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
552 |
SetDParam(0, pass); |
2260
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
553 |
AddNewsItem( |
3e97367f7cbc
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
554 |
(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
|
555 |
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE, |
0 | 556 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
557 |
v->index, |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
558 |
0 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
559 |
); |
0 | 560 |
|
561 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 562 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 563 |
} |
564 |
||
565 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
566 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
567 |
TileIndex tile; |
0 | 568 |
|
2951 | 569 |
if (v->u.road.state == 255) return; |
0 | 570 |
|
571 |
tile = v->tile; |
|
572 |
||
2951 | 573 |
if (!IsTileType(tile, MP_STREET) || !IsLevelCrossing(tile)) return; |
0 | 574 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
575 |
if (VehicleFromPos(tile, v, EnumCheckRoadVehCrashTrain) != NULL) |
0 | 576 |
RoadVehCrash(v); |
577 |
} |
|
578 |
||
579 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
580 |
{ |
|
581 |
if (v->breakdown_ctr != 1) { |
|
582 |
v->breakdown_ctr = 1; |
|
583 |
v->cur_speed = 0; |
|
584 |
||
585 |
if (v->breakdowns_since_last_service != 255) |
|
586 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
587 |
|
0 | 588 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
589 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
590 |
|
541 | 591 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
592 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
|
0 | 593 |
|
594 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
595 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
2989 | 596 |
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; |
0 | 597 |
} |
598 |
} |
|
599 |
||
2989 | 600 |
if ((v->tick_counter & 1) == 0) { |
601 |
if (--v->breakdown_delay == 0) { |
|
0 | 602 |
v->breakdown_ctr = 0; |
603 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
604 |
} |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
609 |
{ |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
610 |
const Order *order; |
0 | 611 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
612 |
switch (v->current_order.type) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
613 |
case OT_GOTO_DEPOT: |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
614 |
// Let a depot order in the orderlist interrupt. |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
615 |
if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
616 |
if (v->current_order.flags & OF_SERVICE_IF_NEEDED && |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
617 |
!VehicleNeedsService(v)) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
618 |
v->cur_order_index++; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
619 |
} |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
620 |
break; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
621 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
622 |
case OT_LOADING: |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
623 |
case OT_LEAVESTATION: |
0 | 624 |
return; |
625 |
} |
|
626 |
||
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
627 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 628 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
629 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 630 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
631 |
if (order == NULL) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
632 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
633 |
v->current_order.flags = 0; |
0 | 634 |
v->dest_tile = 0; |
3123 | 635 |
ClearSlot(v); |
3236 | 636 |
v->vehstatus &= ~VS_WAIT_FOR_SLOT; |
0 | 637 |
return; |
638 |
} |
|
639 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
640 |
if (order->type == v->current_order.type && |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
641 |
order->flags == v->current_order.flags && |
2951 | 642 |
order->station == v->current_order.station) { |
0 | 643 |
return; |
2951 | 644 |
} |
0 | 645 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
646 |
v->current_order = *order; |
0 | 647 |
v->dest_tile = 0; |
3236 | 648 |
/* We have changed the destination STATION, so resume movement */ |
649 |
v->vehstatus &= ~VS_WAIT_FOR_SLOT; |
|
0 | 650 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
651 |
if (order->type == OT_GOTO_STATION) { |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
652 |
const Station* st = GetStation(order->station); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
653 |
const RoadStop* rs; |
3136
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
654 |
TileIndex dest; |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
655 |
uint mindist; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
656 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
657 |
if (order->station == v->last_station_visited) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
658 |
v->last_station_visited = INVALID_STATION; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
659 |
} |
1231
64cc1f5c1c82
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
660 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
661 |
rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
662 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
663 |
if (rs == NULL) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
664 |
// There is no stop left at the station, so don't even TRY to go there |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
665 |
v->cur_order_index++; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
666 |
InvalidateVehicleOrder(v); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
667 |
return; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
668 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
669 |
|
3136
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
670 |
dest = rs->xy; |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
671 |
mindist = DistanceManhattan(v->tile, rs->xy); |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
672 |
for (rs = rs->next; rs != NULL; rs = rs->next) { |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
673 |
uint dist = DistanceManhattan(v->tile, rs->xy); |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
674 |
|
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
675 |
if (dist < mindist) { |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
676 |
mindist = dist; |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
677 |
dest = rs->xy; |
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
678 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
679 |
} |
3136
e2682061ef1d
(svn r3751) -Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list
tron
parents:
3135
diff
changeset
|
680 |
v->dest_tile = dest; |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
681 |
} else if (order->type == OT_GOTO_DEPOT) { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
682 |
v->dest_tile = GetDepot(order->station)->xy; |
0 | 683 |
} |
684 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
685 |
InvalidateVehicleOrder(v); |
0 | 686 |
} |
687 |
||
688 |
static void HandleRoadVehLoading(Vehicle *v) |
|
689 |
{ |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
690 |
switch (v->current_order.type) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
691 |
case OT_LOADING: { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
692 |
Order b; |
0 | 693 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
694 |
if (--v->load_unload_time_rem != 0) return; |
0 | 695 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
696 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
697 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
698 |
if (LoadUnloadVehicle(v)) { |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
699 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
700 |
MarkRoadVehDirty(v); |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
701 |
} |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
702 |
return; |
0 | 703 |
} |
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
704 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
705 |
b = v->current_order; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
706 |
v->current_order.type = OT_LEAVESTATION; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
707 |
v->current_order.flags = 0; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
708 |
if (!(b.flags & OF_NON_STOP)) return; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
709 |
break; |
0 | 710 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
711 |
|
3004
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
712 |
case OT_DUMMY: break; |
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
713 |
|
32d777e2353c
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
714 |
default: return; |
0 | 715 |
} |
716 |
||
717 |
v->cur_order_index++; |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
718 |
InvalidateVehicleOrder(v); |
0 | 719 |
} |
720 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
721 |
static void StartRoadVehSound(const Vehicle* v) |
0 | 722 |
{ |
541 | 723 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
724 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
|
725 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
|
0 | 726 |
SndPlayVehicleFx(s, v); |
727 |
} |
|
728 |
||
729 |
typedef struct RoadVehFindData { |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
730 |
int x; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
731 |
int y; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
732 |
const Vehicle* veh; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
733 |
Direction dir; |
0 | 734 |
} RoadVehFindData; |
735 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
736 |
static void* EnumCheckRoadVehClose(Vehicle *v, void* data) |
0 | 737 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
738 |
static const int8 dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 }; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
739 |
static const int8 dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 }; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
740 |
|
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
741 |
const RoadVehFindData* rvf = data; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
742 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
743 |
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
|
744 |
short y_diff = v->y_pos - rvf->y; |
0 | 745 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
746 |
return |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
747 |
rvf->veh != v && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
748 |
v->type == VEH_Road && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
749 |
v->u.road.state != 254 && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
750 |
myabs(v->z_pos - rvf->veh->z_pos) < 6 && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
751 |
v->direction == rvf->dir && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
752 |
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
753 |
(dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
754 |
(dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
755 |
(dist_y[v->direction] <= 0 || (y_diff < dist_y[v->direction] && y_diff >= 0)) ? |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
756 |
v : NULL; |
0 | 757 |
} |
758 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
759 |
static Vehicle* RoadVehFindCloseTo(Vehicle* v, int x, int y, Direction dir) |
0 | 760 |
{ |
761 |
RoadVehFindData rvf; |
|
762 |
Vehicle *u; |
|
763 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
764 |
if (v->u.road.reverse_ctr != 0) return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
765 |
|
0 | 766 |
rvf.x = x; |
767 |
rvf.y = y; |
|
768 |
rvf.dir = dir; |
|
769 |
rvf.veh = v; |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
770 |
u = VehicleFromPos(TileVirtXY(x, y), &rvf, EnumCheckRoadVehClose); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
771 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
772 |
// This code protects a roadvehicle from being blocked for ever |
826 | 773 |
// 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
|
774 |
// 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
|
775 |
// It can be disabled. |
0 | 776 |
if (u == NULL) { |
3009
c477ab0f00b3
(svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents:
3004
diff
changeset
|
777 |
v->u.road.blocked_ctr = 0; |
0 | 778 |
return NULL; |
779 |
} |
|
780 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
781 |
if (++v->u.road.blocked_ctr > 1480) return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
782 |
|
0 | 783 |
return u; |
784 |
} |
|
785 |
||
2630 | 786 |
static void RoadVehArrivesAt(const Vehicle* v, Station* st) |
0 | 787 |
{ |
2550
5e405f5b2836
(svn r3079) Determine the type of the "first arrival" message for road vehicles using the cargo type and not a magic engine number
tron
parents:
2549
diff
changeset
|
788 |
if (v->cargo_type == CT_PASSENGERS) { |
0 | 789 |
/* Check if station was ever visited before */ |
790 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
791 |
uint32 flags; |
|
792 |
||
793 |
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
|
794 |
SetDParam(0, st->index); |
0 | 795 |
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); |
796 |
AddNewsItem( |
|
797 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
798 |
flags, |
|
799 |
v->index, |
|
800 |
0); |
|
801 |
} |
|
802 |
} else { |
|
803 |
/* Check if station was ever visited before */ |
|
804 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
805 |
uint32 flags; |
|
806 |
||
807 |
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
|
808 |
SetDParam(0, st->index); |
0 | 809 |
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); |
810 |
AddNewsItem( |
|
811 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
812 |
flags, |
|
813 |
v->index, |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
814 |
0 |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
815 |
); |
0 | 816 |
} |
817 |
} |
|
818 |
} |
|
819 |
||
820 |
static bool RoadVehAccelerate(Vehicle *v) |
|
821 |
{ |
|
2951 | 822 |
uint spd = v->cur_speed + 1 + (v->u.road.overtaking != 0 ? 1 : 0); |
0 | 823 |
byte t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
824 |
|
0 | 825 |
// Clamp |
826 |
spd = min(spd, v->max_speed); |
|
827 |
||
828 |
//updates statusbar only if speed have changed to save CPU time |
|
829 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
830 |
v->cur_speed = spd; |
2951 | 831 |
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
|
832 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
2951 | 833 |
} |
0 | 834 |
} |
835 |
||
836 |
// Decrease somewhat when turning |
|
2951 | 837 |
if (!(v->direction & 1)) spd = spd * 3 >> 2; |
0 | 838 |
|
2951 | 839 |
if (spd == 0) return false; |
0 | 840 |
|
2951 | 841 |
if ((byte)++spd == 0) return true; |
0 | 842 |
|
843 |
v->progress = (t = v->progress) - (byte)spd; |
|
844 |
||
845 |
return (t < v->progress); |
|
846 |
} |
|
847 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
848 |
static Direction RoadVehGetNewDirection(const Vehicle* v, int x, int y) |
0 | 849 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
850 |
static const Direction _roadveh_new_dir[] = { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
851 |
DIR_N , DIR_NW, DIR_W , 0, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
852 |
DIR_NE, DIR_N , DIR_SW, 0, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
853 |
DIR_E , DIR_SE, DIR_S |
0 | 854 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
855 |
|
0 | 856 |
x = x - v->x_pos + 1; |
857 |
y = y - v->y_pos + 1; |
|
858 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
859 |
if ((uint)x > 2 || (uint)y > 2) return v->direction; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
860 |
return _roadveh_new_dir[y * 4 + x]; |
0 | 861 |
} |
862 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
863 |
static Direction RoadVehGetSlidingDirection(const Vehicle* v, int x, int y) |
0 | 864 |
{ |
3168
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
865 |
Direction new = RoadVehGetNewDirection(v, x, y); |
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
866 |
Direction old = v->direction; |
3159
2abc21583259
(svn r3785) Replace some if-magic to determine the turning direction for road vehicles with the new DirDiff stuff
tron
parents:
3157
diff
changeset
|
867 |
DirDiff delta; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
868 |
|
3168
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
869 |
if (new == old) return old; |
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
870 |
delta = (DirDifference(new, old) > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
34cfe6f61a12
(svn r3796) When unmagicfying code, do it Right(tm) and also give the variables sensible names. I flipped a 'b' and a 'd' in r3785
tron
parents:
3167
diff
changeset
|
871 |
return ChangeDir(old, delta); |
0 | 872 |
} |
873 |
||
874 |
typedef struct OvertakeData { |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
875 |
const Vehicle* u; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
876 |
const Vehicle* v; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
877 |
TileIndex tile; |
0 | 878 |
byte tilebits; |
879 |
} OvertakeData; |
|
880 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
881 |
static void* EnumFindVehToOvertake(Vehicle* v, void* data) |
0 | 882 |
{ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
883 |
const OvertakeData* od = data; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
884 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
885 |
return |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
886 |
v->tile == od->tile && v->type == VEH_Road && v == od->u && v == od->v ? |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
887 |
v : NULL; |
0 | 888 |
} |
889 |
||
890 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
891 |
{ |
|
892 |
uint32 bits; |
|
893 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
894 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD) & 0x3F; |
0 | 895 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
896 |
if (!(od->tilebits & bits) || (bits & 0x3C) || (bits & 0x3F3F0000)) |
0 | 897 |
return true; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
898 |
return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL; |
0 | 899 |
} |
900 |
||
901 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
902 |
{ |
|
903 |
OvertakeData od; |
|
904 |
byte tt; |
|
905 |
||
906 |
od.v = v; |
|
907 |
od.u = u; |
|
908 |
||
909 |
if (u->max_speed >= v->max_speed && |
|
3236 | 910 |
!(u->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) && |
2951 | 911 |
u->cur_speed != 0) { |
912 |
return; |
|
913 |
} |
|
0 | 914 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
915 |
if (v->direction != u->direction || !(v->direction & 1)) return; |
0 | 916 |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
917 |
if (v->u.road.state >= 32 || (v->u.road.state & 7) > 1) return; |
0 | 918 |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
919 |
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F; |
2951 | 920 |
if ((tt & 3) == 0) return; |
921 |
if ((tt & 0x3C) != 0) return; |
|
0 | 922 |
|
2951 | 923 |
if (tt == 3) tt = (v->direction & 2) ? 2 : 1; |
0 | 924 |
od.tilebits = tt; |
925 |
||
926 |
od.tile = v->tile; |
|
2951 | 927 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 928 |
|
3161 | 929 |
od.tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction)); |
2951 | 930 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 931 |
|
3236 | 932 |
if (od.u->cur_speed == 0 || od.u->vehstatus& (VS_STOPPED | VS_WAIT_FOR_SLOT)) { |
0 | 933 |
v->u.road.overtaking_ctr = 0x11; |
934 |
v->u.road.overtaking = 0x10; |
|
935 |
} else { |
|
2951 | 936 |
// if (FindRoadVehToOvertake(&od)) return; |
0 | 937 |
v->u.road.overtaking_ctr = 0; |
938 |
v->u.road.overtaking = 0x10; |
|
939 |
} |
|
940 |
} |
|
941 |
||
942 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
943 |
{ |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
944 |
if (old_z == v->z_pos) return; |
0 | 945 |
|
946 |
if (old_z < v->z_pos) { |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
947 |
v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10% |
0 | 948 |
} else { |
949 |
uint16 spd = v->cur_speed + 2; |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
950 |
if (spd <= v->max_speed) v->cur_speed = spd; |
0 | 951 |
} |
952 |
} |
|
953 |
||
954 |
static int PickRandomBit(uint bits) |
|
955 |
{ |
|
956 |
uint num = 0; |
|
957 |
uint b = bits; |
|
958 |
uint i; |
|
959 |
||
960 |
do { |
|
2951 | 961 |
if (b & 1) num++; |
0 | 962 |
} while (b >>= 1); |
963 |
||
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
964 |
num = RandomRange(num); |
0 | 965 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
966 |
for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {} |
0 | 967 |
return i; |
968 |
} |
|
969 |
||
970 |
typedef struct { |
|
971 |
TileIndex dest; |
|
972 |
uint maxtracklen; |
|
973 |
uint mindist; |
|
974 |
} FindRoadToChooseData; |
|
975 |
||
3137 | 976 |
static bool EnumRoadTrackFindDist(TileIndex tile, void* data, int track, uint length, byte* state) |
0 | 977 |
{ |
3137 | 978 |
FindRoadToChooseData* frd = data; |
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
979 |
uint dist = DistanceManhattan(tile, frd->dest); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
980 |
|
0 | 981 |
if (dist <= frd->mindist) { |
982 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
983 |
frd->maxtracklen = length; |
|
984 |
} |
|
985 |
frd->mindist = dist; |
|
986 |
} |
|
987 |
return false; |
|
988 |
} |
|
989 |
||
990 |
// Returns direction to choose |
|
991 |
// or -1 if the direction is currently blocked |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
992 |
static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir) |
0 | 993 |
{ |
994 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
995 |
||
996 |
uint16 signal; |
|
997 |
uint bitmask; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
998 |
TileIndex desttile; |
0 | 999 |
FindRoadToChooseData frd; |
1000 |
int best_track; |
|
1001 |
uint best_dist, best_maxlen; |
|
1002 |
uint i; |
|
1003 |
||
1004 |
{ |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1005 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
2484
8e0c88a833fb
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1006 |
signal = GB(r, 16, 16); |
8e0c88a833fb
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1007 |
bitmask = GB(r, 0, 16); |
0 | 1008 |
} |
1009 |
||
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
|
1010 |
if (IsTileType(tile, MP_STREET)) { |
3069
0e6aca11c3da
(svn r3658) Add functions and symbolic names to retrieve road tile types and road pieces
tron
parents:
3054
diff
changeset
|
1011 |
if (GetRoadType(tile) == ROAD_DEPOT && IsTileOwner(tile, v->owner)) { |
2549 | 1012 |
/* Road depot */ |
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1013 |
bitmask |= _road_veh_fp_ax_or[GetRoadDepotDirection(tile)]; |
2549 | 1014 |
} |
3404
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3338
diff
changeset
|
1015 |
} else if (IsTileType(tile, MP_STATION) && IsRoadStopTile(tile)) { |
3074
b07d7f09110b
(svn r3663) - Fix: [Multistop] Check the status of the destination road stop instead of a station's first road stop. This only has effect with road vehicle queuing disabled.
peter1138
parents:
3069
diff
changeset
|
1016 |
if (IsTileOwner(tile, v->owner)) { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1017 |
/* Our station */ |
3092
e790a2dbda83
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1018 |
RoadStopType rstype = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1019 |
|
3092
e790a2dbda83
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1020 |
if (GetRoadStopType(tile) == rstype) { |
e790a2dbda83
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1021 |
const RoadStop *rs = GetRoadStopByTile(tile, rstype); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1022 |
|
3092
e790a2dbda83
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1023 |
if (rs != NULL && (_patches.roadveh_queue || GB(rs->status, 0, 2) != 0)) { |
3404
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3338
diff
changeset
|
1024 |
bitmask |= _road_veh_fp_ax_or[GetRoadStopDir(tile)]; |
3092
e790a2dbda83
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1025 |
} |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1026 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1027 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1028 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1029 |
/* 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
|
1030 |
* 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
|
1031 |
* 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
|
1032 |
*/ |
0 | 1033 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1034 |
/* remove unreachable tracks */ |
1247 | 1035 |
bitmask &= _road_veh_fp_ax_and[enterdir]; |
0 | 1036 |
if (bitmask == 0) { |
1247 | 1037 |
/* No reachable tracks, so we'll reverse */ |
1038 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1039 |
} |
1040 |
||
1041 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1042 |
/* What happens here?? */ |
0 | 1043 |
v->u.road.reverse_ctr = 0; |
1986
5dd3db2b86d7
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
1044 |
if (v->tile != tile) { |
1247 | 1045 |
return_track(_road_reverse_table[enterdir]); |
0 | 1046 |
} |
1047 |
} |
|
1048 |
||
1049 |
desttile = v->dest_tile; |
|
1050 |
if (desttile == 0) { |
|
1247 | 1051 |
// Pick a random track |
0 | 1052 |
return_track(PickRandomBit(bitmask)); |
1053 |
} |
|
1054 |
||
1247 | 1055 |
// Only one track to choose between? |
1056 |
if (!(KillFirstBit2x64(bitmask))) { |
|
0 | 1057 |
return_track(FindFirstBit2x64(bitmask)); |
1058 |
} |
|
1059 |
||
1247 | 1060 |
if (_patches.new_pathfinding_all) { |
1061 |
NPFFindStationOrTileData fstd; |
|
1062 |
NPFFoundTargetData ftd; |
|
1063 |
byte trackdir; |
|
1064 |
||
1065 |
NPFFillWithOrderData(&fstd, v); |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1066 |
trackdir = DiagdirToDiagTrackdir(enterdir); |
1247 | 1067 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1068 |
||
2916
8f1aa489701f
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
Darkvater
parents:
2854
diff
changeset
|
1069 |
ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
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
|
1070 |
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
|
1071 |
/* We are already at our target. Just do something */ |
1247 | 1072 |
//TODO: maybe display error? |
1073 |
//TODO: go straight ahead if possible? |
|
1074 |
return_track(FindFirstBit2x64(bitmask)); |
|
1075 |
} 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
|
1076 |
/* 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
|
1077 |
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
|
1078 |
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
|
1079 |
to the tile closest to our target. */ |
1247 | 1080 |
return_track(ftd.best_trackdir); |
1081 |
} |
|
1082 |
} else { |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1083 |
DiagDirection dir; |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1084 |
|
1247 | 1085 |
if (IsTileType(desttile, MP_STREET)) { |
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1086 |
if (GetRoadType(desttile) == ROAD_DEPOT) { |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1087 |
dir = GetRoadDepotDirection(desttile); |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1088 |
goto do_it; |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1089 |
} |
1247 | 1090 |
} else if (IsTileType(desttile, MP_STATION)) { |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1091 |
if (IsRoadStop(desttile)) { |
3404
3ac4f7fedfb5
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3338
diff
changeset
|
1092 |
dir = GetRoadStopDir(desttile); |
0 | 1093 |
do_it:; |
1247 | 1094 |
/* When we are heading for a depot or station, we just |
1095 |
* pretend we are heading for the tile in front, we'll |
|
1096 |
* see from there */ |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1097 |
desttile += TileOffsByDir(dir); |
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1098 |
if (desttile == tile && bitmask & _road_pf_table_3[dir]) { |
1247 | 1099 |
/* If we are already in front of the |
1100 |
* station/depot and we can get in from here, |
|
1101 |
* we enter */ |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1102 |
return_track(FindFirstBit2x64(bitmask & _road_pf_table_3[dir])); |
1247 | 1103 |
} |
0 | 1104 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1105 |
} |
1247 | 1106 |
// do pathfind |
1107 |
frd.dest = desttile; |
|
0 | 1108 |
|
1247 | 1109 |
best_track = -1; |
1110 |
best_dist = (uint)-1; |
|
1111 |
best_maxlen = (uint)-1; |
|
1112 |
i = 0; |
|
1113 |
do { |
|
1114 |
if (bitmask & 1) { |
|
1115 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track |
|
1116 |
frd.maxtracklen = (uint)-1; |
|
1117 |
frd.mindist = (uint)-1; |
|
3137 | 1118 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd); |
0 | 1119 |
|
1247 | 1120 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
1121 |
best_dist = frd.mindist; |
|
1122 |
best_maxlen = frd.maxtracklen; |
|
1123 |
best_track = i; |
|
1124 |
} |
|
0 | 1125 |
} |
1247 | 1126 |
} while (++i,(bitmask>>=1) != 0); |
1127 |
} |
|
0 | 1128 |
|
1129 |
found_best_track:; |
|
1130 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1131 |
if (HASBIT(signal, best_track)) return -1; |
0 | 1132 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1133 |
return best_track; |
0 | 1134 |
} |
1135 |
||
3123 | 1136 |
#if 0 /* Commented out until NPF works properly here */ |
1137 |
static uint RoadFindPathToStop(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
|
1138 |
{ |
3123 | 1139 |
NPFFindStationOrTileData fstd; |
1140 |
byte trackdir = GetVehicleTrackdir(v); |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
1141 |
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
|
1142 |
|
3123 | 1143 |
fstd.dest_coords = tile; |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1144 |
fstd.station_index = INVALID_STATION; // 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
|
1145 |
|
3123 | 1146 |
return NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE).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
|
1147 |
} |
2107
607a900aefa3
(svn r2617) - Fix: fix some warnings, and reenable vs.net2003 signed/unsigned warnings
Darkvater
parents:
2094
diff
changeset
|
1148 |
#endif |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1149 |
|
0 | 1150 |
typedef struct RoadDriveEntry { |
1151 |
byte x,y; |
|
1152 |
} RoadDriveEntry; |
|
1153 |
||
1154 |
#include "table/roadveh.h" |
|
1155 |
||
1156 |
static const byte _road_veh_data_1[] = { |
|
1157 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1158 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1159 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1160 |
15, 15, 11, 11 |
|
1161 |
}; |
|
1162 |
||
1163 |
static const byte _roadveh_data_2[4] = { 0,1,8,9 }; |
|
1164 |
||
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
|
1165 |
static void RoadVehController(Vehicle *v) |
0 | 1166 |
{ |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1167 |
Direction new_dir; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1168 |
Direction old_dir; |
0 | 1169 |
RoadDriveEntry rd; |
1170 |
int x,y; |
|
1171 |
uint32 r; |
|
1172 |
||
1173 |
// decrease counters |
|
1174 |
v->tick_counter++; |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1175 |
if (v->u.road.reverse_ctr != 0) v->u.road.reverse_ctr--; |
0 | 1176 |
|
1177 |
// handle crashed |
|
1178 |
if (v->u.road.crashed_ctr != 0) { |
|
1179 |
RoadVehIsCrashed(v); |
|
1180 |
return; |
|
1181 |
} |
|
1182 |
||
1183 |
RoadVehCheckTrainCrash(v); |
|
1184 |
||
1185 |
// road vehicle has broken down? |
|
1186 |
if (v->breakdown_ctr != 0) { |
|
1187 |
if (v->breakdown_ctr <= 2) { |
|
1188 |
HandleBrokenRoadVeh(v); |
|
1189 |
return; |
|
1190 |
} |
|
1191 |
v->breakdown_ctr--; |
|
1192 |
} |
|
1193 |
||
3236 | 1194 |
if (v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) return; |
0 | 1195 |
|
1196 |
ProcessRoadVehOrder(v); |
|
1197 |
HandleRoadVehLoading(v); |
|
1198 |
||
2951 | 1199 |
if (v->current_order.type == OT_LOADING) return; |
0 | 1200 |
|
1201 |
if (v->u.road.state == 254) { |
|
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1202 |
DiagDirection dir; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1203 |
const RoadDriveEntry* rdp; |
0 | 1204 |
byte rd2; |
1205 |
||
1206 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1207 |
|
3167
197b5ee5a831
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1208 |
dir = GetRoadDepotDirection(v->tile); |
3153
301c1d71122b
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1209 |
v->direction = DiagDirToDir(dir); |
0 | 1210 |
|
1211 |
rd2 = _roadveh_data_2[dir]; |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1212 |
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
|
1213 |
|
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
|
1214 |
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
|
1215 |
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF); |
0 | 1216 |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1217 |
if (RoadVehFindCloseTo(v, x, y, v->direction) != NULL) return; |
0 | 1218 |
|
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
|
1219 |
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
|
1220 |
|
0 | 1221 |
StartRoadVehSound(v); |
1222 |
||
1223 |
BeginVehicleMove(v); |
|
1224 |
||
1225 |
v->vehstatus &= ~VS_HIDDEN; |
|
1226 |
v->u.road.state = rd2; |
|
1227 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1228 |
|
0 | 1229 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1230 |
UpdateRoadVehDeltaXY(v); |
|
1231 |
SetRoadVehPosition(v,x,y); |
|
1232 |
||
1233 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1234 |
return; |
|
1235 |
} |
|
1236 |
||
2951 | 1237 |
if (!RoadVehAccelerate(v)) return; |
0 | 1238 |
|
1239 |
if (v->u.road.overtaking != 0) { |
|
1240 |
if (++v->u.road.overtaking_ctr >= 35) |
|
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1241 |
/* If overtaking just aborts at a random moment, we can have a out-of-bound problem, |
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1242 |
* if the vehicle started a corner. To protect that, only allow an abort of |
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1243 |
* overtake if we are on straight road, which are the 8 states below */ |
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1244 |
if (v->u.road.state == 0 || v->u.road.state == 1 || |
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1245 |
v->u.road.state == 8 || v->u.road.state == 9 || |
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1246 |
v->u.road.state == 16 || v->u.road.state == 17 || |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1247 |
v->u.road.state == 24 || v->u.road.state == 25) { |
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1248 |
v->u.road.overtaking = 0; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1249 |
} |
0 | 1250 |
} |
1251 |
||
1252 |
BeginVehicleMove(v); |
|
1253 |
||
1254 |
if (v->u.road.state == 255) { |
|
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1255 |
GetNewVehiclePosResult gp; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1256 |
|
0 | 1257 |
GetNewVehiclePos(v, &gp); |
1258 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1259 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction) != NULL) { |
0 | 1260 |
v->cur_speed = 0; |
1261 |
return; |
|
1262 |
} |
|
1263 |
||
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3169
diff
changeset
|
1264 |
if (IsTunnelTile(gp.new_tile) && |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1265 |
VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) { |
0 | 1266 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1267 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1268 |
UpdateRoadVehDeltaXY(v); |
|
1269 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1270 |
return; |
|
1271 |
} |
|
1272 |
||
1273 |
v->x_pos = gp.x; |
|
1274 |
v->y_pos = gp.y; |
|
1275 |
VehiclePositionChanged(v); |
|
1276 |
return; |
|
1277 |
} |
|
1278 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1279 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side << 4)) ^ v->u.road.overtaking][v->u.road.frame + 1]; |
0 | 1280 |
|
1281 |
// switch to another tile |
|
1282 |
if (rd.x & 0x80) { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1283 |
TileIndex tile = v->tile + TileOffsByDir(rd.x & 3); |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1284 |
int dir = RoadFindPathToDest(v, tile, rd.x & 3); |
0 | 1285 |
uint32 r; |
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1286 |
Direction newdir; |
0 | 1287 |
const RoadDriveEntry *rdp; |
1288 |
||
1289 |
if (dir == -1) { |
|
1290 |
v->cur_speed = 0; |
|
1291 |
return; |
|
1292 |
} |
|
1293 |
||
1294 |
again: |
|
1295 |
if ((dir & 7) >= 6) { |
|
1247 | 1296 |
/* Turning around */ |
0 | 1297 |
tile = v->tile; |
1298 |
} |
|
1299 |
||
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1300 |
rdp = _road_drive_data[(dir + (_opt.road_side << 4)) ^ v->u.road.overtaking]; |
0 | 1301 |
|
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
|
1302 |
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
|
1303 |
y = TileY(tile) * 16 + rdp[0].y; |
0 | 1304 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1305 |
newdir = RoadVehGetSlidingDirection(v, x, y); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1306 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1307 |
|
1308 |
r = VehicleEnterTile(v, tile, x, y); |
|
1309 |
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
|
1310 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1311 |
v->cur_speed = 0; |
1312 |
return; |
|
1313 |
} |
|
1314 |
dir = _road_reverse_table[rd.x&3]; |
|
1315 |
goto again; |
|
1316 |
} |
|
1317 |
||
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
|
1318 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1319 |
if ((dir & 7) >= 6) { |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1320 |
v->cur_speed = 0; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1321 |
return; |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1322 |
} |
3338
2c60ed0dcce3
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1323 |
if (IsRoadStop(v->tile)) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1324 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 1325 |
|
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1326 |
// reached a loading bay, mark it as used and clear the usage bit |
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1327 |
SETBIT(rs->status, v->u.road.state & 2 ? 1 : 0); // occupied bay |
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1328 |
CLRBIT(rs->status, 7); // usage bit |
0 | 1329 |
} |
1330 |
} |
|
1331 |
||
1332 |
if (!(r & 4)) { |
|
1333 |
v->tile = tile; |
|
2823
3aee7190192f
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1334 |
v->u.road.state = (byte)dir; |
0 | 1335 |
v->u.road.frame = 0; |
1336 |
} |
|
1337 |
if (newdir != v->direction) { |
|
1338 |
v->direction = newdir; |
|
1339 |
v->cur_speed -= v->cur_speed >> 2; |
|
1340 |
} |
|
1341 |
||
1342 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1343 |
UpdateRoadVehDeltaXY(v); |
|
1344 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1345 |
return; |
|
1346 |
} |
|
1347 |
||
1348 |
if (rd.x & 0x40) { |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1349 |
int dir = RoadFindPathToDest(v, v->tile, rd.x & 3); |
0 | 1350 |
uint32 r; |
1351 |
int tmp; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1352 |
Direction newdir; |
0 | 1353 |
const RoadDriveEntry *rdp; |
1354 |
||
1355 |
if (dir == -1) { |
|
1356 |
v->cur_speed = 0; |
|
1357 |
return; |
|
1358 |
} |
|
1359 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1360 |
tmp = (_opt.road_side << 4) + dir; |
0 | 1361 |
rdp = _road_drive_data[tmp]; |
1362 |
||
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
|
1363 |
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
|
1364 |
y = TileY(v->tile) * 16 + rdp[1].y; |
0 | 1365 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1366 |
newdir = RoadVehGetSlidingDirection(v, x, y); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1367 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1368 |
|
1369 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1370 |
if (r & 8) { |
|
1371 |
v->cur_speed = 0; |
|
1372 |
return; |
|
1373 |
} |
|
1374 |
||
1375 |
v->u.road.state = tmp & ~16; |
|
1376 |
v->u.road.frame = 1; |
|
1377 |
||
1378 |
if (newdir != v->direction) { |
|
1379 |
v->direction = newdir; |
|
1380 |
v->cur_speed -= v->cur_speed >> 2; |
|
1381 |
} |
|
1382 |
||
1383 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1384 |
UpdateRoadVehDeltaXY(v); |
|
1385 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1386 |
return; |
|
1387 |
} |
|
1388 |
||
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1389 |
x = (v->x_pos & ~15) + (rd.x & 15); |
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1390 |
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
|
1391 |
|
0 | 1392 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1393 |
||
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1394 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30)) { |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1395 |
Vehicle* u = RoadVehFindCloseTo(v, x, y, new_dir); |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1396 |
|
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1397 |
if (u != NULL) { |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1398 |
if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u); |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1399 |
return; |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1400 |
} |
0 | 1401 |
} |
1402 |
||
1403 |
old_dir = v->direction; |
|
1404 |
if (new_dir != old_dir) { |
|
1405 |
v->direction = new_dir; |
|
1406 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1407 |
if (old_dir != v->u.road.state) { |
|
1408 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1409 |
UpdateRoadVehDeltaXY(v); |
|
1410 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1411 |
return; |
|
1412 |
} |
|
1413 |
} |
|
1414 |
||
1415 |
if (v->u.road.state >= 0x20 && |
|
1416 |
_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
|
1417 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1418 |
Station* st = GetStationByTile(v->tile); |
0 | 1419 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1420 |
if (v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1421 |
v->current_order.type != OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1422 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1423 |
|
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1424 |
CLRBIT(rs->status, 7); |
0 | 1425 |
|
3315
1f65f8260092
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1426 |
v->last_station_visited = GetStationIndex(v->tile); |
0 | 1427 |
|
1428 |
RoadVehArrivesAt(v, st); |
|
1429 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1430 |
old_order = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1431 |
v->current_order.type = OT_LOADING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1432 |
v->current_order.flags = 0; |
0 | 1433 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1434 |
if (old_order.type == OT_GOTO_STATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1435 |
v->current_order.station == v->last_station_visited) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1436 |
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
|
1437 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP; |
0 | 1438 |
} |
1439 |
||
1440 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
1441 |
if (LoadUnloadVehicle(v)) { |
|
1442 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1443 |
MarkRoadVehDirty(v); |
|
1444 |
} |
|
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
|
1445 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1446 |
return; |
1447 |
} |
|
1448 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1449 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1450 |
if (HASBIT(rs->status, 7)) { |
0 | 1451 |
v->cur_speed = 0; |
1452 |
return; |
|
1453 |
} |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1454 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1455 |
v->current_order.flags = 0; |
3123 | 1456 |
ClearSlot(v); |
3236 | 1457 |
v->vehstatus &= ~VS_WAIT_FOR_SLOT; |
0 | 1458 |
} |
3054
299ca9034442
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1459 |
SETBIT(rs->status, 7); |
0 | 1460 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1461 |
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
|
1462 |
//we have arrived at the correct station |
3123 | 1463 |
ClearSlot(v); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1464 |
} 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
|
1465 |
//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
|
1466 |
//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
|
1467 |
//but I guess we need to clear the slot |
3123 | 1468 |
DEBUG(ms, 0) ("Multistop: Vehicle %d (index %d) arrived at wrong stop.", v->unitnumber, v->index); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1469 |
if (v->tile != v->dest_tile) { |
3123 | 1470 |
DEBUG(ms, 0) ("Multistop: -- Current tile 0x%x is not destination tile 0x%x. Route problem", v->tile, v->dest_tile); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1471 |
} |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1472 |
if (v->dest_tile != v->u.road.slot->xy) { |
3123 | 1473 |
DEBUG(ms, 0) ("Multistop: -- Stop tile 0x%x is not destination tile 0x%x. Multistop desync", v->u.road.slot->xy, v->dest_tile); |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1474 |
} |
3123 | 1475 |
if (v->current_order.type != OT_GOTO_STATION) { |
1476 |
DEBUG(ms, 0) ("Multistop: -- Current order type (%d) is not OT_GOTO_STATION.", v->current_order.type); |
|
1477 |
} else { |
|
1478 |
if (v->current_order.station != st->index) |
|
1479 |
DEBUG(ms, 0) ("Multistop: -- Current station %d is not target station in current_order.station (%d).", |
|
1480 |
st->index, v->current_order.station); |
|
1481 |
} |
|
1482 |
||
1483 |
DEBUG(ms, 0) (" -- Force a slot clearing."); |
|
1484 |
ClearSlot(v); |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1485 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1486 |
|
0 | 1487 |
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
|
1488 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1489 |
} |
1490 |
||
1491 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1492 |
if (r & 8) { |
|
1493 |
v->cur_speed = 0; |
|
1494 |
return; |
|
1495 |
} |
|
1496 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1497 |
if ((r & 4) == 0) v->u.road.frame++; |
0 | 1498 |
|
1499 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1500 |
UpdateRoadVehDeltaXY(v); |
|
1501 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1502 |
} |
|
1503 |
||
1504 |
void RoadVehEnterDepot(Vehicle *v) |
|
1505 |
{ |
|
1506 |
v->u.road.state = 254; |
|
1507 |
v->vehstatus |= VS_HIDDEN; |
|
1508 |
||
1509 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1510 |
||
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
|
1511 |
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
|
1512 |
|
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
|
1513 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1514 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1515 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1516 |
Order t; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1517 |
|
0 | 1518 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1519 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1520 |
t = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1521 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1522 |
v->current_order.flags = 0; |
0 | 1523 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1524 |
// 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
|
1525 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1526 |
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
|
1527 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { |
0 | 1528 |
v->vehstatus |= VS_STOPPED; |
1529 |
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
|
1530 |
SetDParam(0, v->unitnumber); |
0 | 1531 |
AddNewsItem( |
1532 |
STR_9016_ROAD_VEHICLE_IS_WAITING, |
|
1533 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1534 |
v->index, |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1535 |
0 |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1536 |
); |
0 | 1537 |
} |
1538 |
} |
|
1539 |
} |
|
1540 |
||
1541 |
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
|
1542 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1543 |
} |
1544 |
||
1545 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1546 |
{ |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1547 |
if (_age_cargo_skip_counter != 0) return; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1548 |
if (v->cargo_days != 255) v->cargo_days++; |
0 | 1549 |
} |
1550 |
||
1551 |
void RoadVeh_Tick(Vehicle *v) |
|
1552 |
{ |
|
1553 |
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
|
1554 |
RoadVehController(v); |
0 | 1555 |
} |
1556 |
||
1557 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1558 |
{ |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1559 |
const Depot* depot; |
0 | 1560 |
|
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1561 |
if (_patches.servint_roadveh == 0) return; |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1562 |
if (!VehicleNeedsService(v)) return; |
3236 | 1563 |
if (v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) return; |
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1564 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1565 |
|
0 | 1566 |
// Don't interfere with a depot visit scheduled by the user, or a |
1567 |
// depot visit by the order list. |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1568 |
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
|
1569 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 1570 |
return; |
1571 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1572 |
// If we already got a slot at a stop, use that FIRST, and go to a depot later |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1573 |
if (v->u.road.slot != NULL) return; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1574 |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1575 |
depot = FindClosestRoadDepot(v); |
0 | 1576 |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1577 |
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
|
1578 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1579 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1580 |
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
|
1581 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1582 |
} |
1583 |
return; |
|
1584 |
} |
|
1585 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1586 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1587 |
v->current_order.flags & OF_NON_STOP && |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1588 |
!CHANCE16(1, 20)) { |
0 | 1589 |
return; |
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1590 |
} |
0 | 1591 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1592 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1593 |
v->current_order.flags = OF_NON_STOP; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1594 |
v->current_order.station = depot->index; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1595 |
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
|
1596 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1597 |
} |
1598 |
||
1599 |
void OnNewDay_RoadVeh(Vehicle *v) |
|
1600 |
{ |
|
1601 |
int32 cost; |
|
1602 |
Station *st; |
|
1603 |
||
3017
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1604 |
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); |
915fae59d5e0
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1605 |
if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v); |
0 | 1606 |
|
1607 |
AgeVehicle(v); |
|
1608 |
CheckIfRoadVehNeedsService(v); |
|
1609 |
||
3140
69cb681c6d86
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1610 |
CheckOrders(v); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1611 |
|
3123 | 1612 |
//Current slot has expired |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1613 |
if (v->u.road.slot_age-- == 0 && v->u.road.slot != NULL) { |
3123 | 1614 |
DEBUG(ms, 2) ("Multistop: Slot %d expired for vehicle %d (index %d) at stop 0x%x", |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1615 |
v->u.road.slotindex, v->unitnumber, v->index, v->u.road.slot->xy |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1616 |
); |
3123 | 1617 |
ClearSlot(v); |
1618 |
} |
|
1619 |
||
3236 | 1620 |
if (v->vehstatus & VS_STOPPED) return; |
1621 |
||
0 | 1622 |
/* update destination */ |
3138
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1623 |
if (v->current_order.type == OT_GOTO_STATION && |
2bd76fda80c1
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1624 |
v->u.road.slot == NULL && |
3236 | 1625 |
!IsLevelCrossing(v->tile) && |
1626 |
v->u.road.overtaking == 0 && |
|
1627 |
!(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
|
1628 |
RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK; |
3123 | 1629 |
RoadStop *rs; |
1630 |
uint mindist = 0xFFFFFFFF; |
|
1631 |
int i; |
|
1632 |
RoadStop *nearest = NULL; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1633 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1634 |
st = GetStation(v->current_order.station); |
3123 | 1635 |
rs = GetPrimaryRoadStop(st, type); |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1636 |
|
3123 | 1637 |
if (rs != NULL) { |
1638 |
if (DistanceManhattan(v->tile, st->xy) < 16) { |
|
1639 |
int new_slot = -1; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1640 |
|
3123 | 1641 |
DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%x)", v->unitnumber, |
1642 |
v->index, st->index, st->xy); |
|
1643 |
/* Now we find the nearest road stop that has a free slot */ |
|
1644 |
for (i = 0; rs != NULL; rs = rs->next, i++) { |
|
1645 |
uint dist = 0xFFFFFFFF; |
|
1646 |
bool is_slot_free = false; |
|
1647 |
int k; |
|
1648 |
int last_free = -1; |
|
1649 |
||
1650 |
for (k = 0; k < NUM_SLOTS; k++) |
|
1651 |
if (rs->slot[k] == INVALID_VEHICLE) { |
|
1652 |
is_slot_free = true; |
|
1653 |
last_free = k; |
|
1654 |
dist = DistanceManhattan(v->tile, st->xy); |
|
1655 |
break; |
|
1656 |
} |
|
1657 |
||
1658 |
if (!is_slot_free) { |
|
1659 |
DEBUG(ms, 4) ("Multistop: ---- stop %d is full", i); |
|
1660 |
continue; |
|
1661 |
} |
|
1662 |
||
1663 |
DEBUG(ms, 4) ("Multistop: ---- distance to stop %d is %d", i, dist); |
|
1664 |
if (dist < mindist) { |
|
1665 |
nearest = rs; |
|
1666 |
mindist = dist; |
|
1667 |
new_slot = last_free; |
|
1668 |
} |
|
3033
e4f7c60a1742
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1669 |
} |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1670 |
|
3123 | 1671 |
if (nearest != NULL) { /* We have a suitable stop */ |
1672 |
DEBUG(ms, 3) ("Multistop: -- Slot %d of stop at 0x%x assinged.", new_slot, nearest->xy); |
|
1673 |
nearest->slot[new_slot] = v->index; |
|
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
|
1674 |
|
3123 | 1675 |
v->u.road.slot = nearest; |
1676 |
v->dest_tile = nearest->xy; |
|
1677 |
v->u.road.slot_age = 14; |
|
1678 |
v->u.road.slotindex = new_slot; |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1679 |
|
3236 | 1680 |
if (v->vehstatus & VS_WAIT_FOR_SLOT) { |
3123 | 1681 |
DEBUG(ms, 4) ("Multistop: ---- stopped vehicle got a slot. resuming movement"); |
3236 | 1682 |
v->vehstatus &= ~VS_WAIT_FOR_SLOT; |
3123 | 1683 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1684 |
} |
|
1685 |
} else { |
|
1686 |
DEBUG(ms, 2) ("Multistop -- No free slot at station. Waiting"); |
|
3236 | 1687 |
v->vehstatus |= VS_WAIT_FOR_SLOT; |
3123 | 1688 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1689 |
} |
|
1690 |
} else { |
|
1691 |
DEBUG(ms, 5) ("Multistop: --- Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%x)", |
|
1692 |
v->unitnumber, v->index, st->index, st->xy); |
|
1295
5dc810674581
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1693 |
} |
3123 | 1694 |
} else { |
1695 |
DEBUG(ms, 4) ("Multistop: No road stop for vehicle %d (index %d) at station %d (0x%x)", |
|
1696 |
v->unitnumber, v->index, st->index, st->xy); |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1697 |
} |
0 | 1698 |
} |
1699 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1700 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1701 |
|
1702 |
v->profit_this_year -= cost >> 8; |
|
1703 |
||
1704 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1705 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1706 |
||
1707 |
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
|
1708 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1709 |
} |
1710 |
||
1711 |
||
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
|
1712 |
void RoadVehiclesYearlyLoop(void) |
0 | 1713 |
{ |
1714 |
Vehicle *v; |
|
1715 |
||
1716 |
FOR_ALL_VEHICLES(v) { |
|
1717 |
if (v->type == VEH_Road) { |
|
1718 |
v->profit_last_year = v->profit_this_year; |
|
1719 |
v->profit_this_year = 0; |
|
1720 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1721 |
} |
|
1722 |
} |
|
1723 |
} |