Changeset - r12215:7e5ec1b6625d
[Not reviewed]
master
0 17 2
smatz - 15 years ago 2009-06-23 21:44:48
smatz@openttd.org
(svn r16640) -Codechange: move roadstop stuff to separate files
19 files changed with 208 insertions and 163 deletions:
0 comments (0 inline, 0 general)
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -688,6 +688,10 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\roadstop.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\screenshot.cpp"
 
				>
 
			</File>
 
@@ -1328,6 +1332,10 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\roadstop_base.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\roadveh.h"
 
				>
 
			</File>
projects/openttd_vs90.vcproj
Show inline comments
 
@@ -685,6 +685,10 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\roadstop.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\screenshot.cpp"
 
				>
 
			</File>
 
@@ -1325,6 +1329,10 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\roadstop_base.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\roadveh.h"
 
				>
 
			</File>
source.list
Show inline comments
 
@@ -62,6 +62,7 @@ queue.cpp
 
rail.cpp
 
rev.cpp
 
road.cpp
 
roadstop.cpp
 
screenshot.cpp
 
#if SDL
 
	sdl.cpp
 
@@ -260,6 +261,7 @@ road_func.h
 
road_gui.h
 
road_internal.h
 
road_type.h
 
roadstop_base.h
 
roadveh.h
 
screenshot.h
 
sdl.h
src/ai/api/ai_order.cpp
Show inline comments
 
@@ -8,6 +8,7 @@
 
#include "../ai_instance.hpp"
 
#include "../../debug.h"
 
#include "../../vehicle_base.h"
 
#include "../../roadstop_base.h"
 
#include "../../depot_base.h"
 
#include "../../station_map.h"
 
#include "../../waypoint.h"
src/ai/api/ai_station.cpp
Show inline comments
 
@@ -9,6 +9,7 @@
 
#include "../../command_func.h"
 
#include "../../debug.h"
 
#include "../../station_map.h"
 
#include "../../roadstop_base.h"
 
#include "../../string_func.h"
 
#include "../../strings_func.h"
 
#include "../../company_func.h"
src/misc.cpp
Show inline comments
 
@@ -45,6 +45,7 @@ void InitializeTowns();
 
void InitializeTrees();
 
void InitializeSigns();
 
void InitializeStations();
 
void InitializeRoadStops();
 
void InitializeCargoPackets();
 
void InitializeCompanies();
 
void InitializeCheats();
 
@@ -93,6 +94,7 @@ void InitializeGame(uint size_x, uint si
 
	InitializeTrees();
 
	InitializeSigns();
 
	InitializeStations();
 
	InitializeRoadStops();
 
	InitializeCargoPackets();
 
	InitializeIndustries();
 
	InitializeBuildingCounts();
src/newgrf_station.cpp
Show inline comments
 
@@ -7,6 +7,7 @@
 
#include "landscape.h"
 
#include "debug.h"
 
#include "station_map.h"
 
#include "roadstop_base.h"
 
#include "newgrf_commons.h"
 
#include "newgrf_station.h"
 
#include "newgrf_spritegroup.h"
src/openttd.cpp
Show inline comments
 
@@ -48,6 +48,7 @@
 
#include "gamelog.h"
 
#include "cheat_type.h"
 
#include "animated_tile_func.h"
 
#include "roadstop_base.h"
 
#include "functions.h"
 
#include "elrail_func.h"
 
#include "rev.h"
src/order_cmd.cpp
Show inline comments
 
@@ -19,6 +19,7 @@
 
#include "vehicle_func.h"
 
#include "depot_base.h"
 
#include "settings_type.h"
 
#include "roadstop_base.h"
 
#include "core/pool_func.hpp"
 
#include "aircraft.h"
 
#include "roadveh.h"
src/roadstop.cpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file roadstop.cpp Implementation of the roadstop base class. */
 

	
 
#include "stdafx.h"
 
#include "roadveh.h"
 
#include "station_map.h"
 
#include "core/pool_func.hpp"
 
#include "roadstop_base.h"
 

	
 
RoadStopPool _roadstop_pool("RoadStop");
 
INSTANTIATE_POOL_METHODS(RoadStop)
 

	
 
/** De-Initializes a RoadStops. This includes clearing all slots that vehicles might
 
  * have and unlinks it from the linked list of road stops at the given station
 
  */
 
RoadStop::~RoadStop()
 
{
 
	if (CleaningPool()) return;
 

	
 
	/* Clear the slot assignment of all vehicles heading for this road stop */
 
	if (this->num_vehicles != 0) {
 
		RoadVehicle *rv;
 
		FOR_ALL_ROADVEHICLES(rv) {
 
			if (rv->slot == this) ClearSlot(rv);
 
		}
 
	}
 
	assert(this->num_vehicles == 0);
 
}
 

	
 
/**
 
 * Get the next road stop accessible by this vehicle.
 
 * @param v the vehicle to get the next road stop for.
 
 * @return the next road stop accessible.
 
 */
 
RoadStop *RoadStop::GetNextRoadStop(const RoadVehicle *v) const
 
{
 
	for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) {
 
		/* The vehicle cannot go to this roadstop (different roadtype) */
 
		if ((GetRoadTypes(rs->xy) & v->compatible_roadtypes) == ROADTYPES_NONE) continue;
 
		/* The vehicle is articulated and can therefor not go the a standard road stop */
 
		if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue;
 

	
 
		/* The vehicle can actually go to this road stop. So, return it! */
 
		return rs;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
void InitializeRoadStops()
 
{
 
	_roadstop_pool.CleanPool();
 
}
src/roadstop_base.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file roadstop_base.h Base class for roadstops. */
 

	
 
#ifndef ROADSTOP_BASE_H
 
#define ROADSTOP_BASE_H
 

	
 
#include "station_type.h"
 
#include "core/pool_type.hpp"
 
#include "core/bitmath_func.hpp"
 

	
 
typedef Pool<RoadStop, RoadStopID, 32, 64000> RoadStopPool;
 
extern RoadStopPool _roadstop_pool;
 

	
 
/** A Stop for a Road Vehicle */
 
struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> {
 
	enum RoadStopStatusFlags {
 
		RSSFB_BAY0_FREE  = 0, ///< Non-zero when bay 0 is free
 
		RSSFB_BAY1_FREE  = 1, ///< Non-zero when bay 1 is free
 
		RSSFB_BAY_COUNT  = 2, ///< Max. number of bays
 
		RSSFB_ENTRY_BUSY = 7, ///< Non-zero when roadstop entry is busy
 
	};
 

	
 
	static const uint LIMIT           = 16;  ///< The maximum amount of roadstops that are allowed at a single station
 
	static const uint MAX_VEHICLES    = 64;  ///< The maximum number of vehicles that can allocate a slot to this roadstop
 

	
 
	TileIndex        xy;                    ///< Position on the map
 
	byte             status;                ///< Current status of the Stop, @see RoadStopSatusFlag. Access using *Bay and *Busy functions.
 
	byte             num_vehicles;          ///< Number of vehicles currently slotted to this stop
 
	struct RoadStop  *next;                 ///< Next stop of the given type at this station
 

	
 
	/** Initializes a RoadStop */
 
	FORCEINLINE RoadStop(TileIndex tile = INVALID_TILE) :
 
		xy(tile),
 
		status((1 << RSSFB_BAY_COUNT) - 1)
 
	{ }
 

	
 
	~RoadStop();
 

	
 
	/**
 
	 * Checks whether there is a free bay in this road stop
 
	 * @return is at least one bay free?
 
	 */
 
	FORCEINLINE bool HasFreeBay() const
 
	{
 
		return GB(this->status, 0, RSSFB_BAY_COUNT) != 0;
 
	}
 

	
 
	/**
 
	 * Checks whether the given bay is free in this road stop
 
	 * @param nr bay to check
 
	 * @return is given bay free?
 
	 */
 
	FORCEINLINE bool IsFreeBay(uint nr) const
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		return HasBit(this->status, nr);
 
	}
 

	
 
	/**
 
	 * Allocates a bay
 
	 * @return the allocated bay number
 
	 * @pre this->HasFreeBay()
 
	 */
 
	FORCEINLINE uint AllocateBay()
 
	{
 
		assert(this->HasFreeBay());
 

	
 
		/* Find the first free bay. If the bit is set, the bay is free. */
 
		uint bay_nr = 0;
 
		while (!HasBit(this->status, bay_nr)) bay_nr++;
 

	
 
		ClrBit(this->status, bay_nr);
 
		return bay_nr;
 
	}
 

	
 
	/**
 
	 * Allocates a bay in a drive-through road stop
 
	 * @param nr the number of the bay to allocate
 
	 */
 
	FORCEINLINE void AllocateDriveThroughBay(uint nr)
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		ClrBit(this->status, nr);
 
	}
 

	
 
	/**
 
	 * Frees the given bay
 
	 * @param nr the number of the bay to free
 
	 */
 
	FORCEINLINE void FreeBay(uint nr)
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		SetBit(this->status, nr);
 
	}
 

	
 

	
 
	/**
 
	 * Checks whether the entrance of the road stop is occupied by a vehicle
 
	 * @return is entrance busy?
 
	 */
 
	FORCEINLINE bool IsEntranceBusy() const
 
	{
 
		return HasBit(this->status, RSSFB_ENTRY_BUSY);
 
	}
 

	
 
	/**
 
	 * Makes an entrance occupied or free
 
	 * @param busy if true, marks busy; free otherwise
 
	 */
 
	FORCEINLINE void SetEntranceBusy(bool busy)
 
	{
 
		SB(this->status, RSSFB_ENTRY_BUSY, 1, busy);
 
	}
 

	
 
	RoadStop *GetNextRoadStop(const struct RoadVehicle *v) const;
 
};
 

	
 
#define FOR_ALL_ROADSTOPS_FROM(var, start) FOR_ALL_ITEMS_FROM(RoadStop, roadstop_index, var, start)
 
#define FOR_ALL_ROADSTOPS(var) FOR_ALL_ROADSTOPS_FROM(var, 0)
 

	
 
#endif /* ROADSTOP_BASE_H */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -30,6 +30,7 @@
 
#include "depot_base.h"
 
#include "effectvehicle_func.h"
 
#include "settings_type.h"
 
#include "roadstop_base.h"
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
src/saveload/afterload.cpp
Show inline comments
 
@@ -5,6 +5,7 @@
 
#include "../stdafx.h"
 
#include "../void_map.h"
 
#include "../signs_base.h"
 
#include "../roadstop_base.h"
 
#include "../window_func.h"
 
#include "../fios.h"
 
#include "../train.h"
src/saveload/saveload.cpp
Show inline comments
 
@@ -30,6 +30,7 @@
 
#include "../company_func.h"
 
#include "../date_func.h"
 
#include "../autoreplace_base.h"
 
#include "../roadstop_base.h"
 
#include "../statusbar_gui.h"
 
#include "../fileio_func.h"
 
#include "../gamelog.h"
src/saveload/station_sl.cpp
Show inline comments
 
@@ -4,6 +4,7 @@
 

	
 
#include "../stdafx.h"
 
#include "../station_base.h"
 
#include "../roadstop_base.h"
 
#include "../core/bitmath_func.hpp"
 
#include "../core/alloc_func.hpp"
 
#include "../variables.h"
src/station.cpp
Show inline comments
 
@@ -22,13 +22,12 @@
 
#include "settings_type.h"
 
#include "subsidy_func.h"
 
#include "core/pool_func.hpp"
 
#include "roadstop_base.h"
 

	
 
#include "table/strings.h"
 

	
 
StationPool _station_pool("Station");
 
INSTANTIATE_POOL_METHODS(Station)
 
RoadStopPool _roadstop_pool("RoadStop");
 
INSTANTIATE_POOL_METHODS(RoadStop)
 

	
 
Station::Station(TileIndex tile) :
 
	xy(tile),
 
@@ -437,56 +436,7 @@ StationRect& StationRect::operator = (Re
 
}
 

	
 

	
 
/************************************************************************/
 
/*                     RoadStop implementation                          */
 
/************************************************************************/
 

	
 
/** Initializes a RoadStop */
 
RoadStop::RoadStop(TileIndex tile) :
 
	xy(tile),
 
	status(3) // stop is free
 
{
 
}
 

	
 
/** De-Initializes a RoadStops. This includes clearing all slots that vehicles might
 
  * have and unlinks it from the linked list of road stops at the given station
 
  */
 
RoadStop::~RoadStop()
 
{
 
	if (CleaningPool()) return;
 

	
 
	/* Clear the slot assignment of all vehicles heading for this road stop */
 
	if (num_vehicles != 0) {
 
		RoadVehicle *rv;
 
		FOR_ALL_ROADVEHICLES(rv) {
 
			if (rv->slot == this) ClearSlot(rv);
 
		}
 
	}
 
	assert(num_vehicles == 0);
 
}
 

	
 
/**
 
 * Get the next road stop accessible by this vehicle.
 
 * @param v the vehicle to get the next road stop for.
 
 * @return the next road stop accessible.
 
 */
 
RoadStop *RoadStop::GetNextRoadStop(const RoadVehicle *v) const
 
{
 
	for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) {
 
		/* The vehicle cannot go to this roadstop (different roadtype) */
 
		if ((GetRoadTypes(rs->xy) & v->compatible_roadtypes) == ROADTYPES_NONE) continue;
 
		/* The vehicle is articulated and can therefor not go the a standard road stop */
 
		if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue;
 

	
 
		/* The vehicle can actually go to this road stop. So, return it! */
 
		return rs;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
void InitializeStations()
 
{
 
	_station_pool.CleanPool();
 
	_roadstop_pool.CleanPool();
 
}
src/station_base.h
Show inline comments
 
@@ -17,14 +17,11 @@
 
#include "company_type.h"
 
#include "industry_type.h"
 
#include "core/geometry_type.hpp"
 
#include "core/bitmath_func.hpp"
 
#include "viewport_type.h"
 
#include <list>
 

	
 
typedef Pool<Station, StationID, 32, 64000> StationPool;
 
typedef Pool<RoadStop, RoadStopID, 32, 64000> RoadStopPool;
 
extern StationPool _station_pool;
 
extern RoadStopPool _roadstop_pool;
 

	
 
static const byte INITIAL_STATION_RATING = 175;
 

	
 
@@ -50,105 +47,6 @@ struct GoodsEntry {
 
	CargoList cargo; ///< The cargo packets of cargo waiting in this station
 
};
 

	
 
/** A Stop for a Road Vehicle */
 
struct RoadStop : RoadStopPool::PoolItem<&_roadstop_pool> {
 
	enum RoadStopStatusFlags {
 
		RSSFB_BAY0_FREE  = 0, ///< Non-zero when bay 0 is free
 
		RSSFB_BAY1_FREE  = 1, ///< Non-zero when bay 1 is free
 
		RSSFB_BAY_COUNT  = 2, ///< Max. number of bays
 
		RSSFB_ENTRY_BUSY = 7, ///< Non-zero when roadstop entry is busy
 
	};
 

	
 
	static const uint LIMIT           = 16;  ///< The maximum amount of roadstops that are allowed at a single station
 
	static const uint MAX_VEHICLES    = 64;  ///< The maximum number of vehicles that can allocate a slot to this roadstop
 

	
 
	TileIndex        xy;                    ///< Position on the map
 
	byte             status;                ///< Current status of the Stop, @see RoadStopSatusFlag. Access using *Bay and *Busy functions.
 
	byte             num_vehicles;          ///< Number of vehicles currently slotted to this stop
 
	struct RoadStop  *next;                 ///< Next stop of the given type at this station
 

	
 
	RoadStop(TileIndex tile = INVALID_TILE);
 
	~RoadStop();
 

	
 
	/**
 
	 * Checks whether there is a free bay in this road stop
 
	 * @return is at least one bay free?
 
	 */
 
	FORCEINLINE bool HasFreeBay() const
 
	{
 
		return GB(this->status, 0, RSSFB_BAY_COUNT) != 0;
 
	}
 

	
 
	/**
 
	 * Checks whether the given bay is free in this road stop
 
	 * @param nr bay to check
 
	 * @return is given bay free?
 
	 */
 
	FORCEINLINE bool IsFreeBay(uint nr) const
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		return HasBit(this->status, nr);
 
	}
 

	
 
	/**
 
	 * Allocates a bay
 
	 * @return the allocated bay number
 
	 * @pre this->HasFreeBay()
 
	 */
 
	FORCEINLINE uint AllocateBay()
 
	{
 
		assert(this->HasFreeBay());
 

	
 
		/* Find the first free bay. If the bit is set, the bay is free. */
 
		uint bay_nr = 0;
 
		while (!HasBit(this->status, bay_nr)) bay_nr++;
 

	
 
		ClrBit(this->status, bay_nr);
 
		return bay_nr;
 
	}
 

	
 
	/**
 
	 * Allocates a bay in a drive-through road stop
 
	 * @param nr the number of the bay to allocate
 
	 */
 
	FORCEINLINE void AllocateDriveThroughBay(uint nr)
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		ClrBit(this->status, nr);
 
	}
 

	
 
	/**
 
	 * Frees the given bay
 
	 * @param nr the number of the bay to free
 
	 */
 
	FORCEINLINE void FreeBay(uint nr)
 
	{
 
		assert(nr < RSSFB_BAY_COUNT);
 
		SetBit(this->status, nr);
 
	}
 

	
 

	
 
	/**
 
	 * Checks whether the entrance of the road stop is occupied by a vehicle
 
	 * @return is entrance busy?
 
	 */
 
	FORCEINLINE bool IsEntranceBusy() const
 
	{
 
		return HasBit(this->status, RSSFB_ENTRY_BUSY);
 
	}
 

	
 
	/**
 
	 * Makes an entrance occupied or free
 
	 * @param busy if true, marks busy; free otherwise
 
	 */
 
	FORCEINLINE void SetEntranceBusy(bool busy)
 
	{
 
		SB(this->status, RSSFB_ENTRY_BUSY, 1, busy);
 
	}
 

	
 
	RoadStop *GetNextRoadStop(const struct RoadVehicle *v) const;
 
};
 

	
 
struct StationSpecList {
 
	const StationSpec *spec;
 
	uint32 grfid;      ///< GRF ID of this custom station
 
@@ -268,12 +166,4 @@ public:
 
#define FOR_ALL_STATIONS_FROM(var, start) FOR_ALL_ITEMS_FROM(Station, station_index, var, start)
 
#define FOR_ALL_STATIONS(var) FOR_ALL_STATIONS_FROM(var, 0)
 

	
 

	
 
/* Stuff for ROADSTOPS */
 

	
 
#define FOR_ALL_ROADSTOPS_FROM(var, start) FOR_ALL_ITEMS_FROM(RoadStop, roadstop_index, var, start)
 
#define FOR_ALL_ROADSTOPS(var) FOR_ALL_ROADSTOPS_FROM(var, 0)
 

	
 
/* End of stuff for ROADSTOPS */
 

	
 
#endif /* STATION_BASE_H */
src/station_cmd.cpp
Show inline comments
 
@@ -31,6 +31,7 @@
 
#include "string_func.h"
 
#include "animated_tile_func.h"
 
#include "elrail_func.h"
 
#include "roadstop_base.h"
 

	
 
#include "table/strings.h"
 

	
src/station_func.h
Show inline comments
 
@@ -30,9 +30,8 @@ void StationPickerDrawSprite(int x, int 
 

	
 
bool HasStationInUse(StationID station, CompanyID company);
 

	
 
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
 
RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type);
 
uint GetNumRoadStops(const Station *st, RoadStopType type);
 
RoadStop * AllocateRoadStop();
 

	
 
void ClearSlot(struct RoadVehicle *v);
 

	
0 comments (0 inline, 0 general)