author | pasky |
Sat, 12 Mar 2005 08:52:40 +0000 | |
changeset 1494 | 31436e59176a |
parent 1443 | 2b8e1b123d91 |
child 1520 | d88442095697 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
445
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
593
diff
changeset
|
4 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1206
diff
changeset
|
5 |
#include "tile.h" |
0 | 6 |
#include "vehicle.h" |
7 |
#include "command.h" |
|
8 |
#include "pathfind.h" |
|
9 |
#include "station.h" |
|
10 |
#include "gfx.h" |
|
11 |
#include "news.h" |
|
12 |
#include "engine.h" |
|
13 |
#include "gui.h" |
|
14 |
#include "player.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
297
diff
changeset
|
15 |
#include "sound.h" |
1247 | 16 |
#include "npf.h" |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
17 |
#include "depot.h" |
0 | 18 |
|
19 |
static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D}; |
|
20 |
static const byte _ship_sometracks[4] = {0x19, 0x16, 0x25, 0x2A}; |
|
21 |
||
22 |
static byte GetTileShipTrackStatus(uint tile) { |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
23 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_WATER); |
0 | 24 |
return r | r >> 8; |
25 |
} |
|
26 |
||
27 |
void DrawShipEngine(int x, int y, int engine, uint32 image_ormod) |
|
28 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
29 |
int spritenum = ShipVehInfo(engine)->image_index; |
0 | 30 |
|
31 |
if (is_custom_sprite(spritenum)) { |
|
358
da81e0ef68cf
(svn r546) -newgrf: Use GetCustomVehicleIcon() for fetching sprites for vehicle selection dialogs. (Idea by octo, done by pasky).
darkvater
parents:
337
diff
changeset
|
32 |
int sprite = GetCustomVehicleIcon(engine, 6); |
0 | 33 |
|
34 |
if (sprite) { |
|
35 |
DrawSprite(sprite | image_ormod, x, y); |
|
36 |
return; |
|
37 |
} |
|
38 |
spritenum = _engine_original_sprites[engine]; |
|
39 |
} |
|
40 |
DrawSprite((6 + _ship_sprites[spritenum]) | image_ormod, x, y); |
|
41 |
} |
|
42 |
||
43 |
void DrawShipEngineInfo(int engine, int x, int y, int maxw) |
|
44 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
45 |
const ShipVehicleInfo *svi = ShipVehInfo(engine); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
46 |
SetDParam(0, svi->base_cost * (_price.ship_base>>3)>>5); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
47 |
SetDParam(1, svi->max_speed * 10 >> 5); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
48 |
SetDParam(2, _cargoc.names_long_p[svi->cargo_type]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
49 |
SetDParam(3, svi->capacity); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
50 |
SetDParam(4, svi->running_cost * _price.ship_running >> 8); |
0 | 51 |
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw); |
52 |
} |
|
53 |
||
54 |
int GetShipImage(Vehicle *v, byte direction) |
|
55 |
{ |
|
56 |
int spritenum = v->spritenum; |
|
57 |
||
58 |
if (is_custom_sprite(spritenum)) { |
|
59 |
int sprite = GetCustomVehicleSprite(v, direction); |
|
60 |
||
61 |
if (sprite) return sprite; |
|
62 |
spritenum = _engine_original_sprites[v->engine_type]; |
|
63 |
} |
|
64 |
return _ship_sprites[spritenum] + direction; |
|
65 |
} |
|
66 |
||
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
67 |
static Depot *FindClosestShipDepot(Vehicle *v) |
0 | 68 |
{ |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
69 |
Depot *depot; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
70 |
Depot *best_depot = NULL; |
0 | 71 |
uint tile, dist, best_dist = (uint)-1; |
72 |
uint tile2 = v->tile; |
|
73 |
||
1247 | 74 |
if (_patches.new_pathfinding_all) { |
75 |
NPFFoundTargetData ftd; |
|
76 |
byte trackdir = _track_direction_to_trackdir[FIND_FIRST_BIT(v->u.ship.state)][v->direction]; |
|
1330
5d76a0522a11
(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
|
77 |
ftd = NPFRouteToDepotTrialError(v->tile, trackdir, TRANSPORT_WATER, v->owner); |
1247 | 78 |
if (ftd.best_bird_dist == 0) |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
79 |
best_depot = GetDepotByTile(ftd.node.tile); /* Found target */ |
1247 | 80 |
else |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
81 |
best_depot = NULL; /* Did not find target */ |
1247 | 82 |
} else { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
83 |
FOR_ALL_DEPOTS(depot) { |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
84 |
tile = depot->xy; |
1330
5d76a0522a11
(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
|
85 |
if (IsValidDepot(depot) && IsTileDepotType(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) { |
1247 | 86 |
dist = DistanceManhattan(tile, tile2); |
87 |
if (dist < best_dist) { |
|
88 |
best_dist = dist; |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
89 |
best_depot = depot; |
1247 | 90 |
} |
0 | 91 |
} |
92 |
} |
|
93 |
} |
|
94 |
return best_depot; |
|
95 |
} |
|
96 |
||
97 |
static void CheckIfShipNeedsService(Vehicle *v) |
|
98 |
{ |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
99 |
Depot *depot; |
0 | 100 |
|
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
101 |
if (_patches.servint_ships == 0 && !v->set_for_replacement) |
11
836bc4b37b5b
(svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents:
0
diff
changeset
|
102 |
return; |
836bc4b37b5b
(svn r12) Change: removed patch no_train_service. Instead you can set the default service interval for any vehicle type to 'disabled'.
dominik
parents:
0
diff
changeset
|
103 |
|
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
104 |
if (!VehicleNeedsService(v) && !v->set_for_replacement) |
0 | 105 |
return; |
106 |
||
107 |
if (v->vehstatus & VS_STOPPED) |
|
108 |
return; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
109 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
110 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
111 |
v->current_order.flags & OF_FULL_LOAD) |
0 | 112 |
return; |
113 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
114 |
if (_patches.gotodepot && VehicleHasDepotOrders(v)) |
0 | 115 |
return; |
116 |
||
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
117 |
depot = FindClosestShipDepot(v); |
0 | 118 |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
119 |
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
120 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
121 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
122 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
123 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 124 |
} |
125 |
return; |
|
126 |
} |
|
127 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
128 |
v->current_order.type = OT_GOTO_DEPOT; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
129 |
v->current_order.flags = OF_NON_STOP; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
130 |
v->current_order.station = depot->index; |
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
131 |
v->dest_tile = depot->xy; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
132 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 133 |
} |
134 |
||
135 |
void OnNewDay_Ship(Vehicle *v) |
|
136 |
{ |
|
137 |
int32 cost; |
|
138 |
||
139 |
if ((++v->day_counter & 7) == 0) |
|
140 |
DecreaseVehicleValue(v); |
|
141 |
||
142 |
CheckVehicleBreakdown(v); |
|
143 |
AgeVehicle(v); |
|
144 |
CheckIfShipNeedsService(v); |
|
145 |
||
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1035
diff
changeset
|
146 |
CheckOrders(v->index, OC_INIT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
147 |
|
0 | 148 |
if (v->vehstatus & VS_STOPPED) |
149 |
return; |
|
150 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
151 |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
11
diff
changeset
|
152 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
153 |
cost = ShipVehInfo(v->engine_type)->running_cost * _price.ship_running / 364; |
0 | 154 |
v->profit_this_year -= cost >> 8; |
155 |
||
156 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN); |
|
157 |
SubtractMoneyFromPlayerFract(v->owner, cost); |
|
158 |
||
159 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
160 |
//we need this for the profit |
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
161 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 162 |
} |
163 |
||
164 |
static void HandleBrokenShip(Vehicle *v) |
|
165 |
{ |
|
166 |
if (v->breakdown_ctr != 1) { |
|
167 |
v->breakdown_ctr = 1; |
|
168 |
v->cur_speed = 0; |
|
169 |
||
170 |
if (v->breakdowns_since_last_service != 255) |
|
171 |
v->breakdowns_since_last_service++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
172 |
|
0 | 173 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
174 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
175 |
|
541 | 176 |
SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
177 |
SND_10_TRAIN_BREAKDOWN : SND_3A_COMEDY_BREAKDOWN_2, v); |
|
0 | 178 |
|
179 |
if (!(v->vehstatus & VS_HIDDEN)) { |
|
180 |
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
|
181 |
if (u) |
|
182 |
u->u.special.unk0 = v->breakdown_delay * 2; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
if (!(v->tick_counter & 1)) { |
|
187 |
if (!--v->breakdown_delay) { |
|
188 |
v->breakdown_ctr = 0; |
|
1151
06c115ce7b7a
(svn r1652) Fix: train and road vehicle lists are now redrawn when vehicles enters/leaves a depot (Hackykid)
bjarni
parents:
1128
diff
changeset
|
189 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
0 | 190 |
} |
191 |
} |
|
192 |
} |
|
193 |
||
194 |
static void MarkShipDirty(Vehicle *v) |
|
195 |
{ |
|
196 |
v->cur_image = GetShipImage(v, v->direction); |
|
197 |
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); |
|
198 |
} |
|
199 |
||
200 |
static void PlayShipSound(Vehicle *v) |
|
201 |
{ |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
202 |
SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v); |
0 | 203 |
} |
204 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
205 |
static const TileIndexDiffC _dock_offs[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
206 |
{ 2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
207 |
{-2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
208 |
{ 0, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
209 |
{ 2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
210 |
{ 0, -2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
211 |
{ 0, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
212 |
{ 0, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
213 |
{ 0, 0} |
0 | 214 |
}; |
215 |
||
216 |
static void ProcessShipOrder(Vehicle *v) |
|
217 |
{ |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
218 |
const Order *order; |
0 | 219 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
220 |
if (v->current_order.type >= OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
221 |
v->current_order.type <= OT_LEAVESTATION) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
222 |
if (v->current_order.type != OT_GOTO_DEPOT || |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
223 |
!(v->current_order.flags & OF_UNLOAD)) |
0 | 224 |
return; |
225 |
} |
|
226 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
227 |
if (v->current_order.type == OT_GOTO_DEPOT && |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
228 |
(v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
229 |
!VehicleNeedsService(v) && !v->set_for_replacement) { |
0 | 230 |
v->cur_order_index++; |
231 |
} |
|
232 |
||
233 |
||
234 |
if (v->cur_order_index >= v->num_orders) |
|
235 |
v->cur_order_index = 0; |
|
236 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
237 |
order = GetVehicleOrder(v, v->cur_order_index); |
0 | 238 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
239 |
if (order == NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
240 |
v->current_order.type = OT_NOTHING; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
241 |
v->current_order.flags = 0; |
0 | 242 |
v->dest_tile = 0; |
243 |
return; |
|
244 |
} |
|
245 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
246 |
if (order->type == v->current_order.type && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
247 |
order->flags == v->current_order.flags && |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
248 |
order->station == v->current_order.station) |
0 | 249 |
return; |
250 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
251 |
v->current_order = *order; |
0 | 252 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
253 |
if (order->type == OT_GOTO_STATION) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
254 |
const Station *st; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
255 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
256 |
if (order->station == v->last_station_visited) |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
257 |
v->last_station_visited = INVALID_STATION; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
258 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
259 |
st = GetStation(order->station); |
0 | 260 |
if (st->dock_tile != 0) { |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
261 |
v->dest_tile = TILE_ADD(st->dock_tile, ToTileIndexDiff(_dock_offs[_map5[st->dock_tile]-0x4B])); |
0 | 262 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
263 |
} else if (order->type == OT_GOTO_DEPOT) { |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
264 |
v->dest_tile = GetDepot(order->station)->xy; |
0 | 265 |
} else { |
266 |
v->dest_tile = 0; |
|
267 |
} |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
268 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
269 |
InvalidateVehicleOrder(v); |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
926
diff
changeset
|
270 |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
271 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 272 |
} |
273 |
||
274 |
static void HandleShipLoading(Vehicle *v) |
|
275 |
{ |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
276 |
if (v->current_order.type == OT_NOTHING) |
0 | 277 |
return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
278 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
279 |
if (v->current_order.type != OT_DUMMY) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
280 |
if (v->current_order.type != OT_LOADING) |
0 | 281 |
return; |
282 |
||
283 |
if (--v->load_unload_time_rem) |
|
284 |
return; |
|
285 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
286 |
if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { |
0 | 287 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC); |
288 |
if (LoadUnloadVehicle(v)) { |
|
289 |
InvalidateWindow(WC_SHIPS_LIST, v->owner); |
|
290 |
MarkShipDirty(v); |
|
291 |
} |
|
292 |
return; |
|
293 |
} |
|
294 |
PlayShipSound(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
295 |
|
0 | 296 |
{ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
297 |
Order b = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
298 |
v->current_order.type = OT_LEAVESTATION; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
299 |
v->current_order.flags = 0; |
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
300 |
|
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
301 |
if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
302 |
// only the vehicle owner needs to calculate the rest (locally) |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
303 |
if ((_autoreplace_array[v->engine_type] != v->engine_type) || |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
304 |
(_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
305 |
byte flags = 1; |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
306 |
// the flags means, bit 0 = needs to go to depot, bit 1 = have depot in orders |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
307 |
if (VehicleHasDepotOrders(v)) SETBIT(flags, 1); |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
308 |
if (!(HASBIT(flags, 1) && v->set_for_replacement)) { |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
309 |
_current_player = _local_player; |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
310 |
DoCommandP(v->tile, v->index, flags, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_SHOW_NO_ERROR); |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
311 |
_current_player = OWNER_NONE; |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
312 |
} |
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
313 |
} else { // no need to go to a depot |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
314 |
if (v->set_for_replacement) { |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
315 |
// it seems that the user clicked "Stop replacing" |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
316 |
_current_player = _local_player; |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
317 |
DoCommandP(v->tile, v->index, 1 | (1 << 2), NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_SHOW_NO_ERROR); |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
318 |
_current_player = OWNER_NONE; |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
319 |
} |
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
320 |
} |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
321 |
} |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
322 |
if (!(b.flags & OF_NON_STOP)) |
0 | 323 |
return; |
324 |
} |
|
325 |
} |
|
326 |
||
327 |
v->cur_order_index++; |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
328 |
InvalidateVehicleOrder(v); |
0 | 329 |
} |
330 |
||
331 |
static void UpdateShipDeltaXY(Vehicle *v, int dir) |
|
332 |
{ |
|
333 |
#define MKIT(d,c,b,a) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) |
|
334 |
static const uint32 _delta_xy_table[8] = { |
|
335 |
MKIT( -3, -3, 6, 6), |
|
336 |
MKIT(-16, -3, 32, 6), |
|
337 |
MKIT( -3, -3, 6, 6), |
|
338 |
MKIT( -3,-16, 6, 32), |
|
339 |
MKIT( -3, -3, 6, 6), |
|
340 |
MKIT(-16, -3, 32, 6), |
|
341 |
MKIT( -3, -3, 6, 6), |
|
342 |
MKIT( -3,-16, 6, 32), |
|
343 |
}; |
|
344 |
#undef MKIT |
|
345 |
uint32 x = _delta_xy_table[dir]; |
|
346 |
v->x_offs = (byte)x; |
|
347 |
v->y_offs = (byte)(x>>=8); |
|
348 |
v->sprite_width = (byte)(x>>=8); |
|
349 |
v->sprite_height = (byte)(x>>=8); |
|
350 |
} |
|
351 |
||
352 |
static void RecalcShipStuff(Vehicle *v) |
|
353 |
{ |
|
354 |
UpdateShipDeltaXY(v, v->direction); |
|
355 |
v->cur_image = GetShipImage(v, v->direction); |
|
356 |
MarkShipDirty(v); |
|
357 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
358 |
} |
|
359 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
360 |
static const TileIndexDiffC _ship_leave_depot_offs[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
361 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
362 |
{ 0, -1} |
0 | 363 |
}; |
364 |
||
365 |
static void CheckShipLeaveDepot(Vehicle *v) |
|
366 |
{ |
|
367 |
uint tile; |
|
368 |
int d; |
|
369 |
uint m; |
|
370 |
||
371 |
if (v->u.ship.state != 0x80) |
|
372 |
return; |
|
373 |
||
374 |
tile = v->tile; |
|
375 |
d = (_map5[tile]&2) ? 1 : 0; |
|
376 |
||
377 |
// Check first side |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
378 |
if (_ship_sometracks[d] & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[d])))) { |
0 | 379 |
m = (d==0) ? 0x101 : 0x207; |
380 |
// Check second side |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
381 |
} else if (_ship_sometracks[d+2] & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[d])))) { |
0 | 382 |
m = (d==0) ? 0x105 : 0x203; |
383 |
} else { |
|
384 |
return; |
|
385 |
} |
|
386 |
v->direction = (byte)m; |
|
387 |
v->u.ship.state = (byte)(m >> 8); |
|
388 |
v->vehstatus &= ~VS_HIDDEN; |
|
389 |
||
390 |
v->cur_speed = 0; |
|
391 |
RecalcShipStuff(v); |
|
392 |
||
393 |
PlayShipSound(v); |
|
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
394 |
VehicleServiceInDepot(v); |
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
395 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 396 |
} |
397 |
||
398 |
static bool ShipAccelerate(Vehicle *v) |
|
399 |
{ |
|
400 |
uint spd; |
|
401 |
byte t; |
|
402 |
||
403 |
spd = min(v->cur_speed + 1, v->max_speed); |
|
404 |
||
405 |
//updates statusbar only if speed have changed to save CPU time |
|
406 |
if (spd != v->cur_speed) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
407 |
v->cur_speed = spd; |
0 | 408 |
if (_patches.vehicle_speed) |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
409 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 410 |
} |
411 |
||
412 |
// Decrease somewhat when turning |
|
413 |
if (!(v->direction&1)) { |
|
414 |
spd = spd * 3 >> 2; |
|
415 |
} |
|
416 |
||
417 |
if (spd == 0) |
|
418 |
return false; |
|
419 |
||
420 |
if ((byte)++spd == 0) |
|
421 |
return true; |
|
422 |
||
423 |
v->progress = (t = v->progress) - (byte)spd; |
|
424 |
||
425 |
return (t < v->progress); |
|
426 |
} |
|
427 |
||
428 |
||
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
429 |
int32 EstimateShipCost(uint16 engine_type); |
0 | 430 |
|
431 |
static void ShipEnterDepot(Vehicle *v) |
|
432 |
{ |
|
433 |
v->u.ship.state = 0x80; |
|
434 |
v->vehstatus |= VS_HIDDEN; |
|
435 |
v->cur_speed = 0; |
|
436 |
RecalcShipStuff(v); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
437 |
|
578
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
438 |
VehicleServiceInDepot(v); |
1e66514eb621
(svn r998) now vehicles are serviced both when entering and when leaving depots to prevent that vehicles might need service when leaving after a long stay (ln--)
bjarni
parents:
555
diff
changeset
|
439 |
|
0 | 440 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
441 |
||
842 | 442 |
MaybeReplaceVehicle(v); |
0 | 443 |
|
445
beafc0fb8f12
(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
|
444 |
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
beafc0fb8f12
(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
|
445 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
446 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
447 |
Order t; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
448 |
|
0 | 449 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
450 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
451 |
t = v->current_order; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
452 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
453 |
v->current_order.flags = 0; |
0 | 454 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
455 |
if (t.flags & OF_UNLOAD) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
456 |
v->cur_order_index++; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
457 |
} else if (t.flags & OF_FULL_LOAD) { |
0 | 458 |
v->vehstatus |= VS_STOPPED; |
459 |
if (v->owner == _local_player) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
460 |
SetDParam(0, v->unitnumber); |
0 | 461 |
AddNewsItem( |
462 |
STR_981C_SHIP_IS_WAITING_IN_DEPOT, |
|
463 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
|
464 |
v->index, |
|
465 |
0); |
|
466 |
} |
|
467 |
} |
|
468 |
} |
|
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
469 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
0 | 470 |
} |
471 |
||
472 |
static void ShipArrivesAt(Vehicle *v, Station *st) |
|
473 |
{ |
|
474 |
/* Check if station was ever visited before */ |
|
475 |
if (!(st->had_vehicle_of_type & HVOT_SHIP)) { |
|
476 |
uint32 flags; |
|
477 |
st->had_vehicle_of_type |= HVOT_SHIP; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
478 |
SetDParam(0, st->index); |
0 | 479 |
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); |
480 |
AddNewsItem( |
|
481 |
STR_9833_CITIZENS_CELEBRATE_FIRST, |
|
482 |
flags, |
|
483 |
v->index, |
|
484 |
0); |
|
485 |
} |
|
486 |
} |
|
487 |
||
488 |
typedef struct { |
|
489 |
uint skiptile; |
|
490 |
uint dest_coords; |
|
491 |
uint best_bird_dist; |
|
492 |
uint best_length; |
|
493 |
} PathFindShip; |
|
494 |
||
495 |
//extern void dbg_store_path(); |
|
496 |
||
497 |
static bool ShipTrackFollower(uint tile, PathFindShip *pfs, int track, uint length, byte *state) |
|
498 |
{ |
|
499 |
// Found dest? |
|
500 |
if (tile == pfs->dest_coords) { |
|
501 |
pfs->best_bird_dist = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
502 |
|
0 | 503 |
// if (length < pfs->best_length) |
504 |
// dbg_store_path(); |
|
505 |
||
506 |
pfs->best_length = minu(pfs->best_length, length); |
|
507 |
return true; |
|
508 |
} |
|
509 |
||
510 |
// Skip this tile in the calculation |
|
511 |
if (tile != pfs->skiptile) { |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1237
diff
changeset
|
512 |
pfs->best_bird_dist = minu(pfs->best_bird_dist, DistanceMaxPlusManhattan(pfs->dest_coords, tile)); |
0 | 513 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
514 |
|
0 | 515 |
return false; |
516 |
} |
|
517 |
||
518 |
static const byte _ship_search_directions[6][4] = { |
|
519 |
{ 0, 9, 2, 9 }, |
|
520 |
{ 9, 1, 9, 3 }, |
|
521 |
{ 9, 0, 3, 9 }, |
|
522 |
{ 1, 9, 9, 2 }, |
|
523 |
{ 3, 2, 9, 9 }, |
|
524 |
{ 9, 9, 1, 0 }, |
|
525 |
}; |
|
526 |
||
527 |
static const byte _pick_shiptrack_table[6] = {1, 3, 2, 2, 0, 0}; |
|
528 |
||
529 |
static uint FindShipTrack(Vehicle *v, uint tile, int dir, uint bits, uint skiptile, int *track) |
|
530 |
{ |
|
531 |
PathFindShip pfs; |
|
532 |
int i, best_track; |
|
533 |
uint best_bird_dist = 0; |
|
534 |
uint best_length = 0; |
|
535 |
uint r; |
|
536 |
byte ship_dir = v->direction & 3; |
|
537 |
||
538 |
pfs.dest_coords = v->dest_tile; |
|
539 |
pfs.skiptile = skiptile; |
|
540 |
||
541 |
best_track = -1; |
|
542 |
||
543 |
do { |
|
544 |
i = FIND_FIRST_BIT(bits); |
|
545 |
bits = KILL_FIRST_BIT(bits); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
546 |
|
0 | 547 |
pfs.best_bird_dist = (uint)-1; |
548 |
pfs.best_length = (uint)-1; |
|
549 |
||
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
550 |
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
|
551 |
|
0 | 552 |
if (best_track >= 0) { |
553 |
if (pfs.best_bird_dist != 0) { |
|
554 |
/* neither reached the destination, pick the one with the smallest bird dist */ |
|
555 |
if (pfs.best_bird_dist > best_bird_dist) goto bad; |
|
556 |
if (pfs.best_bird_dist < best_bird_dist) goto good; |
|
557 |
} else { |
|
558 |
if (pfs.best_length > best_length) goto bad; |
|
559 |
if (pfs.best_length < best_length) goto good; |
|
560 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
561 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
562 |
/* if we reach this position, there's two paths of equal value so far. |
0 | 563 |
* pick one randomly. */ |
564 |
r = (byte)Random(); |
|
565 |
if (_pick_shiptrack_table[i] == ship_dir) r += 80; |
|
566 |
if (_pick_shiptrack_table[best_track] == ship_dir) r -= 80; |
|
567 |
if (r <= 127) goto bad; |
|
568 |
} |
|
569 |
good:; |
|
570 |
best_track = i; |
|
571 |
best_bird_dist = pfs.best_bird_dist; |
|
572 |
best_length = pfs.best_length; |
|
573 |
bad:; |
|
574 |
||
575 |
} while (bits != 0); |
|
576 |
||
577 |
*track = best_track; |
|
578 |
return best_bird_dist; |
|
579 |
} |
|
580 |
||
1247 | 581 |
/* returns the track to choose on the next tile, or -1 when it's better to |
582 |
* reverse. The tile given is the tile we are about to enter, enterdir is the |
|
583 |
* direction in which we are entering the tile */ |
|
584 |
static int ChooseShipTrack(Vehicle *v, uint tile, int enterdir, uint tracks) |
|
0 | 585 |
{ |
1247 | 586 |
assert(enterdir>=0 && enterdir<=3); |
0 | 587 |
|
1247 | 588 |
if (_patches.new_pathfinding_all) { |
589 |
NPFFindStationOrTileData fstd; |
|
590 |
NPFFoundTargetData ftd; |
|
591 |
uint src_tile = TILE_ADD(tile, TileOffsByDir(_reverse_dir[enterdir])); |
|
592 |
byte track = FIND_FIRST_BIT(v->u.ship.state); |
|
593 |
assert (KILL_FIRST_BIT(v->u.ship.state) == 0); /* Check that only one bit is set in state */ |
|
594 |
assert (v->u.ship.state != 0x80); /* Check that we are not in a depot */ |
|
595 |
assert (track < 6); |
|
596 |
||
597 |
NPFFillWithOrderData(&fstd, v); |
|
598 |
||
1330
5d76a0522a11
(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
|
599 |
ftd = NPFRouteToStationOrTile(src_tile, _track_direction_to_trackdir[track][v->direction], &fstd, TRANSPORT_WATER, v->owner); |
1247 | 600 |
|
601 |
if (ftd.best_bird_dist == 0 && ftd.best_trackdir != 0xff) |
|
602 |
/* Found the target, and it is not our current tile */ |
|
603 |
return ftd.best_trackdir & 7; /* TODO: Wrapper function? */ |
|
604 |
else |
|
605 |
return -1; /* Couldn't find target, reverse */ |
|
606 |
/* TODO: When the target is unreachable, the ship will keep reversing */ |
|
607 |
} else { |
|
608 |
uint b; |
|
609 |
uint tot_dist, dist; |
|
610 |
int track; |
|
611 |
uint tile2; |
|
612 |
||
613 |
tile2 = TILE_ADD(tile, -TileOffsByDir(enterdir)); |
|
614 |
tot_dist = (uint)-1; |
|
615 |
||
616 |
/* Let's find out how far it would be if we would reverse first */ |
|
617 |
b = GetTileShipTrackStatus(tile2) & _ship_sometracks[_reverse_dir[enterdir]] & v->u.ship.state; |
|
618 |
if (b != 0) { |
|
619 |
dist = FindShipTrack(v, tile2, _reverse_dir[enterdir], b, tile, &track); |
|
620 |
if (dist != (uint)-1) |
|
621 |
tot_dist = dist + 1; |
|
622 |
} |
|
623 |
/* And if we would not reverse? */ |
|
624 |
dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track); |
|
625 |
if (dist > tot_dist) |
|
626 |
/* We could better reverse */ |
|
627 |
return -1; |
|
628 |
return track; |
|
0 | 629 |
} |
630 |
} |
|
631 |
||
632 |
static const byte _new_vehicle_direction_table[11] = { |
|
633 |
0, 7, 6, 0, |
|
634 |
1, 0, 5, 0, |
|
635 |
2, 3, 4, |
|
636 |
}; |
|
637 |
||
638 |
static int ShipGetNewDirectionFromTiles(uint new_tile, uint old_tile) |
|
639 |
{ |
|
926
a6d140a6a4de
(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
|
640 |
uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + |
a6d140a6a4de
(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
|
641 |
TileX(new_tile) - TileX(old_tile) + 1; |
0 | 642 |
assert(offs < 11 && offs != 3 && offs != 7); |
643 |
return _new_vehicle_direction_table[offs]; |
|
644 |
} |
|
645 |
||
646 |
static int ShipGetNewDirection(Vehicle *v, int x, int y) |
|
647 |
{ |
|
648 |
uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1); |
|
649 |
assert(offs < 11 && offs != 3 && offs != 7); |
|
650 |
return _new_vehicle_direction_table[offs]; |
|
651 |
} |
|
652 |
||
653 |
static int GetAvailShipTracks(uint tile, int dir) |
|
654 |
{ |
|
159
139cf78bfb28
(svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents:
156
diff
changeset
|
655 |
uint32 r = GetTileTrackStatus(tile, TRANSPORT_WATER); |
0 | 656 |
return (byte) ((r | r >> 8)) & _ship_sometracks[dir]; |
657 |
} |
|
658 |
||
659 |
static const byte _ship_subcoord[4][6][3] = { |
|
660 |
{ |
|
661 |
{15, 8, 1}, |
|
662 |
{ 0, 0, 0}, |
|
663 |
{ 0, 0, 0}, |
|
664 |
{15, 8, 2}, |
|
665 |
{15, 7, 0}, |
|
666 |
{ 0, 0, 0}, |
|
667 |
}, |
|
668 |
{ |
|
669 |
{ 0, 0, 0}, |
|
670 |
{ 8, 0, 3}, |
|
671 |
{ 7, 0, 2}, |
|
672 |
{ 0, 0, 0}, |
|
673 |
{ 8, 0, 4}, |
|
674 |
{ 0, 0, 0}, |
|
675 |
}, |
|
676 |
{ |
|
677 |
{ 0, 8, 5}, |
|
678 |
{ 0, 0, 0}, |
|
679 |
{ 0, 7, 6}, |
|
680 |
{ 0, 0, 0}, |
|
681 |
{ 0, 0, 0}, |
|
682 |
{ 0, 8, 4}, |
|
683 |
}, |
|
684 |
{ |
|
685 |
{ 0, 0, 0}, |
|
686 |
{ 8,15, 7}, |
|
687 |
{ 0, 0, 0}, |
|
688 |
{ 8,15, 6}, |
|
689 |
{ 0, 0, 0}, |
|
690 |
{ 7,15, 0}, |
|
691 |
} |
|
692 |
}; |
|
693 |
||
694 |
static void ShipController(Vehicle *v) |
|
695 |
{ |
|
696 |
GetNewVehiclePosResult gp; |
|
697 |
uint32 r; |
|
698 |
const byte *b; |
|
699 |
int dir,track,tracks; |
|
700 |
||
701 |
v->tick_counter++; |
|
702 |
||
703 |
if (v->breakdown_ctr != 0) { |
|
704 |
if (v->breakdown_ctr <= 2) { |
|
705 |
HandleBrokenShip(v); |
|
706 |
return; |
|
707 |
} |
|
708 |
v->breakdown_ctr--; |
|
709 |
} |
|
710 |
||
711 |
if (v->vehstatus & VS_STOPPED) |
|
712 |
return; |
|
713 |
||
714 |
ProcessShipOrder(v); |
|
715 |
HandleShipLoading(v); |
|
716 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
717 |
if (v->current_order.type == OT_LOADING) |
0 | 718 |
return; |
719 |
||
720 |
CheckShipLeaveDepot(v); |
|
721 |
||
722 |
if (!ShipAccelerate(v)) |
|
723 |
return; |
|
724 |
||
725 |
BeginVehicleMove(v); |
|
726 |
||
727 |
if (GetNewVehiclePos(v, &gp)) { |
|
728 |
// staying in tile |
|
729 |
if (v->u.ship.state == 0x80) { |
|
730 |
gp.x = v->x_pos; |
|
731 |
gp.y = v->y_pos; |
|
732 |
} else { |
|
733 |
/* isnot inside depot */ |
|
734 |
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
|
735 |
if (r & 0x8) goto reverse_direction; |
|
736 |
||
737 |
if (v->dest_tile != 0 && v->dest_tile == gp.new_tile) { |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
738 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 739 |
if ((gp.x&0xF)==8 && (gp.y&0xF)==8) { |
740 |
ShipEnterDepot(v); |
|
741 |
return; |
|
742 |
} |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
743 |
} else if (v->current_order.type == OT_GOTO_STATION) { |
0 | 744 |
Station *st; |
745 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
746 |
v->last_station_visited = v->current_order.station; |
0 | 747 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
748 |
/* Process station in the orderlist. Don't do that for buoys (HVOT_BUOY) */ |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
749 |
st = GetStation(v->current_order.station); |
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
750 |
if (!(st->had_vehicle_of_type & HVOT_BUOY) |
297
6c4ab6ff031f
(svn r303) Fix: [ 1022227 ] Ships could unload cargo at stations without docks
dominik
parents:
193
diff
changeset
|
751 |
&& (st->facilities & FACIL_DOCK)) { /* ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
752 |
v->current_order.type = OT_LOADING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
753 |
v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
754 |
v->current_order.flags |= OF_NON_STOP; |
0 | 755 |
ShipArrivesAt(v, st); |
756 |
||
757 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC); |
|
758 |
if (LoadUnloadVehicle(v)) { |
|
759 |
InvalidateWindow(WC_SHIPS_LIST, v->owner); |
|
760 |
MarkShipDirty(v); |
|
761 |
} |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
762 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
297
6c4ab6ff031f
(svn r303) Fix: [ 1022227 ] Ships could unload cargo at stations without docks
dominik
parents:
193
diff
changeset
|
763 |
} else { /* leave buoys right aways */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
764 |
v->current_order.type = OT_LEAVESTATION; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
765 |
v->current_order.flags = 0; |
0 | 766 |
v->cur_order_index++; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
767 |
InvalidateVehicleOrder(v); |
0 | 768 |
} |
769 |
goto else_end; |
|
770 |
} |
|
771 |
} |
|
772 |
||
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
773 |
if (v->current_order.type == OT_LEAVESTATION) { |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
774 |
v->current_order.type = OT_NOTHING; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
775 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
776 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 777 |
} |
778 |
} |
|
779 |
} else { |
|
780 |
// new tile |
|
1401
44a7e0f04d28
(svn r1905) - Fix: [ 1118810 ] openttd: ship_cmd.c:642 ... Assertion failed. Mapwrap fixed in ship_cmd.c (was implicitely ok before biggermaps).
Darkvater
parents:
1330
diff
changeset
|
781 |
if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) |
926
a6d140a6a4de
(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
|
782 |
goto reverse_direction; |
0 | 783 |
|
784 |
dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile); |
|
785 |
assert(dir == 1 || dir == 3 || dir == 5 || dir == 7); |
|
786 |
dir>>=1; |
|
787 |
tracks = GetAvailShipTracks(gp.new_tile, dir); |
|
788 |
if (tracks == 0) |
|
789 |
goto reverse_direction; |
|
790 |
||
791 |
// Choose a direction, and continue if we find one |
|
792 |
track = ChooseShipTrack(v, gp.new_tile, dir, tracks); |
|
793 |
if (track < 0) |
|
794 |
goto reverse_direction; |
|
795 |
||
796 |
b = _ship_subcoord[dir][track]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
797 |
|
0 | 798 |
gp.x = (gp.x&~0xF) | b[0]; |
799 |
gp.y = (gp.y&~0xF) | b[1]; |
|
800 |
||
801 |
/* Call the landscape function and tell it that the vehicle entered the tile */ |
|
802 |
r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); |
|
803 |
if (r&0x8) goto reverse_direction; |
|
804 |
||
805 |
if (!(r&0x4)) { |
|
806 |
v->tile = gp.new_tile; |
|
807 |
v->u.ship.state = 1 << track; |
|
808 |
} |
|
809 |
||
810 |
v->direction = b[2]; |
|
811 |
} |
|
812 |
else_end:; |
|
813 |
||
814 |
/* update image of ship, as well as delta XY */ |
|
815 |
dir = ShipGetNewDirection(v, gp.x, gp.y); |
|
816 |
v->x_pos = gp.x; |
|
817 |
v->y_pos = gp.y; |
|
818 |
v->z_pos = GetSlopeZ(gp.x, gp.y); |
|
819 |
||
820 |
getout: |
|
821 |
UpdateShipDeltaXY(v, dir); |
|
822 |
v->cur_image = GetShipImage(v, dir); |
|
823 |
VehiclePositionChanged(v); |
|
824 |
EndVehicleMove(v); |
|
825 |
return; |
|
826 |
||
827 |
reverse_direction: |
|
828 |
dir = v->direction ^ 4; |
|
829 |
v->direction = dir; |
|
830 |
goto getout; |
|
831 |
} |
|
832 |
||
833 |
static void AgeShipCargo(Vehicle *v) |
|
834 |
{ |
|
835 |
if (_age_cargo_skip_counter != 0) |
|
836 |
return; |
|
837 |
if (v->cargo_days != 255) |
|
838 |
v->cargo_days++; |
|
839 |
} |
|
840 |
||
841 |
void Ship_Tick(Vehicle *v) |
|
842 |
{ |
|
843 |
AgeShipCargo(v); |
|
844 |
ShipController(v); |
|
845 |
} |
|
846 |
||
847 |
void HandleClickOnShip(Vehicle *v) |
|
848 |
{ |
|
849 |
ShowShipViewWindow(v); |
|
850 |
} |
|
851 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1055
diff
changeset
|
852 |
void ShipsYearlyLoop(void) |
0 | 853 |
{ |
854 |
Vehicle *v; |
|
855 |
||
856 |
FOR_ALL_VEHICLES(v) { |
|
857 |
if (v->type == VEH_Ship) { |
|
858 |
v->profit_last_year = v->profit_this_year; |
|
859 |
v->profit_this_year = 0; |
|
860 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
861 |
} |
|
862 |
} |
|
863 |
} |
|
864 |
||
812
65ecc321b3db
(svn r1283) -Add: AutoRenew is now a client-side patch instead of a game-side patch
truelight
parents:
755
diff
changeset
|
865 |
int32 EstimateShipCost(uint16 engine_type) |
0 | 866 |
{ |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
867 |
return ShipVehInfo(engine_type)->base_cost * (_price.ship_base>>3)>>5; |
0 | 868 |
} |
869 |
||
870 |
// p1 = type to build |
|
871 |
int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
872 |
{ |
|
873 |
int32 value; |
|
874 |
Vehicle *v; |
|
1282
ea2ae881814c
(svn r1786) -Fix: unitnumber is increased to 16bit, so now you can have up to 5000
truelight
parents:
1266
diff
changeset
|
875 |
UnitID unit_num; |
1330
5d76a0522a11
(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
|
876 |
TileIndex tile = TILE_FROM_XY(x,y); |
0 | 877 |
Engine *e; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
878 |
|
1197 | 879 |
if (!IsEngineBuildable(p1, VEH_Ship)) return CMD_ERROR; |
1196
67f7f3017d99
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1151
diff
changeset
|
880 |
|
0 | 881 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
882 |
||
883 |
value = EstimateShipCost(p1); |
|
884 |
if (flags & DC_QUERY_COST) |
|
885 |
return value; |
|
886 |
||
1443
2b8e1b123d91
(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
|
887 |
/* The ai_new queries the vehicle cost before building the route, |
2b8e1b123d91
(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
|
888 |
* so we must check against cheaters no sooner than now. --pasky */ |
2b8e1b123d91
(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
|
889 |
if (!IsTileDepotType(tile, TRANSPORT_WATER)) return CMD_ERROR; |
2b8e1b123d91
(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
|
890 |
if (_map_owner[tile] != _current_player) return CMD_ERROR; |
2b8e1b123d91
(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
|
891 |
|
0 | 892 |
v = AllocateVehicle(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
893 |
if (v == NULL || IsOrderPoolFull() || |
0 | 894 |
(unit_num = GetFreeUnitNumber(VEH_Ship)) > _patches.max_ships) |
895 |
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
|
896 |
|
0 | 897 |
if (flags & DC_EXEC) { |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
898 |
const ShipVehicleInfo *svi = ShipVehInfo(p1); |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
899 |
|
0 | 900 |
v->unitnumber = unit_num; |
901 |
||
902 |
v->owner = _current_player; |
|
903 |
v->tile = tile; |
|
926
a6d140a6a4de
(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
|
904 |
x = TileX(tile) * 16 + 8; |
a6d140a6a4de
(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
|
905 |
y = TileY(tile) * 16 + 8; |
0 | 906 |
v->x_pos = x; |
907 |
v->y_pos = y; |
|
908 |
v->z_pos = GetSlopeZ(x,y); |
|
909 |
||
910 |
v->z_height = 6; |
|
911 |
v->sprite_width = 6; |
|
912 |
v->sprite_height = 6; |
|
913 |
v->x_offs = -3; |
|
914 |
v->y_offs = -3; |
|
915 |
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
|
916 |
|
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
917 |
v->spritenum = svi->image_index; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
918 |
v->cargo_type = svi->cargo_type; |
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
919 |
v->cargo_cap = svi->capacity; |
0 | 920 |
v->value = value; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
921 |
|
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
922 |
v->last_station_visited = INVALID_STATION; |
538
24fdb517fbe5
(svn r920) Replace vehicle info macros with inline functions and add asserts to check limits
tron
parents:
534
diff
changeset
|
923 |
v->max_speed = svi->max_speed; |
0 | 924 |
v->engine_type = (byte)p1; |
925 |
||
926 |
e = &_engines[p1]; |
|
927 |
v->reliability = e->reliability; |
|
928 |
v->reliability_spd_dec = e->reliability_spd_dec; |
|
929 |
v->max_age = e->lifelength * 366; |
|
930 |
_new_ship_id = v->index; |
|
931 |
||
932 |
v->string_id = STR_SV_SHIP_NAME; |
|
933 |
v->u.ship.state = 0x80; |
|
934 |
||
935 |
v->service_interval = _patches.servint_ships; |
|
936 |
v->date_of_last_service = _date; |
|
937 |
v->build_year = _cur_year; |
|
938 |
v->cur_image = 0x0E5E; |
|
939 |
v->type = VEH_Ship; |
|
940 |
||
941 |
VehiclePositionChanged(v); |
|
942 |
||
943 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 944 |
RebuildVehicleLists(); |
0 | 945 |
InvalidateWindow(WC_COMPANY, v->owner); |
946 |
} |
|
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
947 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
948 |
|
0 | 949 |
return value; |
950 |
} |
|
951 |
||
952 |
int32 CmdSellShip(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
953 |
{ |
|
954 |
Vehicle *v; |
|
955 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
956 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
957 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
958 |
v = GetVehicle(p1); |
0 | 959 |
|
1235
b9938f523286
(svn r1739) - Fix: type checking when selling vehicles (TrueLight)
darkvater
parents:
1226
diff
changeset
|
960 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) |
0 | 961 |
return CMD_ERROR; |
962 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
963 |
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
964 |
|
1330
5d76a0522a11
(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
|
965 |
if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || v->u.road.state != 0x80 || !(v->vehstatus&VS_STOPPED)) |
0 | 966 |
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
967 |
|
0 | 968 |
if (flags & DC_EXEC) { |
969 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
588 | 970 |
RebuildVehicleLists(); |
0 | 971 |
InvalidateWindow(WC_COMPANY, v->owner); |
972 |
DeleteWindowById(WC_VEHICLE_VIEW, v->index); |
|
973 |
DeleteVehicle(v); |
|
974 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
975 |
|
1128
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
976 |
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_Ship); // updates the replace Ship window |
ca7f860db7ac
(svn r1629) added a counter to tell how many engines you have of each type to the autoreplace vehicle windows and made them show only the vehicles you actually have in the left list.
bjarni
parents:
1093
diff
changeset
|
977 |
|
0 | 978 |
return -(int32)v->value; |
979 |
} |
|
980 |
||
981 |
// p1 = vehicle |
|
982 |
int32 CmdStartStopShip(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
983 |
{ |
|
984 |
Vehicle *v; |
|
985 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
986 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
987 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
988 |
v = GetVehicle(p1); |
0 | 989 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
990 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) |
0 | 991 |
return CMD_ERROR; |
992 |
||
993 |
if (flags & DC_EXEC) { |
|
994 |
v->vehstatus ^= VS_STOPPED; |
|
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
995 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 996 |
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
997 |
} |
|
998 |
||
1055
cc4f60cc9102
(svn r1556) -Fix: Vehicle list updates should now really work
Celestar
parents:
1053
diff
changeset
|
999 |
InvalidateWindowClasses(WC_SHIPS_LIST); |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
926
diff
changeset
|
1000 |
|
0 | 1001 |
return 0; |
1002 |
} |
|
1003 |
||
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
1004 |
/* Send a ship to the nearest depot |
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
1005 |
p1 = index of the ship |
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
1006 |
p2 = bit 0 = do not stop in depot |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
1007 |
bit 1 = set v->set_for_replacement |
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
1008 |
bit 2 = clear v->set_for_replacement */ |
0 | 1009 |
int32 CmdSendShipToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1010 |
{ |
|
1011 |
Vehicle *v; |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
1012 |
Depot *depot; |
0 | 1013 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1014 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1015 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1016 |
v = GetVehicle(p1); |
0 | 1017 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1018 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) |
0 | 1019 |
return CMD_ERROR; |
1020 |
||
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
1021 |
if (HASBIT(p2, 0)) v->set_for_replacement = true; |
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
1022 |
if (HASBIT(p2, 2)) v->set_for_replacement = false; |
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
1023 |
|
1206
5d3c1d2c3214
(svn r1710) - Fix: [autoreplace] vehicles do no longer go to a depot all the time if the owner clicked 'stop replacing' ( ship+aircraft+road vehicles )
bjarni
parents:
1205
diff
changeset
|
1024 |
if (HASBIT(p2, 1) || HASBIT(p2, 2)) return CMD_ERROR; // vehicle has a depot in schedule. It just needed to alter set_for_replacement |
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
1025 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1026 |
if (v->current_order.type == OT_GOTO_DEPOT) { |
0 | 1027 |
if (flags & DC_EXEC) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1028 |
if (v->current_order.flags & OF_UNLOAD) v->cur_order_index++; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1029 |
v->current_order.type = OT_DUMMY; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1030 |
v->current_order.flags = 0; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1031 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1032 |
} |
1033 |
} else { |
|
1034 |
depot = FindClosestShipDepot(v); |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
1035 |
if (depot == NULL) |
0 | 1036 |
return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT); |
1037 |
||
1038 |
if (flags & DC_EXEC) { |
|
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
1039 |
v->dest_tile = depot->xy; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
541
diff
changeset
|
1040 |
v->current_order.type = OT_GOTO_DEPOT; |
1205
1607043f1831
(svn r1709) - Feature: [autoreplace] ships now automatically goes to a depot if they need to be replaced
bjarni
parents:
1197
diff
changeset
|
1041 |
v->current_order.flags = HASBIT(p2, 0) ? 0 : OF_NON_STOP | OF_FULL_LOAD; |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1282
diff
changeset
|
1042 |
v->current_order.station = depot->index; |
755
80091de50044
(svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents:
679
diff
changeset
|
1043 |
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
0 | 1044 |
} |
1045 |
} |
|
1046 |
||
1047 |
return 0; |
|
1048 |
} |
|
1049 |
||
1050 |
int32 CmdChangeShipServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
1051 |
{ |
|
1052 |
Vehicle *v; |
|
1053 |
||
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1054 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1055 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1056 |
v = GetVehicle(p1); |
0 | 1057 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1058 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) |
0 | 1059 |
return CMD_ERROR; |
1060 |
||
1061 |
if (flags & DC_EXEC) { |
|
1062 |
v->service_interval = (uint16)p2; |
|
1063 |
InvalidateWindowWidget(WC_VEHICLE_DETAILS, v->index, 7); |
|
1064 |
} |
|
1065 |
||
1066 |
return 0; |
|
1067 |
} |
|
1068 |
||
1069 |
||
1070 |
// p1 = vehicle |
|
842 | 1071 |
// p2 = new cargo (0xFF) |
1072 |
// p2 = skip check for stopped in hanger (0x0100) |
|
0 | 1073 |
int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1074 |
{ |
|
1075 |
Vehicle *v; |
|
1076 |
int32 cost; |
|
842 | 1077 |
byte SkipStoppedInDepotCheck = (p2 & 0x100) >> 8; //excludes the cargo value |
0 | 1078 |
|
842 | 1079 |
p2 = p2 & 0xFF; |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1080 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1081 |
if (!IsVehicleIndex(p1)) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
164
diff
changeset
|
1082 |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
1083 |
v = GetVehicle(p1); |
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1084 |
|
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1085 |
if (v->type != VEH_Ship || !CheckOwnership(v->owner)) |
0 | 1086 |
return CMD_ERROR; |
1087 |
||
842 | 1088 |
if (!( SkipStoppedInDepotCheck )) { |
1330
5d76a0522a11
(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
|
1089 |
if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || |
842 | 1090 |
!(v->vehstatus&VS_STOPPED) || |
1091 |
v->u.ship.state != 0x80) |
|
1092 |
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN); |
|
1093 |
} |
|
915 | 1094 |
|
1237
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1095 |
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN); |
1c7a3f9c94b9
(svn r1741) - Fix: added IsVehicleIndex() so it's possible to protect GetVehicle() from reading an invalid vehicle index
bjarni
parents:
1235
diff
changeset
|
1096 |
|
0 | 1097 |
cost = 0; |
1098 |
if (IS_HUMAN_PLAYER(v->owner) && (byte)p2 != v->cargo_type) { |
|
1099 |
cost = _price.ship_base >> 7; |
|
1100 |
} |
|
1101 |
||
1102 |
if (flags & DC_EXEC) { |
|
842 | 1103 |
//autorefitted ships wants to keep the cargo |
1104 |
//it will be checked if the cargo is valid in CmdRenewVehicle |
|
1105 |
if (!(SkipStoppedInDepotCheck)) |
|
915 | 1106 |
v->cargo_count = 0; |
0 | 1107 |
v->cargo_type = (byte)p2; |
1108 |
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
|
1109 |
} |
|
1110 |
||
1111 |
return cost; |
|
1112 |
||
1113 |
} |
|
1114 |
||
1115 |