Mercurial > hg > openttd
changeset 12032:2afeb10ae6ba draft
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
author | yexo <yexo@openttd.org> |
---|---|
date | Tue, 26 May 2009 21:59:49 +0000 |
parents | 34d22b1974a4 |
children | 3a06a1a551f5 |
files | src/aircraft_cmd.cpp src/depot.cpp src/order_cmd.cpp src/order_func.h src/roadveh_cmd.cpp src/saveload/afterload.cpp src/saveload/company_sl.cpp src/saveload/saveload.cpp src/settings.cpp src/settings_internal.h src/settings_type.h src/ship_cmd.cpp src/table/settings.h src/train_cmd.cpp src/vehicle.cpp src/vehicle_cmd.cpp src/vehicle_gui.cpp |
diffstat | 17 files changed, 88 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -378,7 +378,7 @@ v->targetairport = GetStationIndex(tile); v->SetNext(u); - v->service_interval = _settings_game.vehicle.servint_aircraft; + v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_aircraft; v->date_of_last_service = _date; v->build_year = u->build_year = _cur_year; @@ -582,7 +582,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v) { - if (_settings_game.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return; + if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return; if (v->IsInDepot()) { VehicleServiceInDepot(v); return;
--- a/src/depot.cpp +++ b/src/depot.cpp @@ -4,6 +4,7 @@ #include "stdafx.h" #include "depot_base.h" +#include "company_type.h" #include "order_func.h" #include "window_func.h" #include "core/bitmath_func.hpp"
--- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1340,7 +1340,7 @@ Vehicle *v = Vehicle::GetIfValid(p1); /* Check the vehicle type and ownership, and if the service interval and order are in range */ if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; - if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->GetNumOrders()) return CMD_ERROR; + if (serv_int != GetServiceIntervalClamped(serv_int, v->owner) || cur_ord >= v->GetNumOrders()) return CMD_ERROR; if (flags & DC_EXEC) { v->cur_order_index = cur_ord; @@ -1527,9 +1527,9 @@ } } -Date GetServiceIntervalClamped(uint index) +uint16 GetServiceIntervalClamped(uint interval, CompanyID company_id) { - return (_settings_game.vehicle.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS); + return (Company::Get(company_id)->settings.vehicle.servint_ispercent) ? Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS); } /**
--- a/src/order_func.h +++ b/src/order_func.h @@ -47,12 +47,12 @@ #define MAX_SERVINT_DAYS 800 /** - * Get the service interval domain. - * Get the new proposed service interval for the vehicle is indeed, clamped - * within the given bounds. @see MIN_SERVINT_PERCENT ,etc. - * @param index proposed service interval - * @return service interval + * Clamp the service interval to the correct min/max. The actual min/max values + * depend on whether it's in percent or days. + * @param interval proposed service interval + * @param company_id the owner of the vehicle + * @return Clamped service interval */ -Date GetServiceIntervalClamped(uint index); +uint16 GetServiceIntervalClamped(uint interval, CompanyID company_id); #endif /* ORDER_FUNC_H */
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -233,7 +233,7 @@ v->name = NULL; - v->service_interval = _settings_game.vehicle.servint_roadveh; + v->service_interval = Company::Get(v->owner)->settings.vehicle.servint_roadveh; v->date_of_last_service = _date; v->build_year = _cur_year; @@ -1825,7 +1825,7 @@ static void CheckIfRoadVehNeedsService(RoadVehicle *v) { /* If we already got a slot at a stop, use that FIRST, and go to a depot later */ - if (v->slot != NULL || _settings_game.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return; + if (v->slot != NULL || Company::Get(v->owner)->settings.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return; if (v->IsInDepot()) { VehicleServiceInDepot(v); return;
--- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1846,6 +1846,14 @@ } } + if (CheckSavegameVersion(120)) { + extern VehicleDefaultSettings _old_vds; + Company *c; + FOR_ALL_COMPANIES(c) { + c->settings.vehicle = _old_vds; + } + } + AfterLoadLabelMaps(); GamelogPrintDebug(1);
--- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -140,6 +140,13 @@ SLE_CONDVAR(Company, settings.engine_renew_money, SLE_UINT32, 16, SL_MAX_VERSION), SLE_CONDVAR(Company, settings.renew_keep_length, SLE_BOOL, 2, SL_MAX_VERSION), + /* Default vehicle settings */ + SLE_CONDVAR(Company, settings.vehicle.servint_ispercent, SLE_BOOL, 120, SL_MAX_VERSION), + SLE_CONDVAR(Company, settings.vehicle.servint_trains, SLE_UINT16, 120, SL_MAX_VERSION), + SLE_CONDVAR(Company, settings.vehicle.servint_roadveh, SLE_UINT16, 120, SL_MAX_VERSION), + SLE_CONDVAR(Company, settings.vehicle.servint_aircraft, SLE_UINT16, 120, SL_MAX_VERSION), + SLE_CONDVAR(Company, settings.vehicle.servint_ships, SLE_UINT16, 120, SL_MAX_VERSION), + /* Reserve extra space in savegame here. (currently 63 bytes) */ SLE_CONDNULL(63, 2, SL_MAX_VERSION),
--- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -40,7 +40,7 @@ #include "saveload_internal.h" -extern const uint16 SAVEGAME_VERSION = 119; +extern const uint16 SAVEGAME_VERSION = 120; SavegameType _savegame_type; ///< type of savegame we are loading
--- a/src/settings.cpp +++ b/src/settings.cpp @@ -67,6 +67,7 @@ ClientSettings _settings_client; GameSettings _settings_game; GameSettings _settings_newgame; +VehicleDefaultSettings _old_vds; ///< Used for loading default vehicles settings from old savegames typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object); typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList *list); @@ -705,18 +706,23 @@ /* Check service intervals of vehicles, p1 is value of % or day based servicing */ static bool CheckInterval(int32 p1) { - VehicleSettings *ptc = (_game_mode == GM_MENU) ? &_settings_newgame.vehicle : &_settings_game.vehicle; + VehicleDefaultSettings *vds; + if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) { + vds = &_settings_client.company.vehicle; + } else { + vds = &Company::Get(_current_company)->settings.vehicle; + } if (p1) { - ptc->servint_trains = 50; - ptc->servint_roadveh = 50; - ptc->servint_aircraft = 50; - ptc->servint_ships = 50; + vds->servint_trains = 50; + vds->servint_roadveh = 50; + vds->servint_aircraft = 50; + vds->servint_ships = 50; } else { - ptc->servint_trains = 150; - ptc->servint_roadveh = 150; - ptc->servint_aircraft = 360; - ptc->servint_ships = 100; + vds->servint_trains = 150; + vds->servint_roadveh = 150; + vds->servint_aircraft = 360; + vds->servint_ships = 100; } InvalidateDetailsWindow(0); @@ -1425,7 +1431,6 @@ */ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - DEBUG(misc, 0, "Change company setting: %u into %u", p1, p2); if (p1 >= lengthof(_company_settings)) return CMD_ERROR; const SettingDesc *sd = &_company_settings[p1];
--- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -80,4 +80,6 @@ bool SetSettingValue(uint index, const char *value); void SetCompanySetting(uint index, int32 value); +extern VehicleDefaultSettings _old_vds; + #endif /* SETTINGS_H */
--- a/src/settings_type.h +++ b/src/settings_type.h @@ -293,11 +293,6 @@ UnitID max_roadveh; ///< max trucks in game per company UnitID max_aircraft; ///< max planes in game per company UnitID max_ships; ///< max ships in game per company - bool servint_ispercent; ///< service intervals are in percents - uint16 servint_trains; ///< service interval for trains - uint16 servint_roadveh; ///< service interval for road vehicles - uint16 servint_aircraft; ///< service interval for aircraft - uint16 servint_ships; ///< service interval for ships uint8 plane_speed; ///< divisor for speed of aircraft uint8 freight_trains; ///< value to multiply the weight of cargo by bool dynamic_engines; ///< enable dynamic allocation of engine data @@ -338,12 +333,22 @@ byte station_spread; ///< amount a station may spread }; +/** Default settings for vehicles. */ +struct VehicleDefaultSettings { + bool servint_ispercent; ///< service intervals are in percents + uint16 servint_trains; ///< service interval for trains + uint16 servint_roadveh; ///< service interval for road vehicles + uint16 servint_aircraft; ///< service interval for aircraft + uint16 servint_ships; ///< service interval for ships +}; + /** Settings that can be set per company. */ struct CompanySettings { bool engine_renew; ///< is autorenew enabled int16 engine_renew_months; ///< months before/after the maximum vehicle age a vehicle should be renewed uint32 engine_renew_money; ///< minimum amount of money before autorenew is used bool renew_keep_length; ///< sell some wagons if after autoreplace the train is longer than before + VehicleDefaultSettings vehicle; ///< default settings for vehicles }; /** All settings together for the game. */
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -127,7 +127,7 @@ static void CheckIfShipNeedsService(Vehicle *v) { - if (_settings_game.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return; + if (Company::Get(v->owner)->settings.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return; if (v->IsInDepot()) { VehicleServiceInDepot(v); return; @@ -805,7 +805,7 @@ v->name = NULL; v->state = TRACK_BIT_DEPOT; - v->service_interval = _settings_game.vehicle.servint_ships; + v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_ships; v->date_of_last_service = _date; v->build_year = _cur_year; v->cur_image = SPR_IMG_QUERY;
--- a/src/table/settings.h +++ b/src/table/settings.h @@ -377,11 +377,11 @@ SDT_VAR(GameSettings, vehicle.max_roadveh, SLE_UINT16, 0, 0, 500, 0, 5000, 0, STR_CONFIG_SETTING_MAX_ROADVEH, RedrawScreen), SDT_VAR(GameSettings, vehicle.max_aircraft, SLE_UINT16, 0, 0, 200, 0, 5000, 0, STR_CONFIG_SETTING_MAX_AIRCRAFT, RedrawScreen), SDT_VAR(GameSettings, vehicle.max_ships, SLE_UINT16, 0, 0, 300, 0, 5000, 0, STR_CONFIG_SETTING_MAX_SHIPS, RedrawScreen), - SDT_BOOL(GameSettings, vehicle.servint_ispercent, 0,NN, false, STR_CONFIG_SETTING_SERVINT_ISPERCENT, CheckInterval), - SDT_VAR(GameSettings, vehicle.servint_trains, SLE_UINT16, 0,D0, 150, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_TRAINS, InvalidateDetailsWindow), - SDT_VAR(GameSettings, vehicle.servint_roadveh, SLE_UINT16, 0,D0, 150, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_ROADVEH, InvalidateDetailsWindow), - SDT_VAR(GameSettings, vehicle.servint_ships, SLE_UINT16, 0,D0, 360, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_SHIPS, InvalidateDetailsWindow), - SDT_VAR(GameSettings, vehicle.servint_aircraft, SLE_UINT16, 0,D0, 100, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_AIRCRAFT, InvalidateDetailsWindow), + SDTG_CONDBOOL(NULL, 0, NN, _old_vds.servint_ispercent, false, STR_NULL, NULL, 0, 119), + SDTG_CONDVAR(NULL, SLE_UINT16, 0, D0, _old_vds.servint_trains, 150, 5, 800, 0, STR_NULL, NULL, 0, 119), + SDTG_CONDVAR(NULL, SLE_UINT16, 0, D0, _old_vds.servint_roadveh, 150, 5, 800, 0, STR_NULL, NULL, 0, 119), + SDTG_CONDVAR(NULL, SLE_UINT16, 0, D0, _old_vds.servint_ships, 360, 5, 800, 0, STR_NULL, NULL, 0, 119), + SDTG_CONDVAR(NULL, SLE_UINT16, 0, D0, _old_vds.servint_aircraft, 150, 5, 800, 0, STR_NULL, NULL, 0, 119), SDT_BOOL(GameSettings, order.no_servicing_if_no_breakdowns, 0, 0, false, STR_CONFIG_SETTING_NOSERVICE, NULL), SDT_BOOL(GameSettings, vehicle.wagon_speed_limits, 0,NN, true, STR_CONFIG_SETTING_WAGONSPEEDLIMITS, UpdateConsists), SDT_CONDBOOL(GameSettings, vehicle.disable_elrails, 38, SL_MAX_VERSION, 0,NN, false, STR_CONFIG_SETTING_DISABLE_ELRAILS, SettingsDisableElrail), @@ -615,10 +615,15 @@ }; static const SettingDesc _company_settings[] = { - SDT_BOOL(CompanySettings, engine_renew, 0, PC, false, STR_CONFIG_SETTING_AUTORENEW_VEHICLE, NULL), - SDT_VAR(CompanySettings, engine_renew_months, SLE_INT16, 0, PC, 6, -12, 12, 0, STR_CONFIG_SETTING_AUTORENEW_MONTHS, NULL), - SDT_VAR(CompanySettings, engine_renew_money, SLE_UINT, 0, PC|CR,100000, 0, 2000000, 0, STR_CONFIG_SETTING_AUTORENEW_MONEY, NULL), - SDT_BOOL(CompanySettings, renew_keep_length, 0, PC, false, STR_NULL, NULL), + SDT_BOOL(CompanySettings, engine_renew, 0, PC, false, STR_CONFIG_SETTING_AUTORENEW_VEHICLE, NULL), + SDT_VAR(CompanySettings, engine_renew_months, SLE_INT16, 0, PC, 6, -12, 12, 0, STR_CONFIG_SETTING_AUTORENEW_MONTHS, NULL), + SDT_VAR(CompanySettings, engine_renew_money, SLE_UINT, 0, PC|CR, 100000, 0, 2000000, 0, STR_CONFIG_SETTING_AUTORENEW_MONEY, NULL), + SDT_BOOL(CompanySettings, renew_keep_length, 0, PC, false, STR_NULL, NULL), + SDT_BOOL(CompanySettings, vehicle.servint_ispercent, 0, PC, false, STR_CONFIG_SETTING_SERVINT_ISPERCENT, CheckInterval), + SDT_VAR(CompanySettings, vehicle.servint_trains, SLE_UINT16, 0, PC|D0, 150, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_TRAINS, InvalidateDetailsWindow), + SDT_VAR(CompanySettings, vehicle.servint_roadveh, SLE_UINT16, 0, PC|D0, 150, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_ROADVEH, InvalidateDetailsWindow), + SDT_VAR(CompanySettings, vehicle.servint_ships, SLE_UINT16, 0, PC|D0, 360, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_SHIPS, InvalidateDetailsWindow), + SDT_VAR(CompanySettings, vehicle.servint_aircraft, SLE_UINT16, 0, PC|D0, 100, 5, 800, 0, STR_CONFIG_SETTING_SERVINT_AIRCRAFT, InvalidateDetailsWindow), SDT_END() };
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -858,7 +858,7 @@ v->railtype = rvi->railtype; _new_vehicle_id = v->index; - v->service_interval = _settings_game.vehicle.servint_trains; + v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_trains; v->date_of_last_service = _date; v->build_year = _cur_year; v->cur_image = SPR_IMG_QUERY; @@ -4464,7 +4464,7 @@ { static const uint MAX_ACCEPTABLE_DEPOT_DIST = 16; - if (_settings_game.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return; + if (Company::Get(v->owner)->settings.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return; if (v->IsInDepot()) { VehicleServiceInDepot(v); return;
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -90,7 +90,7 @@ return EngineHasReplacementForCompany(Company::Get(this->owner), this->engine_type, this->group_id); } - return _settings_game.vehicle.servint_ispercent ? + return Company::Get(this->owner)->settings.vehicle.servint_ispercent ? (this->reliability < Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) : (this->date_of_last_service + this->service_interval < _date); }
--- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -558,10 +558,11 @@ */ CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - uint16 serv_int = GetServiceIntervalClamped(p2); // Double check the service interval from the user-input Vehicle *v = Vehicle::GetIfValid(p1); + if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; - if (serv_int != p2 || v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; + uint16 serv_int = GetServiceIntervalClamped(p2, v->owner); // Double check the service interval from the user-input + if (serv_int != p2) return CMD_ERROR; if (flags & DC_EXEC) { v->service_interval = serv_int;
--- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1389,14 +1389,15 @@ } /** Checks whether service interval is enabled for the vehicle. */ - static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type) + static bool IsVehicleServiceIntervalEnabled(const VehicleType vehicle_type, CompanyID company_id) { + const VehicleDefaultSettings *vds = &Company::Get(company_id)->settings.vehicle; switch (vehicle_type) { default: NOT_REACHED(); - case VEH_TRAIN: return _settings_game.vehicle.servint_trains != 0; - case VEH_ROAD: return _settings_game.vehicle.servint_roadveh != 0; - case VEH_SHIP: return _settings_game.vehicle.servint_ships != 0; - case VEH_AIRCRAFT: return _settings_game.vehicle.servint_aircraft != 0; + case VEH_TRAIN: return vds->servint_trains != 0; + case VEH_ROAD: return vds->servint_roadveh != 0; + case VEH_SHIP: return vds->servint_ships != 0; + case VEH_AIRCRAFT: return vds->servint_aircraft != 0; } } @@ -1445,7 +1446,7 @@ WIDGET_LIST_END); /* Disable service-scroller when interval is set to disabled */ - this->SetWidgetsDisabledState(!IsVehicleServiceIntervalEnabled(v->type), + this->SetWidgetsDisabledState(!IsVehicleServiceIntervalEnabled(v->type, v->owner), VLD_WIDGET_INCREASE_SERVICING_INTERVAL, VLD_WIDGET_DECREASE_SERVICING_INTERVAL, WIDGET_LIST_END); @@ -1496,7 +1497,7 @@ /* Draw service interval text */ SetDParam(0, v->service_interval); SetDParam(1, v->date_of_last_service); - DrawString(13, this->width - 2, this->height - (v->type != VEH_TRAIN ? 11 : 23), _settings_game.vehicle.servint_ispercent ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS); + DrawString(13, this->width - 2, this->height - (v->type != VEH_TRAIN ? 11 : 23), Company::Get(v->owner)->settings.vehicle.servint_ispercent ? STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT : STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS); switch (v->type) { case VEH_TRAIN: @@ -1537,7 +1538,7 @@ const Vehicle *v = Vehicle::Get(this->window_number); mod = (widget == VLD_WIDGET_DECREASE_SERVICING_INTERVAL) ? -mod : mod; - mod = GetServiceIntervalClamped(mod + v->service_interval); + mod = GetServiceIntervalClamped(mod + v->service_interval, v->owner); if (mod == v->service_interval) return; DoCommandP(v->tile, v->index, mod, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING));