summaryrefslogtreecommitdiff
path: root/src/newgrf_engine.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-12-13 20:21:04 +0000
committerfrosch <frosch@openttd.org>2013-12-13 20:21:04 +0000
commite0d69933f607b7ec20dfe69a2a699c4db6c2ccd1 (patch)
treea483564e9c03006e536ffefae6a93434c5608f78 /src/newgrf_engine.cpp
parent07ecc26efaea11350af69fe737a0826fe6bb6f25 (diff)
downloadopenttd-e0d69933f607b7ec20dfe69a2a699c4db6c2ccd1.tar.xz
(svn r26157) -Feature: [NewGRF] Vehicle variable 4D for determining the position within an articulated vehicle.
Diffstat (limited to 'src/newgrf_engine.cpp')
-rw-r--r--src/newgrf_engine.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 3119524b5..3b48aba83 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -627,6 +627,17 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
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 Vehicle *v)
{ 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));