Changeset - r17298:f10752811f69
[Not reviewed]
master
0 1 0
glx - 14 years ago 2011-02-10 15:58:22
glx@openttd.org
(svn r22048) -Fix (r4495): company 0 does not always exist, so put temporary vehicles in a valid company
1 file changed with 2 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/articulated_vehicles.cpp
Show inline comments
 
@@ -5,24 +5,25 @@
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file articulated_vehicles.cpp Implementation of articulated vehicles. */
 

	
 
#include "stdafx.h"
 
#include "train.h"
 
#include "roadveh.h"
 
#include "vehicle_func.h"
 
#include "engine_func.h"
 
#include "company_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 

	
 
static const uint MAX_ARTICULATED_PARTS = 100; ///< Maximum of articulated parts per vehicle, i.e. when to abort calling the articulated vehicle callback.
 

	
 
/**
 
 * Determines the next articulated part to attach
 
 * @param index Position in chain
 
 * @param front_type Front engine type
 
 * @param front Front engine
 
 * @param mirrored Returns whether the part shall be flipped.
 
@@ -42,24 +43,25 @@ static EngineID GetNextArticulatedPart(u
 
uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
 
{
 
	if (!HasBit(EngInfo(engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) return 0;
 

	
 
	/* If we can't allocate a vehicle now, we can't allocate it in the command
 
	 * either, so it doesn't matter how many articulated parts there are. */
 
	if (!Vehicle::CanAllocateItem()) return 0;
 

	
 
	Vehicle *v = NULL;
 
	if (!purchase_window) {
 
		v = new Vehicle();
 
		v->engine_type = engine_type;
 
		v->owner = _current_company;
 
	}
 

	
 
	uint i;
 
	for (i = 1; i < MAX_ARTICULATED_PARTS; i++) {
 
		if (GetNextArticulatedPart(i, engine_type, v) == INVALID_ENGINE) break;
 
	}
 

	
 
	delete v;
 

	
 
	return i - 1;
 
}
 

	
0 comments (0 inline, 0 general)