changeset 11900:46d45a7511f9 draft

(svn r16300) -Codechange: reduce usage of Vehicle::AllocateList
author smatz <smatz@openttd.org>
date Wed, 13 May 2009 19:26:47 +0000
parents fc1af9d26d2c
children ad8901f29746
files src/aircraft_cmd.cpp src/vehicle_cmd.cpp
diffstat 2 files changed, 6 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -265,10 +265,8 @@
 	/* Prevent building aircraft types at places which can't handle them */
 	if (!CanVehicleUseStation(p1, GetStationByTile(tile))) return CMD_ERROR;
 
-	/* Allocate 2 or 3 vehicle structs, depending on type
-	 * vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */
-	Vehicle *vl[3];
-	if (!Vehicle::AllocateList(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
+	/* We will need to allocate 2 or 3 vehicle structs, depending on type */
+	if (!Vehicle::CanAllocateItem(avi->subtype & AIR_CTOL ? 2 : 3)) {
 		return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
 	}
 
@@ -277,11 +275,9 @@
 		return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
 
 	if (flags & DC_EXEC) {
-		Vehicle *v = vl[0]; // aircraft
-		Vehicle *u = vl[1]; // shadow
+		Vehicle *v = new Aircraft(); // aircraft
+		Vehicle *u = new Aircraft(); // shadow
 
-		v = new (v) Aircraft();
-		u = new (u) Aircraft();
 		v->unitnumber = unit_num;
 		v->direction = DIR_SE;
 
@@ -402,9 +398,7 @@
 
 		/* Aircraft with 3 vehicles (chopper)? */
 		if (v->subtype == AIR_HELICOPTER) {
-			Vehicle *w = vl[2];
-
-			w = new (w) Aircraft();
+			Vehicle *w = new Aircraft();
 			w->engine_type = p1;
 			w->direction = DIR_N;
 			w->owner = _current_company;
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -361,7 +361,7 @@
 			veh_counter++;
 		} while ((v = v->Next()) != NULL);
 
-		if (!Vehicle::AllocateList(NULL, veh_counter)) {
+		if (!Vehicle::CanAllocateItem(veh_counter)) {
 			return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
 		}
 	}