mirror of https://github.com/OpenTTD/OpenTTD
(svn r22639) -Feature: [NewGRF] Support for ship props 14/15 (ocean/canal speed fraction).
parent
662a0a9cd3
commit
9218c56cde
|
@ -72,6 +72,8 @@ struct ShipVehicleInfo {
|
||||||
SoundID sfx;
|
SoundID sfx;
|
||||||
bool old_refittable; ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
|
bool old_refittable; ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
|
||||||
byte visual_effect; ///< Bitstuffed NewGRF visual effect data
|
byte visual_effect; ///< Bitstuffed NewGRF visual effect data
|
||||||
|
byte ocean_speed_frac; ///< Fraction of maximum speed for ocean tiles.
|
||||||
|
byte canal_speed_frac; ///< Fraction of maximum speed for canal/river tiles.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1194,10 +1194,11 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x14: // Ocean speed fraction
|
case 0x14: // Ocean speed fraction
|
||||||
|
svi->ocean_speed_frac = buf->ReadByte();
|
||||||
|
break;
|
||||||
|
|
||||||
case 0x15: // Canal speed fraction
|
case 0x15: // Canal speed fraction
|
||||||
/** @todo Speed fractions for ships on oceans and canals */
|
svi->canal_speed_frac = buf->ReadByte();
|
||||||
buf->ReadByte();
|
|
||||||
ret = CIR_UNHANDLED;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x16: // Retire vehicle early
|
case 0x16: // Retire vehicle early
|
||||||
|
|
|
@ -155,7 +155,12 @@ static void CheckIfShipNeedsService(Vehicle *v)
|
||||||
*/
|
*/
|
||||||
void Ship::UpdateCache()
|
void Ship::UpdateCache()
|
||||||
{
|
{
|
||||||
this->vcache.cached_max_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, ShipVehInfo(this->engine_type)->max_speed);
|
const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
|
||||||
|
|
||||||
|
/* Get speed fraction for the current water type. Aqueducts are always canals. */
|
||||||
|
byte speed_frac = (!IsTileType(this->tile, MP_TUNNELBRIDGE) && GetWaterClass(this->tile) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac;
|
||||||
|
/* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
|
||||||
|
this->vcache.cached_max_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed) * (256 - speed_frac) / 256;
|
||||||
|
|
||||||
this->UpdateVisualEffect();
|
this->UpdateVisualEffect();
|
||||||
}
|
}
|
||||||
|
@ -545,6 +550,11 @@ static void ShipController(Ship *v)
|
||||||
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
|
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
|
||||||
v->tile = gp.new_tile;
|
v->tile = gp.new_tile;
|
||||||
v->state = TrackToTrackBits(track);
|
v->state = TrackToTrackBits(track);
|
||||||
|
|
||||||
|
/* Update ship cache when the water class changes. Aqueducts are always canals. */
|
||||||
|
WaterClass old_wc = IsTileType(gp.old_tile, MP_TUNNELBRIDGE) ? WATER_CLASS_CANAL : GetWaterClass(gp.old_tile);
|
||||||
|
WaterClass new_wc = IsTileType(gp.new_tile, MP_TUNNELBRIDGE) ? WATER_CLASS_CANAL : GetWaterClass(gp.new_tile);
|
||||||
|
if (old_wc != new_wc) v->UpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
v->direction = (Direction)b[2];
|
v->direction = (Direction)b[2];
|
||||||
|
|
Loading…
Reference in New Issue