summaryrefslogtreecommitdiff
path: root/train_cmd.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-05-11 13:31:14 +0000
committerbjarni <bjarni@openttd.org>2006-05-11 13:31:14 +0000
commit2e05a16959ff23ff504f823a9d2b8d92a9a3f873 (patch)
treefc7719c3c53e3f59a9936181309d7e95d37f5698 /train_cmd.c
parent06156142d4857acb6ed04166c28b2ec787ec9c10 (diff)
downloadopenttd-2e05a16959ff23ff504f823a9d2b8d92a9a3f873.tar.xz
(svn r4826) -Fix: [autoreplace] fixed possible problem when autoreplacing and was number of vehicles (of a type, not total) was reached
now the new vehicle gets the same number as the old one, completely removing the problem where we could run out of numbers since we don't have to find free numbers for the new vehicles, autoreplace should be somewhat faster, specially in late games NOTE: in CmdBuildRailVehicle(), bit 0 and 1 in p2 have been switched to make the meaning of bit 0 consistent with the other build commands. CmdCloneVehicle() is modified to follow this as well
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/train_cmd.c b/train_cmd.c
index 81cccfc04..35f5d41af 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -699,8 +699,8 @@ static void AddRearEngineToMultiheadedTrain(Vehicle* v, Vehicle* u, bool buildin
/** Build a railroad vehicle.
* @param tile tile of the depot where rail-vehicle is built
* @param p1 engine type id
- * @param p2 bit 0 prevents any free cars from being added to the train
- * bit 1 when set, the train will get number 0, otherwise it will get a free number
+ * @param p2 bit 0 when set, the train will get number 0, otherwise it will get a free number
+ * bit 1 prevents any free cars from being added to the train
*/
int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
@@ -744,14 +744,10 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v = vl[0];
- if (HASBIT(p2, 1)) {
- // no number is needed, so we assign 0. The engine is likely intended for a train with more than one engine
- unit_num = 0;
- } else {
- unit_num = GetFreeUnitNumber(VEH_Train);
- if (unit_num > _patches.max_trains)
- return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
- }
+ unit_num = (HASBIT(p2, 0) == true) ? 0 : GetFreeUnitNumber(VEH_Train);
+ if (unit_num > _patches.max_trains)
+ return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
+
if (flags & DC_EXEC) {
DiagDirection dir = GetRailDepotDirection(tile);
int x = TileX(tile) * TILE_SIZE + _vehicle_initial_x_fract[dir];
@@ -815,7 +811,7 @@ int32 CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
TrainConsistChanged(v);
UpdateTrainAcceleration(v);
- if (!HASBIT(p2, 0)) { // check if the cars should be added to the new vehicle
+ if (!HASBIT(p2, 1)) { // check if the cars should be added to the new vehicle
NormalizeTrainVehInDepot(v);
}