1
0
Fork 0

(svn r16300) -Codechange: reduce usage of Vehicle::AllocateList

release/1.0
smatz 2009-05-13 19:26:47 +00:00
parent 2bc5189ad5
commit 0274886ae1
2 changed files with 6 additions and 12 deletions

View File

@ -265,10 +265,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Prevent building aircraft types at places which can't handle them */ /* Prevent building aircraft types at places which can't handle them */
if (!CanVehicleUseStation(p1, GetStationByTile(tile))) return CMD_ERROR; if (!CanVehicleUseStation(p1, GetStationByTile(tile))) return CMD_ERROR;
/* Allocate 2 or 3 vehicle structs, depending on type /* We will need to allocate 2 or 3 vehicle structs, depending on type */
* vl[0] = aircraft, vl[1] = shadow, [vl[2] = rotor] */ if (!Vehicle::CanAllocateItem(avi->subtype & AIR_CTOL ? 2 : 3)) {
Vehicle *vl[3];
if (!Vehicle::AllocateList(vl, avi->subtype & AIR_CTOL ? 2 : 3)) {
return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
} }
@ -277,11 +275,9 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Vehicle *v = vl[0]; // aircraft Vehicle *v = new Aircraft(); // aircraft
Vehicle *u = vl[1]; // shadow Vehicle *u = new Aircraft(); // shadow
v = new (v) Aircraft();
u = new (u) Aircraft();
v->unitnumber = unit_num; v->unitnumber = unit_num;
v->direction = DIR_SE; v->direction = DIR_SE;
@ -402,9 +398,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Aircraft with 3 vehicles (chopper)? */ /* Aircraft with 3 vehicles (chopper)? */
if (v->subtype == AIR_HELICOPTER) { if (v->subtype == AIR_HELICOPTER) {
Vehicle *w = vl[2]; Vehicle *w = new Aircraft();
w = new (w) Aircraft();
w->engine_type = p1; w->engine_type = p1;
w->direction = DIR_N; w->direction = DIR_N;
w->owner = _current_company; w->owner = _current_company;

View File

@ -361,7 +361,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
veh_counter++; veh_counter++;
} while ((v = v->Next()) != NULL); } 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); return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
} }
} }