changeset 16107:f1922c797590 draft

(svn r20800) -Fix: [NewGRF] clamp some more vehicle variables
author yexo <yexo@openttd.org>
date Mon, 13 Sep 2010 14:20:30 +0000
parents 530933b50339
children 91fa0edcdf46
files src/newgrf_engine.cpp
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -707,8 +707,8 @@
 			}
 			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 @@
 		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);