summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-11-18 14:32:09 +0000
committerrubidium <rubidium@openttd.org>2010-11-18 14:32:09 +0000
commit2223ff92c7f9f23ced4c63a3591aa46d1c2b52b2 (patch)
tree2aca4783ed87aa6c09a9e38bbc49cbf7daf0f606 /src
parent46186134c892f236ecc610aacd6c18ee95600d5f (diff)
downloadopenttd-2223ff92c7f9f23ced4c63a3591aa46d1c2b52b2.tar.xz
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp7
-rw-r--r--src/engine_type.h2
-rw-r--r--src/newgrf.cpp20
-rw-r--r--src/table/engines.h4
-rw-r--r--src/vehicle.cpp25
5 files changed, 44 insertions, 14 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 16f6363fe..4bccb97b0 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -86,7 +86,12 @@ Engine::Engine(VehicleType type, EngineID base)
/* 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;
}
diff --git a/src/engine_type.h b/src/engine_type.h
index 777038844..8c4ee9b7b 100644
--- a/src/engine_type.h
+++ b/src/engine_type.h
@@ -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
};
/**
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 12696b6dc..fb8f8f331 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -891,6 +891,16 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
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 ShipVehicleChangeInfo(uint engine, int numinfo, int prop
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;
diff --git a/src/table/engines.h b/src/table/engines.h
index 821a249ac..1031078f7 100644
--- a/src/table/engines.h
+++ b/src/table/engines.h
@@ -541,7 +541,7 @@ static const RailVehicleInfo _orig_rail_vehicle_info[] = {
* @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_aircraft_vehicle_info[] = {
* 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 |
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index ce32dcc5f..499f0c49d 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1863,25 +1863,28 @@ void Vehicle::UpdateVisualEffect(bool allow_power_change)
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 */