author | bjarni |
Sun, 30 Jan 2005 13:42:11 +0000 | |
changeset 1224 | 09b0f5a1db97 |
parent 1217 | ab9f02a224ab |
child 1231 | 64cc1f5c1c82 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
3 |
#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
|
4 |
#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
|
5 |
#include "tile.h" |
0 | 6 |
#include "vehicle.h" |
7 |
#include "engine.h" |
|
8 |
#include "command.h" |
|
9 |
#include "station.h" |
|
10 |
#include "news.h" |
|
11 |
#include "gfx.h" |
|
12 |
#include "pathfind.h" |
|
13 |
#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
|
14 |
#include "sound.h" |
0 | 15 |
|
16 |
void ShowRoadVehViewWindow(Vehicle *v); |
|
17 |
||
18 |
static const uint16 _roadveh_images[63] = { |
|
19 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
20 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
21 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
22 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
23 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
24 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
25 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
26 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
27 |
}; |
|
28 |
||
29 |
static const uint16 _roadveh_full_adder[63] = { |
|
30 |
0, 88, 0, 0, 0, 0, 48, 48, |
|
31 |
48, 48, 0, 0, 64, 64, 0, 16, |
|
32 |
16, 0, 88, 0, 0, 0, 0, 48, |
|
33 |
48, 48, 48, 0, 0, 64, 64, 0, |
|
34 |
16, 16, 0, 88, 0, 0, 0, 0, |
|
35 |
48, 48, 48, 48, 0, 0, 64, 64, |
|
36 |
0, 16, 16, 0, 8, 8, 8, 8, |
|
37 |
0, 0, 0, 8, 8, 8, 8 |
|
38 |
}; |
|
39 |
||
40 |
||
41 |
static const uint16 _road_veh_fp_ax_or[4] = { |
|
42 |
0x100,0x200,1,2, |
|
43 |
}; |
|
44 |
||
45 |
static const uint16 _road_veh_fp_ax_and[4] = { |
|
46 |
0x1009, 0x16, 0x520, 0x2A00 |
|
47 |
}; |
|
48 |
||
49 |
static const byte _road_reverse_table[4] = { |
|
50 |
6, 7, 14, 15 |
|
51 |
}; |
|
52 |
||
53 |
static const uint16 _road_pf_table_3[4] = { |
|
54 |
0x910, 0x1600, 0x2005, 0x2A |
|
55 |
}; |
|
56 |
||
57 |
int GetRoadVehImage(Vehicle *v, byte direction) |
|
58 |
{ |
|
59 |
int img = v->spritenum; |
|
60 |
int image; |
|
61 |
||
62 |
if (is_custom_sprite(img)) { |
|
63 |
image = GetCustomVehicleSprite(v, direction); |
|
64 |
if (image) return image; |
|
65 |
img = _engine_original_sprites[v->engine_type]; |
|
66 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
67 |
|
0 | 68 |
image = direction + _roadveh_images[img]; |
69 |
if (v->cargo_count >= (v->cargo_cap >> 1)) |
|
70 |
image += _roadveh_full_adder[img]; |
|
71 |
return image; |
|
72 |
} |
|
73 |
||
74 |
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod) |
|
75 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
76 |
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
|
77 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
78 |
if (is_custom_sprite(spritenum)) { |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
79 |
int sprite = GetCustomVehicleIcon(engine, 6); |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
80 |
|
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
81 |
if (sprite) { |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
82 |
DrawSprite(sprite | image_ormod, x, y); |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
83 |
return; |
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 |
spritenum = _engine_original_sprites[engine]; |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
86 |
} |
9f170b63d48e
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
87 |
DrawSprite((6 + _roadveh_images[spritenum]) | image_ormod, x, y); |
0 | 88 |
} |
89 |
||
90 |
void DrawRoadVehEngineInfo(int engine, int x, int y, int maxw) |
|
91 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
92 |
const RoadVehicleInfo *rvi = RoadVehInfo(engine); |
0 | 93 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
94 |
SetDParam(0, ((_price.roadveh_base >> 3) * rvi->base_cost) >> 5); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
95 |
SetDParam(1, rvi->max_speed * 10 >> 5); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
96 |
SetDParam(2, rvi->running_cost * _price.roadveh_running >> 8); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
97 |
|
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
98 |
SetDParam(4, rvi->capacity); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
99 |
SetDParam(3, _cargoc.names_long_p[rvi->cargo_type]); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
100 |
|
0 | 101 |
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw); |
102 |
} |
|
103 |
||
812
79c99885ad00
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
104 |
int32 EstimateRoadVehCost(byte engine_type) |
0 | 105 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
106 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 107 |
} |
108 |
||
842 | 109 |
// p1 = engine_type |
110 |
// p2 not used |
|
0 | 111 |
int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
112 |
{ |
|
113 |
int32 cost; |
|
114 |
Vehicle *v; |
|
115 |
byte unit_num; |
|
116 |
uint tile = TILE_FROM_XY(x,y); |
|
117 |
Engine *e; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
118 |
|
1197 | 119 |
if (!IsEngineBuildable(p1, VEH_Road)) return CMD_ERROR; |
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
120 |
|
1224
09b0f5a1db97
(svn r1728) - Fix: now a player can only build a road vehicle in depots he owns (hacked client protection)
bjarni
parents:
1217
diff
changeset
|
121 |
if (!IsRoadDepotTile((TileIndex)tile)) return CMD_ERROR; |
09b0f5a1db97
(svn r1728) - Fix: now a player can only build a road vehicle in depots he owns (hacked client protection)
bjarni
parents:
1217
diff
changeset
|
122 |
|
09b0f5a1db97
(svn r1728) - Fix: now a player can only build a road vehicle in depots he owns (hacked client protection)
bjarni
parents:
1217
diff
changeset
|
123 |
if (_map_owner[tile] != _current_player) return CMD_ERROR; |
09b0f5a1db97
(svn r1728) - Fix: now a player can only build a road vehicle in depots he owns (hacked client protection)
bjarni
parents:
1217
diff
changeset
|
124 |
|
0 | 125 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
126 |
||
127 |
cost = EstimateRoadVehCost(p1); |
|
128 |
if (flags & DC_QUERY_COST) |
|
129 |
return cost; |
|
130 |
||
131 |
v = AllocateVehicle(); |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
132 |
if (v == NULL || IsOrderPoolFull()) |
0 | 133 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
134 |
||
135 |
/* find the first free roadveh id */ |
|
136 |
unit_num = GetFreeUnitNumber(VEH_Road); |
|
137 |
if (unit_num > _patches.max_roadveh) |
|
138 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
139 |
||
140 |
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
|
141 |
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
|
142 |
|
0 | 143 |
v->unitnumber = unit_num; |
144 |
v->direction = 0; |
|
145 |
v->owner = _current_player; |
|
146 |
||
147 |
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
|
148 |
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
|
149 |
y = TileY(tile) * 16 + 8; |
0 | 150 |
v->x_pos = x; |
151 |
v->y_pos = y; |
|
152 |
v->z_pos = GetSlopeZ(x,y); |
|
153 |
v->z_height = 6; |
|
154 |
||
155 |
v->u.road.state = 254; |
|
156 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
157 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
158 |
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
|
159 |
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
|
160 |
v->cargo_cap = rvi->capacity; |
0 | 161 |
// v->cargo_count = 0; |
162 |
v->value = cost; |
|
163 |
// v->day_counter = 0; |
|
164 |
// v->next_order_param = v->next_order = 0; |
|
165 |
// v->load_unload_time_rem = 0; |
|
166 |
// v->progress = 0; |
|
167 |
||
168 |
// v->u.road.unk2 = 0; |
|
169 |
// v->u.road.overtaking = 0; |
|
170 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
|
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
175 |
v->last_station_visited = 0xFFFF; |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
176 |
v->max_speed = rvi->max_speed; |
0 | 177 |
v->engine_type = (byte)p1; |
178 |
||
179 |
e = &_engines[p1]; |
|
180 |
v->reliability = e->reliability; |
|
181 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
182 |
v->max_age = e->lifelength * 366; |
|
183 |
_new_roadveh_id = v->index; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
184 |
|
0 | 185 |
v->string_id = STR_SV_ROADVEH_NAME; |
186 |
||
187 |
v->service_interval = _patches.servint_roadveh; |
|
188 |
||
189 |
v->date_of_last_service = _date; |
|
190 |
v->build_year = _cur_year; |
|
191 |
||
192 |
v->type = VEH_Road; |
|
193 |
v->cur_image = 0xC15; |
|
194 |
||
195 |
VehiclePositionChanged(v); |
|
196 |
||
197 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 198 |
RebuildVehicleLists(); |
0 | 199 |
InvalidateWindow(WC_COMPANY, v->owner); |
200 |
} |
|
201 |
||
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
202 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
203 |
|
0 | 204 |
return cost; |
205 |
} |
|
206 |
||
207 |
// p1 = vehicle |
|
208 |
int32 CmdStartStopRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
209 |
{ |
|
210 |
Vehicle *v; |
|
211 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
212 |
v = GetVehicle(p1); |
0 | 213 |
|
214 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
215 |
return CMD_ERROR; |
|
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 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
226 |
// p1 = vehicle index in GetVehicle() |
842 | 227 |
// p2 not used |
0 | 228 |
int32 CmdSellRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
229 |
{ |
|
230 |
Vehicle *v; |
|
231 |
||
232 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
233 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
234 |
v = GetVehicle(p1); |
0 | 235 |
|
236 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
237 |
return CMD_ERROR; |
|
238 |
||
239 |
if (!IsRoadDepotTile(v->tile) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) |
|
240 |
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
|
241 |
|
0 | 242 |
if (flags & DC_EXEC) { |
243 |
// Invalidate depot |
|
244 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 245 |
RebuildVehicleLists(); |
0 | 246 |
InvalidateWindow(WC_COMPANY, v->owner); |
247 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
248 |
DeleteVehicle(v); |
|
249 |
} |
|
1128
d3ffc98b92ad
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1095
diff
changeset
|
250 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
251 |
|
0 | 252 |
return -(int32)v->value; |
253 |
} |
|
254 |
||
255 |
typedef struct RoadFindDepotData { |
|
256 |
uint best_length; |
|
257 |
uint tile; |
|
258 |
byte owner; |
|
259 |
} RoadFindDepotData; |
|
260 |
||
261 |
static const byte _road_pf_directions[16] = { |
|
262 |
0, 1, 0, 1, 2, 1, 255, 255, |
|
263 |
2, 3, 3, 2, 3, 0, 255, 255, |
|
264 |
}; |
|
265 |
||
266 |
static bool EnumRoadSignalFindDepot(uint tile, RoadFindDepotData *rfdd, int track, uint length, byte *state) |
|
267 |
{ |
|
904
bff808a1c7f0
(svn r1390) Use TileOffsByDir() instead of home brewed table
tron
parents:
900
diff
changeset
|
268 |
tile += TileOffsByDir(_road_pf_directions[track]); |
0 | 269 |
|
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
|
270 |
if (IsTileType(tile, MP_STREET) && |
0 | 271 |
(_map5[tile] & 0xF0) == 0x20 && |
272 |
_map_owner[tile] == rfdd->owner) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
273 |
|
0 | 274 |
if (length < rfdd->best_length) { |
275 |
rfdd->best_length = length; |
|
276 |
rfdd->tile = tile; |
|
277 |
} |
|
278 |
} |
|
279 |
return false; |
|
280 |
} |
|
281 |
||
282 |
static int FindClosestRoadDepot(Vehicle *v) |
|
283 |
{ |
|
284 |
uint tile = v->tile; |
|
285 |
int i; |
|
286 |
RoadFindDepotData rfdd; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
287 |
|
0 | 288 |
if (v->u.road.state == 255) { tile = GetVehicleOutOfTunnelTile(v); } |
289 |
||
290 |
rfdd.owner = v->owner; |
|
291 |
rfdd.best_length = (uint)-1; |
|
292 |
||
293 |
/* search in all directions */ |
|
294 |
for(i=0; i!=4; i++) |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
295 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadSignalFindDepot, NULL, &rfdd); |
0 | 296 |
|
297 |
if (rfdd.best_length == (uint)-1) |
|
298 |
return -1; |
|
299 |
||
300 |
return GetDepotByTile(rfdd.tile); |
|
301 |
} |
|
302 |
||
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
303 |
/* Send a road vehicle to the nearest depot |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
304 |
p1 = index of the road vehicle |
1206
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
305 |
p2 = bit 0 = do not stop in depot |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
306 |
bit 1 = set v->set_for_replacement |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
307 |
bit 2 = clear v->set_for_replacement */ |
0 | 308 |
int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
309 |
{ |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
310 |
Vehicle *v = GetVehicle(p1); |
0 | 311 |
int depot; |
312 |
||
313 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
314 |
return CMD_ERROR; |
|
315 |
||
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
316 |
if (HASBIT(p2, 0)) v->set_for_replacement = true; |
1206
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
317 |
if (HASBIT(p2, 2)) v->set_for_replacement = false; |
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
318 |
|
1206
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
319 |
if (HASBIT(p2, 1) || HASBIT(p2, 2)) return CMD_ERROR; // vehicle has a depot in schedule. It just needed to alter set_for_replacement |
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
320 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
321 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 322 |
if (flags & DC_EXEC) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
323 |
if (v->current_order.flags & OF_UNLOAD) |
0 | 324 |
v->cur_order_index++; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
325 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
326 |
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
|
327 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 328 |
} |
329 |
return 0; |
|
330 |
} |
|
331 |
||
332 |
depot = FindClosestRoadDepot(v); |
|
333 |
if (depot < 0) |
|
334 |
return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
|
335 |
||
336 |
if (flags & DC_EXEC) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
337 |
v->current_order.type = OT_GOTO_DEPOT; |
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
338 |
v->current_order.flags = p2 == 0 ? OF_NON_STOP | OF_FULL_LOAD : 0; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
339 |
v->current_order.station = (byte)depot; |
0 | 340 |
v->dest_tile = _depots[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
|
341 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 342 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
343 |
|
0 | 344 |
return 0; |
345 |
} |
|
346 |
||
347 |
int32 CmdTurnRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
348 |
{ |
|
349 |
Vehicle *v; |
|
350 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
351 |
v = GetVehicle(p1); |
0 | 352 |
|
353 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
354 |
return CMD_ERROR; |
|
355 |
||
356 |
if (v->vehstatus & (VS_HIDDEN|VS_STOPPED) || |
|
357 |
v->u.road.crashed_ctr != 0 || |
|
358 |
v->breakdown_ctr != 0 || |
|
359 |
v->u.road.overtaking != 0 || |
|
360 |
v->cur_speed < 5) { |
|
361 |
_error_message = STR_EMPTY; |
|
362 |
return CMD_ERROR; |
|
363 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
364 |
|
0 | 365 |
if (flags & DC_EXEC) { |
366 |
v->u.road.reverse_ctr = 180; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
367 |
} |
0 | 368 |
|
369 |
return 0; |
|
370 |
} |
|
371 |
||
372 |
int32 CmdChangeRoadVehServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
373 |
{ |
|
374 |
Vehicle *v; |
|
375 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
376 |
v = GetVehicle(p1); |
0 | 377 |
|
378 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) |
|
379 |
return CMD_ERROR; |
|
380 |
||
381 |
if (flags & DC_EXEC) { |
|
382 |
v->service_interval = (uint16)p2; |
|
383 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
|
384 |
} |
|
385 |
||
386 |
return 0; |
|
387 |
} |
|
388 |
||
389 |
||
390 |
static void MarkRoadVehDirty(Vehicle *v) |
|
391 |
{ |
|
392 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
393 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
394 |
} |
|
395 |
||
396 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
397 |
{ |
|
398 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
399 |
static const uint32 _delta_xy_table[8] = { |
|
400 |
MKIT(3, 3, -1, -1), |
|
401 |
MKIT(3, 7, -1, -3), |
|
402 |
MKIT(3, 3, -1, -1), |
|
403 |
MKIT(7, 3, -3, -1), |
|
404 |
MKIT(3, 3, -1, -1), |
|
405 |
MKIT(3, 7, -1, -3), |
|
406 |
MKIT(3, 3, -1, -1), |
|
407 |
MKIT(7, 3, -3, -1), |
|
408 |
}; |
|
409 |
#undef MKIT |
|
410 |
uint32 x = _delta_xy_table[v->direction]; |
|
411 |
v->x_offs = (byte)x; |
|
412 |
v->y_offs = (byte)(x>>=8); |
|
413 |
v->sprite_width = (byte)(x>>=8); |
|
414 |
v->sprite_height = (byte)(x>>=8); |
|
415 |
} |
|
416 |
||
417 |
static void ClearCrashedStation(Vehicle *v) |
|
418 |
{ |
|
419 |
uint tile = v->tile; |
|
420 |
byte *b, bb; |
|
421 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
422 |
RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile)); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
423 |
b = &rs->status; |
0 | 424 |
|
425 |
bb = *b; |
|
426 |
||
427 |
// mark station as not busy |
|
428 |
bb &= ~0x80; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
429 |
|
0 | 430 |
// free parking bay |
431 |
bb |= (v->u.road.state&0x02)?2:1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
432 |
|
0 | 433 |
*b = bb; |
434 |
} |
|
435 |
||
436 |
static void RoadVehDelete(Vehicle *v) |
|
437 |
{ |
|
438 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
439 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
440 |
|
588 | 441 |
RebuildVehicleLists(); |
0 | 442 |
InvalidateWindow(WC_COMPANY, v->owner); |
443 |
||
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
|
444 |
if (IsTileType(v->tile, MP_STATION)) |
0 | 445 |
ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
446 |
|
0 | 447 |
BeginVehicleMove(v); |
448 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
449 |
|
0 | 450 |
DeleteVehicle(v); |
451 |
} |
|
452 |
||
453 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
454 |
{ |
|
455 |
byte new_z, old_z; |
|
456 |
||
457 |
// need this hint so it returns the right z coordinate on bridges. |
|
458 |
_get_z_hint = v->z_pos; |
|
459 |
new_z = GetSlopeZ(v->x_pos=x, v->y_pos=y); |
|
460 |
_get_z_hint = 0; |
|
461 |
||
462 |
old_z = v->z_pos; |
|
463 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
464 |
|
0 | 465 |
VehiclePositionChanged(v); |
466 |
EndVehicleMove(v); |
|
467 |
return old_z; |
|
468 |
} |
|
469 |
||
470 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
471 |
{ |
|
472 |
static const int8 _turn_prob[4] = { -1, 0, 0, 1 }; |
|
473 |
uint32 r = Random(); |
|
474 |
v->direction = (v->direction+_turn_prob[r&3])&7; |
|
475 |
BeginVehicleMove(v); |
|
476 |
UpdateRoadVehDeltaXY(v); |
|
477 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
478 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
479 |
} |
|
480 |
||
481 |
static void RoadVehIsCrashed(Vehicle *v) |
|
482 |
{ |
|
483 |
v->u.road.crashed_ctr++; |
|
484 |
if (v->u.road.crashed_ctr == 2) { |
|
485 |
CreateEffectVehicleRel(v,4,4,8,EV_CRASHED_SMOKE); |
|
486 |
} else if (v->u.road.crashed_ctr <= 45) { |
|
487 |
if ((v->tick_counter&7)==0) |
|
488 |
RoadVehSetRandomDirection(v); |
|
489 |
} else if (v->u.road.crashed_ctr >= 2220) { |
|
490 |
RoadVehDelete(v); |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u) |
|
495 |
{ |
|
496 |
if (v->type != VEH_Train || |
|
497 |
myabs(v->z_pos - u->z_pos) > 6 || |
|
498 |
myabs(v->x_pos - u->x_pos) > 4 || |
|
499 |
myabs(v->y_pos - u->y_pos) > 4) |
|
500 |
return NULL; |
|
501 |
return v; |
|
502 |
} |
|
503 |
||
504 |
static void RoadVehCrash(Vehicle *v) |
|
505 |
{ |
|
506 |
uint16 pass; |
|
507 |
||
508 |
v->u.road.crashed_ctr++; |
|
509 |
v->vehstatus |= VS_CRASHED; |
|
510 |
||
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
|
511 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 512 |
|
513 |
pass = 1; |
|
514 |
if (v->cargo_type == 0) |
|
515 |
pass += v->cargo_count; |
|
516 |
v->cargo_count = 0; |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
517 |
SetDParam(0, pass); |
0 | 518 |
|
519 |
AddNewsItem(STR_9031_ROAD_VEHICLE_CRASH_DRIVER+(pass!=1), |
|
520 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
|
521 |
v->index, |
|
522 |
0); |
|
523 |
||
524 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 525 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 526 |
} |
527 |
||
528 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
529 |
{ |
|
530 |
uint tile; |
|
531 |
||
532 |
if (v->u.road.state == 255) |
|
533 |
return; |
|
534 |
||
535 |
tile = v->tile; |
|
536 |
||
537 |
// Make sure it's a road/rail crossing |
|
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
538 |
if (!IsTileType(tile, MP_STREET) || |
1151
614cbcb5b9fe
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
539 |
(_map5[tile] & 0xF0) != 0x10) |
0 | 540 |
return; |
541 |
||
542 |
if (VehicleFromPos(tile, v, (VehicleFromPosProc*)EnumCheckRoadVehCrashTrain) != NULL) |
|
543 |
RoadVehCrash(v); |
|
544 |
} |
|
545 |
||
546 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
547 |
{ |
|
548 |
if (v->breakdown_ctr != 1) { |
|
549 |
v->breakdown_ctr = 1; |
|
550 |
v->cur_speed = 0; |
|
551 |
||
552 |
if (v->breakdowns_since_last_service != 255) |
|
553 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
554 |
|
0 | 555 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
556 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
557 |
|
541 | 558 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
559 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
|
0 | 560 |
|
561 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
562 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
563 |
if (u) |
|
564 |
u->u.special.unk0 = v->breakdown_delay * 2; |
|
565 |
} |
|
566 |
} |
|
567 |
||
568 |
if (!(v->tick_counter & 1)) { |
|
569 |
if (!--v->breakdown_delay) { |
|
570 |
v->breakdown_ctr = 0; |
|
571 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
572 |
} |
|
573 |
} |
|
574 |
} |
|
575 |
||
576 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
577 |
{ |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
578 |
const Order *order; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
579 |
const Station *st; |
0 | 580 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
581 |
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
|
582 |
// Let a depot order in the orderlist interrupt. |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
583 |
if (v->current_order.type != OT_GOTO_DEPOT || |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
584 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 585 |
return; |
586 |
} |
|
587 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
588 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
589 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
590 |
!VehicleNeedsService(v) && !v->set_for_replacement) { |
0 | 591 |
v->cur_order_index++; |
592 |
} |
|
593 |
||
594 |
if (v->cur_order_index >= v->num_orders) |
|
595 |
v->cur_order_index = 0; |
|
596 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
597 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 598 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
599 |
if (order == NULL) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
600 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
601 |
v->current_order.flags = 0; |
0 | 602 |
v->dest_tile = 0; |
603 |
return; |
|
604 |
} |
|
605 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
606 |
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
|
607 |
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
|
608 |
order->station == v->current_order.station) |
0 | 609 |
return; |
610 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
611 |
v->current_order = *order; |
0 | 612 |
|
613 |
v->dest_tile = 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->type == OT_GOTO_STATION) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
616 |
if (order->station == v->last_station_visited) |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
812
diff
changeset
|
617 |
v->last_station_visited = 0xFFFF; |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
618 |
st = GetStation(order->station); |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
619 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
620 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
621 |
int32 *dist; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
622 |
int32 mindist = 0xFFFFFFFF; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
623 |
int num; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
624 |
RoadStopType type; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
625 |
RoadStop *rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
626 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
627 |
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
|
628 |
num = GetNumRoadStops(st, type); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
629 |
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
|
630 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
631 |
assert (rs != NULL); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
632 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
633 |
dist = malloc(num * sizeof(int32)); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
634 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
635 |
do { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
636 |
*dist = GetTileDistAdv(v->tile, rs->xy); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
637 |
if (*dist < mindist) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
638 |
v->dest_tile = rs->xy; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
639 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
640 |
rs = rs->next; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
641 |
} while ( rs != NULL ); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
642 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
643 |
free(dist); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
644 |
dist = NULL; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
645 |
} |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
646 |
} else if (order->type == OT_GOTO_DEPOT) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
647 |
v->dest_tile = _depots[order->station].xy; |
0 | 648 |
} |
649 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
650 |
InvalidateVehicleOrder(v); |
0 | 651 |
} |
652 |
||
653 |
static void HandleRoadVehLoading(Vehicle *v) |
|
654 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
655 |
if (v->current_order.type == OT_NOTHING) |
0 | 656 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
657 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
658 |
if (v->current_order.type != OT_DUMMY) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
659 |
if (v->current_order.type != OT_LOADING) |
0 | 660 |
return; |
661 |
||
662 |
if (--v->load_unload_time_rem) |
|
663 |
return; |
|
664 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
665 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 666 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
667 |
if (LoadUnloadVehicle(v)) { |
|
668 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
669 |
MarkRoadVehDirty(v); |
|
670 |
} |
|
671 |
return; |
|
672 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
673 |
|
0 | 674 |
{ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
675 |
Order b = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
676 |
v->current_order.type = OT_LEAVESTATION; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
677 |
v->current_order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
678 |
if (!(b.flags & OF_NON_STOP)) |
0 | 679 |
return; |
680 |
} |
|
681 |
} |
|
682 |
||
683 |
v->cur_order_index++; |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
684 |
InvalidateVehicleOrder(v); |
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
685 |
|
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
686 |
if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
687 |
// only the vehicle owner needs to calculate the rest (locally) |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
688 |
if ((_autoreplace_array[v->engine_type] != v->engine_type) || |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
689 |
(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
690 |
byte flags = 1; |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
691 |
// the flags means, bit 0 = needs to go to depot, bit 1 = have depot in orders |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
692 |
if (VehicleHasDepotOrders(v)) SETBIT(flags, 1); |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
693 |
if (!(HASBIT(flags, 1) && v->set_for_replacement)) { |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
694 |
_current_player = _local_player; |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
695 |
DoCommandP(v->tile, v->index, flags, NULL, CMD_SEND_ROADVEH_TO_DEPOT | CMD_SHOW_NO_ERROR); |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
696 |
_current_player = OWNER_NONE; |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
697 |
} |
1206
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
698 |
} else { // no need to go to a depot |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
699 |
if (v->set_for_replacement) { |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
700 |
// it seems that the user clicked "Stop replacing" |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
701 |
_current_player = _local_player; |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
702 |
DoCommandP(v->tile, v->index, 1 | (1 << 2), NULL, CMD_SEND_ROADVEH_TO_DEPOT | CMD_SHOW_NO_ERROR); |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
703 |
_current_player = OWNER_NONE; |
9a4ebc971c41
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1203
diff
changeset
|
704 |
} |
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
705 |
} |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
706 |
} |
0 | 707 |
} |
708 |
||
709 |
static void StartRoadVehSound(Vehicle *v) |
|
710 |
{ |
|
541 | 711 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
712 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
|
713 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
|
0 | 714 |
SndPlayVehicleFx(s, v); |
715 |
} |
|
716 |
||
717 |
typedef struct RoadVehFindData { |
|
718 |
int x,y; |
|
719 |
Vehicle *veh; |
|
720 |
byte dir; |
|
721 |
} RoadVehFindData; |
|
722 |
||
1095 | 723 |
static void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf) |
0 | 724 |
{ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
725 |
static const short _dists[] = { |
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
726 |
-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
|
727 |
-4, -1, 4, 8, 4, 1, -4, -8, |
0 | 728 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
729 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
730 |
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
|
731 |
short y_diff = v->y_pos - rvf->y; |
0 | 732 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
733 |
if (rvf->veh == v || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
734 |
v->type != VEH_Road || |
0 | 735 |
v->u.road.state == 254 || |
736 |
myabs(v->z_pos - rvf->veh->z_pos) > 6 || |
|
737 |
v->direction != rvf->dir || |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
738 |
(_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
|
739 |
(_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
|
740 |
(_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
|
741 |
(_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
|
742 |
return NULL; |
0 | 743 |
|
744 |
return v; |
|
745 |
} |
|
746 |
||
747 |
static Vehicle *RoadVehFindCloseTo(Vehicle *v, int x, int y, byte dir) |
|
748 |
{ |
|
749 |
RoadVehFindData rvf; |
|
750 |
Vehicle *u; |
|
751 |
||
752 |
if (v->u.road.reverse_ctr != 0) |
|
753 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
754 |
|
0 | 755 |
rvf.x = x; |
756 |
rvf.y = y; |
|
757 |
rvf.dir = dir; |
|
758 |
rvf.veh = v; |
|
759 |
u = VehicleFromPos(TILE_FROM_XY(x,y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
760 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
761 |
// This code protects a roadvehicle from being blocked for ever |
826 | 762 |
// 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
|
763 |
// 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
|
764 |
// It can be disabled. |
0 | 765 |
if (u == NULL) { |
766 |
v->u.road.unk2 = 0; |
|
767 |
return NULL; |
|
768 |
} |
|
769 |
||
770 |
if (++v->u.road.unk2 > 1480) |
|
771 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
772 |
|
0 | 773 |
return u; |
774 |
} |
|
775 |
||
776 |
static void RoadVehArrivesAt(Vehicle *v, Station *st) |
|
777 |
{ |
|
778 |
if (v->engine_type < 123) { |
|
779 |
/* Check if station was ever visited before */ |
|
780 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
781 |
uint32 flags; |
|
782 |
||
783 |
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
|
784 |
SetDParam(0, st->index); |
0 | 785 |
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); |
786 |
AddNewsItem( |
|
787 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
788 |
flags, |
|
789 |
v->index, |
|
790 |
0); |
|
791 |
} |
|
792 |
} else { |
|
793 |
/* Check if station was ever visited before */ |
|
794 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
795 |
uint32 flags; |
|
796 |
||
797 |
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
|
798 |
SetDParam(0, st->index); |
0 | 799 |
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); |
800 |
AddNewsItem( |
|
801 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
802 |
flags, |
|
803 |
v->index, |
|
804 |
0); |
|
805 |
} |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
static bool RoadVehAccelerate(Vehicle *v) |
|
810 |
{ |
|
811 |
uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0); |
|
812 |
byte t; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
813 |
|
0 | 814 |
// Clamp |
815 |
spd = min(spd, v->max_speed); |
|
816 |
||
817 |
//updates statusbar only if speed have changed to save CPU time |
|
818 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
819 |
v->cur_speed = spd; |
0 | 820 |
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
|
821 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 822 |
} |
823 |
||
824 |
// Decrease somewhat when turning |
|
825 |
if (!(v->direction&1)) |
|
826 |
spd = spd * 3 >> 2; |
|
827 |
||
828 |
if (spd == 0) |
|
829 |
return false; |
|
830 |
||
831 |
if ((byte)++spd == 0) |
|
832 |
return true; |
|
833 |
||
834 |
v->progress = (t = v->progress) - (byte)spd; |
|
835 |
||
836 |
return (t < v->progress); |
|
837 |
} |
|
838 |
||
839 |
static byte RoadVehGetNewDirection(Vehicle *v, int x, int y) |
|
840 |
{ |
|
841 |
static const byte _roadveh_new_dir[11] = { |
|
842 |
0, 7, 6, 0, |
|
843 |
1, 0, 5, 0, |
|
844 |
2, 3, 4 |
|
845 |
}; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
846 |
|
0 | 847 |
x = x - v->x_pos + 1; |
848 |
y = y - v->y_pos + 1; |
|
849 |
||
850 |
if ((uint)x > 2 || (uint)y > 2) |
|
851 |
return v->direction; |
|
852 |
return _roadveh_new_dir[y*4+x]; |
|
853 |
} |
|
854 |
||
855 |
static byte RoadVehGetSlidingDirection(Vehicle *v, int x, int y) |
|
856 |
{ |
|
857 |
byte b = RoadVehGetNewDirection(v,x,y); |
|
858 |
byte d = v->direction; |
|
859 |
if (b == d) return d; |
|
860 |
d = (d+1)&7; |
|
861 |
if (b==d) return d; |
|
862 |
d = (d-2)&7; |
|
863 |
if (b==d) return d; |
|
864 |
if (b==((d-1)&7)) return d; |
|
865 |
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
|
866 |
return (d+2)&7; |
0 | 867 |
} |
868 |
||
869 |
typedef struct OvertakeData { |
|
870 |
Vehicle *u, *v; |
|
871 |
uint tile; |
|
872 |
byte tilebits; |
|
873 |
} OvertakeData; |
|
874 |
||
1095 | 875 |
static void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od) |
0 | 876 |
{ |
877 |
if (v->tile != (TileIndex)od->tile || |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
878 |
v->type != VEH_Road || |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
879 |
v == od->u || |
0 | 880 |
v == od->v) |
881 |
return NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
882 |
return v; |
0 | 883 |
} |
884 |
||
885 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
886 |
{ |
|
887 |
uint32 bits; |
|
888 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
889 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD)&0x3F; |
0 | 890 |
|
891 |
if (!(od->tilebits & bits) || (bits&0x3C) || (bits & 0x3F3F0000)) |
|
892 |
return true; |
|
893 |
return VehicleFromPos(od->tile, od, (VehicleFromPosProc*)EnumFindVehToOvertake) != NULL; |
|
894 |
} |
|
895 |
||
896 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
897 |
{ |
|
898 |
OvertakeData od; |
|
899 |
byte tt; |
|
900 |
||
901 |
od.v = v; |
|
902 |
od.u = u; |
|
903 |
||
904 |
if (u->max_speed >= v->max_speed && |
|
905 |
!(u->vehstatus&VS_STOPPED) && |
|
906 |
u->cur_speed != 0) |
|
907 |
return; |
|
908 |
||
909 |
if (v->direction != u->direction || !(v->direction&1)) |
|
910 |
return; |
|
911 |
||
912 |
if (v->u.road.state >= 32 || (v->u.road.state&7) > 1 ) |
|
913 |
return; |
|
914 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
915 |
tt = (byte)(GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F); |
0 | 916 |
if ((tt & 3) == 0) |
917 |
return; |
|
918 |
if ((tt & 0x3C) != 0) |
|
919 |
return; |
|
920 |
||
921 |
if (tt == 3) { |
|
922 |
tt = (v->direction&2)?2:1; |
|
923 |
} |
|
924 |
od.tilebits = tt; |
|
925 |
||
926 |
od.tile = v->tile; |
|
927 |
if (FindRoadVehToOvertake(&od)) |
|
928 |
return; |
|
929 |
||
900 | 930 |
od.tile = v->tile + TileOffsByDir(v->direction >> 1); |
0 | 931 |
if (FindRoadVehToOvertake(&od)) |
932 |
return; |
|
933 |
||
934 |
if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) { |
|
935 |
v->u.road.overtaking_ctr = 0x11; |
|
936 |
v->u.road.overtaking = 0x10; |
|
937 |
} else { |
|
938 |
// if (FindRoadVehToOvertake(&od)) |
|
939 |
// return; |
|
940 |
v->u.road.overtaking_ctr = 0; |
|
941 |
v->u.road.overtaking = 0x10; |
|
942 |
} |
|
943 |
} |
|
944 |
||
945 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
946 |
{ |
|
947 |
if (old_z == v->z_pos) |
|
948 |
return; |
|
949 |
||
950 |
if (old_z < v->z_pos) { |
|
951 |
v->cur_speed = v->cur_speed * 232 >> 8; |
|
952 |
} else { |
|
953 |
uint16 spd = v->cur_speed + 2; |
|
954 |
if (spd <= v->max_speed) |
|
955 |
v->cur_speed = spd; |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
static int PickRandomBit(uint bits) |
|
960 |
{ |
|
961 |
uint num = 0; |
|
962 |
uint b = bits; |
|
963 |
uint i; |
|
964 |
||
965 |
do { |
|
966 |
if (b & 1) |
|
967 |
num++; |
|
968 |
} while (b >>= 1); |
|
969 |
||
970 |
num = ((uint16)Random() * num >> 16); |
|
971 |
||
972 |
for(i=0; !((bits & 1) && ((int)--num) < 0); bits>>=1,i++); |
|
973 |
return i; |
|
974 |
} |
|
975 |
||
976 |
typedef struct { |
|
977 |
TileIndex dest; |
|
978 |
uint maxtracklen; |
|
979 |
uint mindist; |
|
980 |
} FindRoadToChooseData; |
|
981 |
||
982 |
static bool EnumRoadTrackFindDist(uint tile, FindRoadToChooseData *frd, int track, uint length, byte *state) |
|
983 |
{ |
|
984 |
uint dist = GetTileDist(tile, frd->dest); |
|
985 |
if (dist <= frd->mindist) { |
|
986 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
987 |
frd->maxtracklen = length; |
|
988 |
} |
|
989 |
frd->mindist = dist; |
|
990 |
} |
|
991 |
return false; |
|
992 |
} |
|
993 |
||
994 |
// Returns direction to choose |
|
995 |
// or -1 if the direction is currently blocked |
|
996 |
static int RoadFindPathToDest(Vehicle *v, uint tile, int direction) |
|
997 |
{ |
|
998 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
999 |
||
1000 |
uint16 signal; |
|
1001 |
uint bitmask; |
|
1002 |
uint desttile; |
|
1003 |
FindRoadToChooseData frd; |
|
1004 |
int best_track; |
|
1005 |
uint best_dist, best_maxlen; |
|
1006 |
uint i; |
|
1007 |
byte m5; |
|
1008 |
||
1009 |
{ |
|
1010 |
uint32 r; |
|
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1011 |
r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
0 | 1012 |
signal = (uint16)(r >> 16); |
1013 |
bitmask = (uint16)r; |
|
1014 |
} |
|
1015 |
||
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
|
1016 |
if (IsTileType(tile, MP_STREET)) { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1017 |
if ((_map5[tile]&0xF0) == 0x20 && v->owner == _map_owner[tile]) |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1018 |
/* Road crossing */ |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1019 |
bitmask |= _road_veh_fp_ax_or[_map5[tile]&3]; |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1020 |
} else if (IsTileType(tile, MP_STATION)) { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1021 |
if (_map_owner[tile] == OWNER_NONE || _map_owner[tile] == v->owner) { |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1022 |
/* Our station */ |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1023 |
Station *st = GetStation(_map2[tile]); |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1024 |
byte val = _map5[tile]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1025 |
if (v->cargo_type != CT_PASSENGERS) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1026 |
if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3)) |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1027 |
bitmask |= _road_veh_fp_ax_or[(val-0x43)&3]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1028 |
} else { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1029 |
if (IS_BYTE_INSIDE(val, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stops->status&3)) |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1030 |
bitmask |= _road_veh_fp_ax_or[(val-0x47)&3]; |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1031 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1032 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1033 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1034 |
/* 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
|
1035 |
* 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
|
1036 |
* 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
|
1037 |
*/ |
0 | 1038 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1039 |
/* remove unreachable tracks */ |
0 | 1040 |
bitmask &= _road_veh_fp_ax_and[direction]; |
1041 |
if (bitmask == 0) { |
|
1042 |
// reverse |
|
1043 |
return_track(_road_reverse_table[direction]); |
|
1044 |
} |
|
1045 |
||
1046 |
if (v->u.road.reverse_ctr != 0) { |
|
1047 |
v->u.road.reverse_ctr = 0; |
|
1048 |
if (v->tile != (TileIndex)tile) { |
|
1049 |
return_track(_road_reverse_table[direction]); |
|
1050 |
} |
|
1051 |
} |
|
1052 |
||
1053 |
desttile = v->dest_tile; |
|
1054 |
if (desttile == 0) { |
|
1055 |
// Pick a random direction |
|
1056 |
return_track(PickRandomBit(bitmask)); |
|
1057 |
} |
|
1058 |
||
1059 |
// Only one direction to choose between? |
|
1060 |
if (!(bitmask & (bitmask - 1))) { |
|
1061 |
return_track(FindFirstBit2x64(bitmask)); |
|
1062 |
} |
|
1063 |
||
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
|
1064 |
if (IsTileType(desttile, MP_STREET)) { |
0 | 1065 |
m5 = _map5[desttile]; |
1066 |
if ((m5&0xF0) == 0x20) |
|
1067 |
goto do_it; |
|
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
|
1068 |
} else if (IsTileType(desttile, MP_STATION)) { |
0 | 1069 |
m5 = _map5[desttile]; |
1070 |
if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) { |
|
1071 |
m5 -= 0x43; |
|
1072 |
do_it:; |
|
900 | 1073 |
desttile += TileOffsByDir(m5 & 3); |
0 | 1074 |
if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) { |
1075 |
return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3])); |
|
1076 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1077 |
} |
0 | 1078 |
} |
1079 |
// do pathfind |
|
1080 |
frd.dest = desttile; |
|
1081 |
||
1082 |
best_track = -1; |
|
1083 |
best_dist = (uint)-1; |
|
1084 |
best_maxlen = (uint)-1; |
|
1085 |
i = 0; |
|
1086 |
do { |
|
1087 |
if (bitmask & 1) { |
|
1088 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a direction |
|
1089 |
frd.maxtracklen = (uint)-1; |
|
1090 |
frd.mindist = (uint)-1; |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1091 |
FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _road_pf_directions[i], (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
0 | 1092 |
|
1093 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
|
1094 |
best_dist = frd.mindist; |
|
1095 |
best_maxlen = frd.maxtracklen; |
|
1096 |
best_track = i; |
|
1097 |
} |
|
1098 |
} |
|
1099 |
} while (++i,(bitmask>>=1) != 0); |
|
1100 |
||
1101 |
found_best_track:; |
|
1102 |
||
1103 |
if (HASBIT(signal, best_track)) |
|
1104 |
return -1; |
|
1105 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1106 |
return best_track; |
0 | 1107 |
} |
1108 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1109 |
static int RoadFindPathToStation(const Vehicle *v, TileIndex tile) |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1110 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1111 |
FindRoadToChooseData frd; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1112 |
int i, best_track = -1; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1113 |
uint best_dist = (uint) -1, best_maxlen = (uint) -1; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1114 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1115 |
frd.dest = tile; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1116 |
frd.maxtracklen = (uint) -1; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1117 |
frd.mindist = (uint) -1; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1118 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1119 |
for (i = 0; i < 4; i++) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1120 |
FollowTrack(v->tile, 0x2000 | TRANSPORT_ROAD, i, (TPFEnumProc*)EnumRoadTrackFindDist, NULL, &frd); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1121 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1122 |
if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen )) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1123 |
best_dist = frd.mindist; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1124 |
best_maxlen = frd.maxtracklen; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1125 |
best_track = i; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1126 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1127 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1128 |
return best_maxlen; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1129 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1130 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1131 |
|
0 | 1132 |
typedef struct RoadDriveEntry { |
1133 |
byte x,y; |
|
1134 |
} RoadDriveEntry; |
|
1135 |
||
1136 |
#include "table/roadveh.h" |
|
1137 |
||
1138 |
static const byte _road_veh_data_1[] = { |
|
1139 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1140 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1141 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1142 |
15, 15, 11, 11 |
|
1143 |
}; |
|
1144 |
||
1145 |
static const byte _roadveh_data_2[4] = { 0,1,8,9 }; |
|
1146 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1147 |
static inline void ClearSlot(Vehicle *v, RoadStop *rs) |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1148 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1149 |
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
|
1150 |
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
|
1151 |
rs->slot[v->u.road.slotindex] = INVALID_SLOT; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1152 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1153 |
|
0 | 1154 |
static void RoadVehEventHandler(Vehicle *v) |
1155 |
{ |
|
1156 |
GetNewVehiclePosResult gp; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1157 |
byte new_dir, old_dir; |
0 | 1158 |
RoadDriveEntry rd; |
1159 |
int x,y; |
|
1160 |
Station *st; |
|
1161 |
uint32 r; |
|
1162 |
Vehicle *u; |
|
1163 |
||
1164 |
// decrease counters |
|
1165 |
v->tick_counter++; |
|
1166 |
if (v->u.road.reverse_ctr != 0) |
|
1167 |
v->u.road.reverse_ctr--; |
|
1168 |
||
1169 |
// handle crashed |
|
1170 |
if (v->u.road.crashed_ctr != 0) { |
|
1171 |
RoadVehIsCrashed(v); |
|
1172 |
return; |
|
1173 |
} |
|
1174 |
||
1175 |
RoadVehCheckTrainCrash(v); |
|
1176 |
||
1177 |
// road vehicle has broken down? |
|
1178 |
if (v->breakdown_ctr != 0) { |
|
1179 |
if (v->breakdown_ctr <= 2) { |
|
1180 |
HandleBrokenRoadVeh(v); |
|
1181 |
return; |
|
1182 |
} |
|
1183 |
v->breakdown_ctr--; |
|
1184 |
} |
|
1185 |
||
1186 |
// exit if vehicle is stopped |
|
1187 |
if (v->vehstatus & VS_STOPPED) |
|
1188 |
return; |
|
1189 |
||
1190 |
ProcessRoadVehOrder(v); |
|
1191 |
HandleRoadVehLoading(v); |
|
1192 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1193 |
if (v->current_order.type == OT_LOADING) |
0 | 1194 |
return; |
1195 |
||
1196 |
if (v->u.road.state == 254) { |
|
1197 |
int dir; |
|
1198 |
const RoadDriveEntry*rdp; |
|
1199 |
byte rd2; |
|
1200 |
||
1201 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1202 |
|
0 | 1203 |
dir = _map5[v->tile]&3; |
1204 |
v->direction = dir*2+1; |
|
1205 |
||
1206 |
rd2 = _roadveh_data_2[dir]; |
|
1207 |
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
|
1208 |
|
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
|
1209 |
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
|
1210 |
y = TileY(v->tile) * 16 + (rdp[6].y & 0xF); |
0 | 1211 |
|
1212 |
if (RoadVehFindCloseTo(v,x,y,v->direction)) |
|
1213 |
return; |
|
1214 |
||
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
|
1215 |
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
|
1216 |
|
0 | 1217 |
StartRoadVehSound(v); |
1218 |
||
1219 |
BeginVehicleMove(v); |
|
1220 |
||
1221 |
v->vehstatus &= ~VS_HIDDEN; |
|
1222 |
v->u.road.state = rd2; |
|
1223 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1224 |
|
0 | 1225 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1226 |
UpdateRoadVehDeltaXY(v); |
|
1227 |
SetRoadVehPosition(v,x,y); |
|
1228 |
||
1229 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
1230 |
return; |
|
1231 |
} |
|
1232 |
||
1233 |
if (!RoadVehAccelerate(v)) |
|
1234 |
return; |
|
1235 |
||
1236 |
if (v->u.road.overtaking != 0) { |
|
1237 |
if (++v->u.road.overtaking_ctr >= 35) |
|
1238 |
v->u.road.overtaking = 0; |
|
1239 |
} |
|
1240 |
||
1241 |
BeginVehicleMove(v); |
|
1242 |
||
1243 |
if (v->u.road.state == 255) { |
|
1244 |
GetNewVehiclePos(v, &gp); |
|
1245 |
||
1246 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction)) { |
|
1247 |
v->cur_speed = 0; |
|
1248 |
return; |
|
1249 |
} |
|
1250 |
||
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
|
1251 |
if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && |
0 | 1252 |
(_map5[gp.new_tile]&0xF0) == 0 && |
1253 |
(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
|
1254 |
|
0 | 1255 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1256 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1257 |
UpdateRoadVehDeltaXY(v); |
|
1258 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1259 |
return; |
|
1260 |
} |
|
1261 |
||
1262 |
v->x_pos = gp.x; |
|
1263 |
v->y_pos = gp.y; |
|
1264 |
VehiclePositionChanged(v); |
|
1265 |
return; |
|
1266 |
} |
|
1267 |
||
1268 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side<<4)) ^ v->u.road.overtaking][v->u.road.frame+1]; |
|
1269 |
||
1270 |
// switch to another tile |
|
1271 |
if (rd.x & 0x80) { |
|
900 | 1272 |
uint tile = v->tile + TileOffsByDir(rd.x & 3); |
0 | 1273 |
int dir = RoadFindPathToDest(v, tile, rd.x&3); |
1274 |
int tmp; |
|
1275 |
uint32 r; |
|
1276 |
byte newdir; |
|
1277 |
const RoadDriveEntry *rdp; |
|
1278 |
||
1279 |
if (dir == -1) { |
|
1280 |
v->cur_speed = 0; |
|
1281 |
return; |
|
1282 |
} |
|
1283 |
||
1284 |
again: |
|
1285 |
if ((dir & 7) >= 6) { |
|
1286 |
tile = v->tile; |
|
1287 |
} |
|
1288 |
||
1289 |
tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking; |
|
1290 |
rdp = _road_drive_data[tmp]; |
|
1291 |
||
1292 |
tmp &= ~0x10; |
|
1293 |
||
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
|
1294 |
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
|
1295 |
y = TileY(tile) * 16 + rdp[0].y; |
0 | 1296 |
|
1297 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1298 |
return; |
|
1299 |
||
1300 |
r = VehicleEnterTile(v, tile, x, y); |
|
1301 |
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
|
1302 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1303 |
v->cur_speed = 0; |
1304 |
return; |
|
1305 |
} |
|
1306 |
dir = _road_reverse_table[rd.x&3]; |
|
1307 |
goto again; |
|
1308 |
} |
|
1309 |
||
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1310 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
0 | 1311 |
if ((tmp&7) >= 6) { v->cur_speed = 0; return; } |
1312 |
if (IS_BYTE_INSIDE(_map5[v->tile], 0x43, 0x4B)) { |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1313 |
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
|
1314 |
byte *b = &rs->status; |
0 | 1315 |
|
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1316 |
//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
|
1317 |
//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
|
1318 |
*b = (*b | ((v->u.road.state&2)?2:1)) & ~0x80; |
0 | 1319 |
} |
1320 |
} |
|
1321 |
||
1322 |
if (!(r & 4)) { |
|
1323 |
v->tile = tile; |
|
1324 |
v->u.road.state = (byte)tmp; |
|
1325 |
v->u.road.frame = 0; |
|
1326 |
} |
|
1327 |
if (newdir != v->direction) { |
|
1328 |
v->direction = newdir; |
|
1329 |
v->cur_speed -= v->cur_speed >> 2; |
|
1330 |
} |
|
1331 |
||
1332 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1333 |
UpdateRoadVehDeltaXY(v); |
|
1334 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1335 |
return; |
|
1336 |
} |
|
1337 |
||
1338 |
if (rd.x & 0x40) { |
|
1339 |
int dir = RoadFindPathToDest(v, v->tile, rd.x&3); |
|
1340 |
uint32 r; |
|
1341 |
int tmp; |
|
1342 |
byte newdir; |
|
1343 |
const RoadDriveEntry *rdp; |
|
1344 |
||
1345 |
if (dir == -1) { |
|
1346 |
v->cur_speed = 0; |
|
1347 |
return; |
|
1348 |
} |
|
1349 |
||
1350 |
tmp = (_opt.road_side<<4) + dir; |
|
1351 |
rdp = _road_drive_data[tmp]; |
|
1352 |
||
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
|
1353 |
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
|
1354 |
y = TileY(v->tile) * 16 + rdp[1].y; |
0 | 1355 |
|
1356 |
if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y))) |
|
1357 |
return; |
|
1358 |
||
1359 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1360 |
if (r & 8) { |
|
1361 |
v->cur_speed = 0; |
|
1362 |
return; |
|
1363 |
} |
|
1364 |
||
1365 |
v->u.road.state = tmp & ~16; |
|
1366 |
v->u.road.frame = 1; |
|
1367 |
||
1368 |
if (newdir != v->direction) { |
|
1369 |
v->direction = newdir; |
|
1370 |
v->cur_speed -= v->cur_speed >> 2; |
|
1371 |
} |
|
1372 |
||
1373 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1374 |
UpdateRoadVehDeltaXY(v); |
|
1375 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1376 |
return; |
|
1377 |
} |
|
1378 |
||
1379 |
x = (v->x_pos&~15)+(rd.x&15); |
|
1380 |
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
|
1381 |
|
0 | 1382 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1383 |
||
1384 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) { |
|
1385 |
if (v->u.road.overtaking == 0) |
|
1386 |
RoadVehCheckOvertake(v, u); |
|
1387 |
return; |
|
1388 |
} |
|
1389 |
||
1390 |
old_dir = v->direction; |
|
1391 |
if (new_dir != old_dir) { |
|
1392 |
v->direction = new_dir; |
|
1393 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1394 |
if (old_dir != v->u.road.state) { |
|
1395 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1396 |
UpdateRoadVehDeltaXY(v); |
|
1397 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1398 |
return; |
|
1399 |
} |
|
1400 |
} |
|
1401 |
||
1402 |
if (v->u.road.state >= 0x20 && |
|
1403 |
_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
|
1404 |
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
|
1405 |
byte *b = &rs->status; |
0 | 1406 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1407 |
st = GetStation(_map2[v->tile]); |
0 | 1408 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1409 |
if (v->current_order.type != OT_LEAVESTATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1410 |
v->current_order.type != OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1411 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1412 |
|
0 | 1413 |
*b &= ~0x80; |
1414 |
||
1415 |
v->last_station_visited = _map2[v->tile]; |
|
1416 |
||
1417 |
RoadVehArrivesAt(v, st); |
|
1418 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1419 |
old_order = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1420 |
v->current_order.type = OT_LOADING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1421 |
v->current_order.flags = 0; |
0 | 1422 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1423 |
if (old_order.type == OT_GOTO_STATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1424 |
v->current_order.station == v->last_station_visited) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1425 |
v->current_order.flags = |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1426 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP; |
0 | 1427 |
} |
1428 |
||
1429 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
1430 |
if (LoadUnloadVehicle(v)) { |
|
1431 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
|
1432 |
MarkRoadVehDirty(v); |
|
1433 |
} |
|
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
|
1434 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1435 |
return; |
1436 |
} |
|
1437 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1438 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
0 | 1439 |
if (*b&0x80) { |
1440 |
v->cur_speed = 0; |
|
1441 |
return; |
|
1442 |
} |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1443 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1444 |
v->current_order.flags = 0; |
0 | 1445 |
} |
1446 |
*b |= 0x80; |
|
1447 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1448 |
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
|
1449 |
//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
|
1450 |
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
|
1451 |
} 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
|
1452 |
//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
|
1453 |
//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
|
1454 |
//but I guess we need to clear the slot |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1455 |
DEBUG(misc, 2) ("Multistop: Wrong station, force a slot clearing"); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1456 |
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
|
1457 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1458 |
|
0 | 1459 |
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
|
1460 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1461 |
} |
1462 |
||
1463 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1464 |
if (r & 8) { |
|
1465 |
v->cur_speed = 0; |
|
1466 |
return; |
|
1467 |
} |
|
1468 |
||
1469 |
if ((r & 4) == 0) { |
|
1470 |
v->u.road.frame++; |
|
1471 |
} |
|
1472 |
||
1473 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1474 |
UpdateRoadVehDeltaXY(v); |
|
1475 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1476 |
} |
|
1477 |
||
1478 |
void RoadVehEnterDepot(Vehicle *v) |
|
1479 |
{ |
|
1480 |
v->u.road.state = 254; |
|
1481 |
v->vehstatus |= VS_HIDDEN; |
|
1482 |
||
1483 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1484 |
||
842 | 1485 |
MaybeReplaceVehicle(v); |
0 | 1486 |
|
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
|
1487 |
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
|
1488 |
|
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
|
1489 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1490 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1491 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1492 |
Order t; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1493 |
|
0 | 1494 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1495 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1496 |
t = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1497 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1498 |
v->current_order.flags = 0; |
0 | 1499 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1500 |
// Part of the orderlist? |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1501 |
if (t.flags & OF_UNLOAD) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1502 |
v->cur_order_index++; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1503 |
} else if (t.flags & OF_FULL_LOAD) { |
0 | 1504 |
v->vehstatus |= VS_STOPPED; |
1505 |
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
|
1506 |
SetDParam(0, v->unitnumber); |
0 | 1507 |
AddNewsItem( |
1508 |
STR_9016_ROAD_VEHICLE_IS_WAITING, |
|
1509 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
1510 |
v->index, |
|
1511 |
0); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
} |
|
1515 |
||
1516 |
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
|
1517 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1518 |
} |
1519 |
||
1520 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1521 |
{ |
|
1522 |
if (_age_cargo_skip_counter != 0) |
|
1523 |
return; |
|
1524 |
if (v->cargo_days != 255) |
|
1525 |
v->cargo_days++; |
|
1526 |
} |
|
1527 |
||
1528 |
void RoadVeh_Tick(Vehicle *v) |
|
1529 |
{ |
|
1530 |
AgeRoadVehCargo(v); |
|
1531 |
RoadVehEventHandler(v); |
|
1532 |
} |
|
1533 |
||
1534 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1535 |
{ |
|
1536 |
int i; |
|
1537 |
||
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1538 |
if (_patches.servint_roadveh == 0 && !v->set_for_replacement) |
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
|
1539 |
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
|
1540 |
|
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1541 |
if (!VehicleNeedsService(v) && !v->set_for_replacement) |
0 | 1542 |
return; |
1543 |
||
1544 |
if (v->vehstatus & VS_STOPPED) |
|
1545 |
return; |
|
1546 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
1547 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) |
0 | 1548 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1549 |
|
0 | 1550 |
// Don't interfere with a depot visit scheduled by the user, or a |
1551 |
// depot visit by the order list. |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1552 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1553 |
(v->current_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) != 0) |
0 | 1554 |
return; |
1555 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1556 |
//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
|
1557 |
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
|
1558 |
return; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1559 |
|
0 | 1560 |
i = FindClosestRoadDepot(v); |
1561 |
||
1562 |
if (i < 0 || GetTileDist(v->tile, (&_depots[i])->xy) > 12) { |
|
1203
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1563 |
if (v->current_order.type == OT_GOTO_DEPOT && !( |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1564 |
GetTileDist(v->tile, v->dest_tile) > 25 && v->set_for_replacement)) { |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1565 |
/* a vehicle needs a greater distance to a depot to loose it than to find it since |
c95a16972da5
(svn r1707) - Feature: [autoreplace] road vehicles now tries to find a depot if they needs to be replaced
bjarni
parents:
1197
diff
changeset
|
1566 |
they can circle forever othervise if they are in a loop with an unlucky distance */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1567 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1568 |
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
|
1569 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1570 |
} |
1571 |
return; |
|
1572 |
} |
|
1573 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1574 |
if (v->current_order.type == OT_GOTO_DEPOT && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1575 |
v->current_order.flags & OF_NON_STOP && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1576 |
!CHANCE16(1,20)) |
0 | 1577 |
return; |
1578 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1579 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1580 |
v->current_order.flags = OF_NON_STOP; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1581 |
v->current_order.station = (byte)i; |
0 | 1582 |
v->dest_tile = (&_depots[i])->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
|
1583 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1584 |
} |
1585 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1586 |
int dist_compare(const void *a, const void *b) |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1587 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1588 |
return ( *(const uint32 *)a) - ( *(const uint32 *) b); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1589 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1590 |
|
0 | 1591 |
void OnNewDay_RoadVeh(Vehicle *v) |
1592 |
{ |
|
1593 |
int32 cost; |
|
1594 |
Station *st; |
|
1595 |
||
1596 |
if ((++v->day_counter & 7) == 0) |
|
1597 |
DecreaseVehicleValue(v); |
|
1598 |
||
1599 |
if (v->u.road.unk2 == 0) |
|
1600 |
CheckVehicleBreakdown(v); |
|
1601 |
||
1602 |
AgeVehicle(v); |
|
1603 |
CheckIfRoadVehNeedsService(v); |
|
1604 |
||
1053
dfb5243315f1
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1035
diff
changeset
|
1605 |
CheckOrders(v->index, OC_INIT); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1606 |
|
0 | 1607 |
/* update destination */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1608 |
if (v->current_order.type == OT_GOTO_STATION) { |
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1609 |
RoadStop *rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1610 |
uint32 mindist = 0xFFFFFFFF; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1611 |
int num; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1612 |
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
|
1613 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1614 |
typedef struct { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1615 |
uint32 dist; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1616 |
RoadStop *rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1617 |
} StopStruct; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1618 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1619 |
StopStruct *stop, *firststop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1620 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
1621 |
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
|
1622 |
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
|
1623 |
num = GetNumRoadStops(st, type); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1624 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1625 |
firststop = stop = malloc(num * sizeof(StopStruct)); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1626 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1627 |
//Current slot has expired |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1628 |
if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL)) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1629 |
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
|
1630 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1631 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1632 |
//We do not have a slot, so make one |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1633 |
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
|
1634 |
//first we need to find out how far our stations are away. |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1635 |
assert( rs != NULL); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1636 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1637 |
do { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1638 |
stop->dist = 0xFFFFFFFF; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1639 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1640 |
//FIXME This doesn't fully work yet, as it only goes |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1641 |
//to one tile BEFORE the stop in question and doesn't |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1642 |
//regard the direction of the exit |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1643 |
stop->dist = RoadFindPathToStation(v, rs->xy); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1644 |
stop->rs = rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1645 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1646 |
if (stop->dist < mindist) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1647 |
mindist = stop->dist; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1648 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1649 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1650 |
stop++; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1651 |
rs = rs->next; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1652 |
} while (rs != NULL); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1653 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1654 |
if (mindist < 120) { //if we're reasonably close, get us a slot |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1655 |
int k; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1656 |
bubblesort(firststop, num, sizeof(StopStruct), dist_compare); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1657 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1658 |
stop = firststop; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1659 |
for (k = 0; k < num; k++) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1660 |
int i; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1661 |
for (i = 0; i < NUM_SLOTS; i++) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1662 |
if ((stop->rs->slot[i] == INVALID_SLOT) && (stop->dist < 120)) { |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1663 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1664 |
//Hooray we found a free slot. Assign it |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1665 |
stop->rs->slot[i] = v->index; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1666 |
v->u.road.slot = stop->rs; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1667 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1668 |
v->dest_tile = stop->rs->xy; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1669 |
v->u.road.slot_age = -30; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1670 |
v->u.road.slotindex = i; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1671 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1672 |
goto have_slot; //jump out of BOTH loops |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1673 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1674 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1675 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1676 |
stop++; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1677 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1678 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1679 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1680 |
have_slot: |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1681 |
//now we couldn't assign a slot for one reason or another. |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1682 |
//so we just go to the nearest station |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1683 |
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
|
1684 |
v->dest_tile = firststop->rs->xy; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1685 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1686 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1687 |
free(firststop); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1688 |
firststop = stop = NULL; |
0 | 1689 |
} |
1690 |
||
1691 |
if (v->vehstatus & VS_STOPPED) |
|
1692 |
return; |
|
1693 |
||
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1694 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1695 |
|
1696 |
v->profit_this_year -= cost >> 8; |
|
1697 |
||
1698 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1699 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1700 |
||
1701 |
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
|
1702 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1703 |
} |
1704 |
||
1705 |
void HandleClickOnRoadVeh(Vehicle *v) |
|
1706 |
{ |
|
1707 |
ShowRoadVehViewWindow(v); |
|
1708 |
} |
|
1709 |
||
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
|
1710 |
void RoadVehiclesYearlyLoop(void) |
0 | 1711 |
{ |
1712 |
Vehicle *v; |
|
1713 |
||
1714 |
FOR_ALL_VEHICLES(v) { |
|
1715 |
if (v->type == VEH_Road) { |
|
1716 |
v->profit_last_year = v->profit_this_year; |
|
1717 |
v->profit_this_year = 0; |
|
1718 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1719 |
} |
|
1720 |
} |
|
1721 |
} |
|
1722 |