00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "ship.h"
00014 #include "landscape.h"
00015 #include "timetable.h"
00016 #include "news_func.h"
00017 #include "company_func.h"
00018 #include "pathfinder/npf/npf_func.h"
00019 #include "depot_base.h"
00020 #include "station_base.h"
00021 #include "vehicle_gui.h"
00022 #include "newgrf_engine.h"
00023 #include "pathfinder/yapf/yapf.h"
00024 #include "newgrf_sound.h"
00025 #include "spritecache.h"
00026 #include "strings_func.h"
00027 #include "window_func.h"
00028 #include "date_func.h"
00029 #include "vehicle_func.h"
00030 #include "sound_func.h"
00031 #include "ai/ai.hpp"
00032 #include "pathfinder/opf/opf_ship.h"
00033 #include "engine_base.h"
00034 #include "company_base.h"
00035 #include "tunnelbridge_map.h"
00036 #include "zoom_func.h"
00037
00038 #include "table/strings.h"
00039
00045 WaterClass GetEffectiveWaterClass(TileIndex tile)
00046 {
00047 if (HasTileWaterClass(tile)) return GetWaterClass(tile);
00048 if (IsTileType(tile, MP_TUNNELBRIDGE)) {
00049 assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_WATER);
00050 return WATER_CLASS_CANAL;
00051 }
00052 if (IsTileType(tile, MP_RAILWAY)) {
00053 assert(GetRailGroundType(tile) == RAIL_GROUND_WATER);
00054 return WATER_CLASS_SEA;
00055 }
00056 NOT_REACHED();
00057 }
00058
00059 static const uint16 _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
00060
00061 static inline TrackBits GetTileShipTrackStatus(TileIndex tile)
00062 {
00063 return TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0));
00064 }
00065
00066 static SpriteID GetShipIcon(EngineID engine, EngineImageType image_type)
00067 {
00068 const Engine *e = Engine::Get(engine);
00069 uint8 spritenum = e->u.ship.image_index;
00070
00071 if (is_custom_sprite(spritenum)) {
00072 SpriteID sprite = GetCustomVehicleIcon(engine, DIR_W, image_type);
00073 if (sprite != 0) return sprite;
00074
00075 spritenum = e->original_image_index;
00076 }
00077
00078 return DIR_W + _ship_sprites[spritenum];
00079 }
00080
00081 void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
00082 {
00083 SpriteID sprite = GetShipIcon(engine, image_type);
00084 const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
00085 preferred_x = Clamp(preferred_x, left - UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI), right - UnScaleByZoom(real_sprite->width, ZOOM_LVL_GUI) - UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI));
00086 DrawSprite(sprite, pal, preferred_x, y);
00087 }
00088
00095 void GetShipSpriteSize(EngineID engine, uint &width, uint &height, EngineImageType image_type)
00096 {
00097 const Sprite *spr = GetSprite(GetShipIcon(engine, image_type), ST_NORMAL);
00098
00099 width = UnScaleByZoom(spr->width, ZOOM_LVL_GUI);
00100 height = UnScaleByZoom(spr->height, ZOOM_LVL_GUI);
00101 }
00102
00103 SpriteID Ship::GetImage(Direction direction, EngineImageType image_type) const
00104 {
00105 uint8 spritenum = this->spritenum;
00106
00107 if (is_custom_sprite(spritenum)) {
00108 SpriteID sprite = GetCustomVehicleSprite(this, direction, image_type);
00109 if (sprite != 0) return sprite;
00110
00111 spritenum = this->GetEngine()->original_image_index;
00112 }
00113
00114 return _ship_sprites[spritenum] + direction;
00115 }
00116
00117 static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance)
00118 {
00119
00120 const Depot *depot;
00121 const Depot *best_depot = NULL;
00122
00123
00124
00125
00126
00127 uint best_dist = max_distance == 0 ? UINT_MAX : max_distance + 1;
00128
00129 FOR_ALL_DEPOTS(depot) {
00130 TileIndex tile = depot->xy;
00131 if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) {
00132 uint dist = DistanceManhattan(tile, v->tile);
00133 if (dist < best_dist) {
00134 best_dist = dist;
00135 best_depot = depot;
00136 }
00137 }
00138 }
00139
00140 return best_depot;
00141 }
00142
00143 static void CheckIfShipNeedsService(Vehicle *v)
00144 {
00145 if (Company::Get(v->owner)->settings.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return;
00146 if (v->IsInDepot()) {
00147 VehicleServiceInDepot(v);
00148 return;
00149 }
00150
00151 uint max_distance;
00152 switch (_settings_game.pf.pathfinder_for_ships) {
00153 case VPF_OPF: max_distance = 12; break;
00154 case VPF_NPF: max_distance = _settings_game.pf.npf.maximum_go_to_depot_penalty / NPF_TILE_LENGTH; break;
00155 case VPF_YAPF: max_distance = _settings_game.pf.yapf.maximum_go_to_depot_penalty / YAPF_TILE_LENGTH; break;
00156 default: NOT_REACHED();
00157 }
00158
00159 const Depot *depot = FindClosestShipDepot(v, max_distance);
00160
00161 if (depot == NULL) {
00162 if (v->current_order.IsType(OT_GOTO_DEPOT)) {
00163 v->current_order.MakeDummy();
00164 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
00165 }
00166 return;
00167 }
00168
00169 v->current_order.MakeGoToDepot(depot->index, ODTFB_SERVICE);
00170 v->dest_tile = depot->xy;
00171 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
00172 }
00173
00177 void Ship::UpdateCache()
00178 {
00179 const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
00180
00181
00182 bool is_ocean = GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA;
00183 uint raw_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed);
00184 this->vcache.cached_max_speed = svi->ApplyWaterClassSpeedFrac(raw_speed, is_ocean);
00185
00186
00187 this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
00188
00189 this->UpdateVisualEffect();
00190 }
00191
00192 Money Ship::GetRunningCost() const
00193 {
00194 const Engine *e = this->GetEngine();
00195 uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
00196 return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
00197 }
00198
00199 void Ship::OnNewDay()
00200 {
00201 if ((++this->day_counter & 7) == 0) {
00202 DecreaseVehicleValue(this);
00203 }
00204
00205 CheckVehicleBreakdown(this);
00206 AgeVehicle(this);
00207 CheckIfShipNeedsService(this);
00208
00209 CheckOrders(this);
00210
00211 if (this->running_ticks == 0) return;
00212
00213 CommandCost cost(EXPENSES_SHIP_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS));
00214
00215 this->profit_this_year -= cost.GetCost();
00216 this->running_ticks = 0;
00217
00218 SubtractMoneyFromCompanyFract(this->owner, cost);
00219
00220 SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
00221
00222 SetWindowClassesDirty(WC_SHIPS_LIST);
00223 }
00224
00225 Trackdir Ship::GetVehicleTrackdir() const
00226 {
00227 if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
00228
00229 if (this->IsInDepot()) {
00230
00231 return DiagDirToDiagTrackdir(GetShipDepotDirection(this->tile));
00232 }
00233
00234 if (this->state == TRACK_BIT_WORMHOLE) {
00235
00236 return DiagDirToDiagTrackdir(DirToDiagDir(this->direction));
00237 }
00238
00239 return TrackDirectionToTrackdir(FindFirstTrack(this->state), this->direction);
00240 }
00241
00242 void Ship::MarkDirty()
00243 {
00244 this->UpdateViewport(false, false);
00245 this->UpdateCache();
00246 }
00247
00248 static void PlayShipSound(const Vehicle *v)
00249 {
00250 if (!PlayVehicleSound(v, VSE_START)) {
00251 SndPlayVehicleFx(ShipVehInfo(v->engine_type)->sfx, v);
00252 }
00253 }
00254
00255 void Ship::PlayLeaveStationSound() const
00256 {
00257 PlayShipSound(this);
00258 }
00259
00260 TileIndex Ship::GetOrderStationLocation(StationID station)
00261 {
00262 if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
00263
00264 const Station *st = Station::Get(station);
00265 if (st->dock_tile != INVALID_TILE) {
00266 return TILE_ADD(st->dock_tile, ToTileIndexDiff(GetDockOffset(st->dock_tile)));
00267 } else {
00268 this->IncrementRealOrderIndex();
00269 return 0;
00270 }
00271 }
00272
00273 void Ship::UpdateDeltaXY(Direction direction)
00274 {
00275 #define MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0)
00276 static const uint32 _delta_xy_table[8] = {
00277 MKIT( 6, 6, -3, -3),
00278 MKIT( 6, 32, -3, -16),
00279 MKIT( 6, 6, -3, -3),
00280 MKIT(32, 6, -16, -3),
00281 MKIT( 6, 6, -3, -3),
00282 MKIT( 6, 32, -3, -16),
00283 MKIT( 6, 6, -3, -3),
00284 MKIT(32, 6, -16, -3),
00285 };
00286 #undef MKIT
00287
00288 uint32 x = _delta_xy_table[direction];
00289 this->x_offs = GB(x, 0, 8);
00290 this->y_offs = GB(x, 8, 8);
00291 this->x_extent = GB(x, 16, 8);
00292 this->y_extent = GB(x, 24, 8);
00293 this->z_extent = 6;
00294 }
00295
00296 static const TileIndexDiffC _ship_leave_depot_offs[] = {
00297 {-1, 0},
00298 { 0, -1}
00299 };
00300
00301 static bool CheckShipLeaveDepot(Ship *v)
00302 {
00303 if (!v->IsInDepot()) return false;
00304
00305
00306 if (v->current_order.IsType(OT_GOTO_DEPOT) &&
00307 IsShipDepotTile(v->tile) && GetDepotIndex(v->tile) == v->current_order.GetDestination()) {
00308 VehicleEnterDepot(v);
00309 return true;
00310 }
00311
00312 TileIndex tile = v->tile;
00313 Axis axis = GetShipDepotAxis(tile);
00314
00315
00316 if (DiagdirReachesTracks((DiagDirection)axis) & GetTileShipTrackStatus(TILE_ADD(tile, ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
00317 v->direction = ReverseDir(AxisToDirection(axis));
00318
00319 } else if (DiagdirReachesTracks((DiagDirection)(axis + 2)) & GetTileShipTrackStatus(TILE_ADD(tile, -2 * ToTileIndexDiff(_ship_leave_depot_offs[axis])))) {
00320 v->direction = AxisToDirection(axis);
00321 } else {
00322 return false;
00323 }
00324
00325 v->state = AxisToTrackBits(axis);
00326 v->vehstatus &= ~VS_HIDDEN;
00327
00328 v->cur_speed = 0;
00329 v->UpdateViewport(false, true);
00330 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
00331
00332 PlayShipSound(v);
00333 VehicleServiceInDepot(v);
00334 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
00335 SetWindowClassesDirty(WC_SHIPS_LIST);
00336
00337 return false;
00338 }
00339
00340 static bool ShipAccelerate(Vehicle *v)
00341 {
00342 uint spd;
00343 byte t;
00344
00345 spd = min(v->cur_speed + 1, v->vcache.cached_max_speed);
00346
00347
00348 if (spd != v->cur_speed) {
00349 v->cur_speed = spd;
00350 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
00351 }
00352
00353
00354 spd = v->GetOldAdvanceSpeed(spd);
00355
00356 if (spd == 0) return false;
00357 if ((byte)++spd == 0) return true;
00358
00359 v->progress = (t = v->progress) - (byte)spd;
00360
00361 return (t < v->progress);
00362 }
00363
00369 static void ShipArrivesAt(const Vehicle *v, Station *st)
00370 {
00371
00372 if (!(st->had_vehicle_of_type & HVOT_SHIP)) {
00373 st->had_vehicle_of_type |= HVOT_SHIP;
00374
00375 SetDParam(0, st->index);
00376 AddVehicleNewsItem(
00377 STR_NEWS_FIRST_SHIP_ARRIVAL,
00378 (v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER,
00379 v->index,
00380 st->index
00381 );
00382 AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
00383 }
00384 }
00385
00386
00392 static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
00393 {
00394 assert(IsValidDiagDirection(enterdir));
00395
00396 bool path_found = true;
00397 Track track;
00398 switch (_settings_game.pf.pathfinder_for_ships) {
00399 case VPF_OPF: track = OPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
00400 case VPF_NPF: track = NPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
00401 case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found); break;
00402 default: NOT_REACHED();
00403 }
00404
00405 v->HandlePathfindingResult(path_found);
00406 return track;
00407 }
00408
00409 static const Direction _new_vehicle_direction_table[] = {
00410 DIR_N , DIR_NW, DIR_W , INVALID_DIR,
00411 DIR_NE, DIR_N , DIR_SW, INVALID_DIR,
00412 DIR_E , DIR_SE, DIR_S
00413 };
00414
00415 static Direction ShipGetNewDirectionFromTiles(TileIndex new_tile, TileIndex old_tile)
00416 {
00417 uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
00418 TileX(new_tile) - TileX(old_tile) + 1;
00419 assert(offs < 11 && offs != 3 && offs != 7);
00420 return _new_vehicle_direction_table[offs];
00421 }
00422
00423 static Direction ShipGetNewDirection(Vehicle *v, int x, int y)
00424 {
00425 uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1);
00426 assert(offs < 11 && offs != 3 && offs != 7);
00427 return _new_vehicle_direction_table[offs];
00428 }
00429
00430 static inline TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir)
00431 {
00432 return GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir);
00433 }
00434
00435 static const byte _ship_subcoord[4][6][3] = {
00436 {
00437 {15, 8, 1},
00438 { 0, 0, 0},
00439 { 0, 0, 0},
00440 {15, 8, 2},
00441 {15, 7, 0},
00442 { 0, 0, 0},
00443 },
00444 {
00445 { 0, 0, 0},
00446 { 8, 0, 3},
00447 { 7, 0, 2},
00448 { 0, 0, 0},
00449 { 8, 0, 4},
00450 { 0, 0, 0},
00451 },
00452 {
00453 { 0, 8, 5},
00454 { 0, 0, 0},
00455 { 0, 7, 6},
00456 { 0, 0, 0},
00457 { 0, 0, 0},
00458 { 0, 8, 4},
00459 },
00460 {
00461 { 0, 0, 0},
00462 { 8, 15, 7},
00463 { 0, 0, 0},
00464 { 8, 15, 6},
00465 { 0, 0, 0},
00466 { 7, 15, 0},
00467 }
00468 };
00469
00470 static void ShipController(Ship *v)
00471 {
00472 uint32 r;
00473 const byte *b;
00474 Direction dir;
00475 Track track;
00476 TrackBits tracks;
00477
00478 v->tick_counter++;
00479 v->current_order_time++;
00480
00481 if (v->HandleBreakdown()) return;
00482
00483 if (v->vehstatus & VS_STOPPED) return;
00484
00485 ProcessOrders(v);
00486 v->HandleLoading();
00487
00488 if (v->current_order.IsType(OT_LOADING)) return;
00489
00490 if (CheckShipLeaveDepot(v)) return;
00491
00492 v->ShowVisualEffect();
00493
00494 if (!ShipAccelerate(v)) return;
00495
00496 GetNewVehiclePosResult gp = GetNewVehiclePos(v);
00497 if (v->state != TRACK_BIT_WORMHOLE) {
00498
00499 if (gp.old_tile == gp.new_tile) {
00500
00501 if (v->IsInDepot()) {
00502 gp.x = v->x_pos;
00503 gp.y = v->y_pos;
00504 } else {
00505
00506 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
00507 if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
00508
00509
00510
00511 if (v->current_order.IsType(OT_LEAVESTATION)) {
00512 v->current_order.Free();
00513 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
00514 } else if (v->dest_tile != 0) {
00515
00516 if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
00517 DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
00518
00519
00520 UpdateVehicleTimetable(v, true);
00521 v->IncrementRealOrderIndex();
00522 v->current_order.MakeDummy();
00523 } else {
00524
00525 if (v->dest_tile == gp.new_tile) {
00526 if (v->current_order.IsType(OT_GOTO_DEPOT)) {
00527 if ((gp.x & 0xF) == 8 && (gp.y & 0xF) == 8) {
00528 VehicleEnterDepot(v);
00529 return;
00530 }
00531 } else if (v->current_order.IsType(OT_GOTO_STATION)) {
00532 v->last_station_visited = v->current_order.GetDestination();
00533
00534
00535 Station *st = Station::Get(v->current_order.GetDestination());
00536 if (st->facilities & FACIL_DOCK) {
00537 ShipArrivesAt(v, st);
00538 v->BeginLoading();
00539 } else {
00540 v->current_order.MakeLeaveStation();
00541 v->IncrementRealOrderIndex();
00542 }
00543 }
00544 }
00545 }
00546 }
00547 }
00548 } else {
00549 DiagDirection diagdir;
00550
00551 if (TileX(gp.new_tile) >= MapMaxX() || TileY(gp.new_tile) >= MapMaxY()) {
00552 goto reverse_direction;
00553 }
00554
00555 dir = ShipGetNewDirectionFromTiles(gp.new_tile, gp.old_tile);
00556 assert(dir == DIR_NE || dir == DIR_SE || dir == DIR_SW || dir == DIR_NW);
00557 diagdir = DirToDiagDir(dir);
00558 tracks = GetAvailShipTracks(gp.new_tile, diagdir);
00559 if (tracks == TRACK_BIT_NONE) goto reverse_direction;
00560
00561
00562 track = ChooseShipTrack(v, gp.new_tile, diagdir, tracks);
00563 if (track == INVALID_TRACK) goto reverse_direction;
00564
00565 b = _ship_subcoord[diagdir][track];
00566
00567 gp.x = (gp.x & ~0xF) | b[0];
00568 gp.y = (gp.y & ~0xF) | b[1];
00569
00570
00571 r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
00572 if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
00573
00574 if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
00575 v->tile = gp.new_tile;
00576 v->state = TrackToTrackBits(track);
00577
00578
00579 WaterClass old_wc = GetEffectiveWaterClass(gp.old_tile);
00580 WaterClass new_wc = GetEffectiveWaterClass(gp.new_tile);
00581 if (old_wc != new_wc) v->UpdateCache();
00582 }
00583
00584 v->direction = (Direction)b[2];
00585 }
00586 } else {
00587
00588 if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
00589 v->x_pos = gp.x;
00590 v->y_pos = gp.y;
00591 VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
00592 return;
00593 }
00594 }
00595
00596
00597 dir = ShipGetNewDirection(v, gp.x, gp.y);
00598 v->x_pos = gp.x;
00599 v->y_pos = gp.y;
00600 v->z_pos = GetSlopePixelZ(gp.x, gp.y);
00601
00602 getout:
00603 v->UpdateViewport(true, true);
00604 return;
00605
00606 reverse_direction:
00607 dir = ReverseDir(v->direction);
00608 v->direction = dir;
00609 goto getout;
00610 }
00611
00612 bool Ship::Tick()
00613 {
00614 if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
00615
00616 ShipController(this);
00617
00618 return true;
00619 }
00620
00630 CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
00631 {
00632 tile = GetShipDepotNorthTile(tile);
00633 if (flags & DC_EXEC) {
00634 int x;
00635 int y;
00636
00637 const ShipVehicleInfo *svi = &e->u.ship;
00638
00639 Ship *v = new Ship();
00640 *ret = v;
00641
00642 v->owner = _current_company;
00643 v->tile = tile;
00644 x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
00645 y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
00646 v->x_pos = x;
00647 v->y_pos = y;
00648 v->z_pos = GetSlopePixelZ(x, y);
00649
00650 v->UpdateDeltaXY(v->direction);
00651 v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
00652
00653 v->spritenum = svi->image_index;
00654 v->cargo_type = e->GetDefaultCargoType();
00655 v->cargo_cap = svi->capacity;
00656
00657 v->last_station_visited = INVALID_STATION;
00658 v->engine_type = e->index;
00659
00660 v->reliability = e->reliability;
00661 v->reliability_spd_dec = e->reliability_spd_dec;
00662 v->max_age = e->GetLifeLengthInDays();
00663 _new_vehicle_id = v->index;
00664
00665 v->state = TRACK_BIT_DEPOT;
00666
00667 v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_ships;
00668 v->date_of_last_service = _date;
00669 v->build_year = _cur_year;
00670 v->cur_image = SPR_IMG_QUERY;
00671 v->random_bits = VehicleRandomBits();
00672
00673 v->UpdateCache();
00674
00675 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
00676
00677 v->InvalidateNewGRFCacheOfChain();
00678
00679 v->cargo_cap = e->DetermineCapacity(v);
00680
00681 v->InvalidateNewGRFCacheOfChain();
00682
00683 VehicleMove(v, false);
00684 }
00685
00686 return CommandCost();
00687 }
00688
00689 bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
00690 {
00691 const Depot *depot = FindClosestShipDepot(this, 0);
00692
00693 if (depot == NULL) return false;
00694
00695 if (location != NULL) *location = depot->xy;
00696 if (destination != NULL) *destination = depot->index;
00697
00698 return true;
00699 }