(svn r12454) -Fix (r12452): incorrect calculation for 'first vehicle in this chain of vehicles with the same ID' (thx DaleStan)

-Fix (r12452): wrong loading of random action 2 type 84 for non vehicle (though it shouldn't happen, but who knows ;))
This commit is contained in:
glx 2008-03-28 02:10:25 +00:00
parent b8ac06b462
commit d4f7f5e5fe
2 changed files with 14 additions and 7 deletions

View File

@ -2592,8 +2592,8 @@ static void NewSpriteGroup(byte *buf, int len)
group->type = SGT_RANDOMIZED; group->type = SGT_RANDOMIZED;
group->g.random.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF; group->g.random.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
if (HasBit(type, 2) && feature <= GSF_AIRCRAFT) { if (HasBit(type, 2)) {
group->g.random.var_scope = VSG_SCOPE_RELATIVE; if (feature <= GSF_AIRCRAFT) group->g.random.var_scope = VSG_SCOPE_RELATIVE;
group->g.random.count = grf_load_byte(&buf); group->g.random.count = grf_load_byte(&buf);
} }

View File

@ -405,7 +405,7 @@ static inline const Vehicle *GRV(const ResolverObject *object)
case VSG_SCOPE_SELF: return object->u.vehicle.self; case VSG_SCOPE_SELF: return object->u.vehicle.self;
case VSG_SCOPE_PARENT: return object->u.vehicle.parent; case VSG_SCOPE_PARENT: return object->u.vehicle.parent;
case VSG_SCOPE_RELATIVE: { case VSG_SCOPE_RELATIVE: {
const Vehicle *v; const Vehicle *v = NULL;
switch (GB(object->count, 6, 2)) { switch (GB(object->count, 6, 2)) {
default: NOT_REACHED(); default: NOT_REACHED();
case 0x00: // count back (away from the engine), starting at this vehicle case 0x00: // count back (away from the engine), starting at this vehicle
@ -415,10 +415,17 @@ static inline const Vehicle *GRV(const ResolverObject *object)
case 0x02: // count back, starting at the engine case 0x02: // count back, starting at the engine
v = object->u.vehicle.parent; v = object->u.vehicle.parent;
break; break;
case 0x03: // count back, starting at the first vehicle in this chain of vehicles with the same ID, as for vehicle variable 41 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; const Vehicle *self = object->u.vehicle.self;
while (v != NULL && v->engine_type != object->u.vehicle.self->engine_type) v = v->Next(); for (const Vehicle *u = self->First(); u != self; u = u->Next()) {
break; if (u->engine_type != self->engine_type) {
v = NULL;
} else {
if (v == NULL) v = u;
}
}
if (v == NULL) v = self;
} break;
} }
uint32 count = GB(object->count, 0, 4); uint32 count = GB(object->count, 0, 4);
if (count == 0) count = GetRegister(0x100); if (count == 0) count = GetRegister(0x100);