(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
glx 16 years ago
parent 5ddb78af9f
commit bbdb831301

@ -2584,13 +2584,19 @@ static void NewSpriteGroup(byte *buf, int len)
/* Randomized Sprite Group */
case 0x80: // Self scope
case 0x83: // Parent scope
case 0x84: // Relative scope
{
if (!check_length(bufend - buf, 7, "NewSpriteGroup (Randomized) (1)")) return;
if (!check_length(bufend - buf, HasBit(type, 2) ? 8 : 7, "NewSpriteGroup (Randomized) (1)")) return;
group = AllocateSpriteGroup();
group->type = SGT_RANDOMIZED;
group->g.random.var_scope = HasBit(type, 1) ? VSG_SCOPE_PARENT : VSG_SCOPE_SELF;
if (HasBit(type, 2) && feature <= GSF_AIRCRAFT) {
group->g.random.var_scope = VSG_SCOPE_RELATIVE;
group->g.random.count = grf_load_byte(&buf);
}
uint8 triggers = grf_load_byte(&buf);
group->g.random.triggers = GB(triggers, 0, 7);
group->g.random.cmp_mode = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;

@ -85,6 +85,7 @@ static void NewCanalResolver(ResolverObject *res, TileIndex tile)
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}

@ -64,6 +64,7 @@ static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs)
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}

@ -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;
}

@ -125,6 +125,7 @@ static inline void NewGenericResolver(ResolverObject *res)
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}

@ -291,6 +291,7 @@ static void NewHouseResolver(ResolverObject *res, HouseID house_id, TileIndex ti
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile)

@ -410,6 +410,7 @@ static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *i
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)

@ -170,6 +170,7 @@ static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIn
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}
void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx)

@ -256,6 +256,7 @@ static inline const SpriteGroup *ResolveRandom(const SpriteGroup *group, Resolve
byte index;
object->scope = group->g.random.var_scope;
object->count = group->g.random.count;
if (object->trigger != 0) {
/* Handle triggers */

@ -48,6 +48,8 @@ enum VarSpriteGroupScope {
VSG_SCOPE_SELF,
/* Engine of consists for vehicles, city for stations. */
VSG_SCOPE_PARENT,
/* Any vehicle in the consist (vehicles only) */
VSG_SCOPE_RELATIVE,
};
enum DeterministicSpriteGroupSize {
@ -128,6 +130,7 @@ struct RandomizedSpriteGroup {
RandomizedSpriteGroupCompareMode cmp_mode; ///< Check for these triggers:
byte triggers;
byte count;
byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
byte num_groups; ///< must be power of 2
@ -201,6 +204,7 @@ struct ResolverObject {
bool procedure_call; ///< true if we are currently resolving a var 0x7E procedure result.
byte trigger;
byte count;
uint32 last_value;
uint32 reseed;
VarSpriteGroupScope scope;

@ -571,6 +571,7 @@ static void NewStationResolver(ResolverObject *res, const StationSpec *statspec,
res->last_value = 0;
res->trigger = 0;
res->reseed = 0;
res->count = 0;
}
static const SpriteGroup *ResolveStation(ResolverObject *object)

Loading…
Cancel
Save