From aaf370dce2e4cecab58c81c8cbf31145186e19be Mon Sep 17 00:00:00 2001 From: yexo Date: Mon, 13 Sep 2010 14:20:30 +0000 Subject: [PATCH] (svn r20800) -Fix: [NewGRF] clamp some more vehicle variables --- src/newgrf_engine.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 1866af6c40..f2a70be4d9 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -707,8 +707,8 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by } return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8); } - case 0x12: return max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0); - case 0x13: return GB(max(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0), 8, 8); + case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); + case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8); case 0x14: return v->service_interval; case 0x15: return GB(v->service_interval, 8, 8); case 0x16: return v->last_station_visited; @@ -736,10 +736,10 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x39: return v->cargo_type; case 0x3A: return v->cargo_cap; case 0x3B: return GB(v->cargo_cap, 8, 8); - case 0x3C: return v->cargo.Count(); - case 0x3D: return GB(v->cargo.Count(), 8, 8); + case 0x3C: return ClampToU16(v->cargo.Count()); + case 0x3D: return GB(ClampToU16(v->cargo.Count()), 8, 8); case 0x3E: return v->cargo.Source(); - case 0x3F: return v->cargo.DaysInTransit(); + case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF); case 0x40: return ClampToU16(v->age); case 0x41: return GB(ClampToU16(v->age), 8, 8); case 0x42: return ClampToU16(v->max_age);