Changeset - r14123:a73ffee57a40
[Not reviewed]
master
0 1 0
peter1138 - 15 years ago 2010-01-01 18:10:50
peter1138@openttd.org
(svn r18680) -Fix: Whole station area is already correct size.
1 file changed with 0 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/newgrf_station.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 newgrf_station.cpp Functions for dealing with station classes and custom stations. */
 

	
 
#include "stdafx.h"
 
#include "variables.h"
 
#include "landscape.h"
 
#include "debug.h"
 
#include "station_base.h"
 
#include "waypoint_base.h"
 
#include "roadstop_base.h"
 
#include "newgrf_cargo.h"
 
#include "newgrf_commons.h"
 
#include "newgrf_station.h"
 
#include "newgrf_spritegroup.h"
 
#include "newgrf_sound.h"
 
#include "town.h"
 
#include "newgrf_town.h"
 
#include "gfx_func.h"
 
#include "date_func.h"
 
#include "company_func.h"
 
#include "animated_tile_func.h"
 
#include "functions.h"
 
#include "tunnelbridge_map.h"
 
#include "spritecache.h"
 

	
 
#include "table/strings.h"
 

	
 
static StationClass _station_classes[STAT_CLASS_MAX];
 

	
 
enum {
 
	MAX_SPECLIST = 255,
 
};
 

	
 
enum TriggerArea {
 
	TA_TILE,
 
	TA_PLATFORM,
 
	TA_WHOLE,
 
};
 

	
 
struct ETileArea : TileArea {
 
	ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
 
	{
 
		switch (ta) {
 
			default: NOT_REACHED();
 

	
 
			case TA_TILE:
 
				this->tile = tile;
 
				this->w    = 1;
 
				this->h    = 1;
 
				break;
 

	
 
			case TA_PLATFORM: {
 
				TileIndex start, end;
 
				Axis axis = GetRailStationAxis(tile);
 
				TileIndexDiff delta = TileOffsByDiagDir(AxisToDiagDir(axis));
 

	
 
				for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(tile, end + delta); end += delta) { /* Nothing */ }
 
				for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(tile, start - delta); start -= delta) { /* Nothing */ }
 

	
 
				this->tile = start;
 
				this->w = TileX(end) - TileX(start) + 1;
 
				this->h = TileY(end) - TileY(start) + 1;
 
				break;
 
			}
 

	
 
			case TA_WHOLE:
 
				st->GetTileArea(this, Station::IsExpected(st) ? STATION_RAIL : STATION_WAYPOINT);
 
				this->w++;
 
				this->h++;
 
				break;
 
		}
 
	}
 
};
 

	
 

	
 
/**
 
 * Reset station classes to their default state.
 
 * This includes initialising the Default and Waypoint classes with an empty
 
 * entry, for standard stations and waypoints.
 
 */
 
void ResetStationClasses()
 
{
 
	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
 
		_station_classes[i].id = 0;
 
		_station_classes[i].name = STR_EMPTY;
 
		_station_classes[i].stations = 0;
 

	
 
		free(_station_classes[i].spec);
 
		_station_classes[i].spec = NULL;
 
	}
 

	
 
	/* Set up initial data */
 
	_station_classes[0].id = 'DFLT';
 
	_station_classes[0].name = STR_STATION_CLASS_DFLT;
 
	_station_classes[0].stations = 1;
 
	_station_classes[0].spec = MallocT<StationSpec*>(1);
 
	_station_classes[0].spec[0] = NULL;
 

	
 
	_station_classes[1].id = 'WAYP';
 
	_station_classes[1].name = STR_STATION_CLASS_WAYP;
 
	_station_classes[1].stations = 1;
 
	_station_classes[1].spec = MallocT<StationSpec*>(1);
 
	_station_classes[1].spec[0] = NULL;
 
}
 

	
 
/**
 
 * Allocate a station class for the given class id.
 
 * @param cls A 32 bit value identifying the class.
 
 * @return Index into _station_classes of allocated class.
 
 */
 
StationClassID AllocateStationClass(uint32 cls)
 
{
 
	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
 
		if (_station_classes[i].id == cls) {
 
			/* ClassID is already allocated, so reuse it. */
 
			return i;
 
		} else if (_station_classes[i].id == 0) {
 
			/* This class is empty, so allocate it to the ClassID. */
 
			_station_classes[i].id = cls;
 
			return i;
 
		}
 
	}
 

	
 
	grfmsg(2, "StationClassAllocate: already allocated %d classes, using default", STAT_CLASS_MAX);
 
	return STAT_CLASS_DFLT;
 
}
 

	
 
/** Set the name of a custom station class */
 
void SetStationClassName(StationClassID sclass, StringID name)
 
{
 
	assert(sclass < STAT_CLASS_MAX);
 
	_station_classes[sclass].name = name;
 
}
 

	
 
/** Retrieve the name of a custom station class */
 
StringID GetStationClassName(StationClassID sclass)
 
{
 
	assert(sclass < STAT_CLASS_MAX);
 
	return _station_classes[sclass].name;
 
}
 

	
 
/**
 
 * Get the number of station classes in use.
 
 * @return Number of station classes.
 
 */
 
uint GetNumStationClasses()
 
{
 
	uint i;
 
	for (i = 0; i < STAT_CLASS_MAX && _station_classes[i].id != 0; i++) {}
 
	return i;
 
}
 

	
 
/**
 
 * Return the number of stations for the given station class.
 
 * @param sclass Index of the station class.
 
 * @return Number of stations in the class.
 
 */
 
uint GetNumCustomStations(StationClassID sclass)
 
{
 
	assert(sclass < STAT_CLASS_MAX);
 
	return _station_classes[sclass].stations;
 
}
 

	
 
/**
 
 * Tie a station spec to its station class.
0 comments (0 inline, 0 general)