diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 607bda4030..f896e294c6 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -54,7 +54,7 @@ } config->AnchorUnchangeableSettings(); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company *c = Company::Get(company); c->ai_info = info; @@ -78,7 +78,7 @@ assert(_settings_game.difficulty.competitor_speed <= 4); if ((AI::frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return; - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); const Company *c; FOR_ALL_COMPANIES(c) { if (c->is_ai) { @@ -110,7 +110,7 @@ if (_networking && !_network_server) return; PerformanceMeasurer::SetInactive((PerformanceElement)(PFE_AI0 + company)); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company *c = Company::Get(company); delete c->ai_instance; @@ -130,7 +130,7 @@ * for the server owner to unpause the script again. */ if (_network_dedicated) return; - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company::Get(company)->ai_instance->Pause(); cur_company.Restore(); @@ -138,7 +138,7 @@ /* static */ void AI::Unpause(CompanyID company) { - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company::Get(company)->ai_instance->Unpause(); cur_company.Restore(); @@ -146,7 +146,7 @@ /* static */ bool AI::IsPaused(CompanyID company) { - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); bool paused = Company::Get(company)->ai_instance->IsPaused(); cur_company.Restore(); @@ -256,7 +256,7 @@ } /* Queue the event */ - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company::Get(_current_company)->ai_instance->InsertEvent(event); cur_company.Restore(); @@ -288,7 +288,7 @@ Company *c = Company::GetIfValid(company); assert(c != nullptr && c->ai_instance != nullptr); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); c->ai_instance->Save(); cur_company.Restore(); } else { @@ -302,7 +302,7 @@ Company *c = Company::GetIfValid(company); assert(c != nullptr && c->ai_instance != nullptr); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); c->ai_instance->Load(version); cur_company.Restore(); } else { diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 4932c0f612..91f8969046 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -810,7 +810,7 @@ struct AIConfigWindow : public Window { if (_game_mode != GM_NORMAL) { return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors; } - if (Company::IsValidID(slot) || slot < 0) return false; + if (Company::IsValidID(slot)) return false; int max_slot = GetGameSettings().difficulty.max_no_competitors; for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) { diff --git a/src/aircraft.h b/src/aircraft.h index e97bda1d3f..1855224bcb 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -80,7 +80,7 @@ struct Aircraft FINAL : public SpecializedVehicle { byte previous_pos; ///< Previous desired position of the aircraft. StationID targetairport; ///< Airport to go to next. byte state; ///< State of the airport. @see AirportMovementStates - DirectionByte last_direction; + Direction last_direction; byte number_consecutive_turns; ///< Protection to prevent the aircraft of making a lot of turns in order to reach a specific point. byte turn_counter; ///< Ticks between each turn to prevent > 45 degree turns. byte flags; ///< Aircraft flags. @see AirVehicleFlags diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index eea6216448..00d4ddad04 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1294,7 +1294,7 @@ void HandleMissingAircraftOrders(Aircraft *v) */ const Station *st = GetTargetAirportIfValid(v); if (st == nullptr) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); @@ -1663,7 +1663,7 @@ static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass /* Send the helicopter to a hangar if needed for replacement */ if (v->NeedsAutomaticServicing()) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); DoCommand(v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); } @@ -1714,7 +1714,7 @@ static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ if (v->NeedsAutomaticServicing()) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); DoCommand(v->tile, v->index | DEPOT_SERVICE, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); } diff --git a/src/airport.h b/src/airport.h index 31c68ef002..9e9eee8703 100644 --- a/src/airport.h +++ b/src/airport.h @@ -130,10 +130,10 @@ static const uint64 /** A single location on an airport where aircraft can move to. */ struct AirportMovingData { - int16 x; ///< x-coordinate of the destination. - int16 y; ///< y-coordinate of the destination. - uint16 flag; ///< special flags when moving towards the destination. - DirectionByte direction; ///< Direction to turn the aircraft after reaching the destination. + int16 x; ///< x-coordinate of the destination. + int16 y; ///< y-coordinate of the destination. + uint16 flag; ///< special flags when moving towards the destination. + Direction direction; ///< Direction to turn the aircraft after reaching the destination. }; AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y); diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index f1c6f8f0d1..73bb170fb3 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -79,6 +79,7 @@ struct BuildAirToolbarWindow : Window { ~BuildAirToolbarWindow() { + if (this->IsWidgetLowered(WID_AT_AIRPORT)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -143,6 +144,8 @@ struct BuildAirToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (this->IsWidgetLowered(WID_AT_AIRPORT)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); DeleteWindowById(WC_BUILD_STATION, TRANSPORT_AIR); diff --git a/src/base_station_base.h b/src/base_station_base.h index 3e65020ffa..c98ed28efb 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -64,8 +64,8 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { std::unique_ptr cached_name; ///< NOSAVE: Cache of the resolved name of the station, if not using a custom name Town *town; ///< The town this station is associated with - OwnerByte owner; ///< The owner of this station - StationFacilityByte facilities; ///< The facilities that this station has + Owner owner; ///< The owner of this station + StationFacility facilities; ///< The facilities that this station has uint8 num_specs; ///< Number of specs in the speclist StationSpecList *speclist; ///< List of station specs of this station diff --git a/src/bridge_map.h b/src/bridge_map.h index 18476533b1..b315ac8ecd 100644 --- a/src/bridge_map.h +++ b/src/bridge_map.h @@ -123,10 +123,9 @@ static inline void SetBridgeMiddle(TileIndex t, Axis a) * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing * @param tt the transport type of the bridge - * @param rt the road or rail type * @note this function should not be called directly. */ -static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt) +static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt) { SetTileType(t, MP_TUNNELBRIDGE); SetTileOwner(t, o); @@ -136,7 +135,7 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D _m[t].m5 = 1 << 7 | tt << 2 | d; SB(_me[t].m6, 2, 4, bridgetype); _me[t].m7 = 0; - _me[t].m8 = rt; + _me[t].m8 = 0; } /** @@ -147,18 +146,18 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D * @param owner_tram the new owner of the tram on the bridge * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing - * @param r the road type of the bridge + * @param rts the road types of the bridge * @param upgrade whether the bridge is an upgrade instead of a totally new bridge */ -static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r, bool upgrade) +static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes rts, bool upgrade) { // Backup custom bridgehead data. uint custom_bridge_head_backup = GB(_m[t].m2, 0, 8); - MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0); + MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD); SetRoadOwner(t, ROADTYPE_ROAD, owner_road); if (owner_tram != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, owner_tram); - SetRoadTypes(t, r); + SetRoadTypes(t, rts); // Restore custom bridgehead data if we're upgrading an existing bridge. if (upgrade) SB(_m[t].m2, 0, 8, custom_bridge_head_backup); @@ -170,10 +169,10 @@ static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Ow * @param o the new owner of the bridge ramp * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing - * @param r the rail type of the bridge + * @param rt the rail type of the bridge * @param upgrade whether the bridge is an upgrade instead of a totally new bridge */ -static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r, bool upgrade) +static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt, bool upgrade) { /* Backup bridge signal and custom bridgehead data. */ auto m2_backup = _m[t].m2; @@ -182,7 +181,8 @@ static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetyp auto m6_backup = _me[t].m6; auto m8_backup = _me[t].m8; - MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r); + MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL); + _me[t].m8 = rt; if (upgrade) { /* Restore bridge signal and custom bridgehead data if we're upgrading an existing bridge. */ @@ -206,7 +206,7 @@ static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetyp */ static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d) { - MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0); + MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER); } /** diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index df8a442eca..4d3b920909 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1015,8 +1015,8 @@ void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selecte struct BuildVehicleWindow : Window { VehicleType vehicle_type; ///< Type of vehicles shown in the window. union { - RailTypeByte railtype; ///< Rail type to show, or #RAILTYPE_END. - RoadTypes roadtypes; ///< Road type to show, or #ROADTYPES_ALL. + RailType railtype; ///< Rail type to show, or #RAILTYPE_END. + RoadTypes roadtypes; ///< Road type to show, or #ROADTYPES_ALL. } filter; ///< Filter to apply. bool descending_sort_order; ///< Sort direction, @see _engine_sort_direction byte sort_criteria; ///< Current sort criterium. diff --git a/src/cargo_type.h b/src/cargo_type.h index 79d1c84f46..78c04ae727 100644 --- a/src/cargo_type.h +++ b/src/cargo_type.h @@ -145,12 +145,11 @@ public: /** Types of cargo source and destination */ -enum SourceType { +enum SourceType : byte { ST_INDUSTRY, ///< Source/destination is an industry ST_TOWN, ///< Source/destination is a town ST_HEADQUARTERS, ///< Source/destination are company headquarters }; -typedef SimpleTinyEnumT SourceTypeByte; ///< The SourceType packed into a byte for savegame purposes. typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE) static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 06845dac4d..f376101b45 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -249,7 +249,7 @@ void CargoPacket::PayDeferredPayments() { if (this->flags & CPF_HAS_DEFERRED_PAYMENT) { IterateCargoPacketDeferredPayments(this->index, true, [&](Money &payment, CompanyID cid, VehicleType type) { - Backup cur_company(_current_company, cid, FILE_LINE); + Backup cur_company(_current_company, cid, FILE_LINE); ExpensesType exp; switch (type) { diff --git a/src/cargopacket.h b/src/cargopacket.h index 0f034b859e..a81aecb4b3 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -47,13 +47,13 @@ void ChangeOwnershipOfCargoPacketDeferredPayments(Owner old_owner, Owner new_own */ struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> { private: - Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo. - uint16 count; ///< The amount of cargo in this packet. - byte days_in_transit; ///< Amount of days this packet has been in transit. - SourceTypeByte source_type; ///< Type of \c source_id. - SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid. - StationID source; ///< The station where the cargo came from first. - TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain). + Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo. + uint16 count; ///< The amount of cargo in this packet. + byte days_in_transit; ///< Amount of days this packet has been in transit. + SourceType source_type; ///< Type of \c source_id. + SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid. + StationID source; ///< The station where the cargo came from first. + TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain). union { TileOrStationID loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle. TileOrStationID next_station; ///< Station where the cargo wants to go next. diff --git a/src/command.cpp b/src/command.cpp index b5d3e9bfd3..ff95d3777b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -482,7 +482,7 @@ static const Command _command_proc_table[] = { /** * List of flags for a command log entry */ -enum CommandLogEntryFlagEnum { +enum CommandLogEntryFlag : byte { CLEF_NONE = 0x00, ///< no flag is set CLEF_CMD_FAILED = 0x01, ///< command failed CLEF_GENERATING_WORLD = 0x02, ///< generating world @@ -493,8 +493,7 @@ enum CommandLogEntryFlagEnum { CLEF_BINARY = 0x40, ///< binary_length is > 0 CLEF_SCRIPT = 0x80, ///< command run by AI/game script }; -DECLARE_ENUM_AS_BIT_SET(CommandLogEntryFlagEnum) -typedef SimpleTinyEnumT CommandLogEntryFlag; +DECLARE_ENUM_AS_BIT_SET(CommandLogEntryFlag) struct CommandLogEntry { TileIndex tile; @@ -504,8 +503,8 @@ struct CommandLogEntry { Date date; DateFract date_fract; uint8 tick_skip_counter; - CompanyByte current_company; - CompanyByte local_company; + CompanyID current_company; + CompanyID local_company; CommandLogEntryFlag log_flags; CommandLogEntry() { } @@ -544,7 +543,7 @@ char *DumpCommandLog(char *buffer, const char *last) } const CommandLogEntry &entry = command_log[log_index]; - auto fc = [&](CommandLogEntryFlagEnum flag, char c) -> char { + auto fc = [&](CommandLogEntryFlag flag, char c) -> char { return entry.log_flags & flag ? c : '-'; }; @@ -917,7 +916,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, return_dcpi(CMD_ERROR); } - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); if (exec_as_spectator) cur_company.Change(COMPANY_SPECTATOR); bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0; diff --git a/src/company_base.h b/src/company_base.h index 0c5e162a8d..584c65b4ba 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -74,7 +74,7 @@ struct CompanyProperties { TileIndex location_of_HQ; ///< Northern tile of HQ; #INVALID_TILE when there is none. TileIndex last_build_coordinate; ///< Coordinate of the last build thing by this company. - OwnerByte share_owners[4]; ///< Owners of the 4 shares of the company. #INVALID_OWNER if nobody has bought them yet. + Owner share_owners[4]; ///< Owners of the 4 shares of the company. #INVALID_OWNER if nobody has bought them yet. Year inaugurated_year; ///< Year of starting the company. diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index fdd404900e..c63e43457d 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -44,8 +44,8 @@ void ClearEnginesHiddenFlagOfCompany(CompanyID cid); -CompanyByte _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR. -CompanyByte _current_company; ///< Company currently doing an action. +CompanyID _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR. +CompanyID _current_company; ///< Company currently doing an action. Colours _company_colours[MAX_COMPANIES]; ///< NOSAVE: can be determined from company structs. CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg uint _next_competitor_start; ///< the number of ticks before the next AI is started diff --git a/src/company_func.h b/src/company_func.h index 29650d78cd..99041b6d42 100644 --- a/src/company_func.h +++ b/src/company_func.h @@ -32,8 +32,8 @@ void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cost); CommandCost CheckOwnership(Owner owner, TileIndex tile = 0); CommandCost CheckTileOwnership(TileIndex tile); -extern CompanyByte _local_company; -extern CompanyByte _current_company; +extern CompanyID _local_company; +extern CompanyID _current_company; extern Colours _company_colours[MAX_COMPANIES]; extern CompanyManagerFace _company_manager_face; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 14987c5250..9b59158c0f 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -2630,7 +2630,7 @@ struct CompanyWindow : Window MarkWholeScreenDirty(); } else if (NetworkCompanyIsPassworded(company)) { /* ask for the password */ - ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_PASSWORD); } else { /* just send the join command */ NetworkClientRequestMove(company); diff --git a/src/company_type.h b/src/company_type.h index 771e6d8b93..576a57bf16 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -17,7 +17,7 @@ /** * Enum for all companies/owners. */ -enum Owner { +enum Owner : byte { /* All companies below MAX_COMPANIES are playable * companies, above, they are special, computer controlled 'companies' */ OWNER_BEGIN = 0x00, ///< First owner @@ -45,10 +45,8 @@ static const uint MAX_HISTORY_QUARTERS = 24; ///< The maximum number /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT OwnerByte; typedef Owner CompanyID; -typedef OwnerByte CompanyByte; typedef uint16 CompanyMask; diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index ac6f3bed14..dfbf88345c 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -914,8 +914,7 @@ DEF_CONSOLE_CMD(ConNetworkReconnect) default: /* From a user pov 0 is a new company, internally it's different and all * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */ - playas--; - if (playas < COMPANY_FIRST || playas >= MAX_COMPANIES) return false; + if (playas < COMPANY_FIRST + 1 || playas > MAX_COMPANIES + 1) return false; break; } diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp index d5bcf6dbe1..8526a91a56 100644 --- a/src/core/enum_type.hpp +++ b/src/core/enum_type.hpp @@ -46,8 +46,6 @@ * we will create specialization derived from MakeEnumPropsT<>. * i.e.: * template <> struct EnumPropsT : MakeEnumPropsT {}; - * followed by: - * typedef TinyEnumT TrackByte; */ template struct EnumPropsT; @@ -72,106 +70,4 @@ struct MakeEnumPropsT { static const uint num_bits = Tnum_bits; ///< Number of bits for storing the enum in command parameters }; - - -/** - * In some cases we use byte or uint16 to store values that are defined as enum. It is - * necessary in order to control the sizeof() such values. Some compilers make enum - * the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict - * compiler type - checking causes errors like: - * 'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when - * u->u.rail.railtype is passed as argument or type RailType. In such cases it is better - * to teach the compiler that u->u.rail.railtype is to be treated as RailType. - */ -template struct TinyEnumT; - -/** The general declaration of TinyEnumT<> (above) */ -template -struct TinyEnumT { - typedef Tenum_t enum_type; ///< expose our enumeration type (i.e. Trackdir) to outside - typedef EnumPropsT Props; ///< make easier access to our enumeration properties - typedef typename Props::storage storage_type; ///< small storage type - static const enum_type begin = Props::begin; ///< enum beginning (i.e. TRACKDIR_BEGIN) - static const enum_type end = Props::end; ///< enum end (i.e. TRACKDIR_END) - static const enum_type invalid = Props::invalid;///< invalid value (i.e. INVALID_TRACKDIR) - - storage_type m_val; ///< here we hold the actual value in small (i.e. byte) form - - /** Cast operator - invoked then the value is assigned to the Tenum_t type */ - inline operator enum_type () const - { - return (enum_type)m_val; - } - - /** Assignment operator (from Tenum_t type) */ - inline TinyEnumT& operator = (enum_type e) - { - m_val = (storage_type)e; - return *this; - } - - /** Assignment operator (from Tenum_t type) */ - inline TinyEnumT& operator = (uint u) - { - m_val = (storage_type)u; - return *this; - } - - /** postfix ++ operator on tiny type */ - inline TinyEnumT operator ++ (int) - { - TinyEnumT org = *this; - if (++m_val >= end) m_val -= (storage_type)(end - begin); - return org; - } - - /** prefix ++ operator on tiny type */ - inline TinyEnumT& operator ++ () - { - if (++m_val >= end) m_val -= (storage_type)(end - begin); - return *this; - } -}; - - -/** Template of struct holding enum types (on most archs, enums are stored in an int32). No math operators are provided. */ -template -struct SimpleTinyEnumT { - storage_type m_val; ///< here we hold the actual value in small (i.e. byte) form - - /** Cast operator - invoked then the value is assigned to the storage_type */ - inline operator enum_type () const - { - return (enum_type)this->m_val; - } - - /** Assignment operator (from enum_type) */ - inline SimpleTinyEnumT &operator = (enum_type e) - { - this->m_val = (storage_type)e; - return *this; - } - - /** Assignment operator (from general uint) */ - inline SimpleTinyEnumT &operator = (uint u) - { - this->m_val = (storage_type)u; - return *this; - } - - /** Bit math (or) assignment operator (from enum_type) */ - inline 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) */ - inline 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/crashlog.cpp b/src/crashlog.cpp index 695a1ce164..16c0dd2b7b 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -335,7 +335,7 @@ char *CrashLog::LogGamelog(char *buffer, const char *last) const } /** - * Writes any recent news messages to the buffer. + * Writes up to 32 recent news messages to the buffer, with the most recent first. * @param buffer The begin where to write at. * @param last The last position in the buffer to write to. * @return the position of the \c '\0' character after the buffer. @@ -343,18 +343,14 @@ char *CrashLog::LogGamelog(char *buffer, const char *last) const char *CrashLog::LogRecentNews(char *buffer, const char *last) const { uint total = 0; - for (NewsItem *news = _oldest_news; news != nullptr; news = news->next) { + for (NewsItem *news = _latest_news; news != nullptr; news = news->next) { total++; } uint show = min(total, 32); buffer += seprintf(buffer, last, "Recent news messages (%u of %u):\n", show, total); - uint skip = total - show; - for (NewsItem *news = _oldest_news; news != nullptr; news = news->next) { - if (skip) { - skip--; - continue; - } + int i = 0; + for (NewsItem *news = _latest_news; i < 32 && news != nullptr; news = news->prev, i++) { YearMonthDay ymd; ConvertDateToYMD(news->date, &ymd); buffer += seprintf(buffer, last, "(%i-%02i-%02i) StringID: %u, Type: %u, Ref1: %u, %u, Ref2: %u, %u\n", diff --git a/src/direction_type.h b/src/direction_type.h index e6e08a182f..cf6b9f5cf1 100644 --- a/src/direction_type.h +++ b/src/direction_type.h @@ -23,7 +23,7 @@ * your viewport and not rotated by 45 degrees left or right to get * a "north" used in you games. */ -enum Direction { +enum Direction : byte { DIR_BEGIN = 0, ///< Used to iterate DIR_N = 0, ///< North DIR_NE = 1, ///< Northeast @@ -42,7 +42,6 @@ DECLARE_POSTFIX_INCREMENT(Direction) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT DirectionByte; ///< typedefing-enumification of Direction /** @@ -77,7 +76,7 @@ enum DirDiff { * * This enumeration is used for the 4 direction of the tile-edges. */ -enum DiagDirection { +enum DiagDirection : byte { DIAGDIR_BEGIN = 0, ///< Used for iterations DIAGDIR_NE = 0, ///< Northeast, upper right on your monitor DIAGDIR_SE = 1, ///< Southeast @@ -92,7 +91,6 @@ DECLARE_POSTFIX_INCREMENT(DiagDirection) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT DiagDirectionByte; ///< typedefing-enumification of DiagDirection /** diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index e728a94dc5..2d52609dd3 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -62,7 +62,7 @@ static void DisasterClearSquare(TileIndex tile) switch (GetTileType(tile)) { case MP_RAILWAY: if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailDepot(tile)) { - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); @@ -72,7 +72,7 @@ static void DisasterClearSquare(TileIndex tile) break; case MP_HOUSE: { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); break; diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index bf446fadf3..a44bee9ee4 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -106,6 +106,7 @@ struct BuildDocksToolbarWindow : Window { ~BuildDocksToolbarWindow() { + if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -249,6 +250,8 @@ struct BuildDocksToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER); diff --git a/src/economy.cpp b/src/economy.cpp index 60a8230b1d..e3d0fd1a60 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -297,14 +297,14 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) /* We need to set _current_company to old_owner before we try to move * the client. This is needed as it needs to know whether "you" really * are the current local company. */ - Backup cur_company(_current_company, old_owner, FILE_LINE); + Backup cur_company(_current_company, old_owner, FILE_LINE); /* In all cases, make spectators of clients connected to that company */ if (_networking) NetworkClientsToSpectators(old_owner); if (old_owner == _local_company) { /* Single player cheated to AI company. * There are no spectators in single player, so we must pick some other company. */ assert(!_networking); - Backup cur_company2(_current_company, FILE_LINE); + Backup cur_company2(_current_company, FILE_LINE); Company *c; FOR_ALL_COMPANIES(c) { if (c->index != old_owner) { @@ -340,7 +340,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } /* Sell all the shares that people have on this company */ - Backup cur_company2(_current_company, FILE_LINE); + Backup cur_company2(_current_company, FILE_LINE); c = Company::Get(old_owner); for (i = 0; i < 4; i++) { cur_company2.Change(c->share_owners[i]); @@ -709,7 +709,7 @@ static void CompaniesGenStatistics() CompanyCheckBankrupt(c); } - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); if (!_settings_game.economy.infrastructure_maintenance) { Station *st; @@ -879,7 +879,7 @@ static void CompaniesPayInterest() { const Company *c; - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); FOR_ALL_COMPANIES(c) { cur_company.Change(c->index); @@ -1235,7 +1235,7 @@ CargoPayment::~CargoPayment() if (this->visual_profit == 0 && this->visual_transfer == 0) return; - Backup cur_company(_current_company, this->front->owner, FILE_LINE); + Backup cur_company(_current_company, this->front->owner, FILE_LINE); SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit)); this->front->profit_this_year += (this->visual_profit + this->visual_transfer) << 8; @@ -1578,7 +1578,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station if (!IterateVehicleParts(v_start, IsEmptyAction())) return; if (v->type == VEH_TRAIN && !IterateVehicleParts(v_start, ThroughLoadTrainInPlatformAction())) return; - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); CargoTypes refit_mask = v->GetEngine()->info.refit_mask; @@ -2287,7 +2287,7 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, cost.AddCost(CalculateCompanyValue(c) >> 2); if (flags & DC_EXEC) { - OwnerByte *b = c->share_owners; + Owner *b = c->share_owners; while (*b != COMPANY_SPECTATOR) b++; // share owners is guaranteed to contain at least one COMPANY_SPECTATOR *b = _current_company; @@ -2334,7 +2334,7 @@ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1 cost = -(cost - (cost >> 7)); if (flags & DC_EXEC) { - OwnerByte *b = c->share_owners; + Owner *b = c->share_owners; while (*b != _current_company) b++; // share owners is guaranteed to contain company *b = COMPANY_SPECTATOR; InvalidateWindowData(WC_COMPANY, target_company); diff --git a/src/economy_type.h b/src/economy_type.h index b18f79f611..5f77703632 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -147,7 +147,7 @@ typedef Money Prices[PR_END]; ///< Prices of everything. @see Price typedef int8 PriceMultipliers[PR_END]; /** Types of expenses. */ -enum ExpensesType { +enum ExpensesType : byte { EXPENSES_CONSTRUCTION = 0, ///< Construction costs. EXPENSES_NEW_VEHICLES, ///< New vehicles. EXPENSES_TRAIN_RUN, ///< Running costs trains. @@ -169,7 +169,6 @@ enum ExpensesType { /** Define basic enum properties for ExpensesType */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT ExpensesTypeByte; ///< typedefing-enumification of ExpensesType /** * Categories of a price bases. diff --git a/src/elrail.cpp b/src/elrail.cpp index dbd4c5fd01..d675acac25 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -80,8 +80,8 @@ static inline TLG GetTLG(TileIndex t) } struct DualTrackBits { - TrackBitsByte primary; - TrackBitsByte secondary; + TrackBits primary; + TrackBits secondary; }; /** @@ -177,7 +177,7 @@ static TrackBits MaskWireBits(TileIndex t, TrackBits tracks) /* If the tracks from either a diagonal crossing or don't overlap, both * trackdirs have to be marked to mask the corresponding track bit. Else * one marked trackdir is enough the mask the track bit. */ - TrackBitsByte mask; + TrackBits mask; if (tracks == TRACK_BIT_CROSS || !TracksOverlap(tracks)) { /* If the tracks form either a diagonal crossing or don't overlap, both * trackdirs have to be marked to mask the corresponding track bit. */ diff --git a/src/engine_base.h b/src/engine_base.h index 01e4fcc1d6..cae12d2239 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -34,7 +34,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { uint16 duration_phase_3; ///< Third reliability phase on months, decaying to #reliability_final. byte flags; ///< Flags of the engine. @see EngineFlags CompanyMask preview_asked; ///< Bit for each company which has already been offered a preview. - CompanyByte preview_company;///< Company which is currently being offered a preview \c INVALID_COMPANY means no company. + CompanyID preview_company; ///< Company which is currently being offered a preview \c INVALID_COMPANY means no company. byte preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company. CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company. CompanyMask company_hidden; ///< Bit for each company whether the engine is normally hidden in the build gui for that company. @@ -119,7 +119,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { * @param c Company to check. * @return \c true iff the engine is hidden in the GUI for the given company. */ - inline bool IsHidden(CompanyByte c) const + inline bool IsHidden(CompanyID c) const { return c < MAX_COMPANIES && HasBit(this->company_hidden, c); } @@ -149,7 +149,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { struct EngineIDMapping { uint32 grfid; ///< The GRF ID of the file the entity belongs to uint16 internal_id; ///< The internal ID within the GRF file - VehicleTypeByte type; ///< The engine type + VehicleType type; ///< The engine type uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available (currently not used) }; diff --git a/src/engine_type.h b/src/engine_type.h index 82f10d9d87..1cc0452a5f 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -44,7 +44,7 @@ struct RailVehicleInfo { byte image_index; RailVehicleTypes railveh_type; byte cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices. - RailTypeByte railtype; + RailType railtype; uint16 max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h) uint16 power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers. uint16 weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine. diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index 181e8b6bbc..394b77fb83 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -45,7 +45,7 @@ Game::frame_counter++; - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); cur_company.Change(OWNER_DEITY); Game::instance->GameLoop(); cur_company.Restore(); @@ -84,7 +84,7 @@ config->AnchorUnchangeableSettings(); - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); cur_company.Change(OWNER_DEITY); Game::info = info; @@ -98,7 +98,7 @@ /* static */ void Game::Uninitialize(bool keepConfig) { - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); delete Game::instance; Game::instance = nullptr; @@ -158,7 +158,7 @@ } /* Queue the event */ - Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->InsertEvent(event); cur_company.Restore(); @@ -207,7 +207,7 @@ /* static */ void Game::Save() { if (Game::instance != nullptr && (!_networking || _network_server)) { - Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->Save(); cur_company.Restore(); } else { @@ -218,7 +218,7 @@ /* static */ void Game::Load(int version) { if (Game::instance != nullptr && (!_networking || _network_server)) { - Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->Load(version); cur_company.Restore(); } else { diff --git a/src/genworld.cpp b/src/genworld.cpp index e073ced06a..2171fc1ab2 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -97,7 +97,7 @@ static void CleanupGeneration() static void _GenerateWorld() { /* Make sure everything is done via OWNER_NONE. */ - Backup _cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup _cur_company(_current_company, OWNER_NONE, FILE_LINE); std::unique_lock lock(_modal_progress_work_mutex, std::defer_lock); try { diff --git a/src/gfx.cpp b/src/gfx.cpp index 35747bebf0..5010874810 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -46,7 +46,7 @@ bool _screen_disable_anim = false; ///< Disable palette animation (important f bool _exit_game; GameMode _game_mode; SwitchMode _switch_mode; ///< The next mainloop command. -PauseModeByte _pause_mode; +PauseMode _pause_mode; Palette _cur_palette; static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth() @@ -58,8 +58,8 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, static ReusableBuffer _cursor_backup; -ZoomLevelByte _gui_zoom; ///< GUI Zoom level -ZoomLevelByte _font_zoom; ///< Font Zoom level +ZoomLevel _gui_zoom; ///< GUI Zoom level +ZoomLevel _font_zoom; ///< Font Zoom level /** * The rect for repaint. diff --git a/src/gfx_type.h b/src/gfx_type.h index 7eeddb4078..cc884b06df 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -294,7 +294,7 @@ enum PaletteType { }; /** Types of sprites that might be loaded */ -enum SpriteType { +enum SpriteType : byte { ST_NORMAL = 0, ///< The most basic (normal) sprite ST_MAPGEN = 1, ///< Special sprite for the map generator ST_FONT = 2, ///< A sprite used for fonts diff --git a/src/goal.cpp b/src/goal.cpp index b545c84d25..30f640b4ce 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -79,7 +79,7 @@ CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 case GT_STORY_PAGE: { if (!StoryPage::IsValidID(p2)) return CMD_ERROR; - CompanyByte story_company = StoryPage::Get(p2)->company; + CompanyID story_company = StoryPage::Get(p2)->company; if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return CMD_ERROR; break; } diff --git a/src/goal_base.h b/src/goal_base.h index f82afa5be9..fee4ddce7b 100644 --- a/src/goal_base.h +++ b/src/goal_base.h @@ -21,12 +21,12 @@ extern GoalPool _goal_pool; /** Struct about goals, current and completed */ struct Goal : GoalPool::PoolItem<&_goal_pool> { - CompanyByte company; ///< Goal is for a specific company; INVALID_COMPANY if it is global - GoalTypeByte type; ///< Type of the goal - GoalTypeID dst; ///< Index of type - char *text; ///< Text of the goal. - char *progress; ///< Progress text of the goal. - bool completed; ///< Is the goal completed or not? + CompanyID company; ///< Goal is for a specific company; INVALID_COMPANY if it is global + GoalType type; ///< Type of the goal + GoalTypeID dst; ///< Index of type + char *text; ///< Text of the goal. + char *progress; ///< Progress text of the goal. + bool completed; ///< Is the goal completed or not? /** * We need an (empty) constructor so struct isn't zeroed (as C++ standard states) diff --git a/src/goal_type.h b/src/goal_type.h index aa9dee349d..4321a42b7a 100644 --- a/src/goal_type.h +++ b/src/goal_type.h @@ -18,7 +18,7 @@ static const uint32 GOAL_QUESTION_BUTTON_COUNT = 18; ///< Amount of buttons avai static const byte GOAL_QUESTION_TYPE_COUNT = 4; ///< Amount of question types. /** Types of goal destinations */ -enum GoalType { +enum GoalType : byte { GT_NONE, ///< Destination is not linked GT_TILE, ///< Destination is a tile GT_INDUSTRY, ///< Destination is an industry @@ -26,7 +26,6 @@ enum GoalType { GT_COMPANY, ///< Destination is a company GT_STORY_PAGE, ///< Destination is a story page }; -typedef SimpleTinyEnumT GoalTypeByte; ///< The GoalType packed into a byte for savegame purposes. typedef uint32 GoalTypeID; ///< Contains either tile, industry ID, town ID or company ID (or INVALID_GOALTYPE) static const GoalTypeID INVALID_GOALTYPE = 0xFFFFFFFF; ///< Invalid/unknown index of GoalType diff --git a/src/group.h b/src/group.h index f8c92f9553..1964d549e5 100644 --- a/src/group.h +++ b/src/group.h @@ -65,17 +65,17 @@ struct GroupStatistics { /** Group data. */ struct Group : GroupPool::PoolItem<&_group_pool> { - char *name; ///< Group Name - OwnerByte owner; ///< Group Owner - VehicleTypeByte vehicle_type; ///< Vehicle type of the group + char *name; ///< Group Name + Owner owner; ///< Group Owner + VehicleType vehicle_type; ///< Vehicle type of the group - bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group - Livery livery; ///< Custom colour scheme for vehicles in this group - GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group. + bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group + Livery livery; ///< Custom colour scheme for vehicles in this group + GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group. - bool folded; ///< NOSAVE: Is this group folded in the group view? + bool folded; ///< NOSAVE: Is this group folded in the group view? - GroupID parent; ///< Parent group + GroupID parent; ///< Parent group Group(CompanyID owner = INVALID_COMPANY); ~Group(); diff --git a/src/industry.h b/src/industry.h index 662e9fdec7..1526927a7e 100644 --- a/src/industry.h +++ b/src/industry.h @@ -57,16 +57,16 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { uint16 counter; ///< used for animation and/or production (if available cargo) IndustryType type; ///< type of industry. - OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE + Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE byte random_colour; ///< randomized colour of the industry, for display purpose Year last_prod_year; ///< last year of production byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry - PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy? + PartOfSubsidy part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy? StationList stations_near; ///< NOSAVE: List of nearby stations. std::unique_ptr cached_name; ///< NOSAVE: Cache of the resolved name of the industry - OwnerByte founder; ///< Founder of the industry + Owner founder; ///< Founder of the industry Date construction_date; ///< Date of the construction of the industry uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType) Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 78f8e09766..5b9646170f 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1078,7 +1078,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *user_data) if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees /* found a tree */ - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); _industry_sound_ctr = 1; _industry_sound_tile = tile; @@ -1437,7 +1437,7 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil } /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); @@ -1549,7 +1549,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, /* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry. * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); TILE_AREA_LOOP(tile_walk, ta) { uint curh = TileHeight(tile_walk); @@ -1974,7 +1974,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) { if (flags & DC_EXEC) { /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); /* Prospecting has a chance to fail, however we cannot guarantee that something can * be built on the map, so the chance gets lower when the map is fuller, but there * is nothing we can really do about that. */ @@ -2136,7 +2136,7 @@ static Industry *PlaceIndustry(IndustryType type, IndustryAvailabilityCallType c */ static void PlaceInitialIndustry(IndustryType type, bool try_hard) { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); IncreaseGeneratingWorldProgress(GWP_INDUSTRY); PlaceIndustry(type, IACT_MAPGENERATION, try_hard); @@ -2787,7 +2787,7 @@ void IndustryDailyLoop() return; // Nothing to do? get out } - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); /* perform the required industry changes for the day */ @@ -2815,7 +2815,7 @@ void IndustryDailyLoop() void IndustryMonthlyLoop() { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); _industry_builder.MonthlyLoop(); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 3f03fd7c97..0a8dc25593 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -655,7 +655,7 @@ public: return; } - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); _generating_world = true; _ignore_restrictions = true; diff --git a/src/lang/croatian.txt b/src/lang/croatian.txt index 2b315fe3f1..7a4739fa99 100644 --- a/src/lang/croatian.txt +++ b/src/lang/croatian.txt @@ -333,6 +333,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Odaberi STR_BUTTON_SORT_BY :{BLACK}Sortiraj prema STR_BUTTON_LOCATION :{BLACK}Lokacija STR_BUTTON_RENAME :{BLACK}Preimenuj +STR_BUTTON_CATCHMENT :{BLACK}Područje pokrivanja +STR_TOOLTIP_CATCHMENT :{BLACK}Uključi prikaz područja pokrivanja STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Zatvori prozor STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Naslov prozora - povuci ovo za micanje prozora @@ -361,6 +363,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Uključi STR_BUTTON_DEFAULT :{BLACK}Zadano STR_BUTTON_CANCEL :{BLACK}Odustani STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Upozorenje: Administratori servera mogu pročitati bilo koji tekst upisan ovdje. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/lang/dutch.txt b/src/lang/dutch.txt index 01aaa8683f..4ec2afc301 100644 --- a/src/lang/dutch.txt +++ b/src/lang/dutch.txt @@ -237,6 +237,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Selectee STR_BUTTON_SORT_BY :{BLACK}Sorteren op STR_BUTTON_LOCATION :{BLACK}Locatie STR_BUTTON_RENAME :{BLACK}Hernoemen +STR_BUTTON_CATCHMENT :{BLACK}Dekking +STR_TOOLTIP_CATCHMENT :{BLACK}Schakelt weergave van dekkingsgebied om STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Venster sluiten STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Vensternaam - sleep om venster te verplaatsen @@ -265,6 +267,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Wanneer STR_BUTTON_DEFAULT :{BLACK}Standaard STR_BUTTON_CANCEL :{BLACK}Annuleren STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Waarschuwing: het kan zijn dat serverbeheerders tekst niet kunnen lezen die hier wordt ingevoerd. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/lang/english.txt b/src/lang/english.txt index 82e26dca74..1955ce42c0 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -237,6 +237,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Select f STR_BUTTON_SORT_BY :{BLACK}Sort by STR_BUTTON_LOCATION :{BLACK}Location STR_BUTTON_RENAME :{BLACK}Rename +STR_BUTTON_CATCHMENT :{BLACK}Coverage +STR_TOOLTIP_CATCHMENT :{BLACK}Toggle coverage area display STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Close window STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Window title - drag this to move window @@ -265,6 +267,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}By enabl STR_BUTTON_DEFAULT :{BLACK}Default STR_BUTTON_CANCEL :{BLACK}Cancel STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Warning: Server administrators may be able to read any text entered here. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/lang/finnish.txt b/src/lang/finnish.txt index f936032ee6..17a3fc283c 100644 --- a/src/lang/finnish.txt +++ b/src/lang/finnish.txt @@ -237,6 +237,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Valitse STR_BUTTON_SORT_BY :{BLACK}Lajittele STR_BUTTON_LOCATION :{BLACK}Sijainti STR_BUTTON_RENAME :{BLACK}Nimeä uudelleen +STR_BUTTON_CATCHMENT :{BLACK}Vaikutusalue +STR_TOOLTIP_CATCHMENT :{BLACK}Valitse, näytetäänkö vaikutusalue STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Sulje ikkuna STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Ikkunan otsake – siirrä ikkunaa vetämällä tästä @@ -265,6 +267,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Kun otat STR_BUTTON_DEFAULT :{BLACK}Oletus STR_BUTTON_CANCEL :{BLACK}Peruuta STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Varoitus: Palvelimen ylläpitäjät saattavat nähdä kaiken tähän kirjoittamasi. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :§1234567890+´ qwertyuiopå¨asdfghjklöä' zxcvbnm,.- . diff --git a/src/lang/indonesian.txt b/src/lang/indonesian.txt index aa6e9653ed..8b223f3a7b 100644 --- a/src/lang/indonesian.txt +++ b/src/lang/indonesian.txt @@ -476,6 +476,7 @@ STR_ABOUT_MENU_SCREENSHOT :Ambil gambar STR_ABOUT_MENU_ZOOMIN_SCREENSHOT :Ambil gambar dengan diperbesar STR_ABOUT_MENU_DEFAULTZOOM_SCREENSHOT :Ambil gambar dengan perbesaran normal STR_ABOUT_MENU_GIANT_SCREENSHOT :Ambil gambar keseluruhan peta +STR_ABOUT_MENU_SHOW_FRAMERATE :Tampilkan laju bingkai STR_ABOUT_MENU_ABOUT_OPENTTD :Tentang 'OpenTTD' STR_ABOUT_MENU_SPRITE_ALIGNER :Penjajar Sprite STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Hidup/Matikan kotak batas @@ -1572,6 +1573,7 @@ STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT :Mengaktifkan se STR_CONFIG_SETTING_TOWN_FOUNDING_FORBIDDEN :Dilarang STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED :Diijinkan STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED_CUSTOM_LAYOUT :Diijinkan, layout kota sendiri +STR_CONFIG_SETTING_TOWN_CARGOGENMODE_HELPTEXT :Seberapa banyak kargo dihasilkan oleh rumah di kota , relatif terhadap keseluruhan populasi kota.{}Pertumbuhan kuadrat: Kota yang membesar dua kali menghasilkan penumpang empat kali lipat.{}Pertumbuhan linier: Kota yang membesar dua kali menghasilkan penumpang dua kali lipat. STR_CONFIG_SETTING_TOWN_CARGOGENMODE_BITCOUNT :Linier STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT :Penempatan pohon dalam permainan: {STRING} @@ -3149,11 +3151,11 @@ STR_STATION_VIEW_ACCEPTS_TOOLTIP :{BLACK}Tampilka STR_STATION_VIEW_ACCEPTS_CARGO :{BLACK}Menerima: {WHITE}{CARGO_LIST} STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF :{BLACK}Stasiun memiliki hak transportasi eksklusif di kota ini -STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY :{YELLOW}{COMPANY}{BLACK} beli hak transportasi eksklusif di kota ini +STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY :{YELLOW}{COMPANY}{BLACK} memiliki hak transportasi eksklusif di kota ini STR_STATION_VIEW_RATINGS_BUTTON :{BLACK}Peringkat STR_STATION_VIEW_RATINGS_TOOLTIP :{BLACK}Tampilkna peringkat dari stasiun -STR_STATION_VIEW_SUPPLY_RATINGS_TITLE :{BLACK}Asupan bulanan dan penilaian tempatan: +STR_STATION_VIEW_SUPPLY_RATINGS_TITLE :{BLACK}Asupan bulanan dan peringkat layanan: STR_STATION_VIEW_CARGO_SUPPLY_RATING :{WHITE}{STRING}: {YELLOW}{COMMA} / {STRING} ({COMMA}%) STR_STATION_VIEW_GROUP :{BLACK}Pengelompokkan @@ -3376,6 +3378,7 @@ STR_GROUP_DEFAULT_ROAD_VEHICLES :Kendaraan tanpa STR_GROUP_DEFAULT_SHIPS :Kapal tanpa kelompok STR_GROUP_DEFAULT_AIRCRAFTS :Pesawat tanpa kelompok +STR_GROUP_COUNT_WITH_SUBGROUP :{TINY_FONT}{COMMA} (+{COMMA}) STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP :{BLACK}Kelompok - Klik salah satu untuk melihat daftar kendaraan pada kelompok tersebut STR_GROUP_CREATE_TOOLTIP :{BLACK}Klik untuk membuat kelompok diff --git a/src/lang/italian.txt b/src/lang/italian.txt index 41eed190ab..9bac6561a5 100644 --- a/src/lang/italian.txt +++ b/src/lang/italian.txt @@ -239,6 +239,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Selezion STR_BUTTON_SORT_BY :{BLACK}Ordina per STR_BUTTON_LOCATION :{BLACK}Posizione STR_BUTTON_RENAME :{BLACK}Rinomina +STR_BUTTON_CATCHMENT :{BLACK}Copertura +STR_TOOLTIP_CATCHMENT :{BLACK}Attiva/disattiva la visualizzazione dell'area di copertura STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Chiude la finestra STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Titolo della finestra - trascinarlo per muovere la finestra @@ -267,6 +269,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Mostra a STR_BUTTON_DEFAULT :{BLACK}Predefinito STR_BUTTON_CANCEL :{BLACK}Annulla STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Attenzione: gli amministratori del server potrebbero leggere il testo inserito qui. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :\1234567890'ì qwertyuiopè+asdfghjklòàùviewport; + vp->zoom = _gui_zoom; + vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); + vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); +} + static const struct NWidgetPart _nested_main_window_widgets[] = { NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1), }; diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index a81e2b3724..0bdb1c1c3a 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -174,9 +174,9 @@ CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, PauseMode prev_mode = _pause_mode; if (p2 == 0) { - _pause_mode = _pause_mode & ~p1; + _pause_mode = static_cast(_pause_mode & (byte)~p1); } else { - _pause_mode = _pause_mode | p1; + _pause_mode = static_cast(_pause_mode | (byte)p1); } NetworkHandlePauseChange(prev_mode, (PauseMode)p1); @@ -224,7 +224,7 @@ CommandCost CmdChangeBankBalance(TileIndex tile, DoCommandFlag flags, uint32 p1, if (flags & DC_EXEC) { /* Change company bank balance of company. */ - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); SubtractMoneyFromCompany(CommandCost(expenses_type, -delta)); cur_company.Restore(); } @@ -260,7 +260,7 @@ CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (flags & DC_EXEC) { /* Add money to company */ - Backup cur_company(_current_company, dest_company, FILE_LINE); + Backup cur_company(_current_company, dest_company, FILE_LINE); SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost())); cur_company.Restore(); } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 439ec533e3..e2a5169bc3 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1003,6 +1003,7 @@ struct QueryStringWindow : public Window { QueryString editbox; ///< Editbox. QueryStringFlags flags; ///< Flags controlling behaviour of the window. + Dimension warning_size; ///< How much space to use for the warning text QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) : Window(desc), editbox(max_bytes, max_chars) @@ -1031,12 +1032,27 @@ struct QueryStringWindow : public Window this->flags = flags; this->InitNested(WN_QUERY_STRING); + this->UpdateWarningStringSize(); this->parent = parent; this->SetFocusedWidget(WID_QS_TEXT); } + void UpdateWarningStringSize() + { + if (this->flags & QSF_PASSWORD) { + assert(this->nested_root->smallest_x > 0); + this->warning_size.width = this->nested_root->current_x - (WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT); + this->warning_size.height = GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width); + this->warning_size.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; + } else { + this->warning_size = Dimension{ 0, 0 }; + } + + this->ReInit(); + } + void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override { if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) { @@ -1045,6 +1061,21 @@ struct QueryStringWindow : public Window resize->width = 0; size->width = 0; } + + if (widget == WID_QS_WARNING) { + *size = this->warning_size; + } + } + + void DrawWidget(const Rect &r, int widget) const override + { + if (widget != WID_QS_WARNING) return; + + if (this->flags & QSF_PASSWORD) { + DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT - WD_FRAMERECT_RIGHT, + r.top + WD_FRAMERECT_TOP + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMERECT_BOTTOM - WD_FRAMETEXT_BOTTOM, + STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); + } } void SetStringParameters(int widget) const override @@ -1101,6 +1132,7 @@ static const NWidgetPart _nested_query_string_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2), EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY, WID_QS_WARNING), EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 2b992d099a..f7d779b9d7 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -1266,7 +1266,7 @@ void NetworkClientRequestMove(CompanyID company_id, const char *pass) */ void NetworkClientsToSpectators(CompanyID cid) { - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); /* If our company is changing owner, go to spectators */ if (cid == _local_company) SetLocalCompany(COMPANY_SPECTATOR); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 53bbc4cf7e..d1b5bdaa4c 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2146,15 +2146,17 @@ void ShowNetworkNeedPassword(NetworkPasswordType npt) case NETWORK_GAME_PASSWORD: caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break; case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break; } - ShowQueryString(STR_EMPTY, caption, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_EMPTY, caption, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_PASSWORD); } struct NetworkCompanyPasswordWindow : public Window { QueryString password_editbox; ///< Password editbox. + Dimension warning_size; ///< How much space to use for the warning text NetworkCompanyPasswordWindow(WindowDesc *desc, Window *parent) : Window(desc), password_editbox(lengthof(_settings_client.network.default_company_pass)) { this->InitNested(0); + this->UpdateWarningStringSize(); this->parent = parent; this->querystrings[WID_NCP_PASSWORD] = &this->password_editbox; @@ -2163,6 +2165,32 @@ struct NetworkCompanyPasswordWindow : public Window { this->SetFocusedWidget(WID_NCP_PASSWORD); } + void UpdateWarningStringSize() + { + assert(this->nested_root->smallest_x > 0); + this->warning_size.width = this->nested_root->current_x - (WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT); + this->warning_size.height = GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width); + this->warning_size.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; + + this->ReInit(); + } + + void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + { + if (widget == WID_NCP_WARNING) { + *size = this->warning_size; + } + } + + void DrawWidget(const Rect &r, int widget) const override + { + if (widget != WID_NCP_WARNING) return; + + DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, + r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, + STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); + } + void OnOk() { if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) { @@ -2209,6 +2237,7 @@ static const NWidgetPart _nested_network_company_password_window_widgets[] = { EndContainer(), EndContainer(), EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY, WID_NCP_WARNING), EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_COMPANY_PASSWORD_CANCEL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_OK), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_COMPANY_PASSWORD_OK), diff --git a/src/newgrf.cpp b/src/newgrf.cpp index dec72fadbf..501571ada8 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -662,7 +662,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern _engine_mngr.push_back({ scope_grfid, // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation internal_id, - {static_cast(type)}, + type, static_cast(min(internal_id, _engine_counts[type])) // substitute_id == _engine_counts[subtype] means "no substitute" }); diff --git a/src/newgrf.h b/src/newgrf.h index cf9bcba599..1a0b592ee4 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -238,7 +238,7 @@ struct GRFFile : ZeroedMemoryAllocator { uint8 cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID) std::vector railtype_list; ///< Railtype translation table - RailTypeByte railtype_map[RAILTYPE_END]; + RailType railtype_map[RAILTYPE_END]; CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF diff --git a/src/newgrf_station.h b/src/newgrf_station.h index 9cc2ccd78f..4e4fb2a377 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -81,13 +81,12 @@ struct StationResolverObject : public ResolverObject { const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override; }; -enum StationClassID { +enum StationClassID : byte { STAT_CLASS_BEGIN = 0, ///< the lowest valid value STAT_CLASS_DFLT = 0, ///< Default station class. STAT_CLASS_WAYP, ///< Waypoint class. - STAT_CLASS_MAX = 256, ///< Maximum number of classes. + STAT_CLASS_MAX = 255, ///< Maximum number of classes. }; -typedef SimpleTinyEnumT StationClassIDByte; template <> struct EnumPropsT : MakeEnumPropsT {}; /** Allow incrementing of StationClassID variables */ diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 7aee32cacb..7e99939b17 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -43,10 +43,10 @@ const NewsItem *_statusbar_news_item = nullptr; -static uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages -static uint _total_news = 0; ///< current number of news items -NewsItem *_oldest_news = nullptr; ///< head of news items queue -static NewsItem *_latest_news = nullptr; ///< tail of news items queue +static uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages +static uint _total_news = 0; ///< current number of news items +static NewsItem *_oldest_news = nullptr; ///< head of news items queue +NewsItem *_latest_news = nullptr; ///< tail of news items queue /** * Forced news item. @@ -54,7 +54,7 @@ static NewsItem *_latest_news = nullptr; ///< tail of news items queue * If the message being shown was forced by the user, a pointer is stored * in _forced_news. Otherwise, \a _forced_news variable is nullptr. */ -static const NewsItem *_forced_news = nullptr; ///< item the user has asked for +static const NewsItem *_forced_news = nullptr; /** Current news item (last item shown regularly). */ static const NewsItem *_current_news = nullptr; @@ -331,6 +331,11 @@ struct NewsWindow : Window { *size = maxdim(*size, GetSpriteSize(SPR_GRADIENT)); break; + case WID_N_MGR_NAME: + SetDParamStr(0, static_cast(this->ni->free_data)->president_name); + str = STR_JUST_RAW_STRING; + break; + case WID_N_MESSAGE: CopyInDParam(0, this->ni->params, lengthof(this->ni->params)); str = this->ni->string_id; diff --git a/src/news_gui.h b/src/news_gui.h index 0f42c68c6c..569a8b8a74 100644 --- a/src/news_gui.h +++ b/src/news_gui.h @@ -17,6 +17,6 @@ void ShowLastNewsMessage(); void ShowMessageHistory(); -extern NewsItem *_oldest_news; +extern NewsItem *_latest_news; #endif /* NEWS_GUI_H */ diff --git a/src/openttd.cpp b/src/openttd.cpp index c24570bebb..af2b02082f 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -63,6 +63,7 @@ #include "town.h" #include "subsidy_func.h" #include "gfx_layout.h" +#include "viewport_func.h" #include "viewport_sprite_sorter.h" #include "framerate_type.h" #include "programmable_signals.h" @@ -419,6 +420,7 @@ static void LoadIntroGame(bool load_newgrfs = true) SetLocalCompany(COMPANY_FIRST); } + FixTitleGameZoom(); _pause_mode = PM_UNPAUSED; _cursor.fix_at = false; @@ -1707,7 +1709,7 @@ void StateGameLoop() /* All these actions has to be done from OWNER_NONE * for multiplayer compatibility */ - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP); _tick_skip_counter++; diff --git a/src/openttd.h b/src/openttd.h index 4e074eee65..e4523bbe69 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -68,7 +68,7 @@ inline bool InEventLoopPostCrash() #endif /** Modes of pausing we've got */ -enum PauseMode { +enum PauseMode : byte { PM_UNPAUSED = 0, ///< A normal unpaused game PM_PAUSED_NORMAL = 1 << 0, ///< A game normally paused PM_PAUSED_SAVELOAD = 1 << 1, ///< A game paused for saving/loading @@ -82,10 +82,9 @@ enum PauseMode { PMB_PAUSED_NETWORK = PM_PAUSED_ACTIVE_CLIENTS | PM_PAUSED_JOIN, }; DECLARE_ENUM_AS_BIT_SET(PauseMode) -typedef SimpleTinyEnumT PauseModeByte; /** The current pause mode */ -extern PauseModeByte _pause_mode; +extern PauseMode _pause_mode; enum GameEventFlags : uint32 { GEF_COMPANY_DELETE = 1 << 0, ///< (d) A company has been deleted diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index a0e0804210..b371eba52c 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1846,7 +1846,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 * whether we are not going to a depot as there are three * cases where the full load flag can be active and only * one case where the flag is used for depot orders. In the - * other cases for the OrderTypeByte the flags are not used, + * other cases for the OrderType the flags are not used, * so do not care and those orders should not be active * when this function is called. */ diff --git a/src/order_type.h b/src/order_type.h index e0dc161743..91dd3db46b 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -34,8 +34,8 @@ static const OrderID INVALID_ORDER = 0xFFFFFF; */ static const uint IMPLICIT_ORDER_ONLY_CAP = 32; -/** Order types */ -enum OrderType { +/** Order types. It needs to be 8bits, because we save and load it as such */ +enum OrderType : byte { OT_BEGIN = 0, OT_NOTHING = 0, OT_GOTO_STATION = 1, @@ -45,16 +45,12 @@ enum OrderType { OT_DUMMY = 5, OT_GOTO_WAYPOINT = 6, OT_CONDITIONAL = 7, - OT_IMPLICIT = 8, - OT_WAITING = 9, + OT_IMPLICIT = 8, + OT_WAITING = 9, OT_LOADING_ADVANCE = 10, OT_END }; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT OrderTypeByte; - - /** * Flags related to the unloading order. */ diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 3ef430f965..606652df39 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -1127,7 +1127,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penal { Trackdir trackdir = v->GetVehicleTrackdir(); - AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; + AyStarUserData user = { v->owner, TRANSPORT_ROAD, RAILTYPES_NONE, v->compatible_roadtypes }; NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, INVALID_TILE, INVALID_TRACKDIR, false, nullptr, &user, 0, max_penalty); if (ftd.best_bird_dist != 0) return FindDepotData(); @@ -1147,7 +1147,7 @@ Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDir NPFFillWithOrderData(&fstd, v); Trackdir trackdir = DiagDirToDiagTrackdir(enterdir); - AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; + AyStarUserData user = { v->owner, TRANSPORT_ROAD, RAILTYPES_NONE, v->compatible_roadtypes }; NPFFoundTargetData ftd = NPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, true, &fstd, &user); assert(ftd.best_trackdir != INVALID_TRACKDIR); @@ -1170,7 +1170,7 @@ Track NPFShipChooseTrack(const Ship *v, bool &path_found) NPFFillWithOrderData(&fstd, v); - AyStarUserData user = { v->owner, TRANSPORT_WATER, INVALID_RAILTYPES, ROADTYPES_NONE }; + AyStarUserData user = { v->owner, TRANSPORT_WATER, RAILTYPES_NONE, ROADTYPES_NONE }; NPFFoundTargetData ftd = NPFRouteToStationOrTile(v->tile, trackdir, true, &fstd, &user); /* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains @@ -1194,7 +1194,7 @@ bool NPFShipCheckReverse(const Ship *v) assert(trackdir != INVALID_TRACKDIR); assert(trackdir_rev != INVALID_TRACKDIR); - AyStarUserData user = { v->owner, TRANSPORT_WATER, INVALID_RAILTYPES, ROADTYPES_NONE }; + AyStarUserData user = { v->owner, TRANSPORT_WATER, RAILTYPES_NONE, ROADTYPES_NONE }; ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, v->tile, trackdir_rev, false, &fstd, &user); /* If we didn't find anything, just keep on going straight ahead, otherwise take the reverse flag */ return ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE); diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index bcdaa2ad9d..27e0b49655 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -409,9 +409,7 @@ public: while (pNode->m_parent != nullptr) { steps--; if (pNode->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) { - TrackdirByte td; - td = pNode->GetTrackdir(); - path_cache.td.push_front(td); + path_cache.td.push_front(pNode->GetTrackdir()); path_cache.tile.push_front(pNode->GetTile()); } pNode = pNode->m_parent; diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index 96ba6d8ce9..ddf2af90b4 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -96,9 +96,7 @@ public: while (pNode->m_parent != nullptr) { steps--; if (steps > 0 && steps < YAPF_SHIP_PATH_CACHE_LENGTH) { - TrackdirByte td; - td = pNode->GetTrackdir(); - path_cache.push_front(td); + path_cache.push_front(pNode->GetTrackdir()); } pPrevNode = pNode; pNode = pNode->m_parent; diff --git a/src/plans_base.h b/src/plans_base.h index b1e335a63b..9aa2659114 100644 --- a/src/plans_base.h +++ b/src/plans_base.h @@ -158,7 +158,7 @@ struct PlanLine { }; struct Plan : PlanPool::PoolItem<&_plan_pool> { - OwnerByte owner; + Owner owner; PlanLineVector lines; PlanLine *temp_line; bool visible; diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index e566c99416..e61af4161f 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -982,7 +982,7 @@ bool FloodHalftile(TileIndex t) TrackBits to_remove = lower_track & rail_bits; if (to_remove != 0) { - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); flooded = DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Succeeded(); cur_company.Restore(); if (!flooded) return flooded; // not yet floodable diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index c0e02dedff..96544ae65e 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -490,6 +490,7 @@ struct BuildRailToolbarWindow : Window { ~BuildRailToolbarWindow() { + if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -855,6 +856,8 @@ struct BuildRailToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); this->DisableWidget(WID_RAT_REMOVE); this->SetWidgetDirty(WID_RAT_REMOVE); diff --git a/src/rail_type.h b/src/rail_type.h index 2bd602a37e..7e465866cf 100644 --- a/src/rail_type.h +++ b/src/rail_type.h @@ -26,7 +26,7 @@ static const RailTypeLabel RAILTYPE_MAGLEV_LABEL = 'MGLV'; * * This enumeration defines all 4 possible railtypes. */ -enum RailType { +enum RailType : byte { RAILTYPE_BEGIN = 0, ///< Used for iterations RAILTYPE_RAIL = 0, ///< Standard non-electric rails RAILTYPE_ELECTRIC = 1, ///< Electric rails @@ -44,7 +44,6 @@ enum RailType { DECLARE_POSTFIX_INCREMENT(RailType) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT RailTypeByte; /** * The different railtypes we support, but then a bitmask of them. diff --git a/src/road_gui.cpp b/src/road_gui.cpp index e177a97bd1..e0158d24bc 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -327,6 +327,7 @@ struct BuildRoadToolbarWindow : Window { ~BuildRoadToolbarWindow() { + if (_game_mode != GM_EDITOR && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -545,6 +546,8 @@ struct BuildRoadToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (_game_mode != GM_EDITOR && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); this->SetWidgetsDisabledState(true, WID_ROT_REMOVE, diff --git a/src/road_type.h b/src/road_type.h index 947b18cad1..491871a857 100644 --- a/src/road_type.h +++ b/src/road_type.h @@ -35,7 +35,7 @@ template <> struct EnumPropsT : MakeEnumPropsT struct EnumPropsT : MakeEnumPropsT {}; -typedef SimpleTinyEnumT RoadTypesByte; /** diff --git a/src/roadveh.h b/src/roadveh.h index 95a1b8f577..710add4538 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -84,7 +84,7 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length = false); void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type); struct RoadVehPathCache { - std::deque td; + std::deque td; std::deque tile; uint32 layout_ctr; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index e91332810a..746b5786ce 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1200,7 +1200,7 @@ static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicl static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadBits r) { /* The 'current' company is not necessarily the owner of the vehicle. */ - Backup cur_company(_current_company, c, FILE_LINE); + Backup cur_company(_current_company, c, FILE_LINE); CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, DC_NO_WATER, CMD_BUILD_ROAD); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 44cfe0d822..23e23f159a 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2038,7 +2038,7 @@ bool AfterLoadGame() if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) { Owner o = GetTileOwner(t); if (o < MAX_COMPANIES && !Company::IsValidID(o)) { - Backup cur_company(_current_company, o, FILE_LINE); + Backup cur_company(_current_company, o, FILE_LINE); ChangeTileOwner(t, o, INVALID_OWNER); cur_company.Restore(); } @@ -2339,7 +2339,7 @@ bool AfterLoadGame() _settings_game.economy.town_layout = TL_BETTER_ROADS; } else { _settings_game.economy.allow_town_roads = true; - _settings_game.economy.town_layout = _settings_game.economy.town_layout - 1; + _settings_game.economy.town_layout = static_cast(_settings_game.economy.town_layout - 1); } /* Initialize layout of all towns. Older versions were using different @@ -2358,7 +2358,7 @@ bool AfterLoadGame() case 5: layout = 1; break; case 0: layout = 2; break; } - t->layout = layout - 1; + t->layout = static_cast(layout - 1); } } @@ -3083,7 +3083,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_165)) { /* Adjust zoom level to account for new levels */ - _saved_scrollpos_zoom = _saved_scrollpos_zoom + ZOOM_LVL_SHIFT; + _saved_scrollpos_zoom = static_cast(_saved_scrollpos_zoom + ZOOM_LVL_SHIFT); _saved_scrollpos_x *= ZOOM_LVL_BASE; _saved_scrollpos_y *= ZOOM_LVL_BASE; } diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index 9e7e7145fe..77167d08d6 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -31,7 +31,7 @@ extern byte _trees_tick_ctr; /* Keep track of current game position */ int _saved_scrollpos_x; int _saved_scrollpos_y; -ZoomLevelByte _saved_scrollpos_zoom; +ZoomLevel _saved_scrollpos_zoom; void SaveViewportBeforeSaveGame() { diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp index c6a8a428d1..812b6cbe8c 100644 --- a/src/saveload/oldloader.cpp +++ b/src/saveload/oldloader.cpp @@ -315,7 +315,7 @@ bool LoadOldSaveGame(const char *file) return false; } - _pause_mode = 2; + _pause_mode = PM_PAUSED_SAVELOAD; return true; } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index 2b53eb3fc4..37f723a06f 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -1276,7 +1276,8 @@ bool LoadOldVehicle(LoadgameState *ls, int num) }; if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false; v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset - Train::From(v)->railtype = type == 0x25 ? 1 : 0; // monorail / rail + /* Should be the original values for monorail / rail, can't use RailType constants */ + Train::From(v)->railtype = static_cast(type == 0x25 ? 1 : 0); break; } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 370eb821b8..c76bfa67d8 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -3169,36 +3169,3 @@ void FileToSaveLoad::SetTitle(const char *title) { strecpy(this->title, title, lastof(this->title)); } - -#if 0 -/** - * Function to get the type of the savegame by looking at the file header. - * NOTICE: Not used right now, but could be used if extensions of savegames are garbled - * @param file Savegame to be checked - * @return SL_OLD_LOAD or SL_LOAD of the file - */ -int GetSavegameType(char *file) -{ - const SaveLoadFormat *fmt; - uint32 hdr; - FILE *f; - int mode = SL_OLD_LOAD; - - f = fopen(file, "rb"); - if (fread(&hdr, sizeof(hdr), 1, f) != 1) { - DEBUG(sl, 0, "Savegame is obsolete or invalid format"); - mode = SL_LOAD; // don't try to get filename, just show name as it is written - } else { - /* see if we have any loader for this type. */ - for (fmt = _saveload_formats; fmt != endof(_saveload_formats); fmt++) { - if (fmt->tag == hdr) { - mode = SL_LOAD; // new type of savegame - break; - } - } - } - - fclose(f); - return mode; -} -#endif diff --git a/src/saveload/saveload_internal.h b/src/saveload/saveload_internal.h index d0fecce4e6..b82fe0fdb5 100644 --- a/src/saveload/saveload_internal.h +++ b/src/saveload/saveload_internal.h @@ -53,7 +53,7 @@ void AfterLoadTemplateVehiclesUpdateImage(); extern int32 _saved_scrollpos_x; extern int32 _saved_scrollpos_y; -extern ZoomLevelByte _saved_scrollpos_zoom; +extern ZoomLevel _saved_scrollpos_zoom; extern SavegameType _savegame_type; extern uint32 _ttdp_version; diff --git a/src/saveload/tbtr_template_veh_sl.cpp b/src/saveload/tbtr_template_veh_sl.cpp index 7ec5d95569..a4dfa95089 100644 --- a/src/saveload/tbtr_template_veh_sl.cpp +++ b/src/saveload/tbtr_template_veh_sl.cpp @@ -120,7 +120,7 @@ void AfterLoadTemplateVehiclesUpdateImage() FOR_ALL_TEMPLATES(tv) { if (tv->Prev() == nullptr) { - Backup cur_company(_current_company, tv->owner, FILE_LINE); + Backup cur_company(_current_company, tv->owner, FILE_LINE); StringID err; Train* t = VirtualTrainFromTemplateVehicle(tv, err); if (t != nullptr) { diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 66ef145fc2..70a1a27394 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -36,7 +36,7 @@ struct OldWaypoint { uint8 localidx; uint32 grfid; const StationSpec *spec; - OwnerByte owner; + Owner owner; size_t new_index; }; diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index 39336037aa..143caec27e 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -638,6 +638,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_A_WEBSITE, "WID_A_WEBSITE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_CAPTION, "WID_QS_CAPTION"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_TEXT, "WID_QS_TEXT"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_WARNING, "WID_QS_WARNING"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_DEFAULT, "WID_QS_DEFAULT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_CANCEL, "WID_QS_CANCEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_OK, "WID_QS_OK"); @@ -782,6 +783,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_LABEL, "WID_NCP_LABEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_PASSWORD, "WID_NCP_PASSWORD"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_SAVE_AS_DEFAULT_PASSWORD, "WID_NCP_SAVE_AS_DEFAULT_PASSWORD"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_WARNING, "WID_NCP_WARNING"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_CANCEL, "WID_NCP_CANCEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_OK, "WID_NCP_OK"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NGRFI_CAPTION, "WID_NGRFI_CAPTION"); @@ -1118,6 +1120,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_ROADVEHS, "WID_SV_ROADVEHS"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_SHIPS, "WID_SV_SHIPS"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_PLANES, "WID_SV_PLANES"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_CATCHMENT, "WID_SV_CATCHMENT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_CAPTION, "WID_STL_CAPTION"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_LIST, "WID_STL_LIST"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_SCROLLBAR, "WID_STL_SCROLLBAR"); @@ -1262,6 +1265,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_CENTER_VIEW, "WID_TV_CENTER_VIEW"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_SHOW_AUTHORITY, "WID_TV_SHOW_AUTHORITY"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_CHANGE_NAME, "WID_TV_CHANGE_NAME"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_CATCHMENT, "WID_TV_CATCHMENT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_EXPAND, "WID_TV_EXPAND"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_DELETE, "WID_TV_DELETE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_NEW_TOWN, "WID_TF_NEW_TOWN"); diff --git a/src/script/api/script_cargomonitor.cpp b/src/script/api/script_cargomonitor.cpp index 3cb9b4a8e7..e862fed3e6 100644 --- a/src/script/api/script_cargomonitor.cpp +++ b/src/script/api/script_cargomonitor.cpp @@ -20,7 +20,7 @@ /* static */ int32 ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Town::IsValidID(town_id)) return -1; @@ -31,7 +31,7 @@ /* static */ int32 ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Industry::IsValidID(industry_id)) return -1; @@ -42,7 +42,7 @@ /* static */ int32 ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Town::IsValidID(town_id)) return -1; @@ -53,7 +53,7 @@ /* static */ int32 ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Industry::IsValidID(industry_id)) return -1; diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index b842cb47f0..e0bbdb0024 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -68,7 +68,7 @@ /* static */ bool ScriptRail::IsRailTypeAvailable(RailType rail_type) { - if ((::RailType)rail_type < RAILTYPE_BEGIN || (::RailType)rail_type >= RAILTYPE_END) return false; + if ((::RailType)rail_type >= RAILTYPE_END) return false; return ScriptObject::GetCompany() == OWNER_DEITY || ::HasRailtypeAvail(ScriptObject::GetCompany(), (::RailType)rail_type); } diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 6c178f50ec..def1d251f4 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -1622,6 +1622,7 @@ public: enum QueryStringWidgets { WID_QS_CAPTION = ::WID_QS_CAPTION, ///< Caption of the window. WID_QS_TEXT = ::WID_QS_TEXT, ///< Text of the query. + WID_QS_WARNING = ::WID_QS_WARNING, ///< Warning label about password security WID_QS_DEFAULT = ::WID_QS_DEFAULT, ///< Default button. WID_QS_CANCEL = ::WID_QS_CANCEL, ///< Cancel button. WID_QS_OK = ::WID_QS_OK, ///< OK button. @@ -1841,6 +1842,7 @@ public: WID_NCP_LABEL = ::WID_NCP_LABEL, ///< Label in front of the password field. WID_NCP_PASSWORD = ::WID_NCP_PASSWORD, ///< Input field for the password. WID_NCP_SAVE_AS_DEFAULT_PASSWORD = ::WID_NCP_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password. + WID_NCP_WARNING = ::WID_NCP_WARNING, ///< Warning text about password security WID_NCP_CANCEL = ::WID_NCP_CANCEL, ///< Close the window without changing anything. WID_NCP_OK = ::WID_NCP_OK, ///< Safe the password etc. }; @@ -2328,6 +2330,7 @@ public: WID_SV_ROADVEHS = ::WID_SV_ROADVEHS, ///< List of scheduled road vehs button. WID_SV_SHIPS = ::WID_SV_SHIPS, ///< List of scheduled ships button. WID_SV_PLANES = ::WID_SV_PLANES, ///< List of scheduled planes button. + WID_SV_CATCHMENT = ::WID_SV_CATCHMENT, ///< Toggle catchment area highlight. }; /** Widgets of the #CompanyStationsWindow class. */ @@ -2539,6 +2542,7 @@ public: WID_TV_CENTER_VIEW = ::WID_TV_CENTER_VIEW, ///< Center the main view on this town. WID_TV_SHOW_AUTHORITY = ::WID_TV_SHOW_AUTHORITY, ///< Show the town authority window. WID_TV_CHANGE_NAME = ::WID_TV_CHANGE_NAME, ///< Change the name of this town. + WID_TV_CATCHMENT = ::WID_TV_CATCHMENT, ///< Toggle catchment area highlight. WID_TV_EXPAND = ::WID_TV_EXPAND, ///< Expand this town (scenario editor only). WID_TV_DELETE = ::WID_TV_DELETE, ///< Delete this town (scenario editor only). }; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 123844ec36..9435a1b5c3 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -37,6 +37,7 @@ #include "stringfilter_type.h" #include "querystring_gui.h" #include "fontcache.h" +#include "zoom_func.h" #include @@ -543,6 +544,7 @@ struct GameOptionsWindow : Window { _gui_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index); UpdateCursorSize(); UpdateAllVirtCoords(); + FixTitleGameZoom(); ReInitAllWindows(); break; diff --git a/src/settings_internal.h b/src/settings_internal.h index c6f9b06dd3..3d7b4a17d3 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -20,7 +20,7 @@ * @see VarTypes * @see SettingDescBase */ -enum SettingDescTypeLong { +enum SettingDescType : byte { /* 4 bytes allocated a maximum of 16 types for GenericType */ SDT_BEGIN = 0, SDT_NUMX = 0, ///< any number-type @@ -32,10 +32,9 @@ enum SettingDescTypeLong { SDT_END, /* 10 more possible primitives */ }; -typedef SimpleTinyEnumT SettingDescType; -enum SettingGuiFlagLong { +enum SettingGuiFlag : uint16 { /* 1 byte allocated for a maximum of 8 flags * Flags directing saving/loading of a variable */ SGF_NONE = 0, @@ -52,8 +51,7 @@ enum SettingGuiFlagLong { SGF_ENUM = 1 << 10,///< the setting can take one of the values given by an array of struct SettingDescEnumEntry SGF_NO_NEWGAME = 1 << 11,///< the setting does not apply and is not shown in a new game context }; -DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong) -typedef SimpleTinyEnumT SettingGuiFlag; +DECLARE_ENUM_AS_BIT_SET(SettingGuiFlag) /** * A SettingCategory defines a grouping of the settings. diff --git a/src/settings_type.h b/src/settings_type.h index 76a95c6625..7f4dfdd0df 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -108,8 +108,8 @@ struct GUISettings { uint8 statusbar_pos; ///< position of statusbar, 0=left, 1=center, 2=right uint8 window_snap_radius; ///< windows snap at each other if closer than this uint8 window_soft_limit; ///< soft limit of maximum number of non-stickied non-vital windows (0 = no limit) - ZoomLevelByte zoom_min; ///< minimum zoom out level - ZoomLevelByte zoom_max; ///< maximum zoom out level + ZoomLevel zoom_min; ///< minimum zoom out level + ZoomLevel zoom_max; ///< maximum zoom out level bool disable_unsuitable_building; ///< disable infrastructure building when no suitable vehicles are available byte autosave; ///< how often should we do autosaves? bool threaded_saves; ///< should we do threaded saves? @@ -563,11 +563,11 @@ struct EconomySettings { uint8 town_growth_cargo_transported; ///< percentage of town growth rate which depends on proportion of transported cargo in the last month uint8 larger_towns; ///< the number of cities to build. These start off larger and grow twice as fast uint8 initial_city_size; ///< multiplier for the initial size of the cities compared to towns - TownLayoutByte town_layout; ///< select town layout, @see TownLayout + TownLayout town_layout; ///< select town layout, @see TownLayout TownCargoGenMode town_cargogen_mode; ///< algorithm for generating cargo from houses, @see TownCargoGenMode bool allow_town_roads; ///< towns are allowed to build roads (always allowed when generating world / in SE) uint16 town_min_distance; ///< minimum distance between towns - TownFoundingByte found_town; ///< town founding, @see TownFounding + TownFounding found_town; ///< town founding. bool station_noise_level; ///< build new airports when the town noise level is still within accepted limits uint16 town_noise_population[3]; ///< population to base decision on noise evaluation (@see town_council_tolerance) bool infrastructure_sharing[4]; ///< enable infrastructure sharing for rail/road/water/air diff --git a/src/ship.h b/src/ship.h index 8dd873f671..e739097229 100644 --- a/src/ship.h +++ b/src/ship.h @@ -22,17 +22,17 @@ extern const DiagDirection _ship_search_directions[TRACK_END][DIAGDIR_END]; void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type); WaterClass GetEffectiveWaterClass(TileIndex tile); -typedef std::deque ShipPathCache; +typedef std::deque ShipPathCache; /** * All ships have this type. */ struct Ship FINAL : public SpecializedVehicle { - TrackBitsByte state; ///< The "track" the ship is following. - ShipPathCache path; ///< Cached path. - DirectionByte rotation; ///< Visible direction. - int16 rotation_x_pos; ///< NOSAVE: X Position before rotation. - int16 rotation_y_pos; ///< NOSAVE: Y Position before rotation. + TrackBits state; ///< The "track" the ship is following. + ShipPathCache path; ///< Cached path. + Direction rotation; ///< Visible direction. + int16 rotation_x_pos; ///< NOSAVE: X Position before rotation. + int16 rotation_y_pos; ///< NOSAVE: Y Position before rotation. /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ Ship() : SpecializedVehicleBase() {} diff --git a/src/signs_base.h b/src/signs_base.h index 3e7b4c4651..a4ee0718b7 100644 --- a/src/signs_base.h +++ b/src/signs_base.h @@ -26,7 +26,7 @@ struct Sign : SignPool::PoolItem<&_sign_pool> { int32 x; int32 y; int32 z; - OwnerByte owner; // placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games. + Owner owner; // placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games. Sign(Owner owner = INVALID_OWNER); ~Sign(); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 4c0d020ccd..cc5e36a0e7 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -472,7 +472,7 @@ static void NotifyAllViewports(ViewportMapType map_type) } } -/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleTypeByte. */ +/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleType. */ static const byte _vehicle_type_colours[6] = { PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED }; diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 90327f01fd..870a022460 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -36,8 +36,6 @@ /* Default of 4MB spritecache */ uint _sprite_cache_size = 4; -typedef SimpleTinyEnumT SpriteTypeByte; - static size_t _spritecache_bytes_used = 0; PACK_N(class SpriteDataBuffer { diff --git a/src/station_base.h b/src/station_base.h index 8703df243d..cbbb041957 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -315,7 +315,7 @@ struct Airport : public TileArea { uint64 flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 byte type; ///< Type of this airport, @see AirportTypes byte layout; ///< Airport layout number. - DirectionByte rotation; ///< How this airport is rotated. + Direction rotation; ///< How this airport is rotated. PersistentStorage *psa; ///< Persistent storage for NewGRF airports. @@ -476,7 +476,7 @@ public: BitmapTileArea catchment_tiles; ///< NOSAVE: Set of individual tiles covered by catchment area - StationHadVehicleOfTypeByte had_vehicle_of_type; + StationHadVehicleOfType had_vehicle_of_type; byte time_since_load; byte time_since_unload; diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 46805e1534..804e0cb033 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -83,6 +83,46 @@ int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageTyp return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO); } +/** + * Find stations adjacent to the current tile highlight area, so that existing coverage + * area can be drawn. + */ +static void FindStationsAroundSelection() +{ + /* With distant join we don't know which station will be selected, so don't show any */ + if (_ctrl_pressed) { + SetViewportCatchmentStation(nullptr, true); + return; + } + + /* Tile area for TileHighlightData */ + TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1); + + /* Extended area by one tile */ + uint x = TileX(location.tile); + uint y = TileY(location.tile); + + int max_c = 1; + TileArea ta(TileXY(max(0, x - max_c), max(0, y - max_c)), TileXY(min(MapMaxX(), x + location.w + max_c), min(MapMaxY(), y + location.h + max_c))); + + Station *adjacent = nullptr; + + /* Direct loop instead of FindStationsAroundTiles as we are not interested in catchment area */ + TILE_AREA_LOOP(tile, ta) { + if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) { + Station *st = Station::GetByTile(tile); + if (st == nullptr) continue; + if (adjacent != nullptr && st != adjacent) { + /* Multiple nearby, distant join is required. */ + adjacent = nullptr; + break; + } + adjacent = st; + } + } + SetViewportCatchmentStation(adjacent, true); +} + /** * Check whether we need to redraw the station coverage text. * If it is needed actually make the window for redrawing. @@ -90,9 +130,20 @@ int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageTyp */ void CheckRedrawStationCoverage(const Window *w) { + /* Test if ctrl state changed */ + static bool _last_ctrl_pressed; + if (_ctrl_pressed != _last_ctrl_pressed) { + _thd.dirty = 0xff; + _last_ctrl_pressed = _ctrl_pressed; + } + if (_thd.dirty & 1) { _thd.dirty &= ~1; w->SetDirty(); + + if (_settings_client.gui.station_show_coverage && _thd.drawstyle == HT_RECT) { + FindStationsAroundSelection(); + } } } @@ -779,6 +830,7 @@ static const NWidgetPart _nested_station_view_widgets[] = { EndContainer(), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP), @@ -1301,6 +1353,8 @@ struct StationViewWindow : public Window { DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false); DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false); DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false); + + SetViewportCatchmentStation(Station::Get(this->window_number), false); } /** @@ -1396,6 +1450,10 @@ struct StationViewWindow : public Window { this->SetWidgetDisabledState(WID_SV_CLOSE_AIRPORT, !(st->facilities & FACIL_AIRPORT) || st->owner != _local_company || st->owner == OWNER_NONE); // Also consider SE, where _local_company == OWNER_NONE this->SetWidgetLoweredState(WID_SV_CLOSE_AIRPORT, (st->facilities & FACIL_AIRPORT) && (st->airport.flags & AIRPORT_CLOSED_block) != 0); + extern const Station *_viewport_highlight_station; + this->SetWidgetDisabledState(WID_SV_CATCHMENT, st->facilities == FACIL_NONE); + this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st); + this->DrawWidgets(); if (!this->IsShaded()) { @@ -1877,6 +1935,10 @@ struct StationViewWindow : public Window { this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL) - this->vscroll->GetPosition()); break; + case WID_SV_CATCHMENT: + SetViewportCatchmentStation(Station::Get(this->window_number), !this->IsWidgetLowered(WID_SV_CATCHMENT)); + break; + case WID_SV_LOCATION: if (_ctrl_pressed) { ShowExtraViewPortWindow(Station::Get(this->window_number)->xy); @@ -2254,6 +2316,15 @@ struct SelectStationWindow : Window { this->GetWidget(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION; this->FinishInitNested(0); this->OnInvalidateData(0); + + _thd.freeze = true; + } + + ~SelectStationWindow() + { + if (_settings_client.gui.station_show_coverage) SetViewportCatchmentStation(nullptr, true); + + _thd.freeze = false; } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override @@ -2343,6 +2414,23 @@ struct SelectStationWindow : Window { this->vscroll->SetCount((uint)_stations_nearby_list.size() + 1); this->SetDirty(); } + + void OnMouseOver(Point pt, int widget) override + { + if (widget != WID_JS_PANEL || T::EXPECTED_FACIL == FACIL_WAYPOINT) { + SetViewportCatchmentStation(nullptr, true); + return; + } + + /* Show coverage area of station under cursor */ + uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP); + if (st_index == 0 || st_index > _stations_nearby_list.size()) { + SetViewportCatchmentStation(nullptr, true); + } else { + st_index--; + SetViewportCatchmentStation(Station::Get(_stations_nearby_list[st_index]), true); + } + } }; static WindowDesc _select_station_desc( diff --git a/src/station_type.h b/src/station_type.h index 28d4d3fbe1..bb246e0c77 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -51,7 +51,7 @@ enum RoadStopType { }; /** The facilities a station might be having */ -enum StationFacility { +enum StationFacility : byte { FACIL_NONE = 0, ///< The station has no facilities at all FACIL_TRAIN = 1 << 0, ///< Station with train station FACIL_TRUCK_STOP = 1 << 1, ///< Station with truck stops @@ -61,10 +61,9 @@ enum StationFacility { FACIL_WAYPOINT = 1 << 7, ///< Station is a waypoint }; DECLARE_ENUM_AS_BIT_SET(StationFacility) -typedef SimpleTinyEnumT StationFacilityByte; /** The vehicles that may have visited a station */ -enum StationHadVehicleOfType { +enum StationHadVehicleOfType : byte { HVOT_NONE = 0, ///< Station has seen no vehicles HVOT_TRAIN = 1 << 1, ///< Station has seen a train HVOT_BUS = 1 << 2, ///< Station has seen a bus @@ -75,7 +74,6 @@ enum StationHadVehicleOfType { HVOT_WAYPOINT = 1 << 6, ///< Station is a waypoint (NewGRF only!) }; DECLARE_ENUM_AS_BIT_SET(StationHadVehicleOfType) -typedef SimpleTinyEnumT StationHadVehicleOfTypeByte; /** The different catchment areas used */ enum CatchmentArea { diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index ff775fde9b..5ada8e995d 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -27,6 +27,7 @@ #include "toolbar_gui.h" #include "core/geometry_func.hpp" #include "guitimer_func.h" +#include "zoom_func.h" #include "widgets/statusbar_widget.h" @@ -167,7 +168,7 @@ struct StatusBarWindow : Window { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, msg, TC_FROMSTRING, SA_HOR_CENTER); } else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == nullptr && _statusbar_news_item != nullptr && _statusbar_news_item->string_id != 0) { /* Draw the scrolling news text */ - if (!DrawScrollingStatusText(_statusbar_news_item, this->ticker_scroll, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) { + if (!DrawScrollingStatusText(_statusbar_news_item, ScaleGUITrad(this->ticker_scroll), r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) { InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); if (Company::IsValidID(_local_company)) { /* This is the default text */ diff --git a/src/stdafx.h b/src/stdafx.h index 6c81cdab5b..84d31ec2cb 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -280,17 +280,17 @@ /* MSVCRT of course has to have a different syntax for long long *sigh* */ #if defined(_MSC_VER) || defined(__MINGW32__) - #define OTTD_PRINTF64 "%I64d" - #define OTTD_PRINTF64U "%I64u" - #define OTTD_PRINTFHEX64 "%I64x" - #define PRINTF_SIZE "%Iu" - #define PRINTF_SIZEX "%IX" +# define OTTD_PRINTF64 "%I64d" +# define OTTD_PRINTF64U "%I64u" +# define OTTD_PRINTFHEX64 "%I64x" +# define PRINTF_SIZE "%Iu" +# define PRINTF_SIZEX "%IX" #else - #define OTTD_PRINTF64 "%lld" - #define OTTD_PRINTF64U "%llu" - #define OTTD_PRINTFHEX64 "%llx" - #define PRINTF_SIZE "%zu" - #define PRINTF_SIZEX "%zX" +# define OTTD_PRINTF64 "%lld" +# define OTTD_PRINTF64U "%llu" +# define OTTD_PRINTFHEX64 "%llx" +# define PRINTF_SIZE "%zu" +# define PRINTF_SIZEX "%zX" #endif typedef unsigned char byte; diff --git a/src/story_base.h b/src/story_base.h index 139c41dab7..4cc857b8d3 100644 --- a/src/story_base.h +++ b/src/story_base.h @@ -27,7 +27,7 @@ extern uint32 _story_page_next_sort_value; /* * Each story page element is one of these types. */ -enum StoryPageElementType { +enum StoryPageElementType : byte { SPET_TEXT = 0, ///< A text element. SPET_LOCATION, ///< An element that references a tile along with a one-line text. SPET_GOAL, ///< An element that references a goal. @@ -37,7 +37,6 @@ enum StoryPageElementType { /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT StoryPageElementTypeByte; ///< typedefing-enumification of Direction /** * Struct about story page elements. @@ -47,7 +46,7 @@ typedef TinyEnumT StoryPageElementTypeByte; ///< typedefin struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> { uint32 sort_value; ///< A number that increases for every created story page element. Used for sorting. The id of a story page element is the pool index. StoryPageID page; ///< Id of the page which the page element belongs to - StoryPageElementTypeByte type; ///< Type of page element + StoryPageElementType type; ///< Type of page element uint32 referenced_id; ///< Id of referenced object (location, goal etc.) char *text; ///< Static content text of page element @@ -70,7 +69,7 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> { uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index. Date date; ///< Date when the page was created. - CompanyByte company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global + CompanyID company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global char *title; ///< Title of story page diff --git a/src/subsidy_base.h b/src/subsidy_base.h index 780302e0a2..a7f6f4f3ee 100644 --- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -22,13 +22,13 @@ extern SubsidyPool _subsidy_pool; /** Struct about subsidies, offered and awarded */ struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { - CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy - byte remaining; ///< Remaining months when this subsidy is valid - CompanyByte awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone - SourceTypeByte src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) - SourceTypeByte dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) - SourceID src; ///< Index of source. Either TownID or IndustryID - SourceID dst; ///< Index of destination. Either TownID or IndustryID + CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy + byte remaining; ///< Remaining months when this subsidy is valid + CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone + SourceType src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) + SourceType dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) + SourceID src; ///< Index of source. Either TownID or IndustryID + SourceID dst; ///< Index of destination. Either TownID or IndustryID /** * We need an (empty) constructor so struct isn't zeroed (as C++ standard states) diff --git a/src/subsidy_type.h b/src/subsidy_type.h index 83c33a00a9..968351ffb3 100644 --- a/src/subsidy_type.h +++ b/src/subsidy_type.h @@ -15,14 +15,11 @@ #include "core/enum_type.hpp" /** What part of a subsidy is something? */ -enum PartOfSubsidy { +enum PartOfSubsidy : byte { POS_NONE = 0, ///< nothing POS_SRC = 1 << 0, ///< bit 0 set -> town/industry is source of subsidised path POS_DST = 1 << 1, ///< bit 1 set -> town/industry is destination of subsidised path }; -/** Helper to store the PartOfSubsidy data in a single byte. */ -typedef SimpleTinyEnumT PartOfSubsidyByte; - DECLARE_ENUM_AS_BIT_SET(PartOfSubsidy) typedef uint16 SubsidyID; ///< ID of a subsidy diff --git a/src/table/airport_movement.h b/src/table/airport_movement.h index d9030f652c..df368de892 100644 --- a/src/table/airport_movement.h +++ b/src/table/airport_movement.h @@ -34,7 +34,7 @@ struct AirportFTAbuildup { * @param flags Movement flags. * @param dir Direction. */ -#define AMD(x, y, flags, dir) { x, y, flags, {dir} } +#define AMD(x, y, flags, dir) { x, y, flags, dir } /** Dummy airport. */ static const AirportMovingData _airport_moving_data_dummy[] = { diff --git a/src/table/currency_settings.ini b/src/table/currency_settings.ini index 985b9e8a9b..b26c8265dd 100644 --- a/src/table/currency_settings.ini +++ b/src/table/currency_settings.ini @@ -18,7 +18,7 @@ SDT_END = SDT_END() [defaults] flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/engines.h b/src/table/engines.h index 3b29a8dc17..a5acd28439 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -388,7 +388,7 @@ static const EngineInfo _orig_engine_info[] = { * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76 * Air drag value depends on the top speed of the vehicle. */ -#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, {j}, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0 } +#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0 } #define M RAILVEH_MULTIHEAD #define W RAILVEH_WAGON #define G RAILVEH_SINGLEHEAD diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini index e07ec55656..1b52fac336 100644 --- a/src/table/gameopt_settings.ini +++ b/src/table/gameopt_settings.ini @@ -51,7 +51,7 @@ SDT_END = SDT_END() [defaults] flags = 0 -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index 823cca2e96..9df045ac8c 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -25,7 +25,7 @@ SDTG_END = SDTG_END() [defaults] flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index f829c069fd..83de348c34 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -57,7 +57,7 @@ static size_t ConvertLandscape(const char *value); */ #define NSD_GENERAL(name, def, cmd, guiflags, min, max, interval, many, str, strhelp, strval, proc, load, cat, enumlist)\ - {name, (const void*)(size_t)(def), {(byte)cmd}, {(uint16)guiflags}, min, max, interval, many, str, strhelp, strval, proc, load, cat, enumlist} + {name, (const void*)(size_t)(def), cmd, guiflags, min, max, interval, many, str, strhelp, strval, proc, load, cat, enumlist} /* Macros for various objects to go in the configuration file. * This section is for global variables */ @@ -89,9 +89,9 @@ static size_t ConvertLandscape(const char *value); SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, strhelp, strval, proc, from, to, cat, extver, patxname) #define SDTG_NULL(length, from, to, extver)\ - {{"", nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLEG_NULL_X(length, from, to, extver), nullptr, nullptr, nullptr} + {{"", nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLEG_NULL_X(length, from, to, extver), nullptr, nullptr, nullptr} -#define SDTG_END() {{nullptr, nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLEG_END(), nullptr, nullptr, nullptr} +#define SDTG_END() {{nullptr, nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLEG_END(), nullptr, nullptr, nullptr} /* Macros for various objects to go in the configuration file. * This section is for structures where their various members are saved */ @@ -126,7 +126,7 @@ static size_t ConvertLandscape(const char *value); SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, strhelp, strval, proc, nullptr, from, to, cat, extver, patxname) #define SDT_NULL(length, from, to, extver)\ - {{"", nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLE_CONDNULL_X(length, from, to, extver), nullptr, nullptr, nullptr} + {{"", nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLE_CONDNULL_X(length, from, to, extver), nullptr, nullptr, nullptr} #define SDTC_VAR(var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extver, patxname, orderproc)\ @@ -148,7 +148,7 @@ static size_t ConvertLandscape(const char *value); SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extver, patxname) #define SDT_XREF(from, to, extver, xref)\ - {{"", nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLE_CONDNULL_X(0, from, to, extver), nullptr, xref, nullptr} + {{"", nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLE_CONDNULL_X(0, from, to, extver), nullptr, xref, nullptr} -#define SDT_END() {{nullptr, nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLE_END(), nullptr, nullptr, nullptr} +#define SDT_END() {{nullptr, nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, nullptr}, SLE_END(), nullptr, nullptr, nullptr} diff --git a/src/table/settings.ini b/src/table/settings.ini index bd4effbea2..5dcd56d638 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -126,7 +126,7 @@ SDT_LINKGRAPH_PER_CARGO = SDT_ENUM(GameSettings, linkgraph.distribution_per_carg [defaults] flags = 0 -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/win32_settings.ini b/src/table/win32_settings.ini index 58608edaf8..ac5672a7cc 100644 --- a/src/table/win32_settings.ini +++ b/src/table/win32_settings.ini @@ -23,7 +23,7 @@ SDTG_END = SDTG_END() [defaults] flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/window_settings.ini b/src/table/window_settings.ini index ce0037278e..f2f4dc20a3 100644 --- a/src/table/window_settings.ini +++ b/src/table/window_settings.ini @@ -19,7 +19,7 @@ SDT_END = SDT_END() [defaults] base = WindowDesc flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/tbtr_template_vehicle.h b/src/tbtr_template_vehicle.h index b7c35bcb47..fc46dae328 100644 --- a/src/tbtr_template_vehicle.h +++ b/src/tbtr_template_vehicle.h @@ -93,7 +93,7 @@ public: bool replace_old_only; // Things derived from a virtual train - OwnerByte owner; + Owner owner; EngineID engine_type; ///< The type of engine used for this vehicle. CargoID cargo_type; ///< type of cargo this vehicle is carrying @@ -101,7 +101,7 @@ public: byte cargo_subtype; byte subtype; - RailTypeByte railtype; + RailType railtype; VehicleID index; diff --git a/src/textbuf_gui.h b/src/textbuf_gui.h index ec134c11c6..e8f5159f94 100644 --- a/src/textbuf_gui.h +++ b/src/textbuf_gui.h @@ -22,6 +22,7 @@ enum QueryStringFlags { QSF_ACCEPT_UNCHANGED = 0x01, ///< return success even when the text didn't change QSF_ENABLE_DEFAULT = 0x02, ///< enable the 'Default' button ("\0" is returned) QSF_LEN_IN_CHARS = 0x04, ///< the length of the string is counted in characters + QSF_PASSWORD = 0x08, ///< password entry box, show warning about password security }; DECLARE_ENUM_AS_BIT_SET(QueryStringFlags) diff --git a/src/tilehighlight_type.h b/src/tilehighlight_type.h index 09c1edbcf6..d3d8da5b3c 100644 --- a/src/tilehighlight_type.h +++ b/src/tilehighlight_type.h @@ -55,6 +55,8 @@ struct TileHighlightData { Point outersize; ///< Size, in tile "units", of the blue coverage area excluding the side of the selected area. bool diagonal; ///< Whether the dragged area is a 45 degrees rotated rectangle. + bool freeze; ///< Freeze highlight in place. + Point new_pos; ///< New value for \a pos; used to determine whether to redraw the selection. Point new_size; ///< New value for \a size; used to determine whether to redraw the selection. Point new_offs; ///< New value for \a offs; used to determine whether to redraw the selection. diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index be2d161705..457962388e 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -943,7 +943,9 @@ static CallBackFunction MenuClickBuildRoad(int index) static CallBackFunction ToolbarBuildWaterClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_WATER, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 1); + DropDownList list; + list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false)); + ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true, true); return CBF_NONE; } @@ -963,7 +965,9 @@ static CallBackFunction MenuClickBuildWater(int index) static CallBackFunction ToolbarBuildAirClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_AIR, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 1); + DropDownList list; + list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false)); + ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true, true); return CBF_NONE; } @@ -983,7 +987,11 @@ static CallBackFunction MenuClickBuildAir(int index) static CallBackFunction ToolbarForestClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 3); + DropDownList list; + list.emplace_back(new DropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0, false)); + list.emplace_back(new DropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1, false)); + list.emplace_back(new DropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2, false)); + ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true, true); return CBF_NONE; } @@ -1007,7 +1015,7 @@ static CallBackFunction MenuClickForest(int index) static CallBackFunction ToolbarMusicClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1); + PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1); return CBF_NONE; } @@ -1062,7 +1070,7 @@ static CallBackFunction PlaceLandBlockInfo() static CallBackFunction ToolbarHelpClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10); + PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10); return CBF_NONE; } @@ -1184,7 +1192,7 @@ static CallBackFunction ToolbarSwitchClick(Window *w) } w->ReInit(); - w->SetWidgetLoweredState(WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER); + w->SetWidgetLoweredState(_game_mode == GM_EDITOR ? (uint)WID_TE_SWITCH_BAR : (uint)WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -1254,7 +1262,7 @@ static CallBackFunction ToolbarScenGenIndustry(Window *w) return CBF_NONE; } -static CallBackFunction ToolbarScenBuildRoad(Window *w) +static CallBackFunction ToolbarScenBuildRoadClick(Window *w) { w->HandleButtonClick(WID_TE_ROADS); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); @@ -1879,10 +1887,12 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer { WID_TE_SETTINGS, WID_TE_SAVE, WID_TE_DATE_PANEL, + WID_TE_SMALL_MAP, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT, WID_TE_MUSIC_SOUND, - WID_TE_HELP, WID_TE_SWITCH_BAR, + WID_TE_HELP, + WID_TE_SWITCH_BAR, }; /* If we can place all buttons *and* the panels, show them. */ @@ -2273,6 +2283,31 @@ static WindowDesc _toolb_normal_desc( /* --- Toolbar handling for the scenario editor */ +static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = { + nullptr, // 0 + nullptr, // 1 + MenuClickSettings, // 2 + MenuClickSaveLoad, // 3 + nullptr, // 4 + nullptr, // 5 + nullptr, // 6 + nullptr, // 7 + MenuClickMap, // 8 + nullptr, // 9 + nullptr, // 10 + nullptr, // 11 + nullptr, // 12 + nullptr, // 13 + nullptr, // 14 + nullptr, // 15 + nullptr, // 16 + nullptr, // 17 + nullptr, // 18 + MenuClickMusicWindow, // 19 + MenuClickHelp, // 20 + nullptr, // 21 +}; + static ToolbarButtonProc * const _scen_toolbar_button_procs[] = { ToolbarPauseClick, ToolbarFastForwardClick, @@ -2288,20 +2323,12 @@ static ToolbarButtonProc * const _scen_toolbar_button_procs[] = { ToolbarScenGenLand, ToolbarScenGenTown, ToolbarScenGenIndustry, - ToolbarScenBuildRoad, + ToolbarScenBuildRoadClick, ToolbarScenBuildDocks, ToolbarScenPlantTrees, ToolbarScenPlaceSign, ToolbarBtn_NULL, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, ToolbarMusicClick, - nullptr, ToolbarHelpClick, ToolbarSwitchClick, }; @@ -2404,10 +2431,7 @@ struct ScenarioEditorToolbarWindow : Window { void OnDropdownSelect(int widget, int index) override { - /* The map button is in a different location on the scenario - * editor toolbar, so we need to adjust for it. */ - if (widget == WID_TE_SMALL_MAP) widget = WID_TN_SMALL_MAP; - CallBackFunction cbf = _menu_clicked_procs[widget](index); + CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index); if (cbf != CBF_NONE) _last_started_action = cbf; if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); } @@ -2423,7 +2447,7 @@ struct ScenarioEditorToolbarWindow : Window { case MTEHK_GENLAND: ToolbarScenGenLand(this); break; case MTEHK_GENTOWN: ToolbarScenGenTown(this); break; case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break; - case MTEHK_BUILD_ROAD: ToolbarScenBuildRoad(this); break; + case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break; case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break; case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break; case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break; diff --git a/src/town.h b/src/town.h index 6454647a39..3ff4651c97 100644 --- a/src/town.h +++ b/src/town.h @@ -51,7 +51,7 @@ struct TownCache { uint32 num_houses; ///< Amount of houses uint32 population; ///< Current population of people ViewportSign sign; ///< Location of name sign, UpdateVirtCoord updates this - PartOfSubsidyByte part_of_subsidy; ///< Is this town a source/destination of a subsidy? + PartOfSubsidy part_of_subsidy; ///< Is this town a source/destination of a subsidy? uint32 squared_town_zone_radius[HZB_END]; ///< UpdateTownRadius updates this given the house count BuildingCounts building_counts; ///< The number of each type of building in the town }; @@ -78,7 +78,7 @@ struct Town : TownPool::PoolItem<&_town_pool> { /* Company ratings. */ CompanyMask have_ratings; ///< which companies have a rating uint8 unwanted[MAX_COMPANIES]; ///< how many months companies aren't wanted by towns (bribe) - CompanyByte exclusivity; ///< which company has exclusivity + CompanyID exclusivity; ///< which company has exclusivity uint8 exclusive_counter; ///< months till the exclusivity expires int16 ratings[MAX_COMPANIES]; ///< ratings of each company for this town StringID town_label; ///< Label dependent on _local_company rating. @@ -97,16 +97,16 @@ struct Town : TownPool::PoolItem<&_town_pool> { CargoTypes cargo_accepted_total; ///< NOSAVE: Bitmap of all cargoes accepted by houses in this town. StationList stations_near; ///< NOSAVE: List of nearby stations. - uint16 time_until_rebuild; ///< time until we rebuild a house + uint16 time_until_rebuild; ///< time until we rebuild a house - uint16 grow_counter; ///< counter to count when to grow, value is smaller than or equal to growth_rate - uint16 growth_rate; ///< town growth rate + uint16 grow_counter; ///< counter to count when to grow, value is smaller than or equal to growth_rate + uint16 growth_rate; ///< town growth rate - byte fund_buildings_months; ///< fund buildings program in action? - byte road_build_months; ///< fund road reconstruction in action? + byte fund_buildings_months; ///< fund buildings program in action? + byte road_build_months; ///< fund road reconstruction in action? - bool larger_town; ///< if this is a larger town and should grow more quickly - TownLayoutByte layout; ///< town specific road layout + bool larger_town; ///< if this is a larger town and should grow more quickly + TownLayout layout; ///< town specific road layout std::list psa_list; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 87391dc387..99bb0aacfc 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -182,7 +182,7 @@ void Town::InitializeLayout(TownLayout layout) return; } - this->layout = TileHash(TileX(this->xy), TileY(this->xy)) % (NUM_TLS - 1); + this->layout = static_cast(TileHash(TileX(this->xy), TileY(this->xy)) % (NUM_TLS - 1)); } /** @@ -776,7 +776,7 @@ static void TileLoop_Town(TileIndex tile) } } - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); if ((hs->building_flags & BUILDING_HAS_1_TILE) && HasBit(t->flags, TOWN_IS_GROWING) && @@ -1762,7 +1762,7 @@ static bool GrowTown(Town *t) }; /* Current "company" is a town */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); TileIndex tile = t->xy; // The tile we are working with ATM @@ -2240,7 +2240,7 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size * placement is so bad it couldn't grow at all */ if (t->cache.population > 0) return t; - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN); cur_company.Restore(); assert(rc.Succeeded()); @@ -3214,7 +3214,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags) */ static bool TryClearTile(TileIndex tile) { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); CommandCost r = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); return r.Succeeded(); @@ -3286,7 +3286,7 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags) if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE); if (flags & DC_EXEC) { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); DoCommand(statue_data.best_position, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); BuildObject(OBJECT_STATUE, statue_data.best_position, _current_company, t); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 305a215d07..557e7b36dc 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -327,11 +327,24 @@ public: this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, _networking && !_network_server); } + ~TownViewWindow() + { + SetViewportCatchmentTown(Town::Get(this->window_number), false); + } + void SetStringParameters(int widget) const override { if (widget == WID_TV_CAPTION) SetDParam(0, this->town->index); } + void OnPaint() override + { + extern const Town *_viewport_highlight_town; + this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town); + + this->DrawWidgets(); + } + void DrawWidget(const Rect &r, int widget) const override { if (widget != WID_TV_INFO) return; @@ -438,6 +451,10 @@ public: ShowQueryString(STR_TOWN_NAME, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; + case WID_TV_CATCHMENT: + SetViewportCatchmentTown(Town::Get(this->window_number), !this->IsWidgetLowered(WID_TV_CATCHMENT)); + break; + case WID_TV_EXPAND: { // expand town - only available on Scenario editor /* Warn the user if towns are not allowed to build roads, but do this only once per OpenTTD run. */ static bool _warn_town_no_roads = false; @@ -569,6 +586,7 @@ static const NWidgetPart _nested_town_game_view_widgets[] = { NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_SHOW_AUTHORITY), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP), EndContainer(), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT), NWidget(WWT_RESIZEBOX, COLOUR_BROWN), EndContainer(), }; @@ -601,6 +619,7 @@ static const NWidgetPart _nested_town_editor_view_widgets[] = { NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_EXPAND), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_DELETE), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP), EndContainer(), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT), NWidget(WWT_RESIZEBOX, COLOUR_BROWN), EndContainer(), }; diff --git a/src/town_type.h b/src/town_type.h index 057a7c97c0..5cdb14d53c 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -79,10 +79,8 @@ enum Ratings { RATING_BRIBE_DOWN_TO = -50 // XXX SHOULD BE SOMETHING LOWER? }; -/** - * Town Layouts - */ -enum TownLayout { +/** Town Layouts. It needs to be 8bits, because we save and load it as such */ +enum TownLayout : byte { TL_BEGIN = 0, TL_ORIGINAL = 0, ///< Original algorithm (min. 1 distance between roads) TL_BETTER_ROADS, ///< Extended original algorithm (min. 2 distance between roads) @@ -94,19 +92,15 @@ enum TownLayout { NUM_TLS, ///< Number of town layouts }; template <> struct EnumPropsT : MakeEnumPropsT {}; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT TownLayoutByte; // typedefing-enumification of TownLayout -/** Town founding setting values */ -enum TownFounding { +/** Town founding setting values. It needs to be 8bits, because we save and load it as such */ +enum TownFounding : byte { TF_BEGIN = 0, ///< Used for iterations and limit testing TF_FORBIDDEN = 0, ///< Forbidden TF_ALLOWED, ///< Allowed TF_CUSTOM_LAYOUT, ///< Allowed, with custom town layout TF_END, ///< Used for iterations and limit testing }; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT TownFoundingByte; /** Town cargo generation modes */ enum TownCargoGenMode : byte { diff --git a/src/tracerestrict.h b/src/tracerestrict.h index b85b9767ab..e232e8e76a 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -814,7 +814,7 @@ struct TraceRestrictSlot : TraceRestrictSlotPool::PoolItem<&_tracerestrictslot_p std::vector occupants; uint32 max_occupancy = 1; std::string name; - OwnerByte owner; + Owner owner; static void RebuildVehicleIndex(); static bool ValidateVehicleIndex(); diff --git a/src/track_type.h b/src/track_type.h index 1852f053e9..034688b6a4 100644 --- a/src/track_type.h +++ b/src/track_type.h @@ -18,7 +18,7 @@ * These are used to specify a single track. * Can be translated to a trackbit with TrackToTrackbit */ -enum Track { +enum Track : byte { TRACK_BEGIN = 0, ///< Used for iterations TRACK_X = 0, ///< Track along the x-axis (north-east to south-west) TRACK_Y = 1, ///< Track along the y-axis (north-west to south-east) @@ -34,11 +34,10 @@ enum Track { DECLARE_POSTFIX_INCREMENT(Track) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT TrackByte; /** Bitfield corresponding to Track */ -enum TrackBits { +enum TrackBits : byte { TRACK_BIT_NONE = 0U, ///< No track TRACK_BIT_X = 1U << TRACK_X, ///< X-axis track TRACK_BIT_Y = 1U << TRACK_Y, ///< Y-axis track @@ -62,7 +61,6 @@ enum TrackBits { INVALID_TRACK_BIT = 0xFF, ///< Flag for an invalid trackbits value }; DECLARE_ENUM_AS_BIT_SET(TrackBits) -typedef SimpleTinyEnumT TrackBitsByte; /** * Enumeration for tracks and directions. @@ -73,7 +71,7 @@ typedef SimpleTinyEnumT TrackBitsByte; * reversing track dirs are not considered to be 'valid' except in a small * corner in the road vehicle controller. */ -enum Trackdir { +enum Trackdir : byte { TRACKDIR_BEGIN = 0, ///< Used for iterations TRACKDIR_X_NE = 0, ///< X-axis and direction to north-east TRACKDIR_Y_SE = 1, ///< Y-axis and direction to south-east @@ -97,7 +95,6 @@ enum Trackdir { /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT TrackdirByte; /** * Enumeration of bitmasks for the TrackDirs @@ -105,7 +102,7 @@ typedef TinyEnumT TrackdirByte; * These are a combination of tracks and directions. Values are 0-5 in one * direction (corresponding to the Track enum) and 8-13 in the other direction. */ -enum TrackdirBits { +enum TrackdirBits : uint16 { TRACKDIR_BIT_NONE = 0U, ///< No track build TRACKDIR_BIT_X_NE = 1U << TRACKDIR_X_NE, ///< Track x-axis, direction north-east TRACKDIR_BIT_Y_SE = 1U << TRACKDIR_Y_SE, ///< Track y-axis, direction south-east @@ -124,7 +121,6 @@ enum TrackdirBits { INVALID_TRACKDIR_BIT = 0xFFFF, ///< Flag for an invalid trackdirbit value }; DECLARE_ENUM_AS_BIT_SET(TrackdirBits) -typedef SimpleTinyEnumT TrackdirBitsShort; typedef uint32 TrackStatus; diff --git a/src/train.h b/src/train.h index df2607b0ce..0659ea19fd 100644 --- a/src/train.h +++ b/src/train.h @@ -51,12 +51,11 @@ enum VehicleRailFlags { }; /** Modes for ignoring signals. */ -enum TrainForceProceeding { +enum TrainForceProceeding : byte { TFP_NONE = 0, ///< Normal operation. TFP_STUCK = 1, ///< Proceed till next signal, but ignore being stuck till then. This includes force leaving depots. TFP_SIGNAL = 2, ///< Ignore next signal, after the signal ignore being stuck. }; -typedef SimpleTinyEnumT TrainForceProceedingByte; /** Flags for Train::ConsistChanged */ enum ConsistChangeFlags { @@ -112,9 +111,9 @@ struct Train FINAL : public GroundVehicle { uint16 crash_anim_pos; ///< Crash animation counter. - TrackBitsByte track; - TrainForceProceedingByte force_proceed; - RailTypeByte railtype; + TrackBits track; + TrainForceProceeding force_proceed; + RailType railtype; byte critical_breakdown_count; ///< Counter for the number of critical breakdowns since last service RailTypes compatible_railtypes; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index c7e64b8bc2..a6f558ece5 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3692,7 +3692,7 @@ static Vehicle *CheckTrainAtSignal(Vehicle *v, void *data) struct FindSpaceBetweenTrainsChecker { int32 pos; uint16 distance; - DiagDirectionByte direction; + DiagDirection direction; }; /** Find train in front and keep distance between trains in tunnel/bridge. */ @@ -4230,7 +4230,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse) v->wait_counter -= TILE_SIZE; if (leaving) { // Reset counters. - v->force_proceed = 0; + v->force_proceed = TFP_NONE; v->wait_counter = 0; v->tunnel_bridge_signal_num = 0; update_signal_tunbridge_exit = true; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index bcc129219f..c92880e7a9 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1032,7 +1032,7 @@ Vehicle::~Vehicle() if (this->breakdowns_since_last_service) _vehicles_to_pay_repair.erase(this->index); - if (this->type < VEH_BEGIN || this->type >= VEH_COMPANY_END) { + if (this->type >= VEH_COMPANY_END) { /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, * it may happen that vehicle chain is deleted when visible. * Do not redo this for vehicle types where it is done in PreDestructor(). */ @@ -1349,7 +1349,7 @@ void CallVehicleTicks() v = nullptr; /* do Template Replacement */ - Backup sell_cur_company(_current_company, FILE_LINE); + Backup sell_cur_company(_current_company, FILE_LINE); for (VehicleID index : _vehicles_to_sell) { Vehicle *v = Vehicle::Get(index); SCOPE_INFO_FMT([v], "CallVehicleTicks: sell: %s", scope_dumper().VehicleInfo(v)); @@ -1377,7 +1377,7 @@ void CallVehicleTicks() sell_cur_company.Restore(); /* do Template Replacement */ - Backup tmpl_cur_company(_current_company, FILE_LINE); + Backup tmpl_cur_company(_current_company, FILE_LINE); for (VehicleID index : _vehicles_to_templatereplace) { Train *t = Train::Get(index); @@ -1424,7 +1424,7 @@ void CallVehicleTicks() tmpl_cur_company.Restore(); /* do Auto Replacement */ - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); for (auto &it : _vehicles_to_autoreplace) { v = Vehicle::Get(it.first); /* Autoreplace needs the current company set as the vehicle owner */ @@ -1460,7 +1460,7 @@ void CallVehicleTicks() } cur_company.Restore(); - Backup repair_cur_company(_current_company, FILE_LINE); + Backup repair_cur_company(_current_company, FILE_LINE); for (VehicleID index : _vehicles_to_pay_repair) { Vehicle *v = Vehicle::Get(index); SCOPE_INFO_FMT([v], "CallVehicleTicks: repair: %s", scope_dumper().VehicleInfo(v)); @@ -2200,7 +2200,7 @@ void VehicleEnterDepot(Vehicle *v) } if (v->current_order.IsRefit()) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); CommandCost cost = DoCommand(v->tile, v->index, v->current_order.GetRefitCargo() | 0xFF << 8, DC_EXEC, GetCmdRefitVeh(v)); cur_company.Restore(); @@ -3988,7 +3988,7 @@ void DumpVehicleStats(char *buffer, const char *last) vtypestats virt_train; vtypestats template_train; }; - std::map cstatmap; + std::map cstatmap; Vehicle *v; FOR_ALL_VEHICLES(v) { diff --git a/src/vehicle_base.h b/src/vehicle_base.h index a4e2a3cad1..e31c5d437d 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -287,9 +287,9 @@ public: int32 x_pos; ///< x coordinate. int32 y_pos; ///< y coordinate. int32 z_pos; ///< z coordinate. - DirectionByte direction; ///< facing + Direction direction; ///< facing - OwnerByte owner; ///< Which company owns the vehicle? + Owner owner; ///< Which company owns the vehicle? /** * currently displayed sprite index * 0xfd == custom sprite, 0xfe == custom second head sprite @@ -347,7 +347,7 @@ public: uint16 load_unload_ticks; ///< Ticks to wait before starting next cycle. GroupID group_id; ///< Index of group Pool array byte subtype; ///< subtype (Filled with values from #AircraftSubType/#DisasterSubType/#EffectVehicleType/#GroundVehicleSubtypeFlags) - DirectionByte cur_image_valid_dir; ///< NOSAVE: direction for which cur_image does not need to be regenerated on the next tick + Direction cur_image_valid_dir; ///< NOSAVE: direction for which cur_image does not need to be regenerated on the next tick NewGRFCache grf_cache; ///< Cache of often used calculated NewGRF values VehicleCache vcache; ///< Cache of often used vehicle values. diff --git a/src/vehicle_type.h b/src/vehicle_type.h index df1e58b957..edc4e87506 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -19,8 +19,8 @@ typedef uint32 VehicleID; static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2 -/** Available vehicle types. */ -enum VehicleType { +/** Available vehicle types. It needs to be 8bits, because we save and load it as such */ +enum VehicleType : byte { VEH_BEGIN, VEH_TRAIN = VEH_BEGIN, ///< %Train vehicle type. @@ -39,8 +39,6 @@ enum VehicleType { DECLARE_POSTFIX_INCREMENT(VehicleType) /** Helper information for extract tool. */ template <> struct EnumPropsT : MakeEnumPropsT {}; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT VehicleTypeByte; struct Vehicle; struct Train; @@ -53,7 +51,7 @@ struct DisasterVehicle; /** Base vehicle class. */ struct BaseVehicle { - VehicleTypeByte type; ///< Type of vehicle + VehicleType type; ///< Type of vehicle }; static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle. diff --git a/src/viewport.cpp b/src/viewport.cpp index 9c2e660726..fd2b70cdc5 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1105,6 +1105,65 @@ static void DrawAutorailSelection(const TileInfo *ti, HighLightStyle autorail_ty } } +enum TileHighlightType { + THT_NONE, + THT_WHITE, + THT_BLUE, + THT_RED, +}; + +const Station *_viewport_highlight_station; ///< Currently selected station for coverage area highlight +const Town *_viewport_highlight_town; ///< Currently selected town for coverage area highlight + +/** + * Get tile highlight type of coverage area for a given tile. + * @param t Tile that is being drawn + * @return Tile highlight type to draw + */ +static TileHighlightType GetTileHighlightType(TileIndex t) +{ + if (_viewport_highlight_station != nullptr) { + if (IsTileType(t, MP_STATION) && GetStationIndex(t) == _viewport_highlight_station->index) return THT_WHITE; + if (_viewport_highlight_station->TileIsInCatchment(t)) return THT_BLUE; + } + + if (_viewport_highlight_town != nullptr) { + if (IsTileType(t, MP_HOUSE)) { + if (GetTownIndex(t) == _viewport_highlight_town->index) { + TileHighlightType type = THT_RED; + for (const Station *st : _viewport_highlight_town->stations_near) { + if (st->owner != _current_company) continue; + if (st->TileIsInCatchment(t)) return THT_BLUE; + } + return type; + } + } else if (IsTileType(t, MP_STATION)) { + for (const Station *st : _viewport_highlight_town->stations_near) { + if (st->owner != _current_company) continue; + if (GetStationIndex(t) == st->index) return THT_WHITE; + } + } + } + + return THT_NONE; +} + +/** + * Draw tile highlight for coverage area highlight. + * @param *ti TileInfo Tile that is being drawn + * @param tht Highlight type to draw. + */ +static void DrawTileHighlightType(const TileInfo *ti, TileHighlightType tht) +{ + switch (tht) { + default: + case THT_NONE: break; + case THT_WHITE: DrawTileSelectionRect(ti, PAL_NONE); break; + case THT_BLUE: DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE); break; + case THT_RED: DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING); break; + } +} + /** * Checks if the specified tile is selected and if so draws selection using correct selectionstyle. * @param *ti TileInfo Tile that is being drawn @@ -1115,6 +1174,9 @@ static void DrawTileSelection(const TileInfo *ti) bool is_redsq = _thd.redsq == ti->tile; if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING); + TileHighlightType tht = GetTileHighlightType(ti->tile); + DrawTileHighlightType(ti, tht); + switch (_thd.drawstyle & HT_DRAG_MASK) { default: break; // No tile selection active? @@ -1122,7 +1184,7 @@ static void DrawTileSelection(const TileInfo *ti) if (!is_redsq) { if (IsInsideSelectedRectangle(ti->x, ti->y)) { DrawTileSelectionRect(ti, _thd.make_square_red ? PALETTE_SEL_TILE_RED : PAL_NONE); - } else if (_thd.outersize.x > 0 && + } else if (_thd.outersize.x > 0 && (tht == THT_NONE || tht == THT_RED) && /* Check if it's inside the outer area? */ IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { @@ -2649,7 +2711,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom */ static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom) { - if ((vp->zoom < ZOOM_LVL_DRAW_MAP) && (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE)) { + if ((vp->zoom < ZOOM_LVL_DRAW_MAP) && (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > (int)(180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE))) { if ((bottom - top) > (right - left)) { int t = (top + bottom) >> 1; ViewportDrawChk(vp, left, top, right, t); @@ -3703,6 +3765,8 @@ void UpdateTileSelection() int x1; int y1; + if (_thd.freeze) return; + HighLightStyle new_drawstyle = HT_NONE; bool new_diagonal = false; @@ -5037,6 +5101,25 @@ void StoreRailPlacementEndpoints(TileIndex start_tile, TileIndex end_tile, Track } } +static void MarkCatchmentTilesDirty() +{ + if (_viewport_highlight_town != nullptr) { + MarkWholeScreenDirty(); + return; + } + if (_viewport_highlight_station != nullptr) { + if (_viewport_highlight_station->catchment_tiles.tile == INVALID_TILE) { + MarkWholeScreenDirty(); + _viewport_highlight_station = nullptr; + } else { + BitmapTileIterator it(_viewport_highlight_station->catchment_tiles); + for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) { + MarkTileDirtyByTile(tile); + } + } + } +} + bool CurrentlySnappingRailPlacement() { return (_thd.place_mode & HT_POLY) && GetRailSnapMode() == RSM_SNAP_TO_RAIL; @@ -5083,3 +5166,46 @@ void ResetRailPlacementSnapping() _rail_snap_points.clear(); _current_snap_lock.x = -1; } + +/** + * Select or deselect station for coverage area highlight. + * Selecting a station will deselect a town. + * @param *st Station in question + * @param sel Select or deselect given station + */ +void SetViewportCatchmentStation(const Station *st, bool sel) +{ + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); + if (sel && _viewport_highlight_station != st) { + MarkCatchmentTilesDirty(); + _viewport_highlight_station = st; + _viewport_highlight_town = nullptr; + MarkCatchmentTilesDirty(); + } else if (!sel && _viewport_highlight_station == st) { + MarkCatchmentTilesDirty(); + _viewport_highlight_station = nullptr; + } + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); +} + +/** + * Select or deselect town for coverage area highlight. + * Selecting a town will deselect a station. + * @param *t Town in question + * @param sel Select or deselect given town + */ +void SetViewportCatchmentTown(const Town *t, bool sel) +{ + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + if (sel && _viewport_highlight_town != t) { + _viewport_highlight_station = nullptr; + _viewport_highlight_town = t; + MarkWholeScreenDirty(); + } else if (!sel && _viewport_highlight_town == t) { + _viewport_highlight_town = nullptr; + MarkWholeScreenDirty(); + } + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); +} diff --git a/src/viewport_func.h b/src/viewport_func.h index 6c3fe2c1c0..69096c010a 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -42,6 +42,7 @@ void CheckMarkDirtyFocusedRoutePaths(const Vehicle *veh); bool DoZoomInOutWindow(ZoomStateChange how, Window *w); void ZoomInOrOutToCursorWindow(bool in, Window * w); Point GetTileZoomCenterWindow(bool in, Window * w); +void FixTitleGameZoom(); void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out); /** @@ -117,4 +118,8 @@ void ViewportMapInvalidateTunnelCacheByTile(const TileIndex tile); void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal); void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part, const SubSprite *sub = nullptr); +struct Town; +void SetViewportCatchmentStation(const Station *st, bool sel); +void SetViewportCatchmentTown(const Town *t, bool sel); + #endif /* VIEWPORT_FUNC_H */ diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index d7199d5962..537b970f73 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -1067,7 +1067,7 @@ void DoFloodTile(TileIndex target) bool flooded = false; // Will be set to true if something is changed. - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); Slope tileh = GetTileSlope(target); if (tileh != SLOPE_FLAT) { @@ -1128,7 +1128,7 @@ void DoFloodTile(TileIndex target) */ static void DoDryUp(TileIndex tile) { - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); switch (GetTileType(tile)) { case MP_RAILWAY: diff --git a/src/widget.cpp b/src/widget.cpp index dcdf75c17b..71c874a529 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2634,7 +2634,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, NWidgetResizeBase *nwrb = dynamic_cast(*dest); if (nwrb != nullptr) { assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0); - nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y); + nwrb->SetMinimalSize(ScaleGUITrad(parts->u.xy.x), ScaleGUITrad(parts->u.xy.y)); } break; } @@ -2664,7 +2664,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, } case WPT_PADDING: - if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left); + if (*dest != nullptr) (*dest)->SetPadding(ScaleGUITrad(parts->u.padding.top), ScaleGUITrad(parts->u.padding.right), ScaleGUITrad(parts->u.padding.bottom), ScaleGUITrad(parts->u.padding.left)); break; case WPT_PIPSPACE: { diff --git a/src/widgets/misc_widget.h b/src/widgets/misc_widget.h index 22044c8665..fb7940722e 100644 --- a/src/widgets/misc_widget.h +++ b/src/widgets/misc_widget.h @@ -34,6 +34,7 @@ enum AboutWidgets { enum QueryStringWidgets { WID_QS_CAPTION, ///< Caption of the window. WID_QS_TEXT, ///< Text of the query. + WID_QS_WARNING, ///< Warning label about password security WID_QS_DEFAULT, ///< Default button. WID_QS_CANCEL, ///< Cancel button. WID_QS_OK, ///< OK button. diff --git a/src/widgets/network_widget.h b/src/widgets/network_widget.h index f5773b8ea8..4cb5cc92c2 100644 --- a/src/widgets/network_widget.h +++ b/src/widgets/network_widget.h @@ -122,6 +122,7 @@ enum NetworkCompanyPasswordWidgets { WID_NCP_LABEL, ///< Label in front of the password field. WID_NCP_PASSWORD, ///< Input field for the password. WID_NCP_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password. + WID_NCP_WARNING, ///< Warning text about password security WID_NCP_CANCEL, ///< Close the window without changing anything. WID_NCP_OK, ///< Safe the password etc. }; diff --git a/src/widgets/station_widget.h b/src/widgets/station_widget.h index 53152cb2eb..49f6050f83 100644 --- a/src/widgets/station_widget.h +++ b/src/widgets/station_widget.h @@ -30,6 +30,7 @@ enum StationViewWidgets { WID_SV_ROADVEHS, ///< List of scheduled road vehs button. WID_SV_SHIPS, ///< List of scheduled ships button. WID_SV_PLANES, ///< List of scheduled planes button. + WID_SV_CATCHMENT, ///< Toggle catchment area highlight. WID_SV_DEPARTURES, ///< Departures button. }; diff --git a/src/widgets/toolbar_widget.h b/src/widgets/toolbar_widget.h index c317fc9574..5f0c1b5a4f 100644 --- a/src/widgets/toolbar_widget.h +++ b/src/widgets/toolbar_widget.h @@ -70,10 +70,9 @@ enum ToolbarEditorWidgets { WID_TE_TREES, ///< Tree building toolbar. WID_TE_SIGNS, ///< Sign building. WID_TE_DATE_PANEL, ///< Container for the date widgets. - /* The following three need to have the same actual widget number as the normal toolbar due to shared code. */ - WID_TE_MUSIC_SOUND = WID_TN_MUSIC_SOUND, ///< Music/sound configuration menu. - WID_TE_HELP = WID_TN_HELP, ///< Help menu. - WID_TE_SWITCH_BAR = WID_TN_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. + WID_TE_MUSIC_SOUND, ///< Music/sound configuration menu. + WID_TE_HELP, ///< Help menu. + WID_TE_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. }; #endif /* WIDGETS_TOOLBAR_WIDGET_H */ diff --git a/src/widgets/town_widget.h b/src/widgets/town_widget.h index 59412ee17d..88858b8939 100644 --- a/src/widgets/town_widget.h +++ b/src/widgets/town_widget.h @@ -39,6 +39,7 @@ enum TownViewWidgets { WID_TV_CENTER_VIEW, ///< Center the main view on this town. WID_TV_SHOW_AUTHORITY, ///< Show the town authority window. WID_TV_CHANGE_NAME, ///< Change the name of this town. + WID_TV_CATCHMENT, ///< Toggle catchment area highlight. WID_TV_EXPAND, ///< Expand this town (scenario editor only). WID_TV_DELETE, ///< Delete this town (scenario editor only). }; diff --git a/src/zoom_func.h b/src/zoom_func.h index abf69ca61a..7f52fe78da 100644 --- a/src/zoom_func.h +++ b/src/zoom_func.h @@ -23,7 +23,6 @@ */ static inline int ScaleByZoom(int value, ZoomLevel zoom) { - assert(zoom >= 0); return ((uint) value) << zoom; } @@ -36,7 +35,6 @@ static inline int ScaleByZoom(int value, ZoomLevel zoom) */ static inline int UnScaleByZoom(int value, ZoomLevel zoom) { - assert(zoom >= 0); return (value + (1 << zoom) - 1) >> zoom; } @@ -48,7 +46,6 @@ static inline int UnScaleByZoom(int value, ZoomLevel zoom) */ static inline int ScaleByZoomLower(int value, ZoomLevel zoom) { - assert(zoom >= 0); return ((uint) value) << zoom; } @@ -60,7 +57,6 @@ static inline int ScaleByZoomLower(int value, ZoomLevel zoom) */ static inline int UnScaleByZoomLower(int value, ZoomLevel zoom) { - assert(zoom >= 0); return value >> zoom; } diff --git a/src/zoom_type.h b/src/zoom_type.h index f3326ed03e..95ce0cb86a 100644 --- a/src/zoom_type.h +++ b/src/zoom_type.h @@ -14,11 +14,11 @@ #include "core/enum_type.hpp" -static int const ZOOM_LVL_SHIFT = 2; -static int const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT; +static uint const ZOOM_LVL_SHIFT = 2; +static uint const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT; /** All zoom levels we know. */ -enum ZoomLevel { +enum ZoomLevel : byte { /* Our possible zoom-levels */ ZOOM_LVL_BEGIN = 0, ///< Begin for iteration. ZOOM_LVL_NORMAL = 0, ///< The normal zoom level. @@ -55,11 +55,8 @@ enum ZoomLevel { }; DECLARE_POSTFIX_INCREMENT(ZoomLevel) -/** Type for storing the zoom level in a byte. */ -typedef SimpleTinyEnumT ZoomLevelByte; - -extern ZoomLevelByte _gui_zoom; -extern ZoomLevelByte _font_zoom; +extern ZoomLevel _gui_zoom; +extern ZoomLevel _font_zoom; #define ZOOM_LVL_GUI (_gui_zoom) #define ZOOM_LVL_FONT (_font_zoom)