vehicle.c
changeset 1237 0a1ce05c3d45
parent 1217 ab9f02a224ab
child 1266 9dc5638fe8cc
--- a/vehicle.c	Sun Jan 30 19:51:39 2005 +0000
+++ b/vehicle.c	Sun Jan 30 20:50:06 2005 +0000
@@ -1331,13 +1331,15 @@
 	 the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */
 	uint16 new_engine_type = (uint16)(p2 & 0xFFFF);
 	uint32 autorefit_money = (p2  >> 16) * 100000;
-	Vehicle *v = GetVehicle(p1);
+	Vehicle *v, *u;
 	int cost, build_cost, rear_engine_cost = 0;
-	Vehicle *u = v;
-	byte old_engine_type = v->engine_type;
+	byte old_engine_type;
 
-	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
+	if (!IsVehicleIndex(p1)) return CMD_ERROR;
 
+	v = u = GetVehicle(p1);
+
+	old_engine_type = v->engine_type;
 
 	// first we make sure that it's a valid type the user requested
 	// check that it's an engine that is in the engine array
@@ -1636,6 +1638,8 @@
 	Vehicle *v;
 	StringID str;
 
+	if (!IsVehicleIndex(p1)) return CMD_ERROR;
+
 	v = GetVehicle(p1);
 
 	if (!CheckOwnership(v->owner))