diff options
author | rubidium <rubidium@openttd.org> | 2009-07-04 11:26:57 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-07-04 11:26:57 +0000 |
commit | 571dfb90557e20f0f3b62288856eef68cc95ed1f (patch) | |
tree | d811e87b06b0b8fd7bd210b2d2007956d498d5c8 | |
parent | 65f77a7bee0158dcc3aedc0a360ff65597dad1c8 (diff) | |
download | openttd-571dfb90557e20f0f3b62288856eef68cc95ed1f.tar.xz |
(svn r16736) -Codechange: give some station enums a name and use that instead of 'byte'.
-rw-r--r-- | src/core/enum_type.hpp | 14 | ||||
-rw-r--r-- | src/economy.cpp | 4 | ||||
-rw-r--r-- | src/station.cpp | 2 | ||||
-rw-r--r-- | src/station_base.h | 6 | ||||
-rw-r--r-- | src/station_type.h | 10 |
5 files changed, 28 insertions, 8 deletions
diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp index 1560d42d6..8df7920d3 100644 --- a/src/core/enum_type.hpp +++ b/src/core/enum_type.hpp @@ -145,6 +145,20 @@ struct SimpleTinyEnumT { this->m_val = (storage_type)u; return *this; } + + /** Bit math (or) assignment operator (from enum_type) */ + FORCEINLINE SimpleTinyEnumT &operator |= (enum_type e) + { + this->m_val = (storage_type)((enum_type)this->m_val | e); + return *this; + } + + /** Bit math (and) assignment operator (from enum_type) */ + FORCEINLINE SimpleTinyEnumT &operator &= (enum_type e) + { + this->m_val = (storage_type)((enum_type)this->m_val & e); + return *this; + } }; #endif /* ENUM_TYPE_HPP */ diff --git a/src/economy.cpp b/src/economy.cpp index 0688048b8..562f9e2b1 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -112,7 +112,7 @@ Money CalculateCompanyValue(const Company *c) uint num = 0; FOR_ALL_STATIONS(st) { - if (st->owner == owner) num += CountBits(st->facilities); + if (st->owner == owner) num += CountBits((byte)st->facilities); } value += num * _price.station_value * 25; @@ -184,7 +184,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update) const Station *st; FOR_ALL_STATIONS(st) { - if (st->owner == owner) num += CountBits(st->facilities); + if (st->owner == owner) num += CountBits((byte)st->facilities); } _score_part[owner][SCORE_STATIONS] = num; } diff --git a/src/station.cpp b/src/station.cpp index b5126c79b..4db8c7c0f 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -132,7 +132,7 @@ RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const /** Called when new facility is built on the station. If it is the first facility * it initializes also 'xy' and 'random_bits' members */ -void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy) +void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy) { if (facilities == 0) { xy = facil_xy; diff --git a/src/station_base.h b/src/station_base.h index 446f09c87..b91fb499e 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -110,13 +110,13 @@ public: ViewportSign sign; - byte had_vehicle_of_type; + StationHadVehicleOfTypeByte had_vehicle_of_type; byte time_since_load; byte time_since_unload; byte delete_ctr; OwnerByte owner; - byte facilities; + StationFacilityByte facilities; byte airport_type; /* trainstation width/height */ @@ -145,7 +145,7 @@ public: Station(TileIndex tile = INVALID_TILE); ~Station(); - void AddFacility(byte new_facility_bit, TileIndex facil_xy); + void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy); /** * Mark the sign of a station dirty for repaint. diff --git a/src/station_type.h b/src/station_type.h index 3f2e6846b..513e72571 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -5,6 +5,8 @@ #ifndef STATION_TYPE_H #define STATION_TYPE_H +#include "core/enum_type.hpp" + typedef uint16 StationID; typedef uint16 RoadStopID; @@ -32,15 +34,17 @@ enum RoadStopType { ROADSTOP_TRUCK ///< A standard stop for trucks }; -enum { +enum StationFacility { FACIL_TRAIN = 0x01, FACIL_TRUCK_STOP = 0x02, FACIL_BUS_STOP = 0x04, FACIL_AIRPORT = 0x08, FACIL_DOCK = 0x10, }; +DECLARE_ENUM_AS_BIT_SET(StationFacility); +typedef SimpleTinyEnumT<StationFacility, byte> StationFacilityByte; -enum { +enum StationHadVehicleOfType { // HVOT_PENDING_DELETE = 1 << 0, // not needed anymore HVOT_TRAIN = 1 << 1, HVOT_BUS = 1 << 2, @@ -51,6 +55,8 @@ enum { * can we do? ;-) */ HVOT_BUOY = 1 << 6 }; +DECLARE_ENUM_AS_BIT_SET(StationHadVehicleOfType); +typedef SimpleTinyEnumT<StationHadVehicleOfType, byte> StationHadVehicleOfTypeByte; enum CatchmentArea { CA_NONE = 0, |