From c5a44ce99ea6de8135f037df68e57e26c3b78c1d Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 4 Jul 2009 11:26:57 +0000 Subject: [PATCH] (svn r16736) -Codechange: give some station enums a name and use that instead of 'byte'. --- src/core/enum_type.hpp | 14 ++++++++++++++ src/economy.cpp | 4 ++-- src/station.cpp | 2 +- src/station_base.h | 6 +++--- 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 1560d42d67..8df7920d34 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 0688048b8f..562f9e2b17 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 b5126c79bc..4db8c7c0f3 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 446f09c87b..b91fb499e6 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 3f2e6846b6..513e725719 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 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 StationHadVehicleOfTypeByte; enum CatchmentArea { CA_NONE = 0,