author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5876 | 01bdebe2e50b |
child 5910 | f1409c7e8a87 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
3508
b685e9157aef
(svn r4359) MSV6 Release mode now compiles (problem of UINT_MAX. stdafx.h should be the first include). Thanks to KUDr for solution and testing
belugas
parents:
3491
diff
changeset
|
3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1793
diff
changeset
|
4 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1295
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2150
diff
changeset
|
6 |
#include "functions.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3140
diff
changeset
|
7 |
#include "road_map.h" |
3959 | 8 |
#include "roadveh.h" |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
9 |
#include "station_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
493
diff
changeset
|
10 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
11 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
12 |
#include "tile.h" |
0 | 13 |
#include "vehicle.h" |
14 |
#include "engine.h" |
|
15 |
#include "command.h" |
|
16 |
#include "station.h" |
|
17 |
#include "news.h" |
|
18 |
#include "pathfind.h" |
|
1247 | 19 |
#include "npf.h" |
0 | 20 |
#include "player.h" |
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
241
diff
changeset
|
21 |
#include "sound.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
22 |
#include "depot.h" |
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
23 |
#include "bridge.h" |
3184
118a520164e4
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3169
diff
changeset
|
24 |
#include "tunnel_map.h" |
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
25 |
#include "bridge_map.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1745
diff
changeset
|
26 |
#include "vehicle_gui.h" |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
27 |
#include "newgrf_callbacks.h" |
2962
f0a49b646c48
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2954
diff
changeset
|
28 |
#include "newgrf_engine.h" |
4244
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
29 |
#include "newgrf_text.h" |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
30 |
#include "newgrf_sound.h" |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
31 |
#include "yapf/yapf.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4244
diff
changeset
|
32 |
#include "date.h" |
0 | 33 |
|
34 |
static const uint16 _roadveh_images[63] = { |
|
35 |
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
|
36 |
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
|
37 |
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
|
38 |
0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, |
|
39 |
0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, |
|
40 |
0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, |
|
41 |
0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, |
|
42 |
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 |
|
43 |
}; |
|
44 |
||
45 |
static const uint16 _roadveh_full_adder[63] = { |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
46 |
0, 88, 0, 0, 0, 0, 48, 48, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
47 |
48, 48, 0, 0, 64, 64, 0, 16, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
48 |
16, 0, 88, 0, 0, 0, 0, 48, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
49 |
48, 48, 48, 0, 0, 64, 64, 0, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
50 |
16, 16, 0, 88, 0, 0, 0, 0, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
51 |
48, 48, 48, 48, 0, 0, 64, 64, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
52 |
0, 16, 16, 0, 8, 8, 8, 8, |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
53 |
0, 0, 0, 8, 8, 8, 8 |
0 | 54 |
}; |
55 |
||
56 |
||
57 |
static const uint16 _road_veh_fp_ax_and[4] = { |
|
58 |
0x1009, 0x16, 0x520, 0x2A00 |
|
59 |
}; |
|
60 |
||
61 |
static const byte _road_reverse_table[4] = { |
|
62 |
6, 7, 14, 15 |
|
63 |
}; |
|
64 |
||
65 |
static const uint16 _road_pf_table_3[4] = { |
|
66 |
0x910, 0x1600, 0x2005, 0x2A |
|
67 |
}; |
|
68 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
69 |
int GetRoadVehImage(const Vehicle* v, Direction direction) |
0 | 70 |
{ |
71 |
int img = v->spritenum; |
|
72 |
int image; |
|
73 |
||
74 |
if (is_custom_sprite(img)) { |
|
75 |
image = GetCustomVehicleSprite(v, direction); |
|
2989 | 76 |
if (image != 0) return image; |
2464
e3054f0f0627
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2260
diff
changeset
|
77 |
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index; |
0 | 78 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
79 |
|
0 | 80 |
image = direction + _roadveh_images[img]; |
2989 | 81 |
if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img]; |
0 | 82 |
return image; |
83 |
} |
|
84 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
85 |
void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal) |
0 | 86 |
{ |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
87 |
int spritenum = RoadVehInfo(engine)->image_index; |
378
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
88 |
|
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
89 |
if (is_custom_sprite(spritenum)) { |
3186
4317b5b295c4
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
90 |
int sprite = GetCustomVehicleIcon(engine, DIR_W); |
378
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
91 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
92 |
if (sprite != 0) { |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
93 |
DrawSprite(sprite, pal, x, y); |
378
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
94 |
return; |
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
95 |
} |
2464
e3054f0f0627
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2260
diff
changeset
|
96 |
spritenum = orig_road_vehicle_info[engine - ROAD_ENGINES_INDEX].image_index; |
378
3f1eef0eb2c0
(svn r567) -newgrf: Support for road vehicles customization (seems to work at
celestar
parents:
374
diff
changeset
|
97 |
} |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5651
diff
changeset
|
98 |
DrawSprite(6 + _roadveh_images[spritenum], pal, x, y); |
0 | 99 |
} |
100 |
||
2817 | 101 |
static int32 EstimateRoadVehCost(EngineID engine_type) |
0 | 102 |
{ |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
103 |
return ((_price.roadveh_base >> 3) * RoadVehInfo(engine_type)->base_cost) >> 5; |
0 | 104 |
} |
105 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
106 |
/** Build a road vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
107 |
* @param tile tile of depot where road vehicle is built |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
108 |
* @param p1 bus/truck type being built (engine) |
3816
28ee8b8c2522
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3793
diff
changeset
|
109 |
* @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
110 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
111 |
int32 CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 112 |
{ |
113 |
int32 cost; |
|
114 |
Vehicle *v; |
|
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
115 |
UnitID unit_num; |
0 | 116 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
117 |
|
5215
b8fb685df4c5
(svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents:
5211
diff
changeset
|
118 |
if (!IsEngineBuildable(p1, VEH_Road, _current_player)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE); |
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
119 |
|
0 | 120 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
121 |
||
122 |
cost = EstimateRoadVehCost(p1); |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
123 |
if (flags & DC_QUERY_COST) return cost; |
0 | 124 |
|
1442
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
125 |
/* The ai_new queries the vehicle cost before building the route, |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
126 |
* so we must check against cheaters no sooner than now. --pasky */ |
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
127 |
if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return CMD_ERROR; |
1901
03bf9bf99319
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
128 |
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
1442
a166ae688746
(svn r1946) Fix: [AInew] Allow DC_QUERY_COST even on tiles with no depot built. This is used by the ai_new for deciding if it can afford the vehicles before actually building the depot. Was broken in r1728. Signed-Off-By: TrueLight ;-)
pasky
parents:
1401
diff
changeset
|
129 |
|
0 | 130 |
v = AllocateVehicle(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
131 |
if (v == NULL || IsOrderPoolFull()) |
0 | 132 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
133 |
||
134 |
/* find the first free roadveh id */ |
|
4095
ad7a6bc2bf80
(svn r5427) - Codechange: testing for "== true" is redundant.
peter1138
parents:
4077
diff
changeset
|
135 |
unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_Road); |
0 | 136 |
if (unit_num > _patches.max_roadveh) |
137 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
|
138 |
||
139 |
if (flags & DC_EXEC) { |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
140 |
int x; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
141 |
int y; |
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
142 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
143 |
const RoadVehicleInfo *rvi = RoadVehInfo(p1); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
144 |
|
0 | 145 |
v->unitnumber = unit_num; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
146 |
v->direction = INVALID_DIR; |
0 | 147 |
v->owner = _current_player; |
148 |
||
149 |
v->tile = tile; |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3630
diff
changeset
|
150 |
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3630
diff
changeset
|
151 |
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
0 | 152 |
v->x_pos = x; |
153 |
v->y_pos = y; |
|
154 |
v->z_pos = GetSlopeZ(x,y); |
|
155 |
v->z_height = 6; |
|
156 |
||
157 |
v->u.road.state = 254; |
|
158 |
v->vehstatus = VS_HIDDEN|VS_STOPPED|VS_DEFPAL; |
|
159 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
160 |
v->spritenum = rvi->image_index; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
161 |
v->cargo_type = rvi->cargo_type; |
3870
d9ebc4ea750a
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
162 |
v->cargo_subtype = 0; |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
163 |
v->cargo_cap = rvi->capacity; |
0 | 164 |
// v->cargo_count = 0; |
165 |
v->value = cost; |
|
166 |
// v->day_counter = 0; |
|
167 |
// v->next_order_param = v->next_order = 0; |
|
168 |
// v->load_unload_time_rem = 0; |
|
169 |
// v->progress = 0; |
|
170 |
||
171 |
// v->u.road.unk2 = 0; |
|
172 |
// v->u.road.overtaking = 0; |
|
173 |
||
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
174 |
v->last_station_visited = INVALID_STATION; |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
175 |
v->max_speed = rvi->max_speed; |
0 | 176 |
v->engine_type = (byte)p1; |
177 |
||
1926
530480d14685
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
178 |
e = GetEngine(p1); |
0 | 179 |
v->reliability = e->reliability; |
180 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
181 |
v->max_age = e->lifelength * 366; |
|
2564 | 182 |
_new_vehicle_id = v->index; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
183 |
|
0 | 184 |
v->string_id = STR_SV_ROADVEH_NAME; |
185 |
||
186 |
v->service_interval = _patches.servint_roadveh; |
|
187 |
||
188 |
v->date_of_last_service = _date; |
|
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
189 |
v->build_year = _cur_year; |
0 | 190 |
|
191 |
v->type = VEH_Road; |
|
192 |
v->cur_image = 0xC15; |
|
2804
ea4080819175
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2767
diff
changeset
|
193 |
v->random_bits = VehicleRandomBits(); |
0 | 194 |
|
195 |
VehiclePositionChanged(v); |
|
4574
61a17f80cfb9
(svn r6424) -Codechange: [autoreplace] removed a loop though all vehicles from each time the window is redrawn
bjarni
parents:
4559
diff
changeset
|
196 |
GetPlayer(_current_player)->num_engines[p1]++; |
0 | 197 |
|
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4725
diff
changeset
|
198 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
588 | 199 |
RebuildVehicleLists(); |
0 | 200 |
InvalidateWindow(WC_COMPANY, v->owner); |
2618
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
201 |
if (IsLocalPlayer()) |
9691753519ac
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
202 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); // updates the replace Road window |
0 | 203 |
} |
204 |
||
205 |
return cost; |
|
206 |
} |
|
207 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
208 |
/** Start/Stop a road vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
209 |
* @param tile unused |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
210 |
* @param p1 road vehicle ID to start/stop |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
211 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
212 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
213 |
int32 CmdStartStopRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 214 |
{ |
215 |
Vehicle *v; |
|
4244
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
216 |
uint16 callback; |
0 | 217 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
218 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
219 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
220 |
v = GetVehicle(p1); |
0 | 221 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
222 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 223 |
|
4244
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
224 |
/* Check if this road veh can be started/stopped. The callback will fail or |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
225 |
* return 0xFF if it can. */ |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
226 |
callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
227 |
if (callback != CALLBACK_FAILED && callback != 0xFF) { |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
228 |
StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
229 |
return_cmd_error(error); |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
230 |
} |
d40c73c55357
(svn r5822) - NewGRF: add support for callback 31, vehicle start/stop check. This allows a set to disallow a vehicle from being started, i.e. to not be able to leave the depot. This is almost a partner to callback 1D.
peter1138
parents:
4242
diff
changeset
|
231 |
|
0 | 232 |
if (flags & DC_EXEC) { |
3959 | 233 |
if (IsRoadVehInDepotStopped(v)) { |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
234 |
DeleteVehicleNews(p1, STR_9016_ROAD_VEHICLE_IS_WAITING); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
235 |
} |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3138
diff
changeset
|
236 |
|
0 | 237 |
v->vehstatus ^= VS_STOPPED; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
238 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 239 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
240 |
} |
|
241 |
||
242 |
return 0; |
|
243 |
} |
|
244 |
||
3123 | 245 |
void ClearSlot(Vehicle *v) |
1664
1f909247678d
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
246 |
{ |
3123 | 247 |
RoadStop *rs = v->u.road.slot; |
248 |
if (v->u.road.slot == NULL) return; |
|
249 |
||
1664
1f909247678d
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
250 |
v->u.road.slot = NULL; |
1f909247678d
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
251 |
v->u.road.slot_age = 0; |
3123 | 252 |
|
3431 | 253 |
assert(rs->num_vehicles != 0); |
254 |
rs->num_vehicles--; |
|
255 |
||
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
256 |
DEBUG(ms, 3, "Clearing slot at 0x%X", rs->xy); |
1664
1f909247678d
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
257 |
} |
1f909247678d
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Darkvater
parents:
1530
diff
changeset
|
258 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
259 |
/** Sell a road vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
260 |
* @param tile unused |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
261 |
* @param p1 vehicle ID to be sold |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
262 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
263 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
264 |
int32 CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 265 |
{ |
266 |
Vehicle *v; |
|
267 |
||
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
268 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
269 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
270 |
v = GetVehicle(p1); |
0 | 271 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
272 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 273 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
274 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
275 |
|
3959 | 276 |
if (!IsRoadVehInDepotStopped(v)) { |
0 | 277 |
return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
278 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
279 |
|
0 | 280 |
if (flags & DC_EXEC) { |
281 |
// Invalidate depot |
|
282 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 283 |
RebuildVehicleLists(); |
0 | 284 |
InvalidateWindow(WC_COMPANY, v->owner); |
285 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
5256
9056fd4b30f4
(svn r7386) -Codechange r7385: moved deletion of the vehicle highlight from DeleteVehicle to the sell commands as they are not called as often
bjarni
parents:
5215
diff
changeset
|
286 |
DeleteDepotHighlightOfVehicle(v); |
0 | 287 |
DeleteVehicle(v); |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
288 |
if (IsLocalPlayer()) InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Road); |
0 | 289 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
290 |
|
0 | 291 |
return -(int32)v->value; |
292 |
} |
|
293 |
||
294 |
typedef struct RoadFindDepotData { |
|
295 |
uint best_length; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
296 |
TileIndex tile; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
297 |
OwnerByte owner; |
0 | 298 |
} RoadFindDepotData; |
299 |
||
3186
4317b5b295c4
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3184
diff
changeset
|
300 |
static const DiagDirection _road_pf_directions[] = { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
301 |
DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, INVALID_DIAGDIR, INVALID_DIAGDIR, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
302 |
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, INVALID_DIAGDIR, INVALID_DIAGDIR |
0 | 303 |
}; |
304 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
305 |
static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state) |
0 | 306 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
307 |
RoadFindDepotData* rfdd = (RoadFindDepotData*)data; |
3137 | 308 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
309 |
tile += TileOffsByDiagDir(_road_pf_directions[trackdir]); |
0 | 310 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
311 |
if (IsTileType(tile, MP_STREET) && |
3793
7fe24e10ea63
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3645
diff
changeset
|
312 |
GetRoadTileType(tile) == ROAD_TILE_DEPOT && |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
313 |
IsTileOwner(tile, rfdd->owner) && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
314 |
length < rfdd->best_length) { |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
315 |
rfdd->best_length = length; |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
316 |
rfdd->tile = tile; |
0 | 317 |
} |
318 |
return false; |
|
319 |
} |
|
320 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
321 |
static const Depot* FindClosestRoadDepot(const Vehicle* v) |
0 | 322 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
323 |
TileIndex tile = v->tile; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
324 |
|
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
325 |
if (_patches.yapf.road_use_yapf) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
326 |
Depot* ret = YapfFindNearestRoadDepot(v); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
327 |
return ret; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
328 |
} else if (_patches.new_pathfinding_all) { |
1247 | 329 |
NPFFoundTargetData ftd; |
330 |
/* See where we are now */ |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
331 |
Trackdir trackdir = GetVehicleTrackdir(v); |
1745
1113e1272ca2
(svn r2249) - Fix: [ 1187703 ] [NPF] Road vehicles cannot find a depot when in a roadstop
matthijs
parents:
1709
diff
changeset
|
332 |
|
2006
9d5d7fd428c2
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1998
diff
changeset
|
333 |
ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
334 |
if (ftd.best_bird_dist == 0) { |
1247 | 335 |
return GetDepotByTile(ftd.node.tile); /* Target found */ |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
336 |
} else { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
337 |
return NULL; /* Target not found */ |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
338 |
} |
1247 | 339 |
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ |
340 |
} else { |
|
341 |
RoadFindDepotData rfdd; |
|
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
342 |
|
1247 | 343 |
rfdd.owner = v->owner; |
344 |
rfdd.best_length = (uint)-1; |
|
0 | 345 |
|
1247 | 346 |
/* search in all directions */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
347 |
for (DiagDirection i = DIAGDIR_BEGIN; i != DIAGDIR_END; i++) { |
3137 | 348 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, i, EnumRoadSignalFindDepot, NULL, &rfdd); |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
349 |
} |
0 | 350 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
351 |
if (rfdd.best_length == (uint)-1) return NULL; |
0 | 352 |
|
1247 | 353 |
return GetDepotByTile(rfdd.tile); |
354 |
} |
|
0 | 355 |
} |
356 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
357 |
/** Send a road vehicle to the depot. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
358 |
* @param tile unused |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
359 |
* @param p1 vehicle ID to send to the depot |
4451
2e86da0081b5
(svn r6229) -Feature: Shared order lists now got a "goto depot" button
bjarni
parents:
4445
diff
changeset
|
360 |
* @param p2 various bitmasked elements |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
361 |
* - p2 bit 0-3 - DEPOT_ flags (see vehicle.h) |
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
362 |
* - p2 bit 8-10 - VLW flag (for mass goto depot) |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
363 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
364 |
int32 CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 365 |
{ |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
366 |
Vehicle *v; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
367 |
const Depot *dep; |
0 | 368 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
369 |
if (p2 & DEPOT_MASS_SEND) { |
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
370 |
/* Mass goto depot requested */ |
4546
507b7d9bd834
(svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents:
4544
diff
changeset
|
371 |
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
507b7d9bd834
(svn r6378) -Codechange: Rename VLW_FLAGS to VLW_MASK as it is a mask
Darkvater
parents:
4544
diff
changeset
|
372 |
return SendAllVehiclesToDepot(VEH_Road, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1); |
4463
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
373 |
} |
4d67d3a36fc5
(svn r6246) -Feature: added the many times requested "send all vehicle to depot" button
bjarni
parents:
4451
diff
changeset
|
374 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
375 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
376 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
377 |
v = GetVehicle(p1); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
378 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
379 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 380 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
381 |
if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
1757
89f63a75ffd2
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
382 |
|
4526 | 383 |
if (IsRoadVehInDepot(v)) return CMD_ERROR; |
384 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
385 |
/* If the current orders are already goto-depot */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
386 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
4519
f53d829de680
(svn r6304) -Codechange r6295: Use !! instead of (bool) in commands to send vehicles to depots
bjarni
parents:
4510
diff
changeset
|
387 |
if (!!(p2 & DEPOT_SERVICE) == HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT)) { |
4510
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
388 |
/* We called with a different DEPOT_SERVICE setting. |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
389 |
* Now we change the setting to apply the new one and let the vehicle head for the same depot. |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4546
diff
changeset
|
390 |
* Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
4510
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
391 |
if (flags & DC_EXEC) { |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
392 |
TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
393 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
394 |
} |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
395 |
return 0; |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
396 |
} |
54d30a2372c3
(svn r6295) -Feature: using goto depot with a different control selection will now alter the service/stopping in depot flag instead of cancelling the goto depot order
bjarni
parents:
4506
diff
changeset
|
397 |
|
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
398 |
if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders |
0 | 399 |
if (flags & DC_EXEC) { |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
400 |
/* If the orders to 'goto depot' are in the orders list (forced servicing), |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
401 |
* then skip to the next order; effectively cancelling this forced service */ |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
402 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
0 | 403 |
v->cur_order_index++; |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
404 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
405 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
406 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
407 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 408 |
} |
409 |
return 0; |
|
410 |
} |
|
411 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
412 |
dep = FindClosestRoadDepot(v); |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
413 |
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT); |
0 | 414 |
|
415 |
if (flags & DC_EXEC) { |
|
3236 | 416 |
ClearSlot(v); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
417 |
v->current_order.type = OT_GOTO_DEPOT; |
4412
cae52239a576
(svn r6165) -Feature: control click Goto Depot will now make the vehicle service
bjarni
parents:
4389
diff
changeset
|
418 |
v->current_order.flags = OF_NON_STOP; |
4506
e6a56518135c
(svn r6291) -Feature: Vehicle lists from the station window now also got the goto depot button
bjarni
parents:
4463
diff
changeset
|
419 |
if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT); |
5259
9d7de9a6b364
(svn r7389) -Fix: when forcing a vehicle to go to a depot, clear refit orders from current orders (caused refit error popup when not having no orders)
bjarni
parents:
5256
diff
changeset
|
420 |
v->current_order.refit_cargo = CT_INVALID; |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
421 |
v->current_order.dest = dep->index; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
422 |
v->dest_tile = dep->xy; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
423 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 424 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
425 |
|
0 | 426 |
return 0; |
427 |
} |
|
428 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
429 |
/** Turn a roadvehicle around. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
430 |
* @param tile unused |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
431 |
* @param p1 vehicle ID to turn |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
432 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
433 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3481
diff
changeset
|
434 |
int32 CmdTurnRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 435 |
{ |
436 |
Vehicle *v; |
|
437 |
||
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
438 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1232
diff
changeset
|
439 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
904
diff
changeset
|
440 |
v = GetVehicle(p1); |
0 | 441 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
442 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 443 |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
444 |
if (v->vehstatus & VS_STOPPED || |
0 | 445 |
v->u.road.crashed_ctr != 0 || |
446 |
v->breakdown_ctr != 0 || |
|
447 |
v->u.road.overtaking != 0 || |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
448 |
v->u.road.state == 255 || |
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
449 |
IsRoadVehInDepot(v) || |
0 | 450 |
v->cur_speed < 5) { |
451 |
return CMD_ERROR; |
|
452 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
453 |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
454 |
if (IsTunnelTile(v->tile) && DirToDiagDir(v->direction) == GetTunnelDirection(v->tile)) return CMD_ERROR; |
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
455 |
if (IsBridgeTile(v->tile) && DirToDiagDir(v->direction) == GetBridgeRampDirection(v->tile)) return CMD_ERROR; |
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
456 |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
457 |
if (flags & DC_EXEC) v->u.road.reverse_ctr = 180; |
0 | 458 |
|
459 |
return 0; |
|
460 |
} |
|
461 |
||
462 |
||
463 |
static void MarkRoadVehDirty(Vehicle *v) |
|
464 |
{ |
|
465 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
466 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
467 |
} |
|
468 |
||
469 |
static void UpdateRoadVehDeltaXY(Vehicle *v) |
|
470 |
{ |
|
471 |
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
472 |
static const uint32 _delta_xy_table[8] = { |
|
473 |
MKIT(3, 3, -1, -1), |
|
474 |
MKIT(3, 7, -1, -3), |
|
475 |
MKIT(3, 3, -1, -1), |
|
476 |
MKIT(7, 3, -3, -1), |
|
477 |
MKIT(3, 3, -1, -1), |
|
478 |
MKIT(3, 7, -1, -3), |
|
479 |
MKIT(3, 3, -1, -1), |
|
480 |
MKIT(7, 3, -3, -1), |
|
481 |
}; |
|
482 |
#undef MKIT |
|
483 |
uint32 x = _delta_xy_table[v->direction]; |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
484 |
v->x_offs = GB(x, 0, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
485 |
v->y_offs = GB(x, 8, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
486 |
v->sprite_width = GB(x, 16, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
487 |
v->sprite_height = GB(x, 24, 8); |
0 | 488 |
} |
489 |
||
490 |
static void ClearCrashedStation(Vehicle *v) |
|
491 |
{ |
|
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
492 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 493 |
|
494 |
// mark station as not busy |
|
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
495 |
CLRBIT(rs->status, 7); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
496 |
|
0 | 497 |
// free parking bay |
2671
2c2edd17e9cc
(svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents:
2662
diff
changeset
|
498 |
SETBIT(rs->status, HASBIT(v->u.road.state, 1) ? 1 : 0); |
0 | 499 |
} |
500 |
||
501 |
static void RoadVehDelete(Vehicle *v) |
|
502 |
{ |
|
503 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
504 |
|
588 | 505 |
RebuildVehicleLists(); |
0 | 506 |
InvalidateWindow(WC_COMPANY, v->owner); |
507 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
508 |
if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
509 |
|
0 | 510 |
BeginVehicleMove(v); |
511 |
EndVehicleMove(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
512 |
|
0 | 513 |
DeleteVehicle(v); |
514 |
} |
|
515 |
||
516 |
static byte SetRoadVehPosition(Vehicle *v, int x, int y) |
|
517 |
{ |
|
518 |
byte new_z, old_z; |
|
519 |
||
520 |
// need this hint so it returns the right z coordinate on bridges. |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
521 |
v->x_pos = x; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
522 |
v->y_pos = y; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
523 |
new_z = GetSlopeZ(x, y); |
0 | 524 |
|
525 |
old_z = v->z_pos; |
|
526 |
v->z_pos = new_z; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
527 |
|
0 | 528 |
VehiclePositionChanged(v); |
529 |
EndVehicleMove(v); |
|
530 |
return old_z; |
|
531 |
} |
|
532 |
||
533 |
static void RoadVehSetRandomDirection(Vehicle *v) |
|
534 |
{ |
|
3160 | 535 |
static const DirDiff delta[] = { |
536 |
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT |
|
537 |
}; |
|
538 |
||
0 | 539 |
uint32 r = Random(); |
3160 | 540 |
|
541 |
v->direction = ChangeDir(v->direction, delta[r & 3]); |
|
0 | 542 |
BeginVehicleMove(v); |
543 |
UpdateRoadVehDeltaXY(v); |
|
544 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
545 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
546 |
} |
|
547 |
||
548 |
static void RoadVehIsCrashed(Vehicle *v) |
|
549 |
{ |
|
550 |
v->u.road.crashed_ctr++; |
|
551 |
if (v->u.road.crashed_ctr == 2) { |
|
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1330
diff
changeset
|
552 |
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |
0 | 553 |
} else if (v->u.road.crashed_ctr <= 45) { |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
554 |
if ((v->tick_counter & 7) == 0) RoadVehSetRandomDirection(v); |
0 | 555 |
} else if (v->u.road.crashed_ctr >= 2220) { |
556 |
RoadVehDelete(v); |
|
557 |
} |
|
558 |
} |
|
559 |
||
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
560 |
static void* EnumCheckRoadVehCrashTrain(Vehicle* v, void* data) |
0 | 561 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
562 |
const Vehicle* u = (Vehicle*)data; |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
563 |
|
2989 | 564 |
return |
565 |
v->type == VEH_Train && |
|
566 |
myabs(v->z_pos - u->z_pos) <= 6 && |
|
567 |
myabs(v->x_pos - u->x_pos) <= 4 && |
|
568 |
myabs(v->y_pos - u->y_pos) <= 4 ? |
|
569 |
v : NULL; |
|
0 | 570 |
} |
571 |
||
572 |
static void RoadVehCrash(Vehicle *v) |
|
573 |
{ |
|
574 |
uint16 pass; |
|
575 |
||
576 |
v->u.road.crashed_ctr++; |
|
577 |
v->vehstatus |= VS_CRASHED; |
|
3236 | 578 |
ClearSlot(v); |
0 | 579 |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
580 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 581 |
|
582 |
pass = 1; |
|
2989 | 583 |
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count; |
0 | 584 |
v->cargo_count = 0; |
2951 | 585 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
586 |
SetDParam(0, pass); |
2260
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
587 |
AddNewsItem( |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
588 |
(pass == 1) ? |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2214
diff
changeset
|
589 |
STR_9031_ROAD_VEHICLE_CRASH_DRIVER : STR_9032_ROAD_VEHICLE_CRASH_DIE, |
0 | 590 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), |
591 |
v->index, |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
592 |
0 |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
593 |
); |
0 | 594 |
|
595 |
ModifyStationRatingAround(v->tile, v->owner, -160, 22); |
|
541 | 596 |
SndPlayVehicleFx(SND_12_EXPLOSION, v); |
0 | 597 |
} |
598 |
||
599 |
static void RoadVehCheckTrainCrash(Vehicle *v) |
|
600 |
{ |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
601 |
TileIndex tile; |
0 | 602 |
|
2951 | 603 |
if (v->u.road.state == 255) return; |
0 | 604 |
|
605 |
tile = v->tile; |
|
606 |
||
3560
b2fcf1898eec
(svn r4435) - Fix: an assertion triggered when trying to remove a bridge with the remove-tool (r4348 surfaced this). In CmdRemoveRoad tiletype was not checked for ownership. Intorudce IsLevelCrossingTile() which checks if a tile is a crossing without knowing the type. Suggested by peter1138 and Tron.
Darkvater
parents:
3508
diff
changeset
|
607 |
if (!IsLevelCrossingTile(tile)) return; |
0 | 608 |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
609 |
if (VehicleFromPos(tile, v, EnumCheckRoadVehCrashTrain) != NULL) |
0 | 610 |
RoadVehCrash(v); |
611 |
} |
|
612 |
||
613 |
static void HandleBrokenRoadVeh(Vehicle *v) |
|
614 |
{ |
|
615 |
if (v->breakdown_ctr != 1) { |
|
616 |
v->breakdown_ctr = 1; |
|
617 |
v->cur_speed = 0; |
|
618 |
||
619 |
if (v->breakdowns_since_last_service != 255) |
|
620 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
621 |
|
0 | 622 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
623 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
624 |
|
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
625 |
if (!PlayVehicleSound(v, VSE_BREAKDOWN)) { |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
626 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
627 |
SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
628 |
} |
0 | 629 |
|
630 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
631 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
2989 | 632 |
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; |
0 | 633 |
} |
634 |
} |
|
635 |
||
2989 | 636 |
if ((v->tick_counter & 1) == 0) { |
637 |
if (--v->breakdown_delay == 0) { |
|
0 | 638 |
v->breakdown_ctr = 0; |
639 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
|
640 |
} |
|
641 |
} |
|
642 |
} |
|
643 |
||
644 |
static void ProcessRoadVehOrder(Vehicle *v) |
|
645 |
{ |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
646 |
const Order *order; |
0 | 647 |
|
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
648 |
switch (v->current_order.type) { |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
649 |
case OT_GOTO_DEPOT: |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
650 |
// Let a depot order in the orderlist interrupt. |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
651 |
if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return; |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
652 |
if (v->current_order.flags & OF_SERVICE_IF_NEEDED && |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
653 |
!VehicleNeedsService(v)) { |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
654 |
v->cur_order_index++; |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
655 |
} |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
656 |
break; |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
657 |
|
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
658 |
case OT_LOADING: |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
659 |
case OT_LEAVESTATION: |
0 | 660 |
return; |
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4344
diff
changeset
|
661 |
|
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4344
diff
changeset
|
662 |
default: break; |
0 | 663 |
} |
664 |
||
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
665 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 666 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
667 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 668 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
669 |
if (order == NULL) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
670 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
671 |
v->current_order.flags = 0; |
0 | 672 |
v->dest_tile = 0; |
3123 | 673 |
ClearSlot(v); |
0 | 674 |
return; |
675 |
} |
|
676 |
||
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
677 |
if (order->type == v->current_order.type && |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
678 |
order->flags == v->current_order.flags && |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
679 |
order->dest == v->current_order.dest) { |
0 | 680 |
return; |
2951 | 681 |
} |
0 | 682 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
683 |
v->current_order = *order; |
0 | 684 |
|
4179 | 685 |
switch (order->type) { |
686 |
case OT_GOTO_STATION: { |
|
687 |
const RoadStop* rs; |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
688 |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
689 |
if (order->dest == v->last_station_visited) { |
4179 | 690 |
v->last_station_visited = INVALID_STATION; |
691 |
} |
|
692 |
||
5876 | 693 |
rs = GetStation(order->dest)->GetPrimaryRoadStop( |
5836
a60d2114780e
(svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents:
5668
diff
changeset
|
694 |
v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK |
4179 | 695 |
); |
696 |
||
697 |
if (rs != NULL) { |
|
698 |
TileIndex dest = rs->xy; |
|
699 |
uint mindist = DistanceManhattan(v->tile, rs->xy); |
|
700 |
||
701 |
for (rs = rs->next; rs != NULL; rs = rs->next) { |
|
702 |
uint dist = DistanceManhattan(v->tile, rs->xy); |
|
703 |
||
704 |
if (dist < mindist) { |
|
705 |
mindist = dist; |
|
706 |
dest = rs->xy; |
|
707 |
} |
|
708 |
} |
|
709 |
v->dest_tile = dest; |
|
710 |
} else { |
|
711 |
// There is no stop left at the station, so don't even TRY to go there |
|
712 |
v->cur_order_index++; |
|
713 |
v->dest_tile = 0; |
|
714 |
} |
|
715 |
break; |
|
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
716 |
} |
1231
5fa7581377a9
(svn r1735) -Fix: [ 1112285 ] Fixed an assertion error with stations where stops
celestar
parents:
1224
diff
changeset
|
717 |
|
4179 | 718 |
case OT_GOTO_DEPOT: |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
719 |
v->dest_tile = GetDepot(order->dest)->xy; |
4179 | 720 |
break; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
721 |
|
4179 | 722 |
default: |
723 |
v->dest_tile = 0; |
|
724 |
break; |
|
0 | 725 |
} |
726 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
727 |
InvalidateVehicleOrder(v); |
0 | 728 |
} |
729 |
||
730 |
static void HandleRoadVehLoading(Vehicle *v) |
|
731 |
{ |
|
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
732 |
switch (v->current_order.type) { |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
733 |
case OT_LOADING: { |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
734 |
Order b; |
0 | 735 |
|
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
736 |
if (--v->load_unload_time_rem != 0) return; |
0 | 737 |
|
5211
fb4dc0ca975d
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
738 |
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD || |
fb4dc0ca975d
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
739 |
(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) { |
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
740 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
5211
fb4dc0ca975d
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
741 |
if (LoadUnloadVehicle(v, false)) { |
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
742 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
743 |
MarkRoadVehDirty(v); |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
744 |
} |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
745 |
return; |
0 | 746 |
} |
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
747 |
|
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
748 |
b = v->current_order; |
5651
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5587
diff
changeset
|
749 |
v->LeaveStation(); |
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
750 |
if (!(b.flags & OF_NON_STOP)) return; |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
751 |
break; |
0 | 752 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
753 |
|
3004
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
754 |
case OT_DUMMY: break; |
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
755 |
|
cac6aff8cc52
(svn r3584) Replace the rather obscure control flow for handling road vehicle orders by something remotly comprehensible
tron
parents:
2989
diff
changeset
|
756 |
default: return; |
0 | 757 |
} |
758 |
||
759 |
v->cur_order_index++; |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
926
diff
changeset
|
760 |
InvalidateVehicleOrder(v); |
0 | 761 |
} |
762 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
763 |
static void StartRoadVehSound(const Vehicle* v) |
0 | 764 |
{ |
4656
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
765 |
if (!PlayVehicleSound(v, VSE_START)) { |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
766 |
SoundFx s = RoadVehInfo(v->engine_type)->sfx; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
767 |
if (s == SND_19_BUS_START_PULL_AWAY && (v->tick_counter & 3) == 0) |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
768 |
s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN; |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
769 |
SndPlayVehicleFx(s, v); |
9c1d8c4d3e60
(svn r6532) - Feature: Add support for NewGRF sound effects. Currently sound priority isn't supported.
peter1138
parents:
4574
diff
changeset
|
770 |
} |
0 | 771 |
} |
772 |
||
773 |
typedef struct RoadVehFindData { |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
774 |
int x; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
775 |
int y; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
776 |
const Vehicle* veh; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
777 |
Direction dir; |
0 | 778 |
} RoadVehFindData; |
779 |
||
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
780 |
static void* EnumCheckRoadVehClose(Vehicle *v, void* data) |
0 | 781 |
{ |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
782 |
static const int8 dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 }; |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
783 |
static const int8 dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 }; |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
784 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
785 |
const RoadVehFindData* rvf = (RoadVehFindData*)data; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
786 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
787 |
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
|
788 |
short y_diff = v->y_pos - rvf->y; |
0 | 789 |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
790 |
return |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
791 |
rvf->veh != v && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
792 |
v->type == VEH_Road && |
3959 | 793 |
!IsRoadVehInDepot(v) && |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
794 |
myabs(v->z_pos - rvf->veh->z_pos) < 6 && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
795 |
v->direction == rvf->dir && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
796 |
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
797 |
(dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
798 |
(dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) && |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
799 |
(dist_y[v->direction] <= 0 || (y_diff < dist_y[v->direction] && y_diff >= 0)) ? |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
800 |
v : NULL; |
0 | 801 |
} |
802 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
803 |
static Vehicle* RoadVehFindCloseTo(Vehicle* v, int x, int y, Direction dir) |
0 | 804 |
{ |
805 |
RoadVehFindData rvf; |
|
806 |
Vehicle *u; |
|
807 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
808 |
if (v->u.road.reverse_ctr != 0) return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
809 |
|
0 | 810 |
rvf.x = x; |
811 |
rvf.y = y; |
|
812 |
rvf.dir = dir; |
|
813 |
rvf.veh = v; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
814 |
u = (Vehicle*)VehicleFromPos(TileVirtXY(x, y), &rvf, EnumCheckRoadVehClose); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
815 |
|
63
53cc59601b3c
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
dominik
parents:
19
diff
changeset
|
816 |
// This code protects a roadvehicle from being blocked for ever |
826 | 817 |
// 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
|
818 |
// 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
|
819 |
// It can be disabled. |
0 | 820 |
if (u == NULL) { |
3009
c75f1a8d5ff9
(svn r3589) - Rename u.road.unk2 to u.road.blocked_ctr
peter1138
parents:
3004
diff
changeset
|
821 |
v->u.road.blocked_ctr = 0; |
0 | 822 |
return NULL; |
823 |
} |
|
824 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
825 |
if (++v->u.road.blocked_ctr > 1480) return NULL; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
826 |
|
0 | 827 |
return u; |
828 |
} |
|
829 |
||
2630 | 830 |
static void RoadVehArrivesAt(const Vehicle* v, Station* st) |
0 | 831 |
{ |
2550
4570b91c81aa
(svn r3079) Determine the type of the "first arrival" message for road vehicles using the cargo type and not a magic engine number
tron
parents:
2549
diff
changeset
|
832 |
if (v->cargo_type == CT_PASSENGERS) { |
0 | 833 |
/* Check if station was ever visited before */ |
834 |
if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
|
835 |
uint32 flags; |
|
836 |
||
837 |
st->had_vehicle_of_type |= HVOT_BUS; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
838 |
SetDParam(0, st->index); |
0 | 839 |
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); |
840 |
AddNewsItem( |
|
841 |
STR_902F_CITIZENS_CELEBRATE_FIRST, |
|
842 |
flags, |
|
843 |
v->index, |
|
844 |
0); |
|
845 |
} |
|
846 |
} else { |
|
847 |
/* Check if station was ever visited before */ |
|
848 |
if (!(st->had_vehicle_of_type & HVOT_TRUCK)) { |
|
849 |
uint32 flags; |
|
850 |
||
851 |
st->had_vehicle_of_type |= HVOT_TRUCK; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
852 |
SetDParam(0, st->index); |
0 | 853 |
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); |
854 |
AddNewsItem( |
|
855 |
STR_9030_CITIZENS_CELEBRATE_FIRST, |
|
856 |
flags, |
|
857 |
v->index, |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
858 |
0 |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
859 |
); |
0 | 860 |
} |
861 |
} |
|
862 |
} |
|
863 |
||
864 |
static bool RoadVehAccelerate(Vehicle *v) |
|
865 |
{ |
|
2951 | 866 |
uint spd = v->cur_speed + 1 + (v->u.road.overtaking != 0 ? 1 : 0); |
0 | 867 |
byte t; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
868 |
|
0 | 869 |
// Clamp |
870 |
spd = min(spd, v->max_speed); |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
871 |
if (v->u.road.state == 255) spd = min(spd, SetSpeedLimitOnBridge(v)); |
0 | 872 |
|
873 |
//updates statusbar only if speed have changed to save CPU time |
|
874 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
875 |
v->cur_speed = spd; |
2951 | 876 |
if (_patches.vehicle_speed) { |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
877 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
2951 | 878 |
} |
0 | 879 |
} |
880 |
||
881 |
// Decrease somewhat when turning |
|
2951 | 882 |
if (!(v->direction & 1)) spd = spd * 3 >> 2; |
0 | 883 |
|
2951 | 884 |
if (spd == 0) return false; |
0 | 885 |
|
2951 | 886 |
if ((byte)++spd == 0) return true; |
0 | 887 |
|
888 |
v->progress = (t = v->progress) - (byte)spd; |
|
889 |
||
890 |
return (t < v->progress); |
|
891 |
} |
|
892 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
893 |
static Direction RoadVehGetNewDirection(const Vehicle* v, int x, int y) |
0 | 894 |
{ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
895 |
static const Direction _roadveh_new_dir[] = { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
896 |
DIR_N , DIR_NW, DIR_W , INVALID_DIR, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
897 |
DIR_NE, DIR_N , DIR_SW, INVALID_DIR, |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
898 |
DIR_E , DIR_SE, DIR_S |
0 | 899 |
}; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
900 |
|
0 | 901 |
x = x - v->x_pos + 1; |
902 |
y = y - v->y_pos + 1; |
|
903 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
904 |
if ((uint)x > 2 || (uint)y > 2) return v->direction; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
905 |
return _roadveh_new_dir[y * 4 + x]; |
0 | 906 |
} |
907 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
908 |
static Direction RoadVehGetSlidingDirection(const Vehicle* v, int x, int y) |
0 | 909 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
910 |
Direction new_dir = RoadVehGetNewDirection(v, x, y); |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
911 |
Direction old_dir = v->direction; |
3159
b4a664574e8f
(svn r3785) Replace some if-magic to determine the turning direction for road vehicles with the new DirDiff stuff
tron
parents:
3157
diff
changeset
|
912 |
DirDiff delta; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
913 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
914 |
if (new_dir == old_dir) return old_dir; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
915 |
delta = (DirDifference(new_dir, old_dir) > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
916 |
return ChangeDir(old_dir, delta); |
0 | 917 |
} |
918 |
||
919 |
typedef struct OvertakeData { |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
920 |
const Vehicle* u; |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
921 |
const Vehicle* v; |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
922 |
TileIndex tile; |
0 | 923 |
byte tilebits; |
924 |
} OvertakeData; |
|
925 |
||
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
926 |
static void* EnumFindVehToOvertake(Vehicle* v, void* data) |
0 | 927 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
928 |
const OvertakeData* od = (OvertakeData*)data; |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
929 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
930 |
return |
4170
81bafc4dd1b9
(svn r5607) -Regression [r3597]: Let a road vehicle only overtake if there is no vehicle close except the two involved
tron
parents:
4095
diff
changeset
|
931 |
v->tile == od->tile && v->type == VEH_Road && v != od->u && v != od->v ? |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
932 |
v : NULL; |
0 | 933 |
} |
934 |
||
935 |
static bool FindRoadVehToOvertake(OvertakeData *od) |
|
936 |
{ |
|
937 |
uint32 bits; |
|
938 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
939 |
bits = GetTileTrackStatus(od->tile, TRANSPORT_ROAD) & 0x3F; |
0 | 940 |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
941 |
if (!(od->tilebits & bits) || (bits & 0x3C) || (bits & 0x3F3F0000)) |
0 | 942 |
return true; |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
943 |
return VehicleFromPos(od->tile, od, EnumFindVehToOvertake) != NULL; |
0 | 944 |
} |
945 |
||
946 |
static void RoadVehCheckOvertake(Vehicle *v, Vehicle *u) |
|
947 |
{ |
|
948 |
OvertakeData od; |
|
949 |
byte tt; |
|
950 |
||
951 |
od.v = v; |
|
952 |
od.u = u; |
|
953 |
||
954 |
if (u->max_speed >= v->max_speed && |
|
3431 | 955 |
!(u->vehstatus & VS_STOPPED) && |
2951 | 956 |
u->cur_speed != 0) { |
957 |
return; |
|
958 |
} |
|
0 | 959 |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
960 |
if (v->direction != u->direction || !(v->direction & 1)) return; |
0 | 961 |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
962 |
if (v->u.road.state >= 32 || (v->u.road.state & 7) > 1) return; |
0 | 963 |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2107
diff
changeset
|
964 |
tt = GetTileTrackStatus(v->tile, TRANSPORT_ROAD) & 0x3F; |
2951 | 965 |
if ((tt & 3) == 0) return; |
966 |
if ((tt & 0x3C) != 0) return; |
|
0 | 967 |
|
2951 | 968 |
if (tt == 3) tt = (v->direction & 2) ? 2 : 1; |
0 | 969 |
od.tilebits = tt; |
970 |
||
971 |
od.tile = v->tile; |
|
2951 | 972 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 973 |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
974 |
od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction)); |
2951 | 975 |
if (FindRoadVehToOvertake(&od)) return; |
0 | 976 |
|
3431 | 977 |
if (od.u->cur_speed == 0 || od.u->vehstatus& VS_STOPPED) { |
0 | 978 |
v->u.road.overtaking_ctr = 0x11; |
979 |
v->u.road.overtaking = 0x10; |
|
980 |
} else { |
|
2951 | 981 |
// if (FindRoadVehToOvertake(&od)) return; |
0 | 982 |
v->u.road.overtaking_ctr = 0; |
983 |
v->u.road.overtaking = 0x10; |
|
984 |
} |
|
985 |
} |
|
986 |
||
987 |
static void RoadZPosAffectSpeed(Vehicle *v, byte old_z) |
|
988 |
{ |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
989 |
if (old_z == v->z_pos) return; |
0 | 990 |
|
991 |
if (old_z < v->z_pos) { |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
992 |
v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10% |
0 | 993 |
} else { |
994 |
uint16 spd = v->cur_speed + 2; |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
995 |
if (spd <= v->max_speed) v->cur_speed = spd; |
0 | 996 |
} |
997 |
} |
|
998 |
||
999 |
static int PickRandomBit(uint bits) |
|
1000 |
{ |
|
1001 |
uint num = 0; |
|
1002 |
uint b = bits; |
|
1003 |
uint i; |
|
1004 |
||
1005 |
do { |
|
2951 | 1006 |
if (b & 1) num++; |
0 | 1007 |
} while (b >>= 1); |
1008 |
||
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
1009 |
num = RandomRange(num); |
0 | 1010 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1011 |
for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {} |
0 | 1012 |
return i; |
1013 |
} |
|
1014 |
||
1015 |
typedef struct { |
|
1016 |
TileIndex dest; |
|
1017 |
uint maxtracklen; |
|
1018 |
uint mindist; |
|
1019 |
} FindRoadToChooseData; |
|
1020 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1021 |
static bool EnumRoadTrackFindDist(TileIndex tile, void* data, Trackdir trackdir, uint length, byte* state) |
0 | 1022 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1023 |
FindRoadToChooseData* frd = (FindRoadToChooseData*)data; |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1239
diff
changeset
|
1024 |
uint dist = DistanceManhattan(tile, frd->dest); |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1025 |
|
0 | 1026 |
if (dist <= frd->mindist) { |
1027 |
if (dist != frd->mindist || length < frd->maxtracklen) { |
|
1028 |
frd->maxtracklen = length; |
|
1029 |
} |
|
1030 |
frd->mindist = dist; |
|
1031 |
} |
|
1032 |
return false; |
|
1033 |
} |
|
1034 |
||
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1035 |
static inline NPFFoundTargetData PerfNPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes) |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1036 |
{ |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1037 |
|
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1038 |
void* perf = NpfBeginInterval(); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1039 |
NPFFoundTargetData ret = NPFRouteToStationOrTile(tile, trackdir, target, type, owner, railtypes); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1040 |
int t = NpfEndInterval(perf); |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1041 |
DEBUG(yapf, 4, "[NPFR] %d us - %d rounds - %d open - %d closed -- ", t, 0, _aystar_stats_open_size, _aystar_stats_closed_size); |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1042 |
return ret; |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1043 |
} |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1044 |
|
0 | 1045 |
// Returns direction to choose |
1046 |
// or -1 if the direction is currently blocked |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1047 |
static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir) |
0 | 1048 |
{ |
1049 |
#define return_track(x) {best_track = x; goto found_best_track; } |
|
1050 |
||
1051 |
uint16 signal; |
|
1052 |
uint bitmask; |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
1053 |
TileIndex desttile; |
0 | 1054 |
FindRoadToChooseData frd; |
1055 |
int best_track; |
|
1056 |
uint best_dist, best_maxlen; |
|
1057 |
uint i; |
|
1058 |
||
1059 |
{ |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1060 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_ROAD); |
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1061 |
signal = GB(r, 16, 16); |
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2477
diff
changeset
|
1062 |
bitmask = GB(r, 0, 16); |
0 | 1063 |
} |
1064 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1065 |
if (IsTileType(tile, MP_STREET)) { |
4445
ccb3b02161fe
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1066 |
if (GetRoadTileType(tile) == ROAD_TILE_DEPOT && (!IsTileOwner(tile, v->owner) || GetRoadDepotDirection(tile) == enterdir)) { |
ccb3b02161fe
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1067 |
/* Road depot owned by another player or with the wrong orientation */ |
3937
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1068 |
bitmask = 0; |
2549 | 1069 |
} |
3404
eb8ebfe5df67
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3338
diff
changeset
|
1070 |
} else if (IsTileType(tile, MP_STATION) && IsRoadStopTile(tile)) { |
4445
ccb3b02161fe
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1071 |
if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir) { |
ccb3b02161fe
(svn r6223) -Fix: RVs with empty order list were able to enter the depot or road stop from the back. I introduced this bug when I "improved" GetTileTrackStatus(). (thanks glx for the report and fix).
KUDr
parents:
4434
diff
changeset
|
1072 |
/* different station owner or wrong orientation */ |
3937
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1073 |
bitmask = 0; |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1074 |
} else { |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1075 |
/* Our station */ |
5836
a60d2114780e
(svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents:
5668
diff
changeset
|
1076 |
RoadStop::Type rstype = (v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1077 |
|
3937
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1078 |
if (GetRoadStopType(tile) != rstype) { |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1079 |
// wrong station type |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1080 |
bitmask = 0; |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1081 |
} else { |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1082 |
// proper station type, check if there is free loading bay |
3092
34cfd4aa9cc5
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1083 |
const RoadStop *rs = GetRoadStopByTile(tile, rstype); |
3937
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1084 |
if (rs == NULL || (!_patches.roadveh_queue && GB(rs->status, 0, 2) == 0)) { |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1085 |
// station is full and RV queuing is off |
5728e502f942
(svn r5080) -Fix: RVs can enter other player's depot or roadstop (introduced by YAPF related change of GetTileTrackStatus() - r4419)
KUDr
parents:
3933
diff
changeset
|
1086 |
bitmask = 0; |
3092
34cfd4aa9cc5
(svn r3681) - [Multistop] Check the RoadStop type before check its status. This fixes an assert introduced in r3663. Also fix the return type of GetRoadStopType().
peter1138
parents:
3074
diff
changeset
|
1087 |
} |
241
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1088 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1089 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1090 |
} |
e6e62a5e7f52
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
darkvater
parents:
193
diff
changeset
|
1091 |
/* 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
|
1092 |
* 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
|
1093 |
* 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
|
1094 |
*/ |
0 | 1095 |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
1096 |
/* remove unreachable tracks */ |
1247 | 1097 |
bitmask &= _road_veh_fp_ax_and[enterdir]; |
0 | 1098 |
if (bitmask == 0) { |
1247 | 1099 |
/* No reachable tracks, so we'll reverse */ |
1100 |
return_track(_road_reverse_table[enterdir]); |
|
0 | 1101 |
} |
1102 |
||
1103 |
if (v->u.road.reverse_ctr != 0) { |
|
1247 | 1104 |
/* What happens here?? */ |
0 | 1105 |
v->u.road.reverse_ctr = 0; |
1986
fcc849a38ae6
(svn r2492) Remove some pointless casts and fix some nearby indentation
tron
parents:
1980
diff
changeset
|
1106 |
if (v->tile != tile) { |
1247 | 1107 |
return_track(_road_reverse_table[enterdir]); |
0 | 1108 |
} |
1109 |
} |
|
1110 |
||
1111 |
desttile = v->dest_tile; |
|
1112 |
if (desttile == 0) { |
|
1247 | 1113 |
// Pick a random track |
0 | 1114 |
return_track(PickRandomBit(bitmask)); |
1115 |
} |
|
1116 |
||
1247 | 1117 |
// Only one track to choose between? |
1118 |
if (!(KillFirstBit2x64(bitmask))) { |
|
0 | 1119 |
return_track(FindFirstBit2x64(bitmask)); |
1120 |
} |
|
1121 |
||
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1122 |
if (_patches.yapf.road_use_yapf) { |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1123 |
Trackdir trackdir = YapfChooseRoadTrack(v, tile, enterdir); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1124 |
if (trackdir != INVALID_TRACKDIR) return_track(trackdir); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1125 |
return_track(PickRandomBit(bitmask)); |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
1126 |
} else if (_patches.new_pathfinding_all) { |
1247 | 1127 |
NPFFindStationOrTileData fstd; |
1128 |
NPFFoundTargetData ftd; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1129 |
Trackdir trackdir; |
1247 | 1130 |
|
1131 |
NPFFillWithOrderData(&fstd, v); |
|
1942
c5d5cf5b0263
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
1935
diff
changeset
|
1132 |
trackdir = DiagdirToDiagTrackdir(enterdir); |
1247 | 1133 |
//debug("Finding path. Enterdir: %d, Trackdir: %d", enterdir, trackdir); |
1134 |
||
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1135 |
ftd = PerfNPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE); |
1698
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1136 |
if (ftd.best_trackdir == 0xff) { |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1137 |
/* We are already at our target. Just do something */ |
1247 | 1138 |
//TODO: maybe display error? |
1139 |
//TODO: go straight ahead if possible? |
|
1140 |
return_track(FindFirstBit2x64(bitmask)); |
|
1141 |
} else { |
|
1698
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1142 |
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1143 |
the direction we need to take to get there, if ftd.best_bird_dist is not 0, |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1144 |
we did not find our target, but ftd.best_trackdir contains the direction leading |
3f979f9ecf6c
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1680
diff
changeset
|
1145 |
to the tile closest to our target. */ |
1247 | 1146 |
return_track(ftd.best_trackdir); |
1147 |
} |
|
1148 |
} else { |
|
3167
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1149 |
DiagDirection dir; |
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1150 |
|
1247 | 1151 |
if (IsTileType(desttile, MP_STREET)) { |
3793
7fe24e10ea63
(svn r4789) - Codechange: rename RoadType to RoadTileType and ROAD_{NORMAL,CROSSING,DEPOT} to ROAD_TILE_* for consistency
rubidium
parents:
3645
diff
changeset
|
1152 |
if (GetRoadTileType(desttile) == ROAD_TILE_DEPOT) { |
3167
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1153 |
dir = GetRoadDepotDirection(desttile); |
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1154 |
goto do_it; |
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1155 |
} |
1247 | 1156 |
} else if (IsTileType(desttile, MP_STATION)) { |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1157 |
if (IsRoadStop(desttile)) { |
3404
eb8ebfe5df67
(svn r4215) -Codechange: Renamed *RoadStation* functions to *RoadStop* and moved them to station_map.h to keep consistency
celestar
parents:
3338
diff
changeset
|
1158 |
dir = GetRoadStopDir(desttile); |
0 | 1159 |
do_it:; |
1247 | 1160 |
/* When we are heading for a depot or station, we just |
1161 |
* pretend we are heading for the tile in front, we'll |
|
1162 |
* see from there */ |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1163 |
desttile += TileOffsByDiagDir(dir); |
3167
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1164 |
if (desttile == tile && bitmask & _road_pf_table_3[dir]) { |
1247 | 1165 |
/* If we are already in front of the |
1166 |
* station/depot and we can get in from here, |
|
1167 |
* we enter */ |
|
3167
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1168 |
return_track(FindFirstBit2x64(bitmask & _road_pf_table_3[dir])); |
1247 | 1169 |
} |
0 | 1170 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1171 |
} |
1247 | 1172 |
// do pathfind |
1173 |
frd.dest = desttile; |
|
0 | 1174 |
|
1247 | 1175 |
best_track = -1; |
1176 |
best_dist = (uint)-1; |
|
1177 |
best_maxlen = (uint)-1; |
|
1178 |
i = 0; |
|
1179 |
do { |
|
1180 |
if (bitmask & 1) { |
|
1181 |
if (best_track == -1) best_track = i; // in case we don't find the path, just pick a track |
|
1182 |
frd.maxtracklen = (uint)-1; |
|
1183 |
frd.mindist = (uint)-1; |
|
3611
808337ad2e36
(svn r4506) -Fix: (FS#95) Use the tile hash when pathfinding to a depot. Eats a tiny bit of performance, but the likelihood that the depot is found is greatly increased
celestar
parents:
3560
diff
changeset
|
1184 |
FollowTrack(tile, 0x2000 | TRANSPORT_ROAD, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd); |
0 | 1185 |
|
1247 | 1186 |
if (frd.mindist < best_dist || (frd.mindist==best_dist && frd.maxtracklen < best_maxlen)) { |
1187 |
best_dist = frd.mindist; |
|
1188 |
best_maxlen = frd.maxtracklen; |
|
1189 |
best_track = i; |
|
1190 |
} |
|
0 | 1191 |
} |
1247 | 1192 |
} while (++i,(bitmask>>=1) != 0); |
1193 |
} |
|
0 | 1194 |
|
1195 |
found_best_track:; |
|
1196 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1197 |
if (HASBIT(signal, best_track)) return -1; |
0 | 1198 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1199 |
return best_track; |
0 | 1200 |
} |
1201 |
||
3123 | 1202 |
static uint RoadFindPathToStop(const Vehicle *v, TileIndex tile) |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1203 |
{ |
4271
2428a4eb4f9e
(svn r5899) - Fix [FS#242]: Multistop not working when using NPF (r5033) (mart3p)
Darkvater
parents:
4261
diff
changeset
|
1204 |
uint dist; |
3915
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1205 |
if (_patches.yapf.road_use_yapf) { |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1206 |
// use YAPF |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1207 |
dist = YapfRoadVehDistanceToTile(v, tile); |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1208 |
} else { |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1209 |
// use NPF |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1210 |
NPFFindStationOrTileData fstd; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1211 |
Trackdir trackdir = GetVehicleTrackdir(v); |
3915
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1212 |
assert(trackdir != 0xFF); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1213 |
|
3915
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1214 |
fstd.dest_coords = tile; |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1215 |
fstd.station_index = INVALID_STATION; // indicates that the destination is a tile, not a station |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1216 |
|
3915
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1217 |
dist = NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_ROAD, v->owner, INVALID_RAILTYPE).best_path_dist; |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1218 |
// change units from NPF_TILE_LENGTH to # of tiles |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1219 |
if (dist != UINT_MAX) |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1220 |
dist = (dist + NPF_TILE_LENGTH - 1) / NPF_TILE_LENGTH; |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1221 |
} |
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1222 |
return dist; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1223 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1224 |
|
0 | 1225 |
typedef struct RoadDriveEntry { |
1226 |
byte x,y; |
|
1227 |
} RoadDriveEntry; |
|
1228 |
||
1229 |
#include "table/roadveh.h" |
|
1230 |
||
1231 |
static const byte _road_veh_data_1[] = { |
|
1232 |
20, 20, 16, 16, 0, 0, 0, 0, |
|
1233 |
19, 19, 15, 15, 0, 0, 0, 0, |
|
1234 |
16, 16, 12, 12, 0, 0, 0, 0, |
|
1235 |
15, 15, 11, 11 |
|
1236 |
}; |
|
1237 |
||
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4329
diff
changeset
|
1238 |
static const byte _roadveh_data_2[4] = { 0, 1, 8, 9 }; |
0 | 1239 |
|
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1240 |
static void RoadVehController(Vehicle *v) |
0 | 1241 |
{ |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1242 |
Direction new_dir; |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1243 |
Direction old_dir; |
0 | 1244 |
RoadDriveEntry rd; |
1245 |
int x,y; |
|
1246 |
uint32 r; |
|
1247 |
||
1248 |
// decrease counters |
|
1249 |
v->tick_counter++; |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1250 |
if (v->u.road.reverse_ctr != 0) v->u.road.reverse_ctr--; |
0 | 1251 |
|
1252 |
// handle crashed |
|
1253 |
if (v->u.road.crashed_ctr != 0) { |
|
1254 |
RoadVehIsCrashed(v); |
|
1255 |
return; |
|
1256 |
} |
|
1257 |
||
1258 |
RoadVehCheckTrainCrash(v); |
|
1259 |
||
1260 |
// road vehicle has broken down? |
|
1261 |
if (v->breakdown_ctr != 0) { |
|
1262 |
if (v->breakdown_ctr <= 2) { |
|
1263 |
HandleBrokenRoadVeh(v); |
|
1264 |
return; |
|
1265 |
} |
|
1266 |
v->breakdown_ctr--; |
|
1267 |
} |
|
1268 |
||
3431 | 1269 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 1270 |
|
1271 |
ProcessRoadVehOrder(v); |
|
1272 |
HandleRoadVehLoading(v); |
|
1273 |
||
2951 | 1274 |
if (v->current_order.type == OT_LOADING) return; |
0 | 1275 |
|
3959 | 1276 |
if (IsRoadVehInDepot(v)) { |
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1277 |
DiagDirection dir; |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1278 |
const RoadDriveEntry* rdp; |
0 | 1279 |
byte rd2; |
1280 |
||
1281 |
v->cur_speed = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1282 |
|
3167
8323c2ccd029
(svn r3795) Add a function to request the orientation of a depot
tron
parents:
3161
diff
changeset
|
1283 |
dir = GetRoadDepotDirection(v->tile); |
3153
e83501906eae
(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
1284 |
v->direction = DiagDirToDir(dir); |
0 | 1285 |
|
1286 |
rd2 = _roadveh_data_2[dir]; |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1287 |
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
|
1288 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1289 |
x = TileX(v->tile) * TILE_SIZE + (rdp[6].x & 0xF); |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1290 |
y = TileY(v->tile) * TILE_SIZE + (rdp[6].y & 0xF); |
0 | 1291 |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1292 |
if (RoadVehFindCloseTo(v, x, y, v->direction) != NULL) return; |
0 | 1293 |
|
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1294 |
VehicleServiceInDepot(v); |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
1295 |
|
0 | 1296 |
StartRoadVehSound(v); |
1297 |
||
1298 |
BeginVehicleMove(v); |
|
1299 |
||
1300 |
v->vehstatus &= ~VS_HIDDEN; |
|
1301 |
v->u.road.state = rd2; |
|
1302 |
v->u.road.frame = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1303 |
|
0 | 1304 |
v->cur_image = GetRoadVehImage(v, v->direction); |
1305 |
UpdateRoadVehDeltaXY(v); |
|
1306 |
SetRoadVehPosition(v,x,y); |
|
1307 |
||
4739
e626ef1b522e
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4725
diff
changeset
|
1308 |
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
0 | 1309 |
return; |
1310 |
} |
|
1311 |
||
2951 | 1312 |
if (!RoadVehAccelerate(v)) return; |
0 | 1313 |
|
1314 |
if (v->u.road.overtaking != 0) { |
|
1315 |
if (++v->u.road.overtaking_ctr >= 35) |
|
2823
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1316 |
/* If overtaking just aborts at a random moment, we can have a out-of-bound problem, |
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1317 |
* if the vehicle started a corner. To protect that, only allow an abort of |
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1318 |
* overtake if we are on straight road, which are the 8 states below */ |
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1319 |
if (v->u.road.state == 0 || v->u.road.state == 1 || |
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1320 |
v->u.road.state == 8 || v->u.road.state == 9 || |
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1321 |
v->u.road.state == 16 || v->u.road.state == 17 || |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1322 |
v->u.road.state == 24 || v->u.road.state == 25) { |
2823
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1323 |
v->u.road.overtaking = 0; |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1324 |
} |
0 | 1325 |
} |
1326 |
||
1327 |
BeginVehicleMove(v); |
|
1328 |
||
1329 |
if (v->u.road.state == 255) { |
|
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1330 |
GetNewVehiclePosResult gp; |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1331 |
|
0 | 1332 |
GetNewVehiclePos(v, &gp); |
1333 |
||
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1334 |
if (RoadVehFindCloseTo(v, gp.x, gp.y, v->direction) != NULL) { |
0 | 1335 |
v->cur_speed = 0; |
1336 |
return; |
|
1337 |
} |
|
1338 |
||
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
1339 |
if ((IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) && VehicleEnterTile(v, gp.new_tile, gp.x, gp.y) & 4) { |
0 | 1340 |
//new_dir = RoadGetNewDirection(v, gp.x, gp.y) |
1341 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1342 |
UpdateRoadVehDeltaXY(v); |
|
1343 |
SetRoadVehPosition(v,gp.x,gp.y); |
|
1344 |
return; |
|
1345 |
} |
|
1346 |
||
1347 |
v->x_pos = gp.x; |
|
1348 |
v->y_pos = gp.y; |
|
1349 |
VehiclePositionChanged(v); |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5380
diff
changeset
|
1350 |
if (!(v->vehstatus & VS_HIDDEN)) EndVehicleMove(v); |
0 | 1351 |
return; |
1352 |
} |
|
1353 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1354 |
rd = _road_drive_data[(v->u.road.state + (_opt.road_side << 4)) ^ v->u.road.overtaking][v->u.road.frame + 1]; |
0 | 1355 |
|
1356 |
// switch to another tile |
|
1357 |
if (rd.x & 0x80) { |
|
4559
aa0c13e39840
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
1358 |
TileIndex tile = v->tile + TileOffsByDiagDir(rd.x & 3); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1359 |
int dir = RoadFindPathToDest(v, tile, (DiagDirection)(rd.x & 3)); |
0 | 1360 |
uint32 r; |
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1361 |
Direction newdir; |
0 | 1362 |
const RoadDriveEntry *rdp; |
1363 |
||
1364 |
if (dir == -1) { |
|
1365 |
v->cur_speed = 0; |
|
1366 |
return; |
|
1367 |
} |
|
1368 |
||
1369 |
again: |
|
1370 |
if ((dir & 7) >= 6) { |
|
1247 | 1371 |
/* Turning around */ |
0 | 1372 |
tile = v->tile; |
1373 |
} |
|
1374 |
||
2823
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1375 |
rdp = _road_drive_data[(dir + (_opt.road_side << 4)) ^ v->u.road.overtaking]; |
0 | 1376 |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1377 |
x = TileX(tile) * TILE_SIZE + rdp[0].x; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1378 |
y = TileY(tile) * TILE_SIZE + rdp[0].y; |
0 | 1379 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1380 |
newdir = RoadVehGetSlidingDirection(v, x, y); |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1381 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1382 |
|
1383 |
r = VehicleEnterTile(v, tile, x, y); |
|
1384 |
if (r & 8) { |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1385 |
if (!IsTileType(tile, MP_TUNNELBRIDGE)) { |
0 | 1386 |
v->cur_speed = 0; |
1387 |
return; |
|
1388 |
} |
|
1389 |
dir = _road_reverse_table[rd.x&3]; |
|
1390 |
goto again; |
|
1391 |
} |
|
1392 |
||
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1024
diff
changeset
|
1393 |
if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) { |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1394 |
if ((dir & 7) >= 6) { |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1395 |
v->cur_speed = 0; |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1396 |
return; |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1397 |
} |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3315
diff
changeset
|
1398 |
if (IsRoadStop(v->tile)) { |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1399 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
0 | 1400 |
|
3054
0cde017ea45d
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1401 |
// reached a loading bay, mark it as used and clear the usage bit |
0cde017ea45d
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1402 |
SETBIT(rs->status, v->u.road.state & 2 ? 1 : 0); // occupied bay |
0cde017ea45d
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1403 |
CLRBIT(rs->status, 7); // usage bit |
0 | 1404 |
} |
1405 |
} |
|
1406 |
||
1407 |
if (!(r & 4)) { |
|
1408 |
v->tile = tile; |
|
2823
d4be8420b41c
(svn r3371) -Fix: don't allow road-vehicles to perform an out-of-bound operation while overtaking in a curve (tnx to guru3, Tron and peter1138)
truelight
parents:
2819
diff
changeset
|
1409 |
v->u.road.state = (byte)dir; |
0 | 1410 |
v->u.road.frame = 0; |
1411 |
} |
|
1412 |
if (newdir != v->direction) { |
|
1413 |
v->direction = newdir; |
|
1414 |
v->cur_speed -= v->cur_speed >> 2; |
|
1415 |
} |
|
1416 |
||
1417 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1418 |
UpdateRoadVehDeltaXY(v); |
|
1419 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1420 |
return; |
|
1421 |
} |
|
1422 |
||
1423 |
if (rd.x & 0x40) { |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1424 |
int dir = RoadFindPathToDest(v, v->tile, (DiagDirection)(rd.x & 3)); |
0 | 1425 |
uint32 r; |
1426 |
int tmp; |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3153
diff
changeset
|
1427 |
Direction newdir; |
0 | 1428 |
const RoadDriveEntry *rdp; |
1429 |
||
1430 |
if (dir == -1) { |
|
1431 |
v->cur_speed = 0; |
|
1432 |
return; |
|
1433 |
} |
|
1434 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1435 |
tmp = (_opt.road_side << 4) + dir; |
0 | 1436 |
rdp = _road_drive_data[tmp]; |
1437 |
||
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1438 |
x = TileX(v->tile) * TILE_SIZE + rdp[1].x; |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3404
diff
changeset
|
1439 |
y = TileY(v->tile) * TILE_SIZE + rdp[1].y; |
0 | 1440 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1441 |
newdir = RoadVehGetSlidingDirection(v, x, y); |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1442 |
if (RoadVehFindCloseTo(v, x, y, newdir) != NULL) return; |
0 | 1443 |
|
1444 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1445 |
if (r & 8) { |
|
1446 |
v->cur_speed = 0; |
|
1447 |
return; |
|
1448 |
} |
|
1449 |
||
1450 |
v->u.road.state = tmp & ~16; |
|
1451 |
v->u.road.frame = 1; |
|
1452 |
||
1453 |
if (newdir != v->direction) { |
|
1454 |
v->direction = newdir; |
|
1455 |
v->cur_speed -= v->cur_speed >> 2; |
|
1456 |
} |
|
1457 |
||
1458 |
v->cur_image = GetRoadVehImage(v, newdir); |
|
1459 |
UpdateRoadVehDeltaXY(v); |
|
1460 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1461 |
return; |
|
1462 |
} |
|
1463 |
||
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1464 |
x = (v->x_pos & ~15) + (rd.x & 15); |
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1465 |
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
|
1466 |
|
0 | 1467 |
new_dir = RoadVehGetSlidingDirection(v, x, y); |
1468 |
||
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1469 |
if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30)) { |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1470 |
Vehicle* u = RoadVehFindCloseTo(v, x, y, new_dir); |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1471 |
|
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1472 |
if (u != NULL) { |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1473 |
if (v->u.road.overtaking == 0) RoadVehCheckOvertake(v, u); |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1474 |
return; |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1475 |
} |
0 | 1476 |
} |
1477 |
||
1478 |
old_dir = v->direction; |
|
1479 |
if (new_dir != old_dir) { |
|
1480 |
v->direction = new_dir; |
|
1481 |
v->cur_speed -= (v->cur_speed >> 2); |
|
1482 |
if (old_dir != v->u.road.state) { |
|
1483 |
v->cur_image = GetRoadVehImage(v, new_dir); |
|
1484 |
UpdateRoadVehDeltaXY(v); |
|
1485 |
SetRoadVehPosition(v, v->x_pos, v->y_pos); |
|
1486 |
return; |
|
1487 |
} |
|
1488 |
} |
|
1489 |
||
1490 |
if (v->u.road.state >= 0x20 && |
|
1491 |
_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) { |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1492 |
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1493 |
Station* st = GetStationByTile(v->tile); |
0 | 1494 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1495 |
if (v->current_order.type != OT_LEAVESTATION && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1496 |
v->current_order.type != OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1497 |
Order old_order; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1498 |
|
3054
0cde017ea45d
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1499 |
CLRBIT(rs->status, 7); |
0 | 1500 |
|
3315
c9d989783c55
(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents:
3236
diff
changeset
|
1501 |
v->last_station_visited = GetStationIndex(v->tile); |
0 | 1502 |
|
1503 |
RoadVehArrivesAt(v, st); |
|
1504 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1505 |
old_order = v->current_order; |
5651
79496e6d8a56
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr
parents:
5587
diff
changeset
|
1506 |
v->BeginLoading(); |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1507 |
v->current_order.flags = 0; |
0 | 1508 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1509 |
if (old_order.type == OT_GOTO_STATION && |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1510 |
v->current_order.dest == v->last_station_visited) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1511 |
v->current_order.flags = |
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1927
diff
changeset
|
1512 |
(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP; |
0 | 1513 |
} |
1514 |
||
1515 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC); |
|
5211
fb4dc0ca975d
(svn r7326) -Feature: Add support for gradual (un)loading of vehicles (Maedhros)
peter1138
parents:
5198
diff
changeset
|
1516 |
if (LoadUnloadVehicle(v, true)) { |
0 | 1517 |
InvalidateWindow(WC_ROADVEH_LIST, v->owner); |
1518 |
MarkRoadVehDirty(v); |
|
1519 |
} |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1520 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1521 |
return; |
1522 |
} |
|
1523 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1524 |
if (v->current_order.type != OT_GOTO_DEPOT) { |
3054
0cde017ea45d
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1525 |
if (HASBIT(rs->status, 7)) { |
0 | 1526 |
v->cur_speed = 0; |
1527 |
return; |
|
1528 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1529 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1530 |
v->current_order.flags = 0; |
3123 | 1531 |
ClearSlot(v); |
0 | 1532 |
} |
3054
0cde017ea45d
(svn r3643) Remove a local variable which is just a pointer to a road stop status field and had the sensible name 'b'; instead directly use the road stop status field
tron
parents:
3033
diff
changeset
|
1533 |
SETBIT(rs->status, 7); |
0 | 1534 |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1535 |
if (rs == v->u.road.slot) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1536 |
//we have arrived at the correct station |
3123 | 1537 |
ClearSlot(v); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1538 |
} else if (v->u.road.slot != NULL) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1539 |
//we have arrived at the wrong station |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1540 |
//XXX The question is .. what to do? Actually we shouldn't be here |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1541 |
//but I guess we need to clear the slot |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1542 |
DEBUG(ms, 0, "Vehicle %d (index %d) arrived at wrong stop", v->unitnumber, v->index); |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1543 |
if (v->tile != v->dest_tile) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1544 |
DEBUG(ms, 2, " current tile 0x%X is not destination tile 0x%X. Route problem", v->tile, v->dest_tile); |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1545 |
} |
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1546 |
if (v->dest_tile != v->u.road.slot->xy) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1547 |
DEBUG(ms, 2, " stop tile 0x%X is not destination tile 0x%X. Multistop desync", v->u.road.slot->xy, v->dest_tile); |
3138
7e6c85698ee5
(svn r3754) Miscellaneous changes: indentation, reduce variable scope, constness, avoid some more function pointer casts
tron
parents:
3137
diff
changeset
|
1548 |
} |
3123 | 1549 |
if (v->current_order.type != OT_GOTO_STATION) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1550 |
DEBUG(ms, 2, " current order type (%d) is not OT_GOTO_STATION", v->current_order.type); |
3123 | 1551 |
} else { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1552 |
if (v->current_order.dest != st->index) |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1553 |
DEBUG(ms, 2, " current station %d is not target station in current_order.station (%d)", |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1554 |
st->index, v->current_order.dest); |
3123 | 1555 |
} |
1556 |
||
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1557 |
DEBUG(ms, 2, " force a slot clearing"); |
3123 | 1558 |
ClearSlot(v); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1559 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1560 |
|
0 | 1561 |
StartRoadVehSound(v); |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1562 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1563 |
} |
1564 |
||
1565 |
r = VehicleEnterTile(v, v->tile, x, y); |
|
1566 |
if (r & 8) { |
|
1567 |
v->cur_speed = 0; |
|
1568 |
return; |
|
1569 |
} |
|
1570 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1571 |
if ((r & 4) == 0) v->u.road.frame++; |
0 | 1572 |
|
1573 |
v->cur_image = GetRoadVehImage(v, v->direction); |
|
1574 |
UpdateRoadVehDeltaXY(v); |
|
1575 |
RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y)); |
|
1576 |
} |
|
1577 |
||
1578 |
static void AgeRoadVehCargo(Vehicle *v) |
|
1579 |
{ |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1580 |
if (_age_cargo_skip_counter != 0) return; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1581 |
if (v->cargo_days != 255) v->cargo_days++; |
0 | 1582 |
} |
1583 |
||
1584 |
void RoadVeh_Tick(Vehicle *v) |
|
1585 |
{ |
|
1586 |
AgeRoadVehCargo(v); |
|
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1359
diff
changeset
|
1587 |
RoadVehController(v); |
0 | 1588 |
} |
1589 |
||
1590 |
static void CheckIfRoadVehNeedsService(Vehicle *v) |
|
1591 |
{ |
|
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1592 |
const Depot* depot; |
0 | 1593 |
|
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1594 |
if (_patches.servint_roadveh == 0) return; |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1595 |
if (!VehicleNeedsService(v)) return; |
3431 | 1596 |
if (v->vehstatus & VS_STOPPED) return; |
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1597 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1598 |
|
0 | 1599 |
// Don't interfere with a depot visit scheduled by the user, or a |
1600 |
// depot visit by the order list. |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1601 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1602 |
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0) |
0 | 1603 |
return; |
1604 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1605 |
// If we already got a slot at a stop, use that FIRST, and go to a depot later |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1606 |
if (v->u.road.slot != NULL) return; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1607 |
|
4529
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1608 |
if (IsRoadVehInDepot(v)) { |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1609 |
VehicleServiceInDepot(v); |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1610 |
return; |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1611 |
} |
18bd5e7e35aa
(svn r6356) -Fix: FS#263 planes come out of hangar and drive back into hangar
bjarni
parents:
4527
diff
changeset
|
1612 |
|
3612 | 1613 |
// XXX If we already have a depot order, WHY do we search over and over? |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1614 |
depot = FindClosestRoadDepot(v); |
0 | 1615 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1616 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
1520
d88442095697
(svn r2024) -Fix: [autoreplace] reverted all changes involving v->set_for_replacement as they caused desyncs.
bjarni
parents:
1467
diff
changeset
|
1617 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1618 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1619 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1620 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1621 |
} |
1622 |
return; |
|
1623 |
} |
|
1624 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1625 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1626 |
v->current_order.flags & OF_NON_STOP && |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1627 |
!CHANCE16(1, 20)) { |
0 | 1628 |
return; |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1629 |
} |
0 | 1630 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1631 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1632 |
v->current_order.flags = OF_NON_STOP; |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1633 |
v->current_order.dest = depot->index; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1299
diff
changeset
|
1634 |
v->dest_tile = depot->xy; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1635 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1636 |
} |
1637 |
||
1638 |
void OnNewDay_RoadVeh(Vehicle *v) |
|
1639 |
{ |
|
1640 |
int32 cost; |
|
1641 |
||
3017
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1642 |
if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); |
a75caf4efa2d
(svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents:
3009
diff
changeset
|
1643 |
if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v); |
0 | 1644 |
|
1645 |
AgeVehicle(v); |
|
1646 |
CheckIfRoadVehNeedsService(v); |
|
1647 |
||
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1648 |
CheckOrders(v); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
1649 |
|
3123 | 1650 |
//Current slot has expired |
3481
db0ca6fe9800
(svn r4326) Only reduce the slot age of a vehicle if it has a slot assigned
tron
parents:
3431
diff
changeset
|
1651 |
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot != NULL && v->u.road.slot_age-- == 0) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1652 |
DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X", |
3431 | 1653 |
v->unitnumber, v->index, v->u.road.slot->xy); |
3123 | 1654 |
ClearSlot(v); |
1655 |
} |
|
1656 |
||
3236 | 1657 |
if (v->vehstatus & VS_STOPPED) return; |
1658 |
||
0 | 1659 |
/* update destination */ |
3431 | 1660 |
if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4526
diff
changeset
|
1661 |
Station* st = GetStation(v->current_order.dest); |
5876 | 1662 |
RoadStop* rs = st->GetPrimaryRoadStop(v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1663 |
RoadStop* best = NULL; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1664 |
|
3123 | 1665 |
if (rs != NULL) { |
1666 |
if (DistanceManhattan(v->tile, st->xy) < 16) { |
|
3431 | 1667 |
uint dist, badness; |
1668 |
uint minbadness = UINT_MAX; |
|
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1669 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1670 |
DEBUG(ms, 2, "Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)", |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1671 |
v->unitnumber, v->index, st->index, st->xy |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3990
diff
changeset
|
1672 |
); |
3123 | 1673 |
/* Now we find the nearest road stop that has a free slot */ |
3431 | 1674 |
for (; rs != NULL; rs = rs->next) { |
1675 |
dist = RoadFindPathToStop(v, rs->xy); |
|
1676 |
if (dist == UINT_MAX) { |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1677 |
DEBUG(ms, 4, " stop 0x%X is unreachable, not treating further", rs->xy); |
3123 | 1678 |
continue; |
1679 |
} |
|
3915
914d45c135c7
(svn r5033) -CodeChange: [YAPF] RoadFindPathToStop() can now use YAPF for multistop handling.
KUDr
parents:
3900
diff
changeset
|
1680 |
badness = (rs->num_vehicles + 1) * (rs->num_vehicles + 1) + dist; |
3123 | 1681 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1682 |
DEBUG(ms, 4, " stop 0x%X has %d vehicle%s waiting", rs->xy, rs->num_vehicles, rs->num_vehicles == 1 ? "":"s"); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1683 |
DEBUG(ms, 4, " distance is %u", dist); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1684 |
DEBUG(ms, 4, " badness %u", badness); |
3431 | 1685 |
|
1686 |
if (badness < minbadness) { |
|
1687 |
best = rs; |
|
1688 |
minbadness = badness; |
|
3123 | 1689 |
} |
3033
9cba043eb38f
(svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents:
3032
diff
changeset
|
1690 |
} |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1691 |
|
3431 | 1692 |
if (best != NULL) { |
1693 |
best->num_vehicles++; |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1694 |
DEBUG(ms, 3, "Assigned to stop 0x%X", best->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1695 |
|
3431 | 1696 |
v->u.road.slot = best; |
1697 |
v->dest_tile = best->xy; |
|
1698 |
v->u.road.slot_age = 14; |
|
3123 | 1699 |
} else { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1700 |
DEBUG(ms, 3, "Could not find a suitable stop"); |
3123 | 1701 |
} |
1702 |
} else { |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1703 |
DEBUG(ms, 5, "Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%X)", |
3123 | 1704 |
v->unitnumber, v->index, st->index, st->xy); |
1295
ae28afd6267e
(svn r1799) -Codechange: [ Multistop ] Added debug class "ms" and more debugging
celestar
parents:
1282
diff
changeset
|
1705 |
} |
3123 | 1706 |
} else { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5259
diff
changeset
|
1707 |
DEBUG(ms, 4, "No road stop for vehicle %d (index %d) at station %d (0x%X)", |
3123 | 1708 |
v->unitnumber, v->index, st->index, st->xy); |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1209
diff
changeset
|
1709 |
} |
0 | 1710 |
} |
1711 |
||
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
1712 |
cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
0 | 1713 |
|
1714 |
v->profit_this_year -= cost >> 8; |
|
1715 |
||
1716 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
|
1717 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
1718 |
||
1719 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
1720 |
InvalidateWindowClasses(WC_ROADVEH_LIST); |
0 | 1721 |
} |
1722 |
||
1723 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1053
diff
changeset
|
1724 |
void RoadVehiclesYearlyLoop(void) |
0 | 1725 |
{ |
1726 |
Vehicle *v; |
|
1727 |
||
1728 |
FOR_ALL_VEHICLES(v) { |
|
1729 |
if (v->type == VEH_Road) { |
|
1730 |
v->profit_last_year = v->profit_this_year; |
|
1731 |
v->profit_this_year = 0; |
|
1732 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1733 |
} |
|
1734 |
} |
|
1735 |
} |
|
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1736 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1737 |
/** Refit a road vehicle to the specified cargo type |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1738 |
* @param tile unused |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1739 |
* @param p1 Vehicle ID of the vehicle to refit |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1740 |
* @param p2 Bitstuffed elements |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1741 |
* - p2 = (bit 0-7) - the new cargo type to refit to |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1742 |
* - p2 = (bit 8-15) - the new cargo subtype to refit to |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1743 |
*/ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1744 |
int32 CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1745 |
{ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1746 |
Vehicle *v; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1747 |
int32 cost; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1748 |
CargoID new_cid = GB(p2, 0, 8); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1749 |
byte new_subtype = GB(p2, 8, 8); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1750 |
uint16 capacity = CALLBACK_FAILED; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1751 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
1752 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1753 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1754 |
v = GetVehicle(p1); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1755 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1756 |
if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1757 |
if (!IsRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1758 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1759 |
if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1760 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1761 |
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1762 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1763 |
if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1764 |
/* Back up the cargo type */ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1765 |
CargoID temp_cid = v->cargo_type; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1766 |
byte temp_subtype = v->cargo_subtype; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1767 |
v->cargo_type = new_cid; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1768 |
v->cargo_subtype = new_subtype; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1769 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1770 |
/* Check the refit capacity callback */ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1771 |
capacity = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1772 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1773 |
/* Restore the original cargo type */ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1774 |
v->cargo_type = temp_cid; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1775 |
v->cargo_subtype = temp_subtype; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1776 |
} |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1777 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1778 |
if (capacity == CALLBACK_FAILED) { |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1779 |
/* callback failed or not used, use default capacity */ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1780 |
const RoadVehicleInfo *rvi = RoadVehInfo(v->engine_type); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1781 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1782 |
CargoID old_cid = rvi->cargo_type; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1783 |
/* normally, the capacity depends on the cargo type, a vehicle can |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1784 |
* carry twice as much mail/goods as normal cargo, and four times as |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1785 |
* many passengers |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1786 |
*/ |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1787 |
capacity = rvi->capacity; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1788 |
switch (old_cid) { |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1789 |
case CT_PASSENGERS: break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1790 |
case CT_MAIL: |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1791 |
case CT_GOODS: capacity *= 2; break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1792 |
default: capacity *= 4; break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1793 |
} |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1794 |
switch (new_cid) { |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1795 |
case CT_PASSENGERS: break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1796 |
case CT_MAIL: |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1797 |
case CT_GOODS: capacity /= 2; break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1798 |
default: capacity /= 4; break; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1799 |
} |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1800 |
} |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1801 |
_returned_refit_capacity = capacity; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1802 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1803 |
cost = 0; |
4845
72bbb6e2694e
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4739
diff
changeset
|
1804 |
if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) { |
4544
69f1248a2d97
(svn r6376) -Codechange: [vehicle refit] moved all refit cost calculations into GetRefitCost()
bjarni
parents:
4529
diff
changeset
|
1805 |
cost = GetRefitCost(v->engine_type); |
3990
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1806 |
} |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1807 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1808 |
if (flags & DC_EXEC) { |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1809 |
v->cargo_cap = capacity; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1810 |
v->cargo_count = (v->cargo_type == new_cid) ? min(capacity, v->cargo_count) : 0; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1811 |
v->cargo_type = new_cid; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1812 |
v->cargo_subtype = new_subtype; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1813 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1814 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1815 |
RebuildVehicleLists(); |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1816 |
} |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1817 |
|
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1818 |
return cost; |
a317e665fb77
(svn r5191) - NewGRF: add cargo refit support for road vehicles
peter1138
parents:
3977
diff
changeset
|
1819 |
} |