Changeset - r16504:0f05656995b0
[Not reviewed]
master
0 5 0
rubidium - 14 years ago 2010-11-18 14:32:09
rubidium@openttd.org
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
5 files changed with 44 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/engine.cpp
Show inline comments
 
@@ -86,7 +86,12 @@ Engine::Engine(VehicleType type, EngineI
 
		/* Set road vehicle tractive effort to the default value */
 
		if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C;
 
		/* Set visual effect to the default value */
 
		if (type == VEH_TRAIN) this->u.rail.visual_effect = VE_DEFAULT;
 
		switch (type) {
 
			case VEH_TRAIN: this->u.rail.visual_effect = VE_DEFAULT; break;
 
			case VEH_ROAD:  this->u.road.visual_effect = VE_DEFAULT; break;
 
			case VEH_SHIP:  this->u.ship.visual_effect = VE_DEFAULT; break;
 
			default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects
 
		}
 
		return;
 
	}
 

	
src/engine_type.h
Show inline comments
 
@@ -67,6 +67,7 @@ struct ShipVehicleInfo {
 
	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
 
};
 

	
 
/* AircraftVehicleInfo subtypes, bitmask type.
 
@@ -102,6 +103,7 @@ struct RoadVehicleInfo {
 
	uint8 power;             ///< Power in 10hp units
 
	uint8 tractive_effort;   ///< Coefficient of tractive effort
 
	uint8 air_drag;          ///< Coefficient of air drag
 
	byte visual_effect;      ///< Bitstuffed NewGRF visual effect data
 
};
 

	
 
/**
src/newgrf.cpp
Show inline comments
 
@@ -891,6 +891,16 @@ static ChangeInfoResult RoadVehicleChang
 
				AlterVehicleListOrder(e->index, buf->ReadExtendedByte());
 
				break;
 

	
 
			case 0x21: // Visual effect
 
				rvi->visual_effect = buf->ReadByte();
 
				/* Avoid accidentally setting visual_effect to the default value
 
				 * Since bit 6 (disable effects) is set anyways, we can safely erase some bits. */
 
				if (rvi->visual_effect == VE_DEFAULT) {
 
					assert(HasBit(rvi->visual_effect, VE_DISABLE_EFFECT));
 
					SB(rvi->visual_effect, VE_TYPE_START, VE_TYPE_COUNT, 0);
 
				}
 
				break;
 

	
 
			default:
 
				ret = CommonVehicleChangeInfo(ei, prop, buf);
 
				break;
 
@@ -1007,6 +1017,16 @@ static ChangeInfoResult ShipVehicleChang
 
				AlterVehicleListOrder(e->index, buf->ReadExtendedByte());
 
				break;
 

	
 
			case 0x1C: // Visual effect
 
				svi->visual_effect = buf->ReadByte();
 
				/* Avoid accidentally setting visual_effect to the default value
 
				 * Since bit 6 (disable effects) is set anyways, we can safely erase some bits. */
 
				if (svi->visual_effect == VE_DEFAULT) {
 
					assert(HasBit(svi->visual_effect, VE_DISABLE_EFFECT));
 
					SB(svi->visual_effect, VE_TYPE_START, VE_TYPE_COUNT, 0);
 
				}
 
				break;
 

	
 
			default:
 
				ret = CommonVehicleChangeInfo(ei, prop, buf);
 
				break;
src/table/engines.h
Show inline comments
 
@@ -541,7 +541,7 @@ static const RailVehicleInfo _orig_rail_
 
 * @param f sound effect
 
 * @param g refittable
 
 */
 
#define SVI(a, b, c, d, e, f, g) { a, b, c, d, e, f, g }
 
#define SVI(a, b, c, d, e, f, g) { a, b, c, d, e, f, g, VE_DEFAULT }
 
static const ShipVehicleInfo _orig_ship_vehicle_info[] = {
 
	/*   image_index    capacity                   refittable
 
	 *   |    cost_factor    running_cost          |
 
@@ -645,7 +645,7 @@ static const AircraftVehicleInfo _orig_a
 
 * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76
 
 * Air drag value depends on the top speed of the vehicle.
 
 */
 
#define ROV(a, b, c, d, e, f, g, h) { a, b, c, PR_RUNNING_ROADVEH, d, e, f, g, h, 76, 0 }
 
#define ROV(a, b, c, d, e, f, g, h) { a, b, c, PR_RUNNING_ROADVEH, d, e, f, g, h, 76, 0, VE_DEFAULT }
 
static const RoadVehicleInfo _orig_road_vehicle_info[] = {
 
	/*    image_index       sfx                                 max_speed    power
 
	 *    |    cost_factor  |                                   |   capacity |
src/vehicle.cpp
Show inline comments
 
@@ -1863,25 +1863,28 @@ void Vehicle::UpdateVisualEffect(bool al
 
	this->vcache.cached_vis_effect = 0;
 

	
 
	const Engine *e = Engine::Get(this->engine_type);
 
	if (this->type == VEH_TRAIN) {
 
		if (e->u.rail.visual_effect != VE_DEFAULT) {
 
			this->vcache.cached_vis_effect = e->u.rail.visual_effect;
 
		} else {
 
			Train *t = Train::From(this);
 
			if (t->IsWagon() || t->IsArticulatedPart()) {
 
				/* Wagons and articulated parts have no effect by default */
 
				SetBit(this->vcache.cached_vis_effect, VE_DISABLE_EFFECT);
 
			} else if (e->u.rail.engclass == 0) {
 
	byte default_effect = VE_DEFAULT;
 
	switch (this->type) {
 
		case VEH_TRAIN:    default_effect = e->u.rail.visual_effect; break;
 
		case VEH_ROAD:     default_effect = e->u.road.visual_effect; break;
 
		case VEH_SHIP:     default_effect = e->u.ship.visual_effect; break;
 
		default: break;
 
	}
 
	if (default_effect == VE_DEFAULT) {
 
		if (this->type == VEH_TRAIN && Train::From(this)->IsEngine()) {
 
			if (e->u.rail.engclass == 0) {
 
				/* Steam is offset by -4 units */
 
				SB(this->vcache.cached_vis_effect, VE_OFFSET_START, VE_OFFSET_COUNT, VE_OFFSET_CENTRE - 4);
 
			} else {
 
				/* Diesel fumes and sparks come from the centre */
 
				SB(this->vcache.cached_vis_effect, VE_OFFSET_START, VE_OFFSET_COUNT, VE_OFFSET_CENTRE);
 
			}
 
		} else {
 
			/* Non-train engines do not have a visual effect by default. */
 
			SetBit(this->vcache.cached_vis_effect, VE_DISABLE_EFFECT);
 
		}
 
	} else {
 
		/* Non-trains do not have a visual effect by default. */
 
		SetBit(this->vcache.cached_vis_effect, VE_DISABLE_EFFECT);
 
		this->vcache.cached_vis_effect = default_effect;
 
	}
 

	
 
	/* Check powered wagon / visual effect callback */
0 comments (0 inline, 0 general)