Changeset - r8756:3b4554f1d3d4
[Not reviewed]
master
0 11 0
glx - 16 years ago 2008-03-27 21:36:16
glx@openttd.org
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
11 files changed with 46 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -2584,13 +2584,19 @@ static void NewSpriteGroup(byte *buf, in
 
		/* 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;
src/newgrf_canal.cpp
Show inline comments
 
@@ -85,6 +85,7 @@ static void NewCanalResolver(ResolverObj
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 
}
 

	
 

	
src/newgrf_cargo.cpp
Show inline comments
 
@@ -64,6 +64,7 @@ static void NewCargoResolver(ResolverObj
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 
}
 

	
 

	
src/newgrf_engine.cpp
Show inline comments
 
@@ -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(Re
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 
}
 

	
 

	
src/newgrf_generic.cpp
Show inline comments
 
@@ -125,6 +125,7 @@ static inline void NewGenericResolver(Re
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 
}
 

	
 

	
src/newgrf_house.cpp
Show inline comments
 
@@ -291,6 +291,7 @@ static void NewHouseResolver(ResolverObj
 
	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)
src/newgrf_industries.cpp
Show inline comments
 
@@ -410,6 +410,7 @@ static void NewIndustryResolver(Resolver
 
	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)
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -170,6 +170,7 @@ static void NewIndustryTileResolver(Reso
 
	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)
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -256,6 +256,7 @@ static inline const SpriteGroup *Resolve
 
	byte index;
 

	
 
	object->scope = group->g.random.var_scope;
 
	object->count = group->g.random.count;
 

	
 
	if (object->trigger != 0) {
 
		/* Handle triggers */
src/newgrf_spritegroup.h
Show inline comments
 
@@ -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;
src/newgrf_station.cpp
Show inline comments
 
@@ -571,6 +571,7 @@ static void NewStationResolver(ResolverO
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
	res->count           = 0;
 
}
 

	
 
static const SpriteGroup *ResolveStation(ResolverObject *object)
0 comments (0 inline, 0 general)