summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-09 14:59:02 +0000
committerrubidium <rubidium@openttd.org>2009-01-09 14:59:02 +0000
commitd19706013714c4b1f5b833ce7377118047f31a7c (patch)
treec50b9279882186f1767a0a6d05f3b4df148a5c93 /src/vehicle.cpp
parentde9413454ee70662e1309b49bfd894ca1cf19063 (diff)
downloadopenttd-d19706013714c4b1f5b833ce7377118047f31a7c.tar.xz
(svn r14933) -Codechange: check the whether a pool item can be constructed instead of trying to make it and check for NULL.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index b88a1f3b7..ec20909f1 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -242,17 +242,13 @@ byte VehicleRandomBits()
/* static */ bool Vehicle::AllocateList(Vehicle **vl, int num)
{
+ if (!Vehicle::CanAllocateItem(num)) return false;
+ if (vl == NULL) return true;
+
uint counter = _Vehicle_pool.first_free_index;
for (int i = 0; i != num; i++) {
- Vehicle *v = AllocateRaw(counter);
-
- if (v == NULL) return false;
- v = new (v) InvalidVehicle();
-
- if (vl != NULL) {
- vl[i] = v;
- }
+ vl[i] = new (AllocateRaw(counter)) InvalidVehicle();
counter++;
}