author | rubidium |
Sun, 20 Aug 2006 19:05:28 +0000 | |
changeset 4329 | 9759d5c52010 |
parent 4293 | 2c24234a7aec |
child 4344 | 5d0e40cd67b9 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1802
diff
changeset
|
4 |
#include "openttd.h" |
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
5 |
#include "ship.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
6 |
#include "table/strings.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
7 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
8 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
9 |
#include "tile.h" |
0 | 10 |
#include "vehicle.h" |
11 |
#include "command.h" |
|
12 |
#include "pathfind.h" |
|
3442
c494e7246d7b
(svn r4272) -Codechange: Moved the map-accessing stuff from station.h into station_map.h
celestar
parents:
3421
diff
changeset
|
13 |
#include "station_map.h" |
0 | 14 |
#include "station.h" |
15 |
#include "news.h" |
|
16 |
#include "engine.h" |
|
17 |
#include "player.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
297
diff
changeset
|
18 |
#include "sound.h" |
1247 | 19 |
#include "npf.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
20 |
#include "depot.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
21 |
#include "vehicle_gui.h" |
2962
dbd168a4703a
(svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents:
2916
diff
changeset
|
22 |
#include "newgrf_engine.h" |
3454
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
23 |
#include "water_map.h" |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
24 |
#include "yapf/yapf.h" |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
25 |
#include "debug.h" |
3989
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
26 |
#include "newgrf_callbacks.h" |
4244
44dcec623504
(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
|
27 |
#include "newgrf_text.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4244
diff
changeset
|
28 |
#include "date.h" |
0 | 29 |
|
30 |
static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D}; |
|
31 |
static const byte _ship_sometracks[4] = {0x19, 0x16, 0x25, 0x2A}; |
|
32 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
33 |
static byte GetTileShipTrackStatus(TileIndex tile) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
34 |
{ |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
35 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_WATER); |
0 | 36 |
return r | r >> 8; |
37 |
} |
|
38 |
||
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2464
diff
changeset
|
39 |
void DrawShipEngine(int x, int y, EngineID engine, uint32 image_ormod) |
0 | 40 |
{ |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
41 |
int spritenum = ShipVehInfo(engine)->image_index; |
0 | 42 |
|
43 |
if (is_custom_sprite(spritenum)) { |
|
3186
5798593c2d95
(svn r3832) Replace some magic numbers by (Diag)Direction enums
tron
parents:
3157
diff
changeset
|
44 |
int sprite = GetCustomVehicleIcon(engine, DIR_W); |
0 | 45 |
|
2639 | 46 |
if (sprite != 0) { |
0 | 47 |
DrawSprite(sprite | image_ormod, x, y); |
48 |
return; |
|
49 |
} |
|
2464
3dee59d241c0
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2214
diff
changeset
|
50 |
spritenum = orig_ship_vehicle_info[engine - SHIP_ENGINES_INDEX].image_index; |
0 | 51 |
} |
52 |
DrawSprite((6 + _ship_sprites[spritenum]) | image_ormod, x, y); |
|
53 |
} |
|
54 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
55 |
int GetShipImage(const Vehicle* v, Direction direction) |
0 | 56 |
{ |
57 |
int spritenum = v->spritenum; |
|
58 |
||
59 |
if (is_custom_sprite(spritenum)) { |
|
60 |
int sprite = GetCustomVehicleSprite(v, direction); |
|
61 |
||
2639 | 62 |
if (sprite != 0) return sprite; |
2464
3dee59d241c0
(svn r2990) Remove _engine_original_sprites and replace all uses with references to our (new) original engine/vehicle tables.
peter1138
parents:
2214
diff
changeset
|
63 |
spritenum = orig_ship_vehicle_info[v->engine_type - SHIP_ENGINES_INDEX].image_index; |
0 | 64 |
} |
65 |
return _ship_sprites[spritenum] + direction; |
|
66 |
} |
|
67 |
||
2630 | 68 |
static const Depot* FindClosestShipDepot(const Vehicle* v) |
0 | 69 |
{ |
2630 | 70 |
const Depot* depot; |
71 |
const Depot* best_depot = NULL; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
72 |
uint dist; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
73 |
uint best_dist = (uint)-1; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
74 |
TileIndex tile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
75 |
TileIndex tile2 = v->tile; |
0 | 76 |
|
1247 | 77 |
if (_patches.new_pathfinding_all) { |
78 |
NPFFoundTargetData ftd; |
|
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1751
diff
changeset
|
79 |
byte trackdir = GetVehicleTrackdir(v); |
2006
324916f22a8a
(svn r2514) - Codechange: [NPF] Move the checking of railtype into a funciton IsCompatibleRail().
matthijs
parents:
1998
diff
changeset
|
80 |
ftd = NPFRouteToDepotTrialError(v->tile, trackdir, TRANSPORT_WATER, v->owner, INVALID_RAILTYPE); |
2639 | 81 |
if (ftd.best_bird_dist == 0) { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
82 |
best_depot = GetDepotByTile(ftd.node.tile); /* Found target */ |
2639 | 83 |
} else { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
84 |
best_depot = NULL; /* Did not find target */ |
2639 | 85 |
} |
1247 | 86 |
} else { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
87 |
FOR_ALL_DEPOTS(depot) { |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
88 |
tile = depot->xy; |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1313
diff
changeset
|
89 |
if (IsValidDepot(depot) && IsTileDepotType(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) { |
1247 | 90 |
dist = DistanceManhattan(tile, tile2); |
91 |
if (dist < best_dist) { |
|
92 |
best_dist = dist; |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
93 |
best_depot = depot; |
1247 | 94 |
} |
0 | 95 |
} |
96 |
} |
|
97 |
} |
|
98 |
return best_depot; |
|
99 |
} |
|
100 |
||
101 |
static void CheckIfShipNeedsService(Vehicle *v) |
|
102 |
{ |
|
2630 | 103 |
const Depot* depot; |
0 | 104 |
|
2639 | 105 |
if (_patches.servint_ships == 0) return; |
106 |
if (!VehicleNeedsService(v)) return; |
|
107 |
if (v->vehstatus & VS_STOPPED) return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
108 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
109 |
if (v->current_order.type == OT_GOTO_DEPOT && |
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
110 |
v->current_order.flags & OF_HALT_IN_DEPOT) |
0 | 111 |
return; |
112 |
||
2639 | 113 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; |
0 | 114 |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
115 |
depot = FindClosestShipDepot(v); |
0 | 116 |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
117 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
118 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
119 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
120 |
v->current_order.flags = 0; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
121 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 122 |
} |
123 |
return; |
|
124 |
} |
|
125 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
126 |
v->current_order.type = OT_GOTO_DEPOT; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
127 |
v->current_order.flags = OF_NON_STOP; |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
128 |
v->current_order.station = depot->index; |
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
129 |
v->dest_tile = depot->xy; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
130 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 131 |
} |
132 |
||
133 |
void OnNewDay_Ship(Vehicle *v) |
|
134 |
{ |
|
135 |
int32 cost; |
|
136 |
||
137 |
if ((++v->day_counter & 7) == 0) |
|
138 |
DecreaseVehicleValue(v); |
|
139 |
||
140 |
CheckVehicleBreakdown(v); |
|
141 |
AgeVehicle(v); |
|
142 |
CheckIfShipNeedsService(v); |
|
143 |
||
3140
69cb681c6d86
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
144 |
CheckOrders(v); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
145 |
|
2639 | 146 |
if (v->vehstatus & VS_STOPPED) return; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
147 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
148 |
cost = ShipVehInfo(v->engine_type)->running_cost * _price.ship_running / 364; |
0 | 149 |
v->profit_this_year -= cost >> 8; |
150 |
||
151 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN); |
|
152 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
153 |
||
154 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
155 |
//we need this for the profit |
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
156 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 157 |
} |
158 |
||
159 |
static void HandleBrokenShip(Vehicle *v) |
|
160 |
{ |
|
161 |
if (v->breakdown_ctr != 1) { |
|
162 |
v->breakdown_ctr = 1; |
|
163 |
v->cur_speed = 0; |
|
164 |
||
165 |
if (v->breakdowns_since_last_service != 255) |
|
166 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
167 |
|
0 | 168 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
169 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
170 |
|
541 | 171 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
172 |
SND_10_TRAIN_BREAKDOWN : SND_3A_COMEDY_BREAKDOWN_2, v); |
|
0 | 173 |
|
174 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
175 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
2639 | 176 |
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; |
0 | 177 |
} |
178 |
} |
|
179 |
||
180 |
if (!(v->tick_counter & 1)) { |
|
181 |
if (!--v->breakdown_delay) { |
|
182 |
v->breakdown_ctr = 0; |
|
1151
614cbcb5b9fe
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
183 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
0 | 184 |
} |
185 |
} |
|
186 |
} |
|
187 |
||
188 |
static void MarkShipDirty(Vehicle *v) |
|
189 |
{ |
|
190 |
v->cur_image = GetShipImage(v, v->direction); |
|
191 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
192 |
} |
|
193 |
||
194 |
static void PlayShipSound(Vehicle *v) |
|
195 |
{ |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
196 |
SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v); |
0 | 197 |
} |
198 |
||
199 |
static void ProcessShipOrder(Vehicle *v) |
|
200 |
{ |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
201 |
const Order *order; |
0 | 202 |
|
3005
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
203 |
switch (v->current_order.type) { |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
204 |
case OT_GOTO_DEPOT: |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
205 |
if (!(v->current_order.flags & OF_PART_OF_ORDERS)) return; |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
206 |
if (v->current_order.flags & OF_SERVICE_IF_NEEDED && |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
207 |
!VehicleNeedsService(v)) { |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
208 |
v->cur_order_index++; |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
209 |
} |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
210 |
break; |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
211 |
|
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
212 |
case OT_LOADING: |
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
213 |
case OT_LEAVESTATION: |
0 | 214 |
return; |
215 |
} |
|
216 |
||
3005
db4007baa0ab
(svn r3585) Similar changes to the order handlers of the other vehicle types like r3584
tron
parents:
2962
diff
changeset
|
217 |
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
0 | 218 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
219 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 220 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
221 |
if (order == NULL) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
222 |
v->current_order.type = OT_NOTHING; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
223 |
v->current_order.flags = 0; |
0 | 224 |
v->dest_tile = 0; |
225 |
return; |
|
226 |
} |
|
227 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
228 |
if (order->type == v->current_order.type && |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
229 |
order->flags == v->current_order.flags && |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
230 |
order->station == v->current_order.station) |
0 | 231 |
return; |
232 |
||
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
233 |
v->current_order = *order; |
0 | 234 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
235 |
if (order->type == OT_GOTO_STATION) { |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
236 |
const Station *st; |
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
237 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
238 |
if (order->station == v->last_station_visited) |
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
239 |
v->last_station_visited = INVALID_STATION; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
240 |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
241 |
st = GetStation(order->station); |
0 | 242 |
if (st->dock_tile != 0) { |
3472
7ef2b2d6a632
(svn r4317) -Codechange: More map accessors for ship_cmd. it is now map-access free, but still requires a huge cleanup
celestar
parents:
3454
diff
changeset
|
243 |
v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile))); |
0 | 244 |
} |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
245 |
} else if (order->type == OT_GOTO_DEPOT) { |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
246 |
v->dest_tile = GetDepot(order->station)->xy; |
0 | 247 |
} else { |
248 |
v->dest_tile = 0; |
|
249 |
} |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
250 |
|
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
251 |
InvalidateVehicleOrder(v); |
1020
1223cd937174
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
926
diff
changeset
|
252 |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
253 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 254 |
} |
255 |
||
256 |
static void HandleShipLoading(Vehicle *v) |
|
257 |
{ |
|
2639 | 258 |
if (v->current_order.type == OT_NOTHING) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
259 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
260 |
if (v->current_order.type != OT_DUMMY) { |
2639 | 261 |
if (v->current_order.type != OT_LOADING) return; |
262 |
if (--v->load_unload_time_rem) return; |
|
0 | 263 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
264 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 265 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC); |
266 |
if (LoadUnloadVehicle(v)) { |
|
267 |
InvalidateWindow(WC_SHIPS_LIST, v->owner); |
|
268 |
MarkShipDirty(v); |
|
269 |
} |
|
270 |
return; |
|
271 |
} |
|
272 |
PlayShipSound(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
273 |
|
0 | 274 |
{ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
275 |
Order b = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
276 |
v->current_order.type = OT_LEAVESTATION; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
277 |
v->current_order.flags = 0; |
2639 | 278 |
if (!(b.flags & OF_NON_STOP)) return; |
0 | 279 |
} |
280 |
} |
|
281 |
||
282 |
v->cur_order_index++; |
|
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
283 |
InvalidateVehicleOrder(v); |
0 | 284 |
} |
285 |
||
286 |
static void UpdateShipDeltaXY(Vehicle *v, int dir) |
|
287 |
{ |
|
288 |
#define MKIT(d,c,b,a) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
289 |
static const uint32 _delta_xy_table[8] = { |
|
290 |
MKIT( -3, -3, 6, 6), |
|
291 |
MKIT(-16, -3, 32, 6), |
|
292 |
MKIT( -3, -3, 6, 6), |
|
293 |
MKIT( -3,-16, 6, 32), |
|
294 |
MKIT( -3, -3, 6, 6), |
|
295 |
MKIT(-16, -3, 32, 6), |
|
296 |
MKIT( -3, -3, 6, 6), |
|
297 |
MKIT( -3,-16, 6, 32), |
|
298 |
}; |
|
299 |
#undef MKIT |
|
300 |
uint32 x = _delta_xy_table[dir]; |
|
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2049
diff
changeset
|
301 |
v->x_offs = GB(x, 0, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2049
diff
changeset
|
302 |
v->y_offs = GB(x, 8, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2049
diff
changeset
|
303 |
v->sprite_width = GB(x, 16, 8); |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2049
diff
changeset
|
304 |
v->sprite_height = GB(x, 24, 8); |
0 | 305 |
} |
306 |
||
307 |
static void RecalcShipStuff(Vehicle *v) |
|
308 |
{ |
|
309 |
UpdateShipDeltaXY(v, v->direction); |
|
310 |
v->cur_image = GetShipImage(v, v->direction); |
|
311 |
MarkShipDirty(v); |
|
312 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
313 |
} |
|
314 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
315 |
static const TileIndexDiffC _ship_leave_depot_offs[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
316 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
317 |
{ 0, -1} |
0 | 318 |
}; |
319 |
||
320 |
static void CheckShipLeaveDepot(Vehicle *v) |
|
321 |
{ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
322 |
TileIndex tile; |
3454
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
323 |
Axis axis; |
0 | 324 |
uint m; |
325 |
||
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
326 |
if (!IsShipInDepot(v)) return; |
0 | 327 |
|
328 |
tile = v->tile; |
|
3454
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
329 |
axis = GetShipDepotAxis(tile); |
0 | 330 |
|
331 |
// Check first side |
|
3454
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
332 |
if (_ship_sometracks[axis] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis])))) { |
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
333 |
m = (axis == AXIS_X) ? 0x101 : 0x207; |
0 | 334 |
// Check second side |
3454
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
335 |
} else if (_ship_sometracks[axis + 2] & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis])))) { |
c2447e8c1e23
(svn r4289) -Codechange: Make use of water_map accessors for ships. Make a mental note to clean ship_cmd
celestar
parents:
3442
diff
changeset
|
336 |
m = (axis == AXIS_X) ? 0x105 : 0x203; |
0 | 337 |
} else { |
338 |
return; |
|
339 |
} |
|
2635 | 340 |
v->direction = GB(m, 0, 8); |
341 |
v->u.ship.state = GB(m, 8, 8); |
|
0 | 342 |
v->vehstatus &= ~VS_HIDDEN; |
343 |
||
344 |
v->cur_speed = 0; |
|
345 |
RecalcShipStuff(v); |
|
346 |
||
347 |
PlayShipSound(v); |
|
578
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
348 |
VehicleServiceInDepot(v); |
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
349 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 350 |
} |
351 |
||
352 |
static bool ShipAccelerate(Vehicle *v) |
|
353 |
{ |
|
354 |
uint spd; |
|
355 |
byte t; |
|
356 |
||
357 |
spd = min(v->cur_speed + 1, v->max_speed); |
|
358 |
||
359 |
//updates statusbar only if speed have changed to save CPU time |
|
360 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
361 |
v->cur_speed = spd; |
0 | 362 |
if (_patches.vehicle_speed) |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
363 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 364 |
} |
365 |
||
366 |
// Decrease somewhat when turning |
|
2639 | 367 |
if (!(v->direction & 1)) spd = spd * 3 / 4; |
0 | 368 |
|
2639 | 369 |
if (spd == 0) return false; |
370 |
if ((byte)++spd == 0) return true; |
|
0 | 371 |
|
372 |
v->progress = (t = v->progress) - (byte)spd; |
|
373 |
||
374 |
return (t < v->progress); |
|
375 |
} |
|
376 |
||
2817 | 377 |
static int32 EstimateShipCost(EngineID engine_type) |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
378 |
{ |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
379 |
return ShipVehInfo(engine_type)->base_cost * (_price.ship_base>>3)>>5; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
380 |
} |
0 | 381 |
|
382 |
static void ShipEnterDepot(Vehicle *v) |
|
383 |
{ |
|
384 |
v->u.ship.state = 0x80; |
|
385 |
v->vehstatus |= VS_HIDDEN; |
|
386 |
v->cur_speed = 0; |
|
387 |
RecalcShipStuff(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
388 |
|
578
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
389 |
VehicleServiceInDepot(v); |
86e352980acd
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
390 |
|
0 | 391 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
392 |
||
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
393 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
410
diff
changeset
|
394 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
395 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
396 |
Order t; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
397 |
|
0 | 398 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
399 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
400 |
t = v->current_order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
401 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
402 |
v->current_order.flags = 0; |
0 | 403 |
|
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
404 |
if (HASBIT(t.flags, OFB_PART_OF_ORDERS)) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
405 |
v->cur_order_index++; |
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
406 |
} else if (HASBIT(t.flags, OFB_HALT_IN_DEPOT)) { |
0 | 407 |
v->vehstatus |= VS_STOPPED; |
408 |
if (v->owner == _local_player) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
409 |
SetDParam(0, v->unitnumber); |
0 | 410 |
AddNewsItem( |
411 |
STR_981C_SHIP_IS_WAITING_IN_DEPOT, |
|
412 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
413 |
v->index, |
|
414 |
0); |
|
415 |
} |
|
416 |
} |
|
417 |
} |
|
1055
3aae1d6f12aa
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
418 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 419 |
} |
420 |
||
2630 | 421 |
static void ShipArrivesAt(const Vehicle* v, Station* st) |
0 | 422 |
{ |
423 |
/* Check if station was ever visited before */ |
|
424 |
if (!(st->had_vehicle_of_type & HVOT_SHIP)) { |
|
425 |
uint32 flags; |
|
2639 | 426 |
|
0 | 427 |
st->had_vehicle_of_type |= HVOT_SHIP; |
2639 | 428 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
429 |
SetDParam(0, st->index); |
0 | 430 |
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); |
431 |
AddNewsItem( |
|
432 |
STR_9833_CITIZENS_CELEBRATE_FIRST, |
|
433 |
flags, |
|
434 |
v->index, |
|
435 |
0); |
|
436 |
} |
|
437 |
} |
|
438 |
||
439 |
typedef struct { |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
440 |
TileIndex skiptile; |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
441 |
TileIndex dest_coords; |
0 | 442 |
uint best_bird_dist; |
443 |
uint best_length; |
|
444 |
} PathFindShip; |
|
445 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
446 |
static bool ShipTrackFollower(TileIndex tile, PathFindShip *pfs, int track, uint length, byte *state) |
0 | 447 |
{ |
448 |
// Found dest? |
|
449 |
if (tile == pfs->dest_coords) { |
|
450 |
pfs->best_bird_dist = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
451 |
|
0 | 452 |
pfs->best_length = minu(pfs->best_length, length); |
453 |
return true; |
|
454 |
} |
|
455 |
||
456 |
// Skip this tile in the calculation |
|
457 |
if (tile != pfs->skiptile) { |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1237
diff
changeset
|
458 |
pfs->best_bird_dist = minu(pfs->best_bird_dist, DistanceMaxPlusManhattan(pfs->dest_coords, tile)); |
0 | 459 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
460 |
|
0 | 461 |
return false; |
462 |
} |
|
463 |
||
464 |
static const byte _ship_search_directions[6][4] = { |
|
465 |
{ 0, 9, 2, 9 }, |
|
466 |
{ 9, 1, 9, 3 }, |
|
467 |
{ 9, 0, 3, 9 }, |
|
468 |
{ 1, 9, 9, 2 }, |
|
469 |
{ 3, 2, 9, 9 }, |
|
470 |
{ 9, 9, 1, 0 }, |
|
471 |
}; |
|
472 |
||
473 |
static const byte _pick_shiptrack_table[6] = {1, 3, 2, 2, 0, 0}; |
|
474 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
475 |
static uint FindShipTrack(Vehicle *v, TileIndex tile, int dir, uint bits, TileIndex skiptile, int *track) |
0 | 476 |
{ |
477 |
PathFindShip pfs; |
|
478 |
int i, best_track; |
|
479 |
uint best_bird_dist = 0; |
|
480 |
uint best_length = 0; |
|
481 |
uint r; |
|
482 |
byte ship_dir = v->direction & 3; |
|
483 |
||
484 |
pfs.dest_coords = v->dest_tile; |
|
485 |
pfs.skiptile = skiptile; |
|
486 |
||
487 |
best_track = -1; |
|
488 |
||
489 |
do { |
|
490 |
i = FIND_FIRST_BIT(bits); |
|
491 |
bits = KILL_FIRST_BIT(bits); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
492 |
|
0 | 493 |
pfs.best_bird_dist = (uint)-1; |
494 |
pfs.best_length = (uint)-1; |
|
495 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
496 |
FollowTrack(tile, 0x3800 | TRANSPORT_WATER, _ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
497 |
|
0 | 498 |
if (best_track >= 0) { |
499 |
if (pfs.best_bird_dist != 0) { |
|
500 |
/* neither reached the destination, pick the one with the smallest bird dist */ |
|
501 |
if (pfs.best_bird_dist > best_bird_dist) goto bad; |
|
502 |
if (pfs.best_bird_dist < best_bird_dist) goto good; |
|
503 |
} else { |
|
504 |
if (pfs.best_length > best_length) goto bad; |
|
505 |
if (pfs.best_length < best_length) goto good; |
|
506 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
507 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
508 |
/* if we reach this position, there's two paths of equal value so far. |
0 | 509 |
* pick one randomly. */ |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2049
diff
changeset
|
510 |
r = GB(Random(), 0, 8); |
0 | 511 |
if (_pick_shiptrack_table[i] == ship_dir) r += 80; |
512 |
if (_pick_shiptrack_table[best_track] == ship_dir) r -= 80; |
|
513 |
if (r <= 127) goto bad; |
|
514 |
} |
|
515 |
good:; |
|
516 |
best_track = i; |
|
517 |
best_bird_dist = pfs.best_bird_dist; |
|
518 |
best_length = pfs.best_length; |
|
519 |
bad:; |
|
520 |
||
521 |
} while (bits != 0); |
|
522 |
||
523 |
*track = best_track; |
|
524 |
return best_bird_dist; |
|
525 |
} |
|
526 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
527 |
static inline NPFFoundTargetData PerfNPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes) |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
528 |
{ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
529 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
530 |
void* perf = NpfBeginInterval(); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
531 |
NPFFoundTargetData ret = NPFRouteToStationOrTile(tile, trackdir, target, type, owner, railtypes); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
532 |
int t = NpfEndInterval(perf); |
3947
7ab994b0fe9c
(svn r5093) -CodeChange: [YAPF] min. debug level changed from 1 to 3 and 4 for frequent debug messages (performance stats)
KUDr
parents:
3900
diff
changeset
|
533 |
DEBUG(yapf, 4)("[YAPF][NPFW] %d us - %d rounds - %d open - %d closed -- ", t, 0, _aystar_stats_open_size, _aystar_stats_closed_size); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
534 |
return ret; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
535 |
} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
536 |
|
1247 | 537 |
/* returns the track to choose on the next tile, or -1 when it's better to |
538 |
* reverse. The tile given is the tile we are about to enter, enterdir is the |
|
539 |
* direction in which we are entering the tile */ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
540 |
static int ChooseShipTrack(Vehicle *v, TileIndex tile, int enterdir, uint tracks) |
0 | 541 |
{ |
1247 | 542 |
assert(enterdir>=0 && enterdir<=3); |
0 | 543 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
544 |
if (_patches.yapf.ship_use_yapf) { |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
545 |
Trackdir trackdir = YapfChooseShipTrack(v, tile, enterdir, tracks); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
546 |
return (trackdir != INVALID_TRACKDIR) ? (int)TrackdirToTrack(trackdir) : -1; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
547 |
} else if (_patches.new_pathfinding_all) { |
1247 | 548 |
NPFFindStationOrTileData fstd; |
549 |
NPFFoundTargetData ftd; |
|
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
3140
diff
changeset
|
550 |
TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagDir(enterdir))); |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1751
diff
changeset
|
551 |
byte trackdir = GetVehicleTrackdir(v); |
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1751
diff
changeset
|
552 |
assert (trackdir != 0xFF); /* Check that we are not in a depot */ |
1247 | 553 |
|
554 |
NPFFillWithOrderData(&fstd, v); |
|
555 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3870
diff
changeset
|
556 |
ftd = PerfNPFRouteToStationOrTile(src_tile, trackdir, &fstd, TRANSPORT_WATER, v->owner, INVALID_RAILTYPE); |
1247 | 557 |
|
2639 | 558 |
if (ftd.best_trackdir != 0xff) { |
1698
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1530
diff
changeset
|
559 |
/* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains |
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1530
diff
changeset
|
560 |
the direction we need to take to get there, if ftd.best_bird_dist is not 0, |
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1530
diff
changeset
|
561 |
we did not find our target, but ftd.best_trackdir contains the direction leading |
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1530
diff
changeset
|
562 |
to the tile closest to our target. */ |
1247 | 563 |
return ftd.best_trackdir & 7; /* TODO: Wrapper function? */ |
2639 | 564 |
} else { |
1698
bf364c664a60
(svn r2202) - Fix: [NPF] When a vehicle could not reach its target, it would choose a random direction. It will now try to get as close as possible.
matthijs
parents:
1530
diff
changeset
|
565 |
return -1; /* Already at target, reverse? */ |
2639 | 566 |
} |
1247 | 567 |
} else { |
568 |
uint b; |
|
569 |
uint tot_dist, dist; |
|
570 |
int track; |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
571 |
TileIndex tile2; |
1247 | 572 |
|
573 |
tile2 = TILE_ADD(tile, -TileOffsByDir(enterdir)); |
|
574 |
tot_dist = (uint)-1; |
|
575 |
||
576 |
/* Let's find out how far it would be if we would reverse first */ |
|
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
3140
diff
changeset
|
577 |
b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagDir(enterdir)] & v->u.ship.state; |
1247 | 578 |
if (b != 0) { |
3147
0a09ce6d651a
(svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
3140
diff
changeset
|
579 |
dist = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track); |
1247 | 580 |
if (dist != (uint)-1) |
581 |
tot_dist = dist + 1; |
|
582 |
} |
|
583 |
/* And if we would not reverse? */ |
|
584 |
dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track); |
|
585 |
if (dist > tot_dist) |
|
586 |
/* We could better reverse */ |
|
587 |
return -1; |
|
588 |
return track; |
|
0 | 589 |
} |
590 |
} |
|
591 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
592 |
static const Direction _new_vehicle_direction_table[] = { |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
593 |
DIR_N , DIR_NW, DIR_W , 0, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
594 |
DIR_NE, DIR_N , DIR_SW, 0, |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
595 |
DIR_E , DIR_SE, DIR_S |
0 | 596 |
}; |
597 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
598 |
static int ShipGetNewDirectionFromTiles(TileIndex new_tile, TileIndex old_tile) |
0 | 599 |
{ |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
600 |
uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + |
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
601 |
TileX(new_tile) - TileX(old_tile) + 1; |
0 | 602 |
assert(offs < 11 && offs != 3 && offs != 7); |
603 |
return _new_vehicle_direction_table[offs]; |
|
604 |
} |
|
605 |
||
606 |
static int ShipGetNewDirection(Vehicle *v, int x, int y) |
|
607 |
{ |
|
608 |
uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1); |
|
609 |
assert(offs < 11 && offs != 3 && offs != 7); |
|
610 |
return _new_vehicle_direction_table[offs]; |
|
611 |
} |
|
612 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1942
diff
changeset
|
613 |
static int GetAvailShipTracks(TileIndex tile, int dir) |
0 | 614 |
{ |
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
615 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_WATER); |
0 | 616 |
return (byte) ((r | r >> 8)) & _ship_sometracks[dir]; |
617 |
} |
|
618 |
||
619 |
static const byte _ship_subcoord[4][6][3] = { |
|
620 |
{ |
|
621 |
{15, 8, 1}, |
|
622 |
{ 0, 0, 0}, |
|
623 |
{ 0, 0, 0}, |
|
624 |
{15, 8, 2}, |
|
625 |
{15, 7, 0}, |
|
626 |
{ 0, 0, 0}, |
|
627 |
}, |
|
628 |
{ |
|
629 |
{ 0, 0, 0}, |
|
630 |
{ 8, 0, 3}, |
|
631 |
{ 7, 0, 2}, |
|
632 |
{ 0, 0, 0}, |
|
633 |
{ 8, 0, 4}, |
|
634 |
{ 0, 0, 0}, |
|
635 |
}, |
|
636 |
{ |
|
637 |
{ 0, 8, 5}, |
|
638 |
{ 0, 0, 0}, |
|
639 |
{ 0, 7, 6}, |
|
640 |
{ 0, 0, 0}, |
|
641 |
{ 0, 0, 0}, |
|
642 |
{ 0, 8, 4}, |
|
643 |
}, |
|
644 |
{ |
|
645 |
{ 0, 0, 0}, |
|
646 |
{ 8,15, 7}, |
|
647 |
{ 0, 0, 0}, |
|
648 |
{ 8,15, 6}, |
|
649 |
{ 0, 0, 0}, |
|
650 |
{ 7,15, 0}, |
|
651 |
} |
|
652 |
}; |
|
653 |
||
654 |
static void ShipController(Vehicle *v) |
|
655 |
{ |
|
656 |
GetNewVehiclePosResult gp; |
|
657 |
uint32 r; |
|
658 |
const byte *b; |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
659 |
Direction dir; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
660 |
int track; |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
661 |
int tracks; |
0 | 662 |
|
663 |
v->tick_counter++; |
|
664 |
||
665 |
if (v->breakdown_ctr != 0) { |
|
666 |
if (v->breakdown_ctr <= 2) { |
|
667 |
HandleBrokenShip(v); |
|
668 |
return; |
|
669 |
} |
|
670 |
v->breakdown_ctr--; |
|
671 |
} |
|
672 |
||
2639 | 673 |
if (v->vehstatus & VS_STOPPED) return; |
0 | 674 |
|
675 |
ProcessShipOrder(v); |
|
676 |
HandleShipLoading(v); |
|
677 |
||
2639 | 678 |
if (v->current_order.type == OT_LOADING) return; |
0 | 679 |
|
680 |
CheckShipLeaveDepot(v); |
|
681 |
||
2639 | 682 |
if (!ShipAccelerate(v)) return; |
0 | 683 |
|
684 |
BeginVehicleMove(v); |
|
685 |
||
686 |
if (GetNewVehiclePos(v, &gp)) { |
|
687 |
// staying in tile |
|
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
688 |
if (IsShipInDepot(v)) { |
0 | 689 |
gp.x = v->x_pos; |
690 |
gp.y = v->y_pos; |
|
691 |
} else { |
|
692 |
/* isnot inside depot */ |
|
693 |
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
|
694 |
if (r & 0x8) goto reverse_direction; |
|
695 |
||
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
696 |
/* A leave station order only needs one tick to get processed, so we can |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
697 |
* always skip ahead. */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
698 |
if (v->current_order.type == OT_LEAVESTATION) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
699 |
v->current_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
700 |
v->current_order.flags = 0; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
701 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
702 |
} else if (v->dest_tile != 0) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
703 |
/* We have a target, let's see if we reached it... */ |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
704 |
if (v->current_order.type == OT_GOTO_STATION && |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
705 |
IsBuoyTile(v->dest_tile) && |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
706 |
DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
707 |
/* We got within 3 tiles of our target buoy, so let's skip to our |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
708 |
* next order */ |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
709 |
v->cur_order_index++; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
710 |
v->current_order.type = OT_DUMMY; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
711 |
InvalidateVehicleOrder(v); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
712 |
} else { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
713 |
/* Non-buoy orders really need to reach the tile */ |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
714 |
if (v->dest_tile == gp.new_tile) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
715 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
716 |
if ((gp.x&0xF)==8 && (gp.y&0xF)==8) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
717 |
ShipEnterDepot(v); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
718 |
return; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
719 |
} |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
720 |
} else if (v->current_order.type == OT_GOTO_STATION) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
721 |
Station *st; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
722 |
|
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
723 |
v->last_station_visited = v->current_order.station; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
724 |
|
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
725 |
/* Process station in the orderlist. */ |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
726 |
st = GetStation(v->current_order.station); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
727 |
if (st->facilities & FACIL_DOCK) { /* ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations */ |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
728 |
v->current_order.type = OT_LOADING; |
3610
d33499b2250c
(svn r4505) -Fix (FS#94) Ships can now be used to set up feeders as well.
celestar
parents:
3491
diff
changeset
|
729 |
v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER; |
1751
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
730 |
v->current_order.flags |= OF_NON_STOP; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
731 |
ShipArrivesAt(v, st); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
732 |
|
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
733 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
734 |
if (LoadUnloadVehicle(v)) { |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
735 |
InvalidateWindow(WC_SHIPS_LIST, v->owner); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
736 |
MarkShipDirty(v); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
737 |
} |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
738 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
739 |
} else { /* leave stations without docks right aways */ |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
740 |
v->current_order.type = OT_LEAVESTATION; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
741 |
v->current_order.flags = 0; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
742 |
v->cur_order_index++; |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
743 |
InvalidateVehicleOrder(v); |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
744 |
} |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
745 |
} |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
746 |
} |
954dd2900ac9
(svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents:
1698
diff
changeset
|
747 |
} |
0 | 748 |
} |
749 |
} |
|
750 |
} else { |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
751 |
DiagDirection diagdir; |
0 | 752 |
// new tile |
1401
56d372a75b74
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1330
diff
changeset
|
753 |
if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) |
926
bd4312619522
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
754 |
goto reverse_direction; |
0 | 755 |
|
756 |
dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile); |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
757 |
assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW); |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
758 |
diagdir = DirToDiagDir(dir); |
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
759 |
tracks = GetAvailShipTracks(gp.new_tile, diagdir); |
0 | 760 |
if (tracks == 0) |
761 |
goto reverse_direction; |
|
762 |
||
763 |
// Choose a direction, and continue if we find one |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
764 |
track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks); |
0 | 765 |
if (track < 0) |
766 |
goto reverse_direction; |
|
767 |
||
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
768 |
b = _ship_subcoord[diagdir][track]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
769 |
|
0 | 770 |
gp.x = (gp.x&~0xF) | b[0]; |
771 |
gp.y = (gp.y&~0xF) | b[1]; |
|
772 |
||
773 |
/* Call the landscape function and tell it that the vehicle entered the tile */ |
|
774 |
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
|
775 |
if (r&0x8) goto reverse_direction; |
|
776 |
||
777 |
if (!(r&0x4)) { |
|
778 |
v->tile = gp.new_tile; |
|
779 |
v->u.ship.state = 1 << track; |
|
780 |
} |
|
781 |
||
782 |
v->direction = b[2]; |
|
783 |
} |
|
784 |
||
785 |
/* update image of ship, as well as delta XY */ |
|
786 |
dir = ShipGetNewDirection(v, gp.x, gp.y); |
|
787 |
v->x_pos = gp.x; |
|
788 |
v->y_pos = gp.y; |
|
789 |
v->z_pos = GetSlopeZ(gp.x, gp.y); |
|
790 |
||
791 |
getout: |
|
792 |
UpdateShipDeltaXY(v, dir); |
|
793 |
v->cur_image = GetShipImage(v, dir); |
|
794 |
VehiclePositionChanged(v); |
|
795 |
EndVehicleMove(v); |
|
796 |
return; |
|
797 |
||
798 |
reverse_direction: |
|
3157
40de8616c04c
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3147
diff
changeset
|
799 |
dir = ReverseDir(v->direction); |
0 | 800 |
v->direction = dir; |
801 |
goto getout; |
|
802 |
} |
|
803 |
||
804 |
static void AgeShipCargo(Vehicle *v) |
|
805 |
{ |
|
2639 | 806 |
if (_age_cargo_skip_counter != 0) return; |
807 |
if (v->cargo_days != 255) v->cargo_days++; |
|
0 | 808 |
} |
809 |
||
810 |
void Ship_Tick(Vehicle *v) |
|
811 |
{ |
|
812 |
AgeShipCargo(v); |
|
813 |
ShipController(v); |
|
814 |
} |
|
815 |
||
816 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1055
diff
changeset
|
817 |
void ShipsYearlyLoop(void) |
0 | 818 |
{ |
819 |
Vehicle *v; |
|
820 |
||
821 |
FOR_ALL_VEHICLES(v) { |
|
822 |
if (v->type == VEH_Ship) { |
|
823 |
v->profit_last_year = v->profit_this_year; |
|
824 |
v->profit_this_year = 0; |
|
825 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
826 |
} |
|
827 |
} |
|
828 |
} |
|
829 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
830 |
/** Build a ship. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
831 |
* @param tile tile of depot where ship is built |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
832 |
* @param p1 ship type being built (engine) |
3816
2cdb29b57c1f
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3645
diff
changeset
|
833 |
* @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
834 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
835 |
int32 CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 836 |
{ |
837 |
int32 value; |
|
838 |
Vehicle *v; |
|
1282
e7a73ee62d2f
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
839 |
UnitID unit_num; |
0 | 840 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
841 |
|
2854
6b85a5f4b65f
(svn r3402) -Fix: [building/cloning] added a string telling if build failed due to not being able to build a vehicle. Triggered when cloning a retired design
bjarni
parents:
2819
diff
changeset
|
842 |
if (!IsEngineBuildable(p1, VEH_Ship)) return_cmd_error(STR_ENGINE_NOT_BUILDABLE); |
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
843 |
|
0 | 844 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
845 |
||
846 |
value = EstimateShipCost(p1); |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
847 |
if (flags & DC_QUERY_COST) return value; |
0 | 848 |
|
1443
d9c101f7634b
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1401
diff
changeset
|
849 |
/* The ai_new queries the vehicle cost before building the route, |
d9c101f7634b
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1401
diff
changeset
|
850 |
* so we must check against cheaters no sooner than now. --pasky */ |
d9c101f7634b
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1401
diff
changeset
|
851 |
if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR; |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
852 |
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
1443
d9c101f7634b
(svn r1947) As in r1946, permit DC_QUERY_COST even on non-depot tiles - so that it works for the ai_new. It is de iure not a bug yet but let's be safe against future annoying headaches. Signed-Off-By: TrueLight
pasky
parents:
1401
diff
changeset
|
853 |
|
0 | 854 |
v = AllocateVehicle(); |
4095
55a5642143f1
(svn r5427) - Codechange: testing for "== true" is redundant.
peter1138
parents:
3989
diff
changeset
|
855 |
unit_num = HASBIT(p2, 0) ? 0 : GetFreeUnitNumber(VEH_Ship); |
3816
2cdb29b57c1f
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3645
diff
changeset
|
856 |
|
2cdb29b57c1f
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
bjarni
parents:
3645
diff
changeset
|
857 |
if (v == NULL || IsOrderPoolFull() || unit_num > _patches.max_ships) |
0 | 858 |
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
859 |
|
0 | 860 |
if (flags & DC_EXEC) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
861 |
int x; |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
862 |
int y; |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
863 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
864 |
const ShipVehicleInfo *svi = ShipVehInfo(p1); |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
865 |
|
0 | 866 |
v->unitnumber = unit_num; |
867 |
||
868 |
v->owner = _current_player; |
|
869 |
v->tile = tile; |
|
3645
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3610
diff
changeset
|
870 |
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
86af43f87885
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3610
diff
changeset
|
871 |
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
0 | 872 |
v->x_pos = x; |
873 |
v->y_pos = y; |
|
874 |
v->z_pos = GetSlopeZ(x,y); |
|
875 |
||
876 |
v->z_height = 6; |
|
877 |
v->sprite_width = 6; |
|
878 |
v->sprite_height = 6; |
|
879 |
v->x_offs = -3; |
|
880 |
v->y_offs = -3; |
|
881 |
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
882 |
|
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
883 |
v->spritenum = svi->image_index; |
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
884 |
v->cargo_type = svi->cargo_type; |
3870
766d7bd6c299
(svn r4910) - NewGRF: add and initialize cargo subtype for vehicle visual variations
peter1138
parents:
3816
diff
changeset
|
885 |
v->cargo_subtype = 0; |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
886 |
v->cargo_cap = svi->capacity; |
0 | 887 |
v->value = value; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
888 |
|
1266
9dc5638fe8cc
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
889 |
v->last_station_visited = INVALID_STATION; |
538
5dd99f3b7eca
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
890 |
v->max_speed = svi->max_speed; |
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2464
diff
changeset
|
891 |
v->engine_type = p1; |
0 | 892 |
|
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1901
diff
changeset
|
893 |
e = GetEngine(p1); |
0 | 894 |
v->reliability = e->reliability; |
895 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
896 |
v->max_age = e->lifelength * 366; |
|
2564 | 897 |
_new_vehicle_id = v->index; |
0 | 898 |
|
899 |
v->string_id = STR_SV_SHIP_NAME; |
|
900 |
v->u.ship.state = 0x80; |
|
901 |
||
902 |
v->service_interval = _patches.servint_ships; |
|
903 |
v->date_of_last_service = _date; |
|
4329
9759d5c52010
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4293
diff
changeset
|
904 |
v->build_year = _cur_year; |
0 | 905 |
v->cur_image = 0x0E5E; |
906 |
v->type = VEH_Ship; |
|
2804
b932fe148d36
(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
peter1138
parents:
2791
diff
changeset
|
907 |
v->random_bits = VehicleRandomBits(); |
0 | 908 |
|
909 |
VehiclePositionChanged(v); |
|
910 |
||
911 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 912 |
RebuildVehicleLists(); |
0 | 913 |
InvalidateWindow(WC_COMPANY, v->owner); |
2618
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
914 |
if (IsLocalPlayer()) |
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
915 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window |
0 | 916 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
917 |
|
0 | 918 |
return value; |
919 |
} |
|
920 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
921 |
/** Sell a ship. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
922 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
923 |
* @param p1 vehicle ID to be sold |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
924 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
925 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
926 |
int32 CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 927 |
{ |
928 |
Vehicle *v; |
|
929 |
||
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
930 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
931 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
932 |
v = GetVehicle(p1); |
0 | 933 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
934 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 935 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
936 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
937 |
|
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
938 |
if (!IsShipInDepotStopped(v)) { |
0 | 939 |
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); |
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
940 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
941 |
|
0 | 942 |
if (flags & DC_EXEC) { |
943 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 944 |
RebuildVehicleLists(); |
0 | 945 |
InvalidateWindow(WC_COMPANY, v->owner); |
946 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
947 |
DeleteVehicle(v); |
|
2618
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
948 |
if (IsLocalPlayer()) |
7546b838230b
(svn r3156) -Fix: removed some cases where autoreplace windows were redrawn when nothing was changed
bjarni
parents:
2574
diff
changeset
|
949 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window |
0 | 950 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
951 |
|
0 | 952 |
return -(int32)v->value; |
953 |
} |
|
954 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
955 |
/** Start/Stop a ship. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
956 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
957 |
* @param p1 ship ID to start/stop |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
958 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
959 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
960 |
int32 CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 961 |
{ |
962 |
Vehicle *v; |
|
4244
44dcec623504
(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
|
963 |
uint16 callback; |
0 | 964 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
965 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
966 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
967 |
v = GetVehicle(p1); |
0 | 968 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
969 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 970 |
|
4244
44dcec623504
(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
|
971 |
/* Check if this ship can be started/stopped. The callback will fail or |
44dcec623504
(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
|
972 |
* return 0xFF if it can. */ |
44dcec623504
(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
|
973 |
callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
44dcec623504
(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
|
974 |
if (callback != CALLBACK_FAILED && callback != 0xFF) { |
44dcec623504
(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
|
975 |
StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
44dcec623504
(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
|
976 |
return_cmd_error(error); |
44dcec623504
(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
|
977 |
} |
44dcec623504
(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
|
978 |
|
0 | 979 |
if (flags & DC_EXEC) { |
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
980 |
if (IsShipInDepotStopped(v)) { |
3139
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3005
diff
changeset
|
981 |
DeleteVehicleNews(p1, STR_981C_SHIP_IS_WAITING_IN_DEPOT); |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3005
diff
changeset
|
982 |
} |
4c950c7ec5c9
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3005
diff
changeset
|
983 |
|
0 | 984 |
v->vehstatus ^= VS_STOPPED; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
985 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 986 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
987 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 988 |
} |
989 |
||
990 |
return 0; |
|
991 |
} |
|
992 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
993 |
/** Send a ship to the depot. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
994 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
995 |
* @param p1 vehicle ID to send to the depot |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
996 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
997 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
998 |
int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 999 |
{ |
1000 |
Vehicle *v; |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1001 |
const Depot *dep; |
0 | 1002 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1003 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1004 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1005 |
v = GetVehicle(p1); |
0 | 1006 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1007 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; |
0 | 1008 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1009 |
if (v->vehstatus & VS_CRASHED) return CMD_ERROR; |
1757
b179d50241dc
(svn r2261) - Fix: When crashed vehicles try to find a depot for servicing, openttd asserts.
matthijs
parents:
1752
diff
changeset
|
1010 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1011 |
/* If the current orders are already goto-depot */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1012 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 1013 |
if (flags & DC_EXEC) { |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1014 |
/* If the orders to 'goto depot' are in the orders list (forced servicing), |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1015 |
* then skip to the next order; effectively cancelling this forced service */ |
1530
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1016 |
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) |
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1017 |
v->cur_order_index++; |
caa16c506a22
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1520
diff
changeset
|
1018 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1019 |
v->current_order.type = OT_DUMMY; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1020 |
v->current_order.flags = 0; |
755
823358e83abf
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1021 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1022 |
} |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1023 |
return 0; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1024 |
} |
0 | 1025 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1026 |
dep = FindClosestShipDepot(v); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1027 |
if (dep == NULL) |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1028 |
return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1029 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1030 |
if (flags & DC_EXEC) { |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1031 |
v->dest_tile = dep->xy; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1032 |
v->current_order.type = OT_GOTO_DEPOT; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1033 |
v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1034 |
v->current_order.station = dep->index; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1790
diff
changeset
|
1035 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1036 |
} |
1037 |
||
1038 |
return 0; |
|
1039 |
} |
|
1040 |
||
1041 |
||
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1042 |
/** Refits a ship to the specified cargo type. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
1043 |
* @param tile unused |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1044 |
* @param p1 vehicle ID of the ship to refit |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1045 |
* @param p2 various bitstuffed elements |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1046 |
* - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF) |
3954
634cd5e35803
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
1047 |
* - p2 = (bit 8-15) - the new cargo subtype to refit to |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1048 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3476
diff
changeset
|
1049 |
int32 CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1050 |
{ |
1051 |
Vehicle *v; |
|
1052 |
int32 cost; |
|
3954
634cd5e35803
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
1053 |
CargoID new_cid = GB(p2, 0, 8); //gets the cargo number |
634cd5e35803
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
1054 |
byte new_subtype = GB(p2, 8, 8); |
3989
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1055 |
uint16 capacity = CALLBACK_FAILED; |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1056 |
|
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1057 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1058 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1059 |
v = GetVehicle(p1); |
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1060 |
|
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1061 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR; |
2567
735280bafe7a
(svn r3104) -Codechange: [refit] removed now obsolite code that the old autoreplace needed
bjarni
parents:
2564
diff
changeset
|
1062 |
|
3961
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
1063 |
if (!IsShipInDepotStopped(v)) { |
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
1064 |
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); |
e2783f244ac6
(svn r5120) Add IsShipInDepot{Stopped,}() and remove some redundant checks
tron
parents:
3955
diff
changeset
|
1065 |
} |
0 | 1066 |
|
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1067 |
/* Check cargo */ |
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1068 |
if (!ShipVehInfo(v->engine_type)->refittable) return CMD_ERROR; |
2704
dc9ae68dfd74
(svn r3248) - Codechange: Change interface of CanRefitTo() to supply the engine type directly instead of getting it from a vehicle. This allows the function to be used before vehicles are involved.
peter1138
parents:
2662
diff
changeset
|
1069 |
if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
915 | 1070 |
|
1237
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1071 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN); |
0a1ce05c3d45
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1072 |
|
3989
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1073 |
/* Check the refit capacity callback */ |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1074 |
if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1075 |
/* Back up the existing cargo type */ |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1076 |
CargoID temp_cid = v->cargo_type; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1077 |
byte temp_subtype = v->cargo_subtype; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1078 |
v->cargo_type = new_cid; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1079 |
v->cargo_subtype = new_subtype; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1080 |
|
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1081 |
capacity = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1082 |
|
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1083 |
/* Restore the cargo type */ |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1084 |
v->cargo_type = temp_cid; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1085 |
v->cargo_subtype = temp_subtype; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1086 |
} |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1087 |
|
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1088 |
if (capacity == CALLBACK_FAILED) { |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1089 |
capacity = ShipVehInfo(v->engine_type)->capacity; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1090 |
} |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1091 |
_returned_refit_capacity = capacity; |
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1092 |
|
0 | 1093 |
cost = 0; |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1094 |
if (IS_HUMAN_PLAYER(v->owner) && new_cid != v->cargo_type) { |
4242
e6baba95f369
(svn r5819) - NewGRF: add support for refit costs specified in NewGRF. This may affect the default refit costs for the default rail vehicles.
peter1138
parents:
4095
diff
changeset
|
1095 |
cost = (EngInfo(v->engine_type)->refit_cost * _price.ship_base) >> 10; |
0 | 1096 |
} |
1097 |
||
1098 |
if (flags & DC_EXEC) { |
|
3989
a5d50d90fd21
(svn r5188) - NewGRF: check refit capacity callback when refitting a ship
peter1138
parents:
3961
diff
changeset
|
1099 |
v->cargo_cap = capacity; |
3955
81e7e25e4599
(svn r5104) - When refitting a vehicle to its existing cargo type, don't lose the cargo onboard (useful when adding wagons to a train)
peter1138
parents:
3954
diff
changeset
|
1100 |
v->cargo_count = (v->cargo_type == new_cid) ? min(v->cargo_cap, v->cargo_count) : 0; |
1802
448f187042d3
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents:
1793
diff
changeset
|
1101 |
v->cargo_type = new_cid; |
3954
634cd5e35803
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
1102 |
v->cargo_subtype = new_subtype; |
0 | 1103 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
3954
634cd5e35803
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
1104 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
634cd5e35803
(svn r5103) - Add cargo subtype parameter to refit commands (mart3p)
peter1138
parents:
3948
diff
changeset
|
1105 |
RebuildVehicleLists(); |
0 | 1106 |
} |
1107 |
||
1108 |
return cost; |
|
1109 |
||
1110 |
} |