|
@@ -191,97 +191,97 @@ static void CheckIfShipNeedsService(Vehi
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
v->current_order.MakeGoToDepot(depot->index, ODTFB_SERVICE);
|
|
|
v->SetDestTile(depot->xy);
|
|
|
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Update the caches of this ship.
|
|
|
*/
|
|
|
void Ship::UpdateCache()
|
|
|
{
|
|
|
const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
|
|
|
|
|
|
/* Get speed fraction for the current water type. Aqueducts are always canals. */
|
|
|
bool is_ocean = GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA;
|
|
|
uint raw_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed);
|
|
|
this->vcache.cached_max_speed = svi->ApplyWaterClassSpeedFrac(raw_speed, is_ocean);
|
|
|
|
|
|
/* Update cargo aging period. */
|
|
|
this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
|
|
|
|
|
|
this->UpdateVisualEffect();
|
|
|
}
|
|
|
|
|
|
Money Ship::GetRunningCost() const
|
|
|
{
|
|
|
const Engine *e = this->GetEngine();
|
|
|
uint cost_factor = GetVehicleProperty(this, PROP_SHIP_RUNNING_COST_FACTOR, e->u.ship.running_cost);
|
|
|
return GetPrice(PR_RUNNING_SHIP, cost_factor, e->GetGRF());
|
|
|
}
|
|
|
|
|
|
void Ship::OnNewDay()
|
|
|
{
|
|
|
if ((++this->day_counter & 7) == 0) {
|
|
|
DecreaseVehicleValue(this);
|
|
|
}
|
|
|
|
|
|
CheckVehicleBreakdown(this);
|
|
|
AgeVehicle(this);
|
|
|
CheckIfShipNeedsService(this);
|
|
|
|
|
|
CheckOrders(this);
|
|
|
|
|
|
if (this->running_ticks == 0) return;
|
|
|
|
|
|
CommandCost cost(EXPENSES_SHIP_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * Ticks::DAY_TICKS));
|
|
|
CommandCost cost(EXPENSES_SHIP_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS));
|
|
|
|
|
|
this->profit_this_year -= cost.GetCost();
|
|
|
this->running_ticks = 0;
|
|
|
|
|
|
SubtractMoneyFromCompanyFract(this->owner, cost);
|
|
|
|
|
|
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
|
|
|
/* we need this for the profit */
|
|
|
SetWindowClassesDirty(WC_SHIPS_LIST);
|
|
|
}
|
|
|
|
|
|
Trackdir Ship::GetVehicleTrackdir() const
|
|
|
{
|
|
|
if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR;
|
|
|
|
|
|
if (this->IsInDepot()) {
|
|
|
/* We'll assume the ship is facing outwards */
|
|
|
return DiagDirToDiagTrackdir(GetShipDepotDirection(this->tile));
|
|
|
}
|
|
|
|
|
|
if (this->state == TRACK_BIT_WORMHOLE) {
|
|
|
/* ship on aqueduct, so just use its direction and assume a diagonal track */
|
|
|
return DiagDirToDiagTrackdir(DirToDiagDir(this->direction));
|
|
|
}
|
|
|
|
|
|
return TrackDirectionToTrackdir(FindFirstTrack(this->state), this->direction);
|
|
|
}
|
|
|
|
|
|
void Ship::MarkDirty()
|
|
|
{
|
|
|
this->colourmap = PAL_NONE;
|
|
|
this->UpdateViewport(true, false);
|
|
|
this->UpdateCache();
|
|
|
}
|
|
|
|
|
|
void Ship::PlayLeaveStationSound(bool force) const
|
|
|
{
|
|
|
if (PlayVehicleSound(this, VSE_START, force)) return;
|
|
|
SndPlayVehicleFx(ShipVehInfo(this->engine_type)->sfx, this);
|
|
|
}
|
|
|
|
|
|
TileIndex Ship::GetOrderStationLocation(StationID station)
|
|
|
{
|
|
|
if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
|
|
|
|
|
|
const Station *st = Station::Get(station);
|
|
|
if (CanVehicleUseStation(this, st)) {
|
|
|
return st->xy;
|