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