File diff r21555:3572cbdcf0a5 → r21556:54687a87c1ce
src/vehiclelist.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * 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 vehiclelist.cpp Lists of vehicles. */
 

	
 
#include "stdafx.h"
 
#include "train.h"
 
#include "vehiclelist.h"
 
#include "group.h"
 

	
 
#include "safeguards.h"
 

	
 
/**
 
 * Pack a VehicleListIdentifier in a single uint32.
 
 * @return The packed identifier.
 
 */
 
uint32 VehicleListIdentifier::Pack()
 
uint32 VehicleListIdentifier::Pack() const
 
{
 
	byte c = this->company == OWNER_NONE ? 0xF : (byte)this->company;
 
	assert(c             < (1 <<  4));
 
	assert(this->vtype   < (1 <<  2));
 
	assert(this->index   < (1 << 20));
 
	assert(this->type    < VLT_END);
 
	assert_compile(VLT_END <= (1 <<  3));
 

	
 
	return c << 28 | this->type << 23 | this->vtype << 26 | this->index;
 
}
 

	
 
/**
 
 * Unpack a VehicleListIdentifier from a single uint32.
 
 * @param data The data to unpack.
 
 * @return true iff the data was valid (enough).
 
 */
 
bool VehicleListIdentifier::Unpack(uint32 data)
 
{
 
	byte c        = GB(data, 28, 4);
 
	this->company = c == 0xF ? OWNER_NONE : (CompanyID)c;
 
	this->type    = (VehicleListType)GB(data, 23, 3);
 
	this->vtype   = (VehicleType)GB(data, 26, 2);
 
	this->index   = GB(data, 0, 20);