Changeset - r17236:40bfbfc512f0
[Not reviewed]
master
0 3 0
frosch - 13 years ago 2011-02-05 20:37:00
frosch@openttd.org
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
3 files changed with 12 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/engine.cpp
Show inline comments
 
@@ -136,24 +136,33 @@ Engine::Engine(VehicleType type, EngineI
 
			this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base;
 
			break;
 
	}
 
}
 

	
 
Engine::~Engine()
 
{
 
	UnloadWagonOverrides(this);
 
	free(this->name);
 
}
 

	
 
/**
 
 * Checks whether the engine spec is properly initialised.
 
 * @return true if enabled
 
 */
 
bool Engine::IsEnabled() const
 
{
 
	return this->info.string_id != STR_NEWGRF_INVALID_ENGINE;
 
}
 

	
 
/**
 
 * Determines whether an engine can carry something.
 
 * A vehicle cannot carry anything if its capacity is zero, or none of the possible cargos is available in the climate.
 
 * @return true if the vehicle can carry something.
 
 */
 
bool Engine::CanCarryCargo() const
 
{
 
	/* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity
 
	 * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used
 
	 * for livery selection etc.
 
	 * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect.
 
	 */
 
	switch (this->type) {
 
@@ -926,25 +935,25 @@ bool IsEngineBuildable(EngineID engine, 
 
{
 
	const Engine *e = Engine::GetIfValid(engine);
 

	
 
	/* check if it's an engine that is in the engine array */
 
	if (e == NULL) return false;
 

	
 
	/* check if it's an engine of specified type */
 
	if (e->type != type) return false;
 

	
 
	/* check if it's available */
 
	if (!HasBit(e->company_avail, company)) return false;
 

	
 
	if (e->info.string_id == STR_NEWGRF_INVALID_ENGINE) return false;
 
	if (!e->IsEnabled()) return false;
 

	
 
	if (type == VEH_TRAIN) {
 
		/* Check if the rail type is available to this company */
 
		const Company *c = Company::Get(company);
 
		if (((GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Check if an engine is refittable.
src/engine_base.h
Show inline comments
 
@@ -52,24 +52,25 @@ struct Engine : EnginePool::PoolItem<&_e
 
	 * NUM_CARGO real cargo plus two pseudo cargo sprite groups.
 
	 * Used for obtaining the sprite offset of custom sprites, and for
 
	 * evaluating callbacks.
 
	 */
 
	GRFFilePropsBase<NUM_CARGO + 2> grf_prop;
 
	uint16 overrides_count;
 
	struct WagonOverride *overrides;
 
	uint16 list_position;
 

	
 
	Engine();
 
	Engine(VehicleType type, EngineID base);
 
	~Engine();
 
	bool IsEnabled() const;
 

	
 
	/**
 
	 * Determines the default cargo type of an engine.
 
	 *
 
	 * Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used
 
	 * for livery selection etc..
 
	 *
 
	 * Vehicles with CT_INVALID as default cargo are usally not available, but it can appear as default cargo of articulated parts.
 
	 *
 
	 * @return The default cargo type.
 
	 * @see CanCarryCargo
 
	 */
src/strings.cpp
Show inline comments
 
@@ -1101,25 +1101,25 @@ static char *FormatString(char *buff, co
 
					args[0] = g->index;
 
					buff = GetStringWithArgs(buff, STR_FORMAT_GROUP_NAME, args, endof(args), last);
 
				}
 
				break;
 
			}
 

	
 
			case SCC_ENGINE_NAME: { // {ENGINE}
 
				EngineID engine = (EngineID)GetInt32(&argv, argve, &argt, SCC_ENGINE_NAME);
 
				const Engine *e = Engine::Get(engine);
 

	
 
				assert(e != NULL);
 

	
 
				if (e->name != NULL && e->info.string_id != STR_NEWGRF_INVALID_ENGINE) {
 
				if (e->name != NULL && e->IsEnabled()) {
 
					buff = strecpy(buff, e->name, last);
 
				} else {
 
					buff = GetStringWithArgs(buff, e->info.string_id, NULL, NULL, last);
 
				}
 
				break;
 
			}
 

	
 
			case SCC_VEHICLE_NAME: { // {VEHICLE}
 
				const Vehicle *v = Vehicle::Get(GetInt32(&argv, argve, &argt, SCC_VEHICLE_NAME));
 

	
 
				assert(v != NULL);
 

	
0 comments (0 inline, 0 general)