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
 
@@ -83,13 +83,18 @@ Engine::Engine(VehicleType type, EngineI
 
		this->info.climates = 0x80;
 
		/* Set model life to maximum to make wagons available */
 
		this->info.base_life = 0xFF;
 
		/* 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;
 
	}
 

	
 
	/* Copy the original engine info for this slot */
 
	this->info = _orig_engine_info[_engine_offsets[type] + base];
 

	
src/engine_type.h
Show inline comments
 
@@ -64,12 +64,13 @@ struct ShipVehicleInfo {
 
	byte cost_factor;
 
	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
 
};
 

	
 
/* 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 */
 
enum AircraftSubTypeBits {
 
@@ -99,12 +100,13 @@ struct RoadVehicleInfo {
 
	uint16 max_speed;        ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
 
	byte capacity;
 
	uint8 weight;            ///< Weight in 1/4t units
 
	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
 
};
 

	
 
/**
 
 * Information about a vehicle
 
 *  @see table/engines.h
 
 */
src/newgrf.cpp
Show inline comments
 
@@ -888,12 +888,22 @@ static ChangeInfoResult RoadVehicleChang
 
				break;
 

	
 
			case 0x20: // Alter purchase list sort order
 
				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;
 
		}
 
	}
 

	
 
@@ -1004,12 +1014,22 @@ static ChangeInfoResult ShipVehicleChang
 
				break;
 

	
 
			case 0x1B: // Alter purchase list sort order
 
				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
 
@@ -538,13 +538,13 @@ static const RailVehicleInfo _orig_rail_
 
 * @param c max_speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
 
 * @param d capacity (persons, bags, tons, pieces, items, cubic metres, ...)
 
 * @param e running_cost
 
 * @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          |
 
	 *   |    |    max_speed |  sfx                |
 
	 *   |    |    |    |    |  |                  | */
 
	SVI( 1, 160,  48, 220, 140, SND_06_SHIP_HORN,  0 ), //  0 MPS Oil Tanker
 
@@ -642,13 +642,13 @@ static const AircraftVehicleInfo _orig_a
 
 * @param f capacity (persons, bags, tons, pieces, items, cubic metres, ...)
 
 * @param g weight (1/4 ton)
 
 * @param h power (10 hp)
 
 * 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 |
 
	 *    |    |    running_cost                                |   |    weight
 
	 *    |    |    |       |                                   |   |    |   |*/
 
	ROV(  0, 120,  91, SND_19_BUS_START_PULL_AWAY,            112, 31,  42,  9), //  0 MPS Regal Bus
src/vehicle.cpp
Show inline comments
 
@@ -1860,31 +1860,34 @@ CommandCost Vehicle::SendToDepot(DoComma
 
void Vehicle::UpdateVisualEffect(bool allow_power_change)
 
{
 
	bool powered_before = HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER);
 
	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 */
 
	if (HasBit(e->info.callback_mask, CBM_VEHICLE_VISUAL_EFFECT)) {
 
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_VISUAL_EFFECT, 0, 0, this->engine_type, this);
 

	
0 comments (0 inline, 0 general)