mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r16640) -Codechange: move roadstop stuff to separate files
This commit is contained in:
parent
8bb88e5f72
commit
0045096403
|
@ -687,6 +687,10 @@
|
|||
RelativePath=".\..\src\road.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\roadstop.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\screenshot.cpp"
|
||||
>
|
||||
|
@ -1327,6 +1331,10 @@
|
|||
RelativePath=".\..\src\road_type.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\roadstop_base.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\roadveh.h"
|
||||
>
|
||||
|
|
|
@ -684,6 +684,10 @@
|
|||
RelativePath=".\..\src\road.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\roadstop.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\screenshot.cpp"
|
||||
>
|
||||
|
@ -1324,6 +1328,10 @@
|
|||
RelativePath=".\..\src\road_type.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\roadstop_base.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\roadveh.h"
|
||||
>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 size_y, bool reset_date)
|
|||
InitializeTrees();
|
||||
InitializeSigns();
|
||||
InitializeStations();
|
||||
InitializeRoadStops();
|
||||
InitializeCargoPackets();
|
||||
InitializeIndustries();
|
||||
InitializeBuildingCounts();
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* $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();
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/* $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 */
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 = (Rect src)
|
|||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* 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();
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -30,9 +30,8 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue