Changeset - r21074:afd3cbf5c9c8
[Not reviewed]
master
0 2 0
frosch - 11 years ago 2013-12-13 20:21:04
frosch@openttd.org
(svn r26157) -Feature: [NewGRF] Vehicle variable 4D for determining the position within an articulated vehicle.
2 files changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/newgrf_engine.cpp
Show inline comments
 
@@ -627,6 +627,17 @@ static uint32 VehicleGetVariable(Vehicle
 
			if (!v->IsPrimaryVehicle()) return 0;
 
			return v->GetCurrentMaxSpeed();
 

	
 
		case 0x4D: // Position within articulated vehicle
 
			if (!HasBit(v->grf_cache.cache_valid, NCVV_POSITION_IN_VEHICLE)) {
 
				byte artic_before = 0;
 
				for (const Vehicle *u = v; u->IsArticulatedPart(); u = u->Previous()) artic_before++;
 
				byte artic_after = 0;
 
				for (const Vehicle *u = v; u->HasArticulatedPart(); u = u->Next()) artic_after++;
 
				v->grf_cache.position_in_vehicle = artic_before | artic_after << 8;
 
				SetBit(v->grf_cache.cache_valid, NCVV_POSITION_IN_VEHICLE);
 
			}
 
			return v->grf_cache.position_in_vehicle;
 

	
 
		/* Variables which use the parameter */
 
		case 0x60: // Count consist's engine ID occurrence
 
			if (v->type != VEH_TRAIN) return v->GetEngine()->grf_prop.local_id == parameter ? 1 : 0;
 
@@ -1293,6 +1304,7 @@ void FillNewGRFVehicleCache(const Vehicl
 
		{ 0x41, NCVV_POSITION_SAME_ID_LENGTH },
 
		{ 0x42, NCVV_CONSIST_CARGO_INFORMATION },
 
		{ 0x43, NCVV_COMPANY_INFORMATION },
 
		{ 0x4D, NCVV_POSITION_IN_VEHICLE },
 
	};
 
	assert_compile(NCVV_END == lengthof(cache_entries));
 

	
src/vehicle_base.h
Show inline comments
 
@@ -58,6 +58,7 @@ enum NewGRFCacheValidValues {
 
	NCVV_POSITION_SAME_ID_LENGTH   = 1, ///< This bit will be set if the NewGRF var 41 currently stored is valid.
 
	NCVV_CONSIST_CARGO_INFORMATION = 2, ///< This bit will be set if the NewGRF var 42 currently stored is valid.
 
	NCVV_COMPANY_INFORMATION       = 3, ///< This bit will be set if the NewGRF var 43 currently stored is valid.
 
	NCVV_POSITION_IN_VEHICLE       = 4, ///< This bit will be set if the NewGRF var 4D currently stored is valid.
 
	NCVV_END,                           ///< End of the bits.
 
};
 

	
 
@@ -68,6 +69,7 @@ struct NewGRFCache {
 
	uint32 position_same_id_length;   ///< Cache for NewGRF var 41.
 
	uint32 consist_cargo_information; ///< Cache for NewGRF var 42. (Note: The cargotype is untranslated in the cache because the accessing GRF is yet unknown.)
 
	uint32 company_information;       ///< Cache for NewGRF var 43.
 
	uint32 position_in_vehicle;       ///< Cache for NewGRF var 4D.
 
	uint8  cache_valid;               ///< Bitset that indicates which cache values are valid.
 
};
 

	
0 comments (0 inline, 0 general)