* Build a ship. * @param flags type of operation. * @param tile tile of the depot where ship is built. * @param e the engine to build. * @param[out] ret the vehicle that has been built. * @return the cost of this operation or an error. */
| 863 | * @return the cost of this operation or an error. |
| 864 | */ |
| 865 | CommandCost CmdBuildShip(DoCommandFlags flags, TileIndex tile, const Engine *e, Vehicle **ret) |
| 866 | { |
| 867 | tile = GetShipDepotNorthTile(tile); |
| 868 | if (flags.Test(DoCommandFlag::Execute)) { |
| 869 | int x; |
| 870 | int y; |
| 871 | |
| 872 | const ShipVehicleInfo *svi = &e->VehInfo<ShipVehicleInfo>(); |
| 873 | |
| 874 | Ship *v = new Ship(); |
| 875 | *ret = v; |
| 876 | |
| 877 | v->owner = _current_company; |
| 878 | v->tile = tile; |
| 879 | x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
| 880 | y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
| 881 | v->x_pos = x; |
| 882 | v->y_pos = y; |
| 883 | v->z_pos = GetSlopePixelZ(x, y); |
| 884 | |
| 885 | v->direction = DiagDirToDir(GetShipDepotDirection(tile)); |
| 886 | |
| 887 | /* UpdateDeltaXY() requires rotation to be initialised as well. */ |
| 888 | v->rotation = v->direction; |
| 889 | v->UpdateDeltaXY(); |
| 890 | |
| 891 | v->vehstatus = {VehState::Hidden, VehState::Stopped, VehState::DefaultPalette}; |
| 892 | |
| 893 | v->spritenum = svi->image_index; |
| 894 | v->cargo_type = e->GetDefaultCargoType(); |
| 895 | assert(IsValidCargoType(v->cargo_type)); |
| 896 | v->cargo_cap = svi->capacity; |
| 897 | v->refit_cap = 0; |
| 898 | |
| 899 | v->last_station_visited = StationID::Invalid(); |
| 900 | v->last_loading_station = StationID::Invalid(); |
| 901 | v->engine_type = e->index; |
| 902 | |
| 903 | v->reliability = e->reliability; |
| 904 | v->reliability_spd_dec = e->reliability_spd_dec; |
| 905 | v->max_age = e->GetLifeLengthInDays(); |
| 906 | |
| 907 | v->state = TRACK_BIT_DEPOT; |
| 908 | |
| 909 | v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_ships); |
| 910 | v->date_of_last_service = TimerGameEconomy::date; |
| 911 | v->date_of_last_service_newgrf = TimerGameCalendar::date; |
| 912 | v->build_year = TimerGameCalendar::year; |
| 913 | v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); |
| 914 | v->random_bits = Random(); |
| 915 | |
| 916 | v->acceleration = svi->acceleration; |
| 917 | v->UpdateCache(); |
| 918 | |
| 919 | if (e->flags.Test(EngineFlag::ExclusivePreview)) v->vehicle_flags.Set(VehicleFlag::BuiltAsPrototype); |
| 920 | v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent); |
| 921 | |
| 922 | v->InvalidateNewGRFCacheOfChain(); |
no test coverage detected