Changeset - r17838:9b7a4cc981f2
[Not reviewed]
master
0 3 0
michi_cc - 13 years ago 2011-07-07 14:16:22
michi_cc@openttd.org
(svn r22639) -Feature: [NewGRF] Support for ship props 14/15 (ocean/canal speed fraction).
3 files changed with 17 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/engine_type.h
Show inline comments
 
@@ -69,12 +69,14 @@ struct ShipVehicleInfo {
 
	uint16 max_speed;      ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
 
	uint16 capacity;
 
	byte running_cost;
 
	SoundID sfx;
 
	bool old_refittable;   ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
 
	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.
 
};
 

	
 
/**
 
 * AircraftVehicleInfo subtypes, bitmask type.
 
 * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
 
 * in which case bit 1 tells us whether it's a big(fast) plane or not.
src/newgrf.cpp
Show inline comments
 
@@ -1191,16 +1191,17 @@ static ChangeInfoResult ShipVehicleChang
 

	
 
			case 0x13: // Refit cost
 
				ei->refit_cost = buf->ReadByte();
 
				break;
 

	
 
			case 0x14: // Ocean speed fraction
 
				svi->ocean_speed_frac = buf->ReadByte();
 
				break;
 

	
 
			case 0x15: // Canal speed fraction
 
				/** @todo Speed fractions for ships on oceans and canals */
 
				buf->ReadByte();
 
				ret = CIR_UNHANDLED;
 
				svi->canal_speed_frac = buf->ReadByte();
 
				break;
 

	
 
			case 0x16: // Retire vehicle early
 
				ei->retire_early = buf->ReadByte();
 
				break;
 

	
src/ship_cmd.cpp
Show inline comments
 
@@ -152,13 +152,18 @@ static void CheckIfShipNeedsService(Vehi
 

	
 
/**
 
 * Update the caches of this ship.
 
 */
 
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();
 
}
 

	
 
Money Ship::GetRunningCost() const
 
{
 
@@ -542,12 +547,17 @@ static void ShipController(Ship *v)
 
			r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y);
 
			if (HasBit(r, VETS_CANNOT_ENTER)) goto reverse_direction;
 

	
 
			if (!HasBit(r, VETS_ENTERED_WORMHOLE)) {
 
				v->tile = gp.new_tile;
 
				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];
 
		}
 
	} else {
 
		/* On a bridge */
0 comments (0 inline, 0 general)