diff options
author | smatz <smatz@openttd.org> | 2009-06-23 21:44:48 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-06-23 21:44:48 +0000 |
commit | 0045096403ed050cf972aef6d146535bbb88f713 (patch) | |
tree | c2d5afb33a93771903898ca7192ded5d3d40c731 /src | |
parent | 8bb88e5f7236738f2101b96a3d23a4252464a615 (diff) | |
download | openttd-0045096403ed050cf972aef6d146535bbb88f713.tar.xz |
(svn r16640) -Codechange: move roadstop stuff to separate files
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/api/ai_order.cpp | 1 | ||||
-rw-r--r-- | src/ai/api/ai_station.cpp | 1 | ||||
-rw-r--r-- | src/misc.cpp | 2 | ||||
-rw-r--r-- | src/newgrf_station.cpp | 1 | ||||
-rw-r--r-- | src/openttd.cpp | 1 | ||||
-rw-r--r-- | src/order_cmd.cpp | 1 | ||||
-rw-r--r-- | src/roadstop.cpp | 54 | ||||
-rw-r--r-- | src/roadstop_base.h | 122 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 1 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 1 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 1 | ||||
-rw-r--r-- | src/saveload/station_sl.cpp | 1 | ||||
-rw-r--r-- | src/station.cpp | 52 | ||||
-rw-r--r-- | src/station_base.h | 110 | ||||
-rw-r--r-- | src/station_cmd.cpp | 1 | ||||
-rw-r--r-- | src/station_func.h | 3 |
16 files changed, 190 insertions, 163 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp index be5b33012..56c0a78b7 100644 --- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -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" diff --git a/src/ai/api/ai_station.cpp b/src/ai/api/ai_station.cpp index 1a7ef468d..5628ab547 100644 --- a/src/ai/api/ai_station.cpp +++ b/src/ai/api/ai_station.cpp @@ -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" diff --git a/src/misc.cpp b/src/misc.cpp index 6a990a007..8434ab6e1 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -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(); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index f3d4d4b92..38f4c88c0 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -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" diff --git a/src/openttd.cpp b/src/openttd.cpp index 4c2576400..667316b28 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -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" diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 2ec2110c6..8c63e19f6 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -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" diff --git a/src/roadstop.cpp b/src/roadstop.cpp new file mode 100644 index 000000000..eda4daa94 --- /dev/null +++ b/src/roadstop.cpp @@ -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(); +} diff --git a/src/roadstop_base.h b/src/roadstop_base.h new file mode 100644 index 000000000..6a18f5cbe --- /dev/null +++ b/src/roadstop_base.h @@ -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 */ diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 894477e68..7182afcb9 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -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" diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 91e826567..6ea186f0c 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -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" diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index bdc292fcc..0fa193b58 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -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" diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index d85a5728b..4af681ad8 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -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" diff --git a/src/station.cpp b/src/station.cpp index d55618751..8ee0c17e4 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -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(); } diff --git a/src/station_base.h b/src/station_base.h index c2d364711..7ab2c9c0b 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -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 */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index c559ff31e..0b2028da8 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -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" diff --git a/src/station_func.h b/src/station_func.h index 893e12bc6..2b5fbf57d 100644 --- a/src/station_func.h +++ b/src/station_func.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); |