summaryrefslogtreecommitdiff
path: root/src/newgrf_engine.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2008-03-27 21:36:16 +0000
committerglx <glx@openttd.org>2008-03-27 21:36:16 +0000
commit90616adcb014e1bfc827d9f59358dd4fb69e20bc (patch)
tree34162967a065797d3c669ce564b884065fe86878 /src/newgrf_engine.cpp
parenta729283a3c3388f015fc424db50761b47d93bf08 (diff)
downloadopenttd-90616adcb014e1bfc827d9f59358dd4fb69e20bc.tar.xz
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
Diffstat (limited to 'src/newgrf_engine.cpp')
-rw-r--r--src/newgrf_engine.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index ef31b976c..f36f3e52a 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -400,7 +400,32 @@ enum {
/* Vehicle Resolver Functions */
static inline const Vehicle *GRV(const ResolverObject *object)
{
- return object->scope == VSG_SCOPE_SELF ? object->u.vehicle.self : object->u.vehicle.parent;
+ switch (object->scope) {
+ default: NOT_REACHED();
+ case VSG_SCOPE_SELF: return object->u.vehicle.self;
+ case VSG_SCOPE_PARENT: return object->u.vehicle.parent;
+ case VSG_SCOPE_RELATIVE: {
+ const Vehicle *v;
+ switch (GB(object->count, 6, 2)) {
+ default: NOT_REACHED();
+ case 0x00: // count back (away from the engine), starting at this vehicle
+ case 0x01: // count forward (toward the engine), starting at this vehicle
+ v = object->u.vehicle.self;
+ break;
+ case 0x02: // count back, starting at the engine
+ v = object->u.vehicle.parent;
+ break;
+ case 0x03: // count back, starting at the first vehicle in this chain of vehicles with the same ID, as for vehicle variable 41
+ v = object->u.vehicle.parent;
+ while (v != NULL && v->engine_type != object->u.vehicle.self->engine_type) v = v->Next();
+ break;
+ }
+ uint32 count = GB(object->count, 0, 4);
+ if (count == 0) count = GetRegister(0x100);
+ while (v != NULL && count-- != 0) v = (GB(object->count, 6, 2) == 0x01) ? v->Previous() : v->Next();
+ return v;
+ }
+ }
}
@@ -816,6 +841,7 @@ static inline void NewVehicleResolver(ResolverObject *res, EngineID engine_type,
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
+ res->count = 0;
}