Merge branch 'master' into jgrpp

Replace build and refit, and group collapse implementations
Fix template creation build and refit

# Conflicts:
#	Makefile.bundle.in
#	config.lib
#	src/animated_tile.cpp
#	src/blitter/32bpp_anim.hpp
#	src/blitter/32bpp_base.hpp
#	src/blitter/8bpp_base.hpp
#	src/blitter/null.hpp
#	src/build_vehicle_gui.cpp
#	src/command.cpp
#	src/command_func.h
#	src/console_gui.cpp
#	src/core/smallstack_type.hpp
#	src/date.cpp
#	src/debug.cpp
#	src/genworld_gui.cpp
#	src/ground_vehicle.hpp
#	src/group_gui.cpp
#	src/lang/korean.txt
#	src/linkgraph/linkgraph_gui.h
#	src/main_gui.cpp
#	src/misc_gui.cpp
#	src/network/core/game.h
#	src/network/core/packet.cpp
#	src/network/core/udp.cpp
#	src/network/core/udp.h
#	src/network/network_content.cpp
#	src/network/network_type.h
#	src/network/network_udp.cpp
#	src/newgrf_house.h
#	src/openttd.cpp
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/os/unix/crashlog_unix.cpp
#	src/os/windows/crashlog_win.cpp
#	src/osk_gui.cpp
#	src/pathfinder/opf/opf_ship.cpp
#	src/rail_cmd.cpp
#	src/rail_gui.cpp
#	src/saveload/saveload.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/smallmap_gui.h
#	src/station_base.h
#	src/station_cmd.cpp
#	src/table/gameopt_settings.ini
#	src/table/newgrf_debug_data.h
#	src/table/settings.ini
#	src/timetable_gui.cpp
#	src/toolbar_gui.cpp
#	src/train_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_gui.cpp
#	src/vehiclelist.cpp
#	src/viewport.cpp
#	src/widgets/dropdown.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2019-03-27 18:12:04 +00:00
422 changed files with 4697 additions and 6619 deletions

View File

@@ -164,11 +164,9 @@ public:
/** Gets the ScriptScanner instance that is used to find AI Libraries */
static AIScannerLibrary *GetScannerLibrary();
#if defined(ENABLE_NETWORK)
/** Wrapper function for AIScanner::HasAI */
static bool HasAI(const struct ContentInfo *ci, bool md5sum);
static bool HasAILibrary(const ContentInfo *ci, bool md5sum);
#endif
private:
static uint frame_counter; ///< Tick counter for the AI code
static class AIScannerInfo *scanner_info; ///< ScriptScanner instance that is used to find AIs

View File

@@ -30,9 +30,9 @@ public:
class AIInfo *GetInfo() const;
/* virtual */ int GetSetting(const char *name) const;
/* virtual */ void SetSetting(const char *name, int value);
/* virtual */ void AddRandomDeviation();
int GetSetting(const char *name) const override;
void SetSetting(const char *name, int value) override;
void AddRandomDeviation() override;
/**
* When ever the AI Scanner is reloaded, all infos become invalid. This
@@ -45,9 +45,9 @@ public:
bool ResetInfo(bool force_exact_match);
protected:
/* virtual */ void PushExtraConfigList();
/* virtual */ void ClearConfigList();
/* virtual */ ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match);
void PushExtraConfigList() override;
void ClearConfigList() override;
ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) override;
};
#endif /* AI_CONFIG_HPP */

View File

@@ -362,8 +362,6 @@
InvalidateWindowClassesData(WC_AI_SETTINGS);
}
#if defined(ENABLE_NETWORK)
/**
* Check whether we have an AI (library) with the exact characteristics as ci.
* @param ci the characteristics to search on (shortname and md5sum)
@@ -380,8 +378,6 @@
return AI::scanner_library->HasScript(ci, md5sum);
}
#endif /* defined(ENABLE_NETWORK) */
/* static */ AIScannerInfo *AI::GetScannerInfo()
{
return AI::scanner_info;

View File

@@ -98,7 +98,7 @@ struct AIListWindow : public Window {
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_AIL_CAPTION:
@@ -107,7 +107,7 @@ struct AIListWindow : public Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_AIL_LIST) {
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
@@ -118,7 +118,7 @@ struct AIListWindow : public Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_AIL_LIST: {
@@ -183,7 +183,7 @@ struct AIListWindow : public Window {
DeleteWindowByClass(WC_QUERY_STRING);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_AIL_LIST: { // Select one of the AIs
@@ -211,7 +211,7 @@ struct AIListWindow : public Window {
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_AIL_LIST);
}
@@ -221,7 +221,7 @@ struct AIListWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
delete this;
@@ -317,7 +317,7 @@ struct AISettingsWindow : public Window {
this->RebuildVisibleSettings();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_AIS_CAPTION:
@@ -346,7 +346,7 @@ struct AISettingsWindow : public Window {
this->vscroll->SetCount((int)this->visible_settings.size());
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_AIS_BACKGROUND) {
this->line_height = max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
@@ -357,7 +357,7 @@ struct AISettingsWindow : public Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_AIS_BACKGROUND) return;
@@ -421,7 +421,7 @@ struct AISettingsWindow : public Window {
}
}
virtual void OnPaint()
void OnPaint() override
{
if (this->closing_dropdown) {
this->closing_dropdown = false;
@@ -430,7 +430,7 @@ struct AISettingsWindow : public Window {
this->DrawWidgets();
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_AIS_BACKGROUND: {
@@ -481,7 +481,7 @@ struct AISettingsWindow : public Window {
DropDownList *list = new DropDownList();
for (int i = config_item.min_value; i <= config_item.max_value; i++) {
*list->Append() = new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false);
list->push_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
}
ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true);
@@ -530,7 +530,7 @@ struct AISettingsWindow : public Window {
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (StrEmpty(str)) return;
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
@@ -542,7 +542,7 @@ struct AISettingsWindow : public Window {
this->SetDirty();
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
assert(this->clicked_dropdown);
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
@@ -553,7 +553,7 @@ struct AISettingsWindow : public Window {
this->SetDirty();
}
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
{
/* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
* the same dropdown button was clicked again, and then not open the dropdown again.
@@ -564,12 +564,12 @@ struct AISettingsWindow : public Window {
this->SetDirty();
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_AIS_BACKGROUND);
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
if (this->timeout.Elapsed(delta_ms)) {
this->clicked_button = -1;
@@ -582,7 +582,7 @@ struct AISettingsWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
this->RebuildVisibleSettings();
HideDropDownMenu(this);
@@ -646,7 +646,7 @@ struct ScriptTextfileWindow : public TextfileWindow {
this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
}
/* virtual */ void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_TF_CAPTION) {
SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI);
@@ -743,7 +743,7 @@ struct AIConfigWindow : public Window {
DeleteWindowByClass(WC_AI_SETTINGS);
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_AIC_NUMBER:
@@ -767,7 +767,7 @@ struct AIConfigWindow : public Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_AIC_GAMELIST:
@@ -819,7 +819,7 @@ struct AIConfigWindow : public Window {
return slot < max_slot;
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_AIC_GAMELIST: {
@@ -858,7 +858,7 @@ struct AIConfigWindow : public Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == NULL) return;
@@ -928,9 +928,7 @@ struct AIConfigWindow : public Window {
if (!_network_available) {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
} else {
#if defined(ENABLE_NETWORK)
ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI, CONTENT_TYPE_GAME);
#endif
}
break;
}
@@ -941,7 +939,7 @@ struct AIConfigWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!IsEditable(this->selected_slot)) {
this->selected_slot = INVALID_COMPANY;
@@ -1098,7 +1096,7 @@ struct AIDebugWindow : public Window {
this->InvalidateData(-1);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_AID_LOG_PANEL) {
resize->height = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
@@ -1106,7 +1104,7 @@ struct AIDebugWindow : public Window {
}
}
virtual void OnPaint()
void OnPaint() override
{
this->SelectValidDebugCompany();
@@ -1184,7 +1182,7 @@ struct AIDebugWindow : public Window {
this->last_vscroll_pos = this->vscroll->GetPosition();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_AID_NAME_TEXT:
@@ -1207,7 +1205,7 @@ struct AIDebugWindow : public Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (ai_debug_company == INVALID_COMPANY) return;
@@ -1266,7 +1264,7 @@ struct AIDebugWindow : public Window {
this->last_vscroll_pos = this->vscroll->GetPosition();
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
/* Also called for hotkeys, so check for disabledness */
if (this->IsWidgetDisabled(widget)) return;
@@ -1336,7 +1334,7 @@ struct AIDebugWindow : public Window {
}
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
/* Save the current string to static member so it can be restored next time the window is opened. */
@@ -1351,7 +1349,7 @@ struct AIDebugWindow : public Window {
* This is the company ID of the AI/GS which wrote a new log message, or -1 in other cases.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
/* If the log message is related to the active company tab, check the break string.
* This needs to be done in gameloop-scope, so the AI is suspended immediately. */
@@ -1408,7 +1406,7 @@ struct AIDebugWindow : public Window {
(ai_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(ai_debug_company)));
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
}

View File

@@ -25,14 +25,14 @@ public:
*/
void Initialize(class AIInfo *info);
/* virtual */ int GetSetting(const char *name);
/* virtual */ ScriptInfo *FindLibrary(const char *library, int version);
int GetSetting(const char *name) override;
ScriptInfo *FindLibrary(const char *library, int version) override;
private:
/* virtual */ void RegisterAPI();
/* virtual */ void Died();
/* virtual */ CommandCallback *GetDoCommandCallback();
/* virtual */ void LoadDummyScript();
void RegisterAPI() override;
void Died() override;
CommandCallback *GetDoCommandCallback() override;
void LoadDummyScript() override;
};
#endif /* AI_INSTANCE_HPP */

View File

@@ -19,7 +19,7 @@ public:
AIScannerInfo();
~AIScannerInfo();
/* virtual */ void Initialize();
void Initialize() override;
/**
* Select a random AI.
@@ -42,11 +42,11 @@ public:
void SetDummyAI(class AIInfo *info);
protected:
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, const char *last);
/* virtual */ const char *GetFileName() const { return PATHSEP "info.nut"; }
/* virtual */ Subdirectory GetDirectory() const { return AI_DIR; }
/* virtual */ const char *GetScannerName() const { return "AIs"; }
/* virtual */ void RegisterAPI(class Squirrel *engine);
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
const char *GetFileName() const override { return PATHSEP "info.nut"; }
Subdirectory GetDirectory() const override { return AI_DIR; }
const char *GetScannerName() const override { return "AIs"; }
void RegisterAPI(class Squirrel *engine) override;
private:
AIInfo *info_dummy; ///< The dummy AI.
@@ -54,7 +54,7 @@ private:
class AIScannerLibrary : public ScriptScanner {
public:
/* virtual */ void Initialize();
void Initialize() override;
/**
* Find a library in the pool.
@@ -65,11 +65,11 @@ public:
class AILibrary *FindLibrary(const char *library, int version);
protected:
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, const char *last);
/* virtual */ const char *GetFileName() const { return PATHSEP "library.nut"; }
/* virtual */ Subdirectory GetDirectory() const { return AI_LIBRARY_DIR; }
/* virtual */ const char *GetScannerName() const { return "AI Libraries"; }
/* virtual */ void RegisterAPI(class Squirrel *engine);
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
const char *GetFileName() const override { return PATHSEP "library.nut"; }
Subdirectory GetDirectory() const override { return AI_LIBRARY_DIR; }
const char *GetScannerName() const override { return "AI Libraries"; }
void RegisterAPI(class Squirrel *engine) override;
};
#endif /* AI_SCANNER_HPP */

View File

@@ -795,6 +795,7 @@ int GetAircraftFlightLevel(T *v, bool takeoff)
}
template int GetAircraftFlightLevel(DisasterVehicle *v, bool takeoff);
template int GetAircraftFlightLevel(Aircraft *v, bool takeoff);
/**
* Find the entry point to an airport depending on direction which

View File

@@ -87,14 +87,14 @@ struct BuildAirToolbarWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) delete this;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_AT_AIRPORT:
@@ -114,7 +114,7 @@ struct BuildAirToolbarWindow : Window {
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
void OnPlaceObject(Point pt, TileIndex tile) override
{
switch (this->last_user_action) {
case WID_AT_AIRPORT:
@@ -129,19 +129,19 @@ struct BuildAirToolbarWindow : Window {
}
}
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
{
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
{
if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
}
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
this->RaiseButtons();
@@ -219,7 +219,7 @@ class BuildAirportWindow : public PickerWindowBase {
DropDownList *list = new DropDownList();
for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
*list->Append() = new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false);
list->push_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
}
return list;
@@ -268,7 +268,7 @@ public:
DeleteWindowById(WC_SELECT_STATION, 0);
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN:
@@ -293,7 +293,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN: {
@@ -357,7 +357,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_AP_AIRPORT_LIST: {
@@ -394,7 +394,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
this->DrawWidgets();
@@ -462,7 +462,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_AP_CLASS_DROPDOWN:
@@ -535,7 +535,7 @@ public:
this->SelectOtherAirport(-1);
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
assert(widget == WID_AP_CLASS_DROPDOWN);
_selected_airport_class = (AirportClassID)index;
@@ -543,7 +543,7 @@ public:
this->SelectFirstAvailableAirport(false);
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
CheckRedrawStationCoverage(this);
}

View File

@@ -19,7 +19,7 @@
#include "safeguards.h"
/** The table/list with animated tiles. */
SmallVector<TileIndex, 256> _animated_tiles;
std::vector<TileIndex> _animated_tiles;
/**
* Removes the given tile from the animated tile table.
@@ -27,10 +27,10 @@ SmallVector<TileIndex, 256> _animated_tiles;
*/
void DeleteAnimatedTile(TileIndex tile)
{
TileIndex *to_remove = _animated_tiles.Find(tile);
if (to_remove != _animated_tiles.End()) {
auto to_remove = std::find(_animated_tiles.begin(), _animated_tiles.end(), tile);
if (to_remove != _animated_tiles.end()) {
/* The order of the remaining elements must stay the same, otherwise the animation loop may miss a tile. */
_animated_tiles.ErasePreservingOrder(to_remove);
_animated_tiles.erase(to_remove);
MarkTileDirtyByTile(tile, ZOOM_LVL_DRAW_MAP);
}
}
@@ -43,7 +43,7 @@ void DeleteAnimatedTile(TileIndex tile)
void AddAnimatedTile(TileIndex tile)
{
MarkTileDirtyByTile(tile, ZOOM_LVL_DRAW_MAP);
_animated_tiles.Include(tile);
include(_animated_tiles, tile);
}
/**
@@ -58,8 +58,8 @@ void AnimateAnimatedTiles()
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
const TileIndex *ti = _animated_tiles.Begin();
while (ti < _animated_tiles.End()) {
const TileIndex *ti = _animated_tiles.data();
while (ti < _animated_tiles.data() + _animated_tiles.size()) {
const TileIndex curr = *ti;
switch (GetTileType(curr)) {
case MP_HOUSE:
@@ -100,5 +100,5 @@ void AnimateAnimatedTiles()
*/
void InitializeAnimatedTiles()
{
_animated_tiles.Clear();
_animated_tiles.clear();
}

View File

@@ -201,16 +201,16 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
* @param engine Model to investigate.
* @param[out] cargoes Total amount of units that can be transported, summed by cargo.
* @param[out] refits Whether a (possibly partial) refit for each cargo is possible.
* @param cargo_type Selected refitted cargo type
* @param cargo_capacity Capacity of selected refitted cargo type
*/
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits)
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint16 cargo_capacity)
{
cargoes->Clear();
*refits = 0;
const Engine *e = Engine::Get(engine);
CargoID cargo_type;
uint16 cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
if (cargo_type < NUM_CARGO && cargo_capacity > 0) {
(*cargoes)[cargo_type] += cargo_capacity;
if (IsEngineRefittable(engine)) SetBit(*refits, cargo_type);

View File

@@ -299,7 +299,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
if (refit_cargo == CT_INVALID) return CommandCost(); // incompatible cargoes
/* Build the new vehicle */
cost = DoCommand(old_veh->tile, e, 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh));
cost = DoCommand(old_veh->tile, e | (CT_INVALID << 24), 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh));
if (cost.Failed()) return cost;
Vehicle *new_veh = Vehicle::Get(_new_vehicle_id);

View File

@@ -123,7 +123,7 @@ class ReplaceVehicleWindow : public Window {
byte side = draw_left ? 0 : 1;
GUIEngineList *list = &this->engines[side];
list->Clear();
list->clear();
const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, type) {
@@ -140,7 +140,7 @@ class ReplaceVehicleWindow : public Window {
if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
}
*list->Append() = eid;
list->push_back(eid);
if (eid == this->sel_engine[side]) selected_engine = eid; // The selected engine is still in the list
}
this->sel_engine[side] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
@@ -160,8 +160,8 @@ class ReplaceVehicleWindow : public Window {
if (this->engines[0].NeedRebuild()) {
/* We need to rebuild the left engines list */
this->GenerateReplaceVehList(true);
this->vscroll[0]->SetCount(this->engines[0].Length());
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].Length() != 0) {
this->vscroll[0]->SetCount(this->engines[0].size());
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) {
this->sel_engine[0] = this->engines[0][0];
}
}
@@ -170,7 +170,7 @@ class ReplaceVehicleWindow : public Window {
/* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */
if (this->sel_engine[0] == INVALID_ENGINE) {
/* Always empty the right engines list when nothing is selected in the left engines list */
this->engines[1].Clear();
this->engines[1].clear();
this->sel_engine[1] = INVALID_ENGINE;
} else {
if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
@@ -180,11 +180,11 @@ class ReplaceVehicleWindow : public Window {
}
/* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
this->GenerateReplaceVehList(false);
this->vscroll[1]->SetCount(this->engines[1].Length());
this->vscroll[1]->SetCount(this->engines[1].size());
if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
int position = 0;
for (EngineID *it = this->engines[1].Begin(); it != this->engines[1].End(); ++it) {
if (*it == this->sel_engine[1]) break;
for (EngineID &eid : this->engines[1]) {
if (eid == this->sel_engine[1]) break;
++position;
}
this->vscroll[1]->ScrollTowards(position);
@@ -237,7 +237,7 @@ public:
this->sel_group = id_g;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING: {
@@ -316,7 +316,7 @@ public:
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_RV_CAPTION:
@@ -353,7 +353,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING:
@@ -384,7 +384,7 @@ public:
case WID_RV_RIGHT_MATRIX: {
int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
EngineID start = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
EngineID end = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].Length());
EngineID end = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].size());
/* Do the actual drawing */
DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
@@ -394,7 +394,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
if (this->engines[0].NeedRebuild() || this->engines[1].NeedRebuild()) this->GenerateLists();
@@ -423,9 +423,16 @@ public:
/* Draw details panels. */
for (int side = 0; side < 2; side++) {
if (this->sel_engine[side] != INVALID_ENGINE) {
/* Use default engine details without refitting */
const Engine *e = Engine::Get(this->sel_engine[side]);
TestedEngineDetails ted;
ted.cost = 0;
ted.cargo = e->GetDefaultCargoType();
ted.capacity = e->GetDisplayDefaultCapacity(&ted.mail_capacity);
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? WID_RV_LEFT_DETAILS : WID_RV_RIGHT_DETAILS);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side]);
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side], ted);
needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
}
}
@@ -437,7 +444,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING:
@@ -461,8 +468,8 @@ public:
case WID_RV_TRAIN_ENGINEWAGON_DROPDOWN: {
DropDownList *list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false);
*list->Append() = new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false);
list->push_back(new DropDownListStringItem(STR_REPLACE_ENGINES, 1, false));
list->push_back(new DropDownListStringItem(STR_REPLACE_WAGONS, 0, false));
ShowDropDownList(this, list, this->replace_engines ? 1 : 0, WID_RV_TRAIN_ENGINEWAGON_DROPDOWN);
break;
}
@@ -501,7 +508,7 @@ public:
click_side = 1;
}
uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
size_t engine_count = this->engines[click_side].Length();
size_t engine_count = this->engines[click_side].size();
EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
@@ -516,7 +523,7 @@ public:
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_RV_SORT_DROPDOWN:
@@ -557,7 +564,7 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll[0]->SetCapacityFromWidget(this, WID_RV_LEFT_MATRIX);
this->vscroll[1]->SetCapacityFromWidget(this, WID_RV_RIGHT_MATRIX);
@@ -568,7 +575,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (data != 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */

View File

@@ -76,9 +76,9 @@ struct BaseSet {
{
free(this->name);
for (TranslatedStrings::iterator iter = this->description.Begin(); iter != this->description.End(); iter++) {
free(iter->first);
free(iter->second);
for (auto &pair : this->description) {
free(pair.first);
free(pair.second);
}
for (uint i = 0; i < NUM_FILES; i++) {
@@ -122,16 +122,16 @@ struct BaseSet {
{
if (isocode != NULL) {
/* First the full ISO code */
for (TranslatedStrings::const_iterator iter = this->description.Begin(); iter != this->description.End(); iter++) {
if (strcmp(iter->first, isocode) == 0) return iter->second;
for (const auto &pair : this->description) {
if (strcmp(pair.first, isocode) == 0) return pair.second;
}
/* Then the first two characters */
for (TranslatedStrings::const_iterator iter = this->description.Begin(); iter != this->description.End(); iter++) {
if (strncmp(iter->first, isocode, 2) == 0) return iter->second;
for (const auto &pair : this->description) {
if (strncmp(pair.first, isocode, 2) == 0) return pair.second;
}
}
/* Then fall back */
return this->description.Begin()->second;
return this->description.front().second;
}
/**
@@ -176,7 +176,7 @@ protected:
static Tbase_set *duplicate_sets; ///< All sets that aren't available, but needed for not downloading base sets when a newer version than the one on BaNaNaS is loaded.
static const Tbase_set *used_set; ///< The currently used set
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename);
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override;
/**
* Get the extension that is used to identify this set.

View File

@@ -277,7 +277,6 @@ template <class Tbase_set>
return p;
}
#if defined(ENABLE_NETWORK)
#include "network/network_content.h"
template <class Tbase_set> const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s)
@@ -307,22 +306,6 @@ template <class Tbase_set>
(TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != NULL);
}
#else
template <class Tbase_set>
const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s)
{
return NULL;
}
template <class Tbase_set>
/* static */ bool BaseMedia<Tbase_set>::HasSet(const ContentInfo *ci, bool md5sum)
{
return false;
}
#endif /* ENABLE_NETWORK */
/**
* Count the number of available graphics sets.
* @return the number of sets

View File

@@ -110,6 +110,12 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
*/
virtual void UpdateVirtCoord() = 0;
virtual void MoveSign(TileIndex new_xy)
{
this->xy = new_xy;
this->UpdateVirtCoord();
}
/**
* Get the tile area for a given station type.
* @param ta tile area to fill.

View File

@@ -37,23 +37,23 @@ public:
~Blitter_32bppAnim();
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash);
/* virtual */ void SetLine(void *video, int x, int y, uint8 *colours, uint width);
/* virtual */ void SetLine32(void *video, int x, int y, uint32 *colours, uint width);
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
/* virtual */ int BufferSize(int width, int height);
/* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
void SetPixel(void *video, int x, int y, uint8 colour) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetLine(void *video, int x, int y, uint8 *colours, uint width) override;
void SetLine32(void *video, int x, int y, uint32 *colours, uint width) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
int BufferSize(int width, int height) override;
void PaletteAnimate(const Palette &palette) override;
Blitter::PaletteAnimation UsePaletteAnimation() override;
/* virtual */ const char *GetName() { return "32bpp-anim"; }
/* virtual */ int GetBytesPerPixel() { return 6; }
/* virtual */ void PostResize();
const char *GetName() override { return "32bpp-anim"; }
int GetBytesPerPixel() override { return 6; }
void PostResize() override;
/**
* Look up the colour in the current palette.
@@ -79,7 +79,7 @@ public:
class FBlitter_32bppAnim : public BlitterFactory {
public:
FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); }
Blitter *CreateInstance() override { return new Blitter_32bppAnim(); }
};
#endif /* BLITTER_32BPP_ANIM_HPP */

View File

@@ -28,15 +28,15 @@
/** A partially 32 bpp blitter with palette animation. */
class Blitter_32bppSSE2_Anim : public Blitter_32bppAnim {
public:
/* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ const char *GetName() { return "32bpp-sse2-anim"; }
void PaletteAnimate(const Palette &palette) override;
const char *GetName() override { return "32bpp-sse2-anim"; }
};
/** Factory for the partially 32bpp blitter with animation. */
class FBlitter_32bppSSE2_Anim : public BlitterFactory {
public:
FBlitter_32bppSSE2_Anim() : BlitterFactory("32bpp-sse2-anim", "32bpp partially SSE2 Animation Blitter (palette animation)", HasCPUIDFlag(1, 3, 26)) {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSSE2_Anim(); }
Blitter *CreateInstance() override { return new Blitter_32bppSSE2_Anim(); }
};
#endif /* WITH_SSE */

View File

@@ -35,19 +35,19 @@ private:
public:
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent, bool animated>
/* virtual */ void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) {
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
}
/* virtual */ const char *GetName() { return "32bpp-sse4-anim"; }
const char *GetName() override { return "32bpp-sse4-anim"; }
};
/** Factory for the SSE4 32 bpp blitter (with palette animation). */
class FBlitter_32bppSSE4_Anim: public BlitterFactory {
public:
FBlitter_32bppSSE4_Anim() : BlitterFactory("32bpp-sse4-anim", "SSE4 Blitter (palette animation)", HasCPUIDFlag(1, 2, 19)) {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSSE4_Anim(); }
Blitter *CreateInstance() override { return new Blitter_32bppSSE4_Anim(); }
};
#endif /* WITH_SSE */

View File

@@ -20,21 +20,21 @@
/** Base for all 32bpp blitters. */
class Blitter_32bppBase : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 32; }
/* virtual */ void *MoveTo(void *video, int x, int y);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash);
/* virtual */ void SetLine(void *video, int x, int y, uint8 *colours, uint width);
/* virtual */ void SetLine32(void *video, int x, int y, uint32 *colours, uint width);
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
/* virtual */ int BufferSize(int width, int height);
/* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
/* virtual */ int GetBytesPerPixel() { return 4; }
uint8 GetScreenDepth() override { return 32; }
void *MoveTo(void *video, int x, int y) override;
void SetPixel(void *video, int x, int y, uint8 colour) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetLine(void *video, int x, int y, uint8 *colours, uint width) override;
void SetLine32(void *video, int x, int y, uint32 *colours, uint width) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override;
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
int BufferSize(int width, int height) override;
void PaletteAnimate(const Palette &palette) override;
Blitter::PaletteAnimation UsePaletteAnimation() override;
int GetBytesPerPixel() override { return 4; }
/**
* Look up the colour in the current palette.

View File

@@ -24,10 +24,10 @@ public:
byte data[]; ///< Data, all zoomlevels.
};
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
/* virtual */ const char *GetName() { return "32bpp-optimized"; }
const char *GetName() override { return "32bpp-optimized"; }
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
};
@@ -36,7 +36,7 @@ public:
class FBlitter_32bppOptimized : public BlitterFactory {
public:
FBlitter_32bppOptimized() : BlitterFactory("32bpp-optimized", "32bpp Optimized Blitter (no palette animation)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppOptimized(); }
Blitter *CreateInstance() override { return new Blitter_32bppOptimized(); }
};
#endif /* BLITTER_32BPP_OPTIMIZED_HPP */

View File

@@ -26,18 +26,18 @@ class Blitter_32bppSimple : public Blitter_32bppBase {
uint8 v; ///< Brightness-channel
};
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
/* virtual */ const char *GetName() { return "32bpp-simple"; }
const char *GetName() override { return "32bpp-simple"; }
};
/** Factory for the simple 32 bpp blitter. */
class FBlitter_32bppSimple : public BlitterFactory {
public:
FBlitter_32bppSimple() : BlitterFactory("32bpp-simple", "32bpp Simple Blitter (no palette animation)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); }
Blitter *CreateInstance() override { return new Blitter_32bppSimple(); }
};
#endif /* BLITTER_32BPP_SIMPLE_HPP */

View File

@@ -68,22 +68,22 @@ public:
/** The SSE2 32 bpp blitter (without palette animation). */
class Blitter_32bppSSE2 : public Blitter_32bppSimple, public Blitter_32bppSSE_Base {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) {
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
}
/* virtual */ const char *GetName() { return "32bpp-sse2"; }
const char *GetName() override { return "32bpp-sse2"; }
};
/** Factory for the SSE2 32 bpp blitter (without palette animation). */
class FBlitter_32bppSSE2 : public BlitterFactory {
public:
FBlitter_32bppSSE2() : BlitterFactory("32bpp-sse2", "32bpp SSE2 Blitter (no palette animation)", HasCPUIDFlag(1, 3, 26)) {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSSE2(); }
Blitter *CreateInstance() override { return new Blitter_32bppSSE2(); }
};
#endif /* WITH_SSE */

View File

@@ -27,17 +27,17 @@
/** The SSE4 32 bpp blitter (without palette animation). */
class Blitter_32bppSSE4 : public Blitter_32bppSSSE3 {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
/* virtual */ const char *GetName() { return "32bpp-sse4"; }
const char *GetName() override { return "32bpp-sse4"; }
};
/** Factory for the SSE4 32 bpp blitter (without palette animation). */
class FBlitter_32bppSSE4: public BlitterFactory {
public:
FBlitter_32bppSSE4() : BlitterFactory("32bpp-sse4", "32bpp SSE4 Blitter (no palette animation)", HasCPUIDFlag(1, 2, 19)) {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSSE4(); }
Blitter *CreateInstance() override { return new Blitter_32bppSSE4(); }
};
#endif /* WITH_SSE */

View File

@@ -27,17 +27,17 @@
/** The SSSE3 32 bpp blitter (without palette animation). */
class Blitter_32bppSSSE3 : public Blitter_32bppSSE2 {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
/* virtual */ const char *GetName() { return "32bpp-ssse3"; }
const char *GetName() override { return "32bpp-ssse3"; }
};
/** Factory for the SSSE3 32 bpp blitter (without palette animation). */
class FBlitter_32bppSSSE3: public BlitterFactory {
public:
FBlitter_32bppSSSE3() : BlitterFactory("32bpp-ssse3", "32bpp SSSE3 Blitter (no palette animation)", HasCPUIDFlag(1, 2, 9)) {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSSSE3(); }
Blitter *CreateInstance() override { return new Blitter_32bppSSSE3(); }
};
#endif /* WITH_SSE */

View File

@@ -17,21 +17,21 @@
/** Base for all 8bpp blitters. */
class Blitter_8bppBase : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 8; }
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
/* virtual */ void *MoveTo(void *video, int x, int y);
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash);
/* virtual */ void SetLine(void *video, int x, int y, uint8 *colours, uint width);
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
/* virtual */ int BufferSize(int width, int height);
/* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
/* virtual */ int GetBytesPerPixel() { return 1; }
uint8 GetScreenDepth() override { return 8; }
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
void *MoveTo(void *video, int x, int y) override;
void SetPixel(void *video, int x, int y, uint8 colour) override;
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
void SetLine(void *video, int x, int y, uint8 *colours, uint width) override;
void DrawRect(void *video, int width, int height, uint8 colour) override;
void CopyFromBuffer(void *video, const void *src, int width, int height) override;
void CopyToBuffer(const void *video, void *dst, int width, int height) override;
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override;
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
int BufferSize(int width, int height) override;
void PaletteAnimate(const Palette &palette) override;
Blitter::PaletteAnimation UsePaletteAnimation() override;
int GetBytesPerPixel() override { return 1; }
};
#endif /* BLITTER_8BPP_BASE_HPP */

View File

@@ -24,17 +24,17 @@ public:
byte data[]; ///< Data, all zoomlevels.
};
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
const char *GetName() override { return "8bpp-optimized"; }
};
/** Factory for the 8bpp blitter optimised for speed. */
class FBlitter_8bppOptimized : public BlitterFactory {
public:
FBlitter_8bppOptimized() : BlitterFactory("8bpp-optimized", "8bpp Optimized Blitter (compression + all-ZoomLevel cache)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); }
Blitter *CreateInstance() override { return new Blitter_8bppOptimized(); }
};
#endif /* BLITTER_8BPP_OPTIMIZED_HPP */

View File

@@ -18,17 +18,17 @@
/** Most trivial 8bpp blitter. */
class Blitter_8bppSimple FINAL : public Blitter_8bppBase {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
/* virtual */ const char *GetName() { return "8bpp-simple"; }
const char *GetName() override { return "8bpp-simple"; }
};
/** Factory for the most trivial 8bpp blitter. */
class FBlitter_8bppSimple : public BlitterFactory {
public:
FBlitter_8bppSimple() : BlitterFactory("8bpp-simple", "8bpp Simple Blitter (relative slow, but never wrong)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); }
Blitter *CreateInstance() override { return new Blitter_8bppSimple(); }
};
#endif /* BLITTER_8BPP_SIMPLE_HPP */

View File

@@ -17,32 +17,33 @@
/** Blitter that does nothing. */
class Blitter_Null : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 0; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) {};
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) {};
/* virtual */ Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
/* virtual */ void *MoveTo(void *video, int x, int y) { return NULL; };
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour) {};
/* virtual */ void SetLine(void *video, int x, int y, uint8 *colours, uint width) {};
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour) {};
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) {};
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height) {};
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height) {};
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) {};
/* virtual */ int BufferSize(int width, int height) { return 0; };
/* virtual */ void PaletteAnimate(const Palette &palette) { };
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation() { return Blitter::PALETTE_ANIMATION_NONE; };
uint8 GetScreenDepth() override { return 0; }
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override {};
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override {};
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
void *MoveTo(void *video, int x, int y) override { return NULL; };
void SetPixel(void *video, int x, int y, uint8 colour) override {};
void DrawRect(void *video, int width, int height, uint8 colour) override {};
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override {};
void SetLine(void *video, int x, int y, uint8 *colours, uint width) override {};
void SetLine32(void *video, int x, int y, uint32 *colours, uint width) override {};
void CopyFromBuffer(void *video, const void *src, int width, int height) override {};
void CopyToBuffer(const void *video, void *dst, int width, int height) override {};
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override {};
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override {};
int BufferSize(int width, int height) override { return 0; };
void PaletteAnimate(const Palette &palette) override { };
Blitter::PaletteAnimation UsePaletteAnimation() override { return Blitter::PALETTE_ANIMATION_NONE; };
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ int GetBytesPerPixel() { return 0; }
const char *GetName() override { return "null"; }
int GetBytesPerPixel() override { return 0; }
};
/** Factory for the blitter that does nothing. */
class FBlitter_Null : public BlitterFactory {
public:
FBlitter_Null() : BlitterFactory("null", "Null Blitter (does nothing)") {}
/* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); }
Blitter *CreateInstance() override { return new Blitter_Null(); }
};
#endif /* BLITTER_NULL_HPP */

View File

@@ -13,7 +13,7 @@
#include "base_media_base.h"
#include "blitter/factory.hpp"
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE)
#if defined(WITH_FREETYPE)
#include "core/geometry_func.hpp"
#include "fontcache.h"
@@ -56,7 +56,7 @@ public:
ResizeWindow(this, _screen.width, _screen.height);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
GfxFillRect(r.left, r.top, r.right, r.bottom, 4, FILLRECT_OPAQUE);
GfxFillRect(r.left, r.top, r.right, r.bottom, 0, FILLRECT_CHECKER);
@@ -88,7 +88,7 @@ public:
{
}
virtual void OnDownloadComplete(ContentID cid)
void OnDownloadComplete(ContentID cid) override
{
/* We have completed downloading. We can trigger finding the right set now. */
BaseGraphics::FindSets();
@@ -142,7 +142,7 @@ public:
_network_content_client.RemoveCallback(this);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
/* We cache the button size. This is safe as no reinit can happen here. */
if (this->button_size.width == 0) {
@@ -165,14 +165,14 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != 0) return;
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMETEXT_BOTTOM, STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_BAFD_YES:
@@ -189,13 +189,13 @@ public:
}
}
virtual void OnConnect(bool success)
void OnConnect(bool success) override
{
/* Once connected, request the metadata. */
_network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
}
virtual void OnReceiveContentInfo(const ContentInfo *ci)
void OnReceiveContentInfo(const ContentInfo *ci) override
{
/* And once the meta data is received, start downloading it. */
_network_content_client.Select(ci->id);
@@ -204,7 +204,7 @@ public:
}
};
#endif /* defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) */
#endif /* defined(WITH_FREETYPE) */
/**
* Handle all procedures for bootstrapping OpenTTD without a base graphics set.
@@ -220,7 +220,7 @@ bool HandleBootstrap()
if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
/* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(_WIN32) || defined(__APPLE__))
#if defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(_WIN32) || defined(__APPLE__))
if (!_network_available) goto failure;
/* First tell the game we're bootstrapping. */

View File

@@ -116,11 +116,11 @@ private:
void BuildBridge(uint8 i)
{
switch ((TransportType)(this->type >> 15)) {
case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->Get(i)->index; break;
case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->Get(i)->index; break;
case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->at(i).index; break;
case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->at(i).index; break;
default: break;
}
DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index,
DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->at(i).index,
CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
}
@@ -156,7 +156,7 @@ public:
this->bridges->NeedResort();
this->SortBridgeList();
this->vscroll->SetCount(bl->Length());
this->vscroll->SetCount(bl->size());
}
~BuildBridgeWindow()
@@ -166,7 +166,7 @@ public:
delete bridges;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BBS_DROPDOWN_ORDER: {
@@ -189,11 +189,11 @@ public:
case WID_BBS_BRIDGE_LIST: {
Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
Dimension text_dim = {0, 0}; // Biggest text dimension
for (int i = 0; i < (int)this->bridges->Length(); i++) {
const BridgeSpec *b = this->bridges->Get(i)->spec;
for (int i = 0; i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->at(i).spec;
sprite_dim = maxdim(sprite_dim, GetSpriteSize(b->sprite));
SetDParam(2, this->bridges->Get(i)->cost);
SetDParam(2, this->bridges->at(i).cost);
SetDParam(1, b->speed);
SetDParam(0, b->material);
text_dim = maxdim(text_dim, GetStringBoundingBox(_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO));
@@ -210,7 +210,7 @@ public:
}
}
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
{
/* Position the window so hopefully the first bridge from the list is under the mouse pointer. */
NWidgetBase *list = this->GetWidget<NWidgetBase>(WID_BBS_BRIDGE_LIST);
@@ -220,7 +220,7 @@ public:
return corner;
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_BBS_DROPDOWN_ORDER:
@@ -229,10 +229,10 @@ public:
case WID_BBS_BRIDGE_LIST: {
uint y = r.top;
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->Length(); i++) {
const BridgeSpec *b = this->bridges->Get(i)->spec;
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->at(i).spec;
SetDParam(2, this->bridges->Get(i)->cost);
SetDParam(2, this->bridges->at(i).cost);
SetDParam(1, b->speed);
SetDParam(0, b->material);
@@ -246,10 +246,10 @@ public:
}
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
const uint8 i = keycode - '1';
if (i < 9 && i < this->bridges->Length()) {
if (i < 9 && i < this->bridges->size()) {
/* Build the requested bridge */
this->BuildBridge(i);
delete this;
@@ -258,13 +258,13 @@ public:
return ES_NOT_HANDLED;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
default: break;
case WID_BBS_BRIDGE_LIST: {
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BBS_BRIDGE_LIST);
if (i < this->bridges->Length()) {
if (i < this->bridges->size()) {
this->BuildBridge(i);
delete this;
}
@@ -282,7 +282,7 @@ public:
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
if (widget == WID_BBS_DROPDOWN_CRITERIA && this->bridges->SortType() != index) {
this->bridges->SetSortType(index);
@@ -291,7 +291,7 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_BBS_BRIDGE_LIST);
}
@@ -425,17 +425,18 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
/* Re-check bridge building possibility is initial bridge builindg query indicated a bridge type dependent failure */
if (query_per_bridge_type && DoCommand(end, start, type | brd_type, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_QUERY_COST, CMD_BUILD_BRIDGE).Failed()) continue;
/* bridge is accepted, add to list */
BuildBridgeData *item = bl->Append();
item->index = brd_type;
item->spec = GetBridgeSpec(brd_type);
/*C++17: BuildBridgeData &item = */ bl->emplace_back();
BuildBridgeData &item = bl->back();
item.index = brd_type;
item.spec = GetBridgeSpec(brd_type);
/* Add to terraforming & bulldozing costs the cost of the
* bridge itself (not computed with DC_QUERY_COST) */
item->cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item->spec->price) >> 8) + infra_cost;
item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost;
}
}
}
if (bl != NULL && bl->Length() != 0) {
if (bl != NULL && bl->size() != 0) {
new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl);
} else {
delete bl;

View File

@@ -82,9 +82,6 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = {
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0),
EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_REFIT_SEL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_BUILD_REFIT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_BUTTON, STR_BUY_REFIT_VEHICLE_BUY_VEHICLE_TOOLTIP),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
@@ -100,7 +97,6 @@ byte _engine_sort_last_criteria[] = {0, 0, 0, 0}; ///< Las
bool _engine_sort_last_order[] = {false, false, false, false}; ///< Last set direction of the sort order, for each vehicle type.
bool _engine_sort_show_hidden_engines[] = {false, false, false, false}; ///< Last set 'show hidden engines' setting for each vehicle type.
static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY}; ///< Last set filter criteria, for each vehicle type.
static bool _refit_on_buy = false; ///< to save user's choice for at least this game session
/**
* Determines order of engines by engineID
@@ -537,11 +533,11 @@ static GUIEngineList::FilterFunction * const _filter_funcs[] = {
&CargoFilter,
};
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine)
static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, TestedEngineDetails &te)
{
CargoArray cap;
CargoTypes refits;
GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits);
GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits, te.cargo, te.capacity);
for (CargoID c = 0; c < NUM_CARGO; c++) {
if (cap[c] == 0) continue;
@@ -557,19 +553,25 @@ static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine)
}
/* Draw rail wagon specific details */
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
/* Purchase cost */
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
} else {
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL;
/* Wagon weight - (including cargo) */
uint weight = e->GetDisplayWeight();
SetDParam(0, weight);
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * GetTotalCapacityOfArticulatedParts(engine_number) / 16 : 0);
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
SetDParam(1, cargo_weight + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
y += FONT_HEIGHT_NORMAL;
@@ -595,14 +597,21 @@ static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine
}
/* Draw locomotive specific details */
static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
/* Purchase Cost - Engine weight */
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayWeight());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
SetDParam(2, e->GetDisplayWeight());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
} else {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayWeight());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
}
y += FONT_HEIGHT_NORMAL;
/* Max speed - Engine power */
@@ -637,20 +646,26 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin
}
/* Draw road vehicle specific details */
static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number)
static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
/* Purchase Cost */
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
} else {
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL;
/* Road vehicle weight - (including cargo) */
int16 weight = e->GetDisplayWeight();
SetDParam(0, weight);
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(e->GetDefaultCargoType())->weight * GetTotalCapacityOfArticulatedParts(engine_number) / 16 : 0);
uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
SetDParam(1, cargo_weight + weight);
DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
y += FONT_HEIGHT_NORMAL;
@@ -667,9 +682,16 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
y += FONT_HEIGHT_NORMAL;
} else {
/* Purchase cost - Max speed */
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
SetDParam(2, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
} else {
SetDParam(0, e->GetCost());
SetDParam(2, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL;
}
@@ -682,7 +704,7 @@ static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_n
}
/* Draw ship specific details */
static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable)
static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
@@ -691,13 +713,27 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
uint ocean_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, true);
uint canal_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, false);
SetDParam(0, e->GetCost());
if (ocean_speed == canal_speed) {
SetDParam(1, ocean_speed);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
SetDParam(2, ocean_speed);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
} else {
SetDParam(0, e->GetCost());
SetDParam(1, ocean_speed);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL;
} else {
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
} else {
SetDParam(0, e->GetCost());
DrawString(left, right, y, STR_PURCHASE_INFO_COST);
}
y += FONT_HEIGHT_NORMAL;
SetDParam(0, ocean_speed);
@@ -710,8 +746,8 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
}
/* Cargo type + capacity */
SetDParam(0, e->GetDefaultCargoType());
SetDParam(1, e->GetDisplayDefaultCapacity());
SetDParam(0, te.cargo);
SetDParam(1, te.capacity);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
y += FONT_HEIGHT_NORMAL;
@@ -733,31 +769,35 @@ static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_numb
* @param refittable If set, the aircraft can be refitted.
* @return Bottom of the used area.
*/
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable)
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
CargoID cargo = e->GetDefaultCargoType();
/* Purchase cost - Max speed */
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
if (te.cost != 0) {
SetDParam(0, e->GetCost() + te.cost);
SetDParam(1, te.cost);
SetDParam(2, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
} else {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
}
y += FONT_HEIGHT_NORMAL;
/* Cargo capacity */
uint16 mail_capacity;
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
if (mail_capacity > 0) {
SetDParam(0, cargo);
SetDParam(1, capacity);
if (te.mail_capacity > 0) {
SetDParam(0, te.cargo);
SetDParam(1, te.capacity);
SetDParam(2, CT_MAIL);
SetDParam(3, mail_capacity);
SetDParam(3, te.mail_capacity);
DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
} else {
/* Note, if the default capacity is selected by the refit capacity
* callback, then the capacity shown is likely to be incorrect. */
SetDParam(0, cargo);
SetDParam(1, capacity);
SetDParam(0, te.cargo);
SetDParam(1, te.capacity);
SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
}
@@ -814,7 +854,7 @@ static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
* @param engine_number the engine of which to draw the info of
* @return y after drawing all the text
*/
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
{
const Engine *e = Engine::Get(engine_number);
YearMonthDay ymd;
@@ -826,30 +866,30 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
default: NOT_REACHED();
case VEH_TRAIN:
if (e->u.rail.railveh_type == RAILVEH_WAGON) {
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail);
y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
} else {
y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail);
y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
}
articulated_cargo = true;
break;
case VEH_ROAD:
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number);
y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
articulated_cargo = true;
break;
case VEH_SHIP:
y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable);
y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
break;
case VEH_AIRCRAFT:
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable);
y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
break;
}
if (articulated_cargo) {
/* Cargo type + capacity, or N/A */
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number);
int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, te);
if (new_y == y) {
SetDParam(0, CT_INVALID);
@@ -901,7 +941,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
/* Obligatory sanity checks! */
assert(max <= eng_list->Length());
assert(max <= eng_list->size());
bool rtl = _current_text_dir == TD_RTL;
int step_size = GetEngineListHeight(type);
@@ -993,9 +1033,30 @@ struct BuildVehicleWindow : Window {
byte cargo_filter_criteria; ///< Selected cargo filter
int details_height; ///< Minimal needed height of the details panels (found so far).
Scrollbar *vscroll;
bool build_and_refit; ///< Build and refit. This is beauty, but we need some persistence to save user choice for this game session at least
bool virtual_train_mode; ///< Are we building a virtual train?
Train **virtual_train_out; ///< Virtual train ptr
TestedEngineDetails te; ///< Tested cost and capacity after refit.
void SetBuyVehicleText()
{
NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter[this->cargo_filter_criteria] != CF_ANY && this->cargo_filter[this->cargo_filter_criteria] != CF_NONE;
if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter[this->cargo_filter_criteria];
if (this->virtual_train_mode) {
widget->widget_data = STR_TMPL_CONFIRM;
widget->tool_tip = STR_TMPL_CONFIRM;
} else {
if (refit) {
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type;
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type;
} else {
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type;
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type;
}
}
}
BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type, Train **virtual_train_out) : Window(desc)
{
@@ -1033,7 +1094,6 @@ struct BuildVehicleWindow : Window {
* So we just hide it, and enlarge the Rename button by the now vacant place. */
if (this->listview_mode) {
this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
this->GetWidget<NWidgetStacked>(WID_BV_BUILD_REFIT_SEL)->SetDisplayedPlane(SZSP_NONE);
}
/* disable renaming engines in network games if you are not the server */
@@ -1045,18 +1105,6 @@ struct BuildVehicleWindow : Window {
widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
this->build_and_refit = _refit_on_buy;
this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit);
widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
if (this->virtual_train_mode) {
widget->widget_data = STR_TMPL_CONFIRM;
widget->tool_tip = STR_TMPL_CONFIRM;
} else {
widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + type;
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + type;
}
widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
widget->widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
widget->tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
@@ -1075,7 +1123,11 @@ struct BuildVehicleWindow : Window {
this->eng_list.ForceRebuild();
this->GenerateBuildList(); // generate the list, since we need it in the next line
/* Select the first engine in the list as default when opening the window */
if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0];
if (this->eng_list.size() > 0) {
this->SelectEngine(this->eng_list[0]);
} else {
this->SelectEngine(INVALID_ENGINE);
}
}
/** Populate the filter list and set the cargo filter criteria. */
@@ -1122,7 +1174,42 @@ struct BuildVehicleWindow : Window {
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
}
void OnInit()
void SelectEngine(EngineID engine)
{
CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
if (cargo == CF_ANY) cargo = CF_NONE;
this->sel_engine = engine;
this->SetBuyVehicleText();
if (this->sel_engine == INVALID_ENGINE) return;
const Engine *e = Engine::Get(this->sel_engine);
if (!e->CanCarryCargo()) {
this->te.cost = 0;
this->te.cargo = CT_INVALID;
return;
}
if (!this->listview_mode) {
/* Query for cost and refitted capacity */
CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type), NULL);
if (ret.Succeeded()) {
this->te.cost = ret.GetCost() - e->GetCost();
this->te.capacity = _returned_refit_capacity;
this->te.mail_capacity = _returned_mail_refit_capacity;
this->te.cargo = (cargo == CT_INVALID) ? e->GetDefaultCargoType() : cargo;
return;
}
}
/* Purchase test was not possible or failed, fill in the defaults instead. */
this->te.cost = 0;
this->te.capacity = e->GetDisplayDefaultCapacity(&this->te.mail_capacity);
this->te.cargo = e->GetDefaultCargoType();
}
void OnInit() override
{
this->SetCargoFilterArray();
}
@@ -1131,10 +1218,10 @@ struct BuildVehicleWindow : Window {
void FilterEngineList()
{
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
if (0 == this->eng_list.Length()) { // no engine passed through the filter, invalidate the previously selected engine
this->sel_engine = INVALID_ENGINE;
} else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list
this->sel_engine = this->eng_list[0];
if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
this->SelectEngine(INVALID_ENGINE);
} else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
this->SelectEngine(this->eng_list[0]);
}
}
@@ -1154,7 +1241,7 @@ struct BuildVehicleWindow : Window {
this->filter.railtype = (this->listview_mode || this->virtual_train_mode) ? RAILTYPE_END : GetRailType(this->window_number);
this->eng_list.Clear();
this->eng_list.clear();
/* Make list of all available train engines and wagons.
* Also check to see if the previously selected engine is still available,
@@ -1172,7 +1259,7 @@ struct BuildVehicleWindow : Window {
/* Filter now! So num_engines and num_wagons is valid */
if (!FilterSingleEngine(eid)) continue;
*this->eng_list.Append() = eid;
this->eng_list.push_back(eid);
if (rvi->railveh_type != RAILVEH_WAGON) {
num_engines++;
@@ -1183,7 +1270,7 @@ struct BuildVehicleWindow : Window {
if (eid == this->sel_engine) sel_id = eid;
}
this->sel_engine = sel_id;
this->SelectEngine(sel_id);
/* make engines first, and then wagons, sorted by selected sort_criteria */
_engine_sort_direction = false;
@@ -1202,7 +1289,7 @@ struct BuildVehicleWindow : Window {
{
EngineID sel_id = INVALID_ENGINE;
this->eng_list.Clear();
this->eng_list.clear();
const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
@@ -1210,29 +1297,29 @@ struct BuildVehicleWindow : Window {
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
*this->eng_list.Append() = eid;
this->eng_list.push_back(eid);
if (eid == this->sel_engine) sel_id = eid;
}
this->sel_engine = sel_id;
this->SelectEngine(sel_id);
}
/* Figure out what ship EngineIDs to put in the list */
void GenerateBuildShipList()
{
EngineID sel_id = INVALID_ENGINE;
this->eng_list.Clear();
this->eng_list.clear();
const Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
EngineID eid = e->index;
if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
*this->eng_list.Append() = eid;
this->eng_list.push_back(eid);
if (eid == this->sel_engine) sel_id = eid;
}
this->sel_engine = sel_id;
this->SelectEngine(sel_id);
}
/* Figure out what aircraft EngineIDs to put in the list */
@@ -1240,7 +1327,7 @@ struct BuildVehicleWindow : Window {
{
EngineID sel_id = INVALID_ENGINE;
this->eng_list.Clear();
this->eng_list.clear();
const Station *st = this->listview_mode ? NULL : Station::GetByTile(this->window_number);
@@ -1256,11 +1343,11 @@ struct BuildVehicleWindow : Window {
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
*this->eng_list.Append() = eid;
this->eng_list.push_back(eid);
if (eid == this->sel_engine) sel_id = eid;
}
this->sel_engine = sel_id;
this->SelectEngine(sel_id);
}
/* Generate the list of vehicles */
@@ -1271,7 +1358,7 @@ struct BuildVehicleWindow : Window {
default: NOT_REACHED();
case VEH_TRAIN:
this->GenerateBuildTrainList();
this->eng_list.Compact();
this->eng_list.shrink_to_fit();
this->eng_list.RebuildDone();
return; // trains should not reach the last sorting
case VEH_ROAD:
@@ -1290,11 +1377,11 @@ struct BuildVehicleWindow : Window {
_engine_sort_direction = this->descending_sort_order;
EngList_Sort(&this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]);
this->eng_list.Compact();
this->eng_list.shrink_to_fit();
this->eng_list.RebuildDone();
}
void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_BV_SORT_ASCENDING_DESCENDING:
@@ -1314,8 +1401,8 @@ struct BuildVehicleWindow : Window {
case WID_BV_LIST: {
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST);
size_t num_items = this->eng_list.Length();
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
size_t num_items = this->eng_list.size();
this->SelectEngine((i < num_items) ? this->eng_list[i] : INVALID_ENGINE);
this->SetDirty();
if (_ctrl_pressed) {
this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
@@ -1341,13 +1428,6 @@ struct BuildVehicleWindow : Window {
break;
}
case WID_BV_BUILD_REFIT: {
_refit_on_buy = this->build_and_refit = !this->build_and_refit;
this->SetWidgetLoweredState(WID_BV_BUILD_REFIT, this->build_and_refit);
this->SetDirty();
break;
}
case WID_BV_BUILD: {
EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) {
@@ -1361,19 +1441,9 @@ struct BuildVehicleWindow : Window {
? CcBuildWagon : CcBuildPrimaryVehicle;
cmd = GetCmdBuildVeh(this->vehicle_type);
}
if (!this->IsWidgetDisabled(WID_BV_BUILD_REFIT) && this->build_and_refit) {
/* build and refit */
char text_buffer[2];
text_buffer[0] = 'R';
text_buffer[1] = this->cargo_filter[this->cargo_filter_criteria];
if ((cmd & 0xFFFF) == CMD_BUILD_VEHICLE) {
cmd = (cmd & ~0xFFFF) | CMD_BUILD_VEHICLE_NT;
}
DoCommandP(this->window_number, sel_eng, 0, cmd, callback, text_buffer, true, 2);
} else {
/* build only */
DoCommandP(this->window_number, sel_eng, 0, cmd, callback);
}
CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
if (cargo == CF_ANY) cargo = CF_NONE;
DoCommandP(this->window_number, sel_eng | (cargo << 24), 0, cmd, callback);
}
break;
}
@@ -1395,7 +1465,7 @@ struct BuildVehicleWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
/* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
@@ -1408,7 +1478,7 @@ struct BuildVehicleWindow : Window {
this->eng_list.ForceRebuild();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_BV_CAPTION:
@@ -1440,7 +1510,7 @@ struct BuildVehicleWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BV_LIST:
@@ -1461,6 +1531,13 @@ struct BuildVehicleWindow : Window {
break;
}
case WID_BV_BUILD:
*size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
*size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
size->width += padding.width;
size->height += padding.height;
break;
case WID_BV_SHOW_HIDE:
*size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
*size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
@@ -1470,11 +1547,11 @@ struct BuildVehicleWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_BV_LIST:
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size()), this->sel_engine, false, DEFAULT_GROUP);
break;
case WID_BV_SORT_ASCENDING_DESCENDING:
@@ -1483,20 +1560,13 @@ struct BuildVehicleWindow : Window {
}
}
virtual void OnPaint()
void OnPaint() override
{
this->GenerateBuildList();
this->vscroll->SetCount(this->eng_list.Length());
this->vscroll->SetCount(this->eng_list.size());
this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD, WID_BV_RENAME, WIDGET_LIST_END);
// disable build and refit if all or none cargo type selected
if (this->cargo_filter[this->cargo_filter_criteria] == CF_ANY || this->cargo_filter[this->cargo_filter_criteria] == CF_NONE) {
this->DisableWidget(WID_BV_BUILD_REFIT);
} else {
this->EnableWidget(WID_BV_BUILD_REFIT);
}
this->DrawWidgets();
if (!this->IsShaded()) {
@@ -1505,7 +1575,7 @@ struct BuildVehicleWindow : Window {
if (this->sel_engine != INVALID_ENGINE) {
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL);
int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine);
nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine, this->te);
needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
}
if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
@@ -1517,14 +1587,14 @@ struct BuildVehicleWindow : Window {
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
DoCommandP(0, this->rename_engine, 0, CMD_RENAME_ENGINE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type), NULL, str);
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_BV_SORT_DROPDOWN:
@@ -1542,13 +1612,14 @@ struct BuildVehicleWindow : Window {
/* deactivate filter if criteria is 'Show All', activate it otherwise */
this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
this->eng_list.ForceRebuild();
this->SelectEngine(this->sel_engine);
}
break;
}
this->SetDirty();
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
}

View File

@@ -221,7 +221,7 @@ struct CheatWindow : Window {
this->InitNested();
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_C_PANEL) return;
@@ -283,7 +283,7 @@ struct CheatWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_C_PANEL) return;
@@ -330,7 +330,7 @@ struct CheatWindow : Window {
size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + this->line_height * lengthof(_cheats_ui);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_C_PANEL);
uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / this->line_height;
@@ -384,13 +384,13 @@ struct CheatWindow : Window {
this->SetDirty();
}
virtual void OnTimeout()
void OnTimeout() override
{
this->clicked = 0;
this->SetDirty();
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
/* Was 'cancel' pressed or nothing entered? */
if (str == NULL || StrEmpty(str)) return;

View File

@@ -305,7 +305,6 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdPlantTree, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_PLANT_TREE
DEF_CMD(CmdBuildVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_BUILD_VEHICLE
DEF_CMD(CmdBuildVehicle, CMD_NO_TEST | CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_BUILD_VEHICLE_NT
DEF_CMD(CmdSellVehicle, CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION ), // CMD_SELL_VEHICLE
DEF_CMD(CmdRefitVehicle, 0, CMDT_VEHICLE_CONSTRUCTION ), // CMD_REFIT_VEHICLE
DEF_CMD(CmdSendVehicleToDepot, 0, CMDT_VEHICLE_MANAGEMENT ), // CMD_SEND_VEHICLE_TO_DEPOT
@@ -692,7 +691,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
/* only execute the test call if it's toplevel, or we're not execing. */
if (_docommand_recursive == 1 || !(flags & DC_EXEC) ) {
if (_docommand_recursive == 1) _cleared_object_areas.Clear();
if (_docommand_recursive == 1) _cleared_object_areas.clear();
SetTownRatingTestMode(true);
res = command.Execute(tile, flags & ~DC_EXEC, p1, p2, text, binary_length);
SetTownRatingTestMode(false);
@@ -715,7 +714,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
/* Execute the command here. All cost-relevant functions set the expenses type
* themselves to the cost object at some point */
if (_docommand_recursive == 1) _cleared_object_areas.Clear();
if (_docommand_recursive == 1) _cleared_object_areas.clear();
res = command.Execute(tile, flags, p1, p2, text, binary_length);
if (res.Failed()) {
error:
@@ -800,10 +799,8 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
return false;
}
#ifdef ENABLE_NETWORK
/* Only set p2 when the command does not come from the network. */
if (!(cmd & CMD_NETWORK_COMMAND) && GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = CLIENT_ID_SERVER;
#endif
CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only, binary_length);
if (res.Failed()) {
@@ -884,10 +881,8 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
/* Flags get send to the DoCommand */
DoCommandFlag flags = CommandFlagsToDCFlags(cmd_flags);
#ifdef ENABLE_NETWORK
/* Make sure p2 is properly set to a ClientID. */
assert(!(cmd_flags & CMD_CLIENT_ID) || p2 != 0);
#endif
/* Do not even think about executing out-of-bounds tile-commands */
if (tile != 0 && (tile >= MapSize() || (!IsValidTile(tile) && (cmd_flags & CMD_ALL_TILES) == 0))) return_dcpi(CMD_ERROR);
@@ -908,7 +903,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0;
/* Test the command. */
_cleared_object_areas.Clear();
_cleared_object_areas.clear();
SetTownRatingTestMode(true);
BasePersistentStorageArray::SwitchMode(PSM_ENTER_TESTMODE);
CommandCost res = command.Execute(tile, flags, p1, p2, text, binary_length);
@@ -934,7 +929,6 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
return_dcpi(res);
}
#ifdef ENABLE_NETWORK
/*
* If we are in network, and the command is not from the network
* send it to the command-queue and abort execution
@@ -949,12 +943,11 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
* reset the storages as we've not executed the command. */
return_dcpi(CommandCost());
}
#endif /* ENABLE_NETWORK */
DEBUG(desync, 1, "cmd: date{%08x; %02x; %02x}; %02x; %06x; %08x; %08x; %08x; \"%s\" (%s)", _date, _date_fract, _tick_skip_counter, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text, GetCommandName(cmd));
/* Actually try and execute the command. If no cost-type is given
* use the construction one */
_cleared_object_areas.Clear();
_cleared_object_areas.clear();
BasePersistentStorageArray::SwitchMode(PSM_ENTER_COMMAND);
CommandCost res2 = command.Execute(tile, flags | DC_EXEC, p1, p2, text, binary_length);
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_COMMAND);

View File

@@ -42,9 +42,7 @@ bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only, uint32 binary_length);
#ifdef ENABLE_NETWORK
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company, uint32 binary_length);
#endif /* ENABLE_NETWORK */
extern Money _additional_cash_required;

View File

@@ -253,7 +253,6 @@ enum Commands {
CMD_PLANT_TREE, ///< plant a tree
CMD_BUILD_VEHICLE, ///< build a vehicle
CMD_BUILD_VEHICLE_NT, ///< build a vehicle (no test)
CMD_SELL_VEHICLE, ///< sell a vehicle
CMD_REFIT_VEHICLE, ///< refit the cargo space of a vehicle
CMD_SEND_VEHICLE_TO_DEPOT, ///< send a vehicle to a depot

View File

@@ -106,10 +106,8 @@ void SetLocalCompany(CompanyID new_company)
/* company could also be COMPANY_SPECTATOR or OWNER_NONE */
assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
#ifdef ENABLE_NETWORK
/* Delete the chat window, if you were team chatting. */
InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company);
#endif
assert(IsLocalCompany());
@@ -605,9 +603,7 @@ void StartupCompanies()
/** Start a new competitor company if possible. */
static bool MaybeStartNewCompany()
{
#ifdef ENABLE_NETWORK
if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return false;
#endif /* ENABLE_NETWORK */
Company *c;
@@ -800,9 +796,7 @@ void CompanyNewsInformation::FillData(const Company *c, const Company *other)
*/
void CompanyAdminUpdate(const Company *company)
{
#ifdef ENABLE_NETWORK
if (_network_server) NetworkAdminCompanyUpdate(company);
#endif /* ENABLE_NETWORK */
}
/**
@@ -812,9 +806,7 @@ void CompanyAdminUpdate(const Company *company)
*/
void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
{
#ifdef ENABLE_NETWORK
if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason);
#endif /* ENABLE_NETWORK */
}
/**
@@ -840,7 +832,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* This command is only executed in a multiplayer game */
if (!_networking) return CMD_ERROR;
#ifdef ENABLE_NETWORK
/* Has the network client a correct ClientIndex? */
if (!(flags & DC_EXEC)) return CommandCost();
@@ -884,7 +875,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
NetworkServerNewCompany(c, ci);
#endif /* ENABLE_NETWORK */
break;
}
@@ -893,9 +883,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
Company *c = DoStartupNewCompany(true, company_id);
#ifdef ENABLE_NETWORK
if (c != NULL) NetworkServerNewCompany(c, NULL);
#endif /* ENABLE_NETWORK */
break;
}

View File

@@ -291,7 +291,7 @@ struct CompanyFinancesWindow : Window {
this->owner = (Owner)this->window_number;
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_CF_CAPTION:
@@ -310,7 +310,7 @@ struct CompanyFinancesWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
int type = _settings_client.gui.expenses_layout;
switch (widget) {
@@ -338,7 +338,7 @@ struct CompanyFinancesWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_CF_EXPS_CATEGORY:
@@ -399,7 +399,7 @@ struct CompanyFinancesWindow : Window {
this->GetWidget<NWidgetStacked>(WID_CF_SEL_BUTTONS)->SetDisplayedPlane(plane);
}
virtual void OnPaint()
void OnPaint() override
{
if (!this->IsShaded()) {
if (!this->small) {
@@ -429,7 +429,7 @@ struct CompanyFinancesWindow : Window {
this->DrawWidgets();
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_CF_TOGGLE_SIZE: // toggle size
@@ -458,7 +458,7 @@ struct CompanyFinancesWindow : Window {
}
}
virtual void OnHundredthTick()
void OnHundredthTick() override
{
const Company *c = Company::Get((CompanyID)this->window_number);
if (c->money > this->max_money) {
@@ -528,17 +528,17 @@ public:
return this->result >= COLOUR_END ? STR_COLOUR_DEFAULT : _colour_dropdown[this->result];
}
uint Height(uint width) const
uint Height(uint width) const override
{
return max(FONT_HEIGHT_NORMAL, ScaleGUITrad(12) + 2);
}
bool Selectable() const
bool Selectable() const override
{
return true;
}
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override
{
bool rtl = _current_text_dir == TD_RTL;
int height = bottom - top;
@@ -566,7 +566,7 @@ private:
uint rows;
uint line_height;
GUIGroupList groups;
SmallVector<int, 32> indents;
std::vector<int> indents;
Scrollbar *vscroll;
void ShowColourDropDownMenu(uint32 widget)
@@ -610,10 +610,10 @@ private:
if (default_livery != NULL) {
/* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
default_col = (primary ? default_livery->colour1 : default_livery->colour2) + COLOUR_END;
*list->Append() = new DropDownListColourItem(default_col, false);
list->push_back(new DropDownListColourItem(default_col, false));
}
for (uint i = 0; i < lengthof(_colour_dropdown); i++) {
*list->Append() = new DropDownListColourItem(i, HasBit(used_colours, i));
list->push_back(new DropDownListColourItem(i, HasBit(used_colours, i)));
}
byte sel = (default_livery == NULL || HasBit(livery->in_use, primary ? 0 : 1)) ? (primary ? livery->colour1 : livery->colour2) : default_col;
@@ -644,11 +644,11 @@ private:
void AddChildren(GUIGroupList *source, GroupID parent, int indent)
{
for (const Group **g = source->Begin(); g != source->End(); g++) {
if ((*g)->parent != parent) continue;
*this->groups.Append() = *g;
*this->indents.Append() = indent;
AddChildren(source, (*g)->index, indent + 1);
for (const Group *g : *source) {
if (g->parent != parent) continue;
this->groups.push_back(g);
this->indents.push_back(indent);
AddChildren(source, g->index, indent + 1);
}
}
@@ -656,8 +656,8 @@ private:
{
if (!this->groups.NeedRebuild()) return;
this->groups.Clear();
this->indents.Clear();
this->groups.clear();
this->indents.clear();
if (this->livery_class >= LC_GROUP_RAIL) {
GUIGroupList list;
@@ -666,7 +666,7 @@ private:
const Group *g;
FOR_ALL_GROUPS(g) {
if (g->owner == owner && g->vehicle_type == vtype) {
*list.Append() = g;
list.push_back(g);
}
}
@@ -676,7 +676,7 @@ private:
AddChildren(&list, INVALID_GROUP, 0);
}
this->groups.Compact();
this->groups.shrink_to_fit();
this->groups.RebuildDone();
}
@@ -690,7 +690,7 @@ private:
}
}
} else {
this->rows = this->groups.Length();
this->rows = this->groups.size();
}
this->vscroll->SetCount(this->rows);
@@ -744,7 +744,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_SCL_SPACER_DROPDOWN: {
@@ -797,7 +797,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
bool local = (CompanyID)this->window_number == _local_company;
@@ -811,7 +811,7 @@ public:
this->DrawWidgets();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_SCL_CAPTION:
@@ -851,7 +851,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_SCL_MATRIX) return;
@@ -906,7 +906,7 @@ public:
}
}
} else {
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->groups.Length());
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->groups.size());
for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
const Group *g = this->groups[i];
SetDParam(0, g->index);
@@ -915,7 +915,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
/* Livery Class buttons */
@@ -946,7 +946,7 @@ public:
this->groups.ForceRebuild();
this->BuildGroupList((CompanyID)this->window_number);
if (this->groups.Length() > 0) {
if (this->groups.size() > 0) {
this->sel = this->groups[0]->index;
}
}
@@ -989,12 +989,12 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_SCL_MATRIX);
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
bool local = (CompanyID)this->window_number == _local_company;
if (!local) return;
@@ -1020,7 +1020,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -1033,7 +1033,7 @@ public:
if (!Group::IsValidID(this->sel)) {
this->sel = INVALID_GROUP;
if (this->groups.Length() > 0) this->sel = this->groups[0]->index;
if (this->groups.size() > 0) this->sel = this->groups[0]->index;
}
this->SetDirty();
@@ -1372,7 +1372,7 @@ public:
}
}
virtual void OnInit()
void OnInit() override
{
/* Size of the boolean yes/no button. */
Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
@@ -1395,7 +1395,7 @@ public:
this->number_dim = number_dim;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_SCMF_FACE: {
@@ -1454,7 +1454,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
/* lower the non-selected gender button */
this->SetWidgetsLoweredState(!this->is_female, WID_SCMF_MALE, WID_SCMF_MALE2, WIDGET_LIST_END);
@@ -1515,7 +1515,7 @@ public:
this->DrawWidgets();
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT:
@@ -1604,7 +1604,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
/* Toggle size, advanced/simple face selection */
@@ -1713,7 +1713,7 @@ public:
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
/* Set a new company manager face number */
@@ -1868,7 +1868,7 @@ struct CompanyInfrastructureWindow : Window
return total;
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_CI_CAPTION:
@@ -1877,7 +1877,7 @@ struct CompanyInfrastructureWindow : Window
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
const Company *c = Company::Get((CompanyID)this->window_number);
@@ -2000,7 +2000,7 @@ struct CompanyInfrastructureWindow : Window
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
const Company *c = Company::Get((CompanyID)this->window_number);
int y = r.top;
@@ -2103,7 +2103,7 @@ struct CompanyInfrastructureWindow : Window
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -2282,7 +2282,7 @@ struct CompanyWindow : Window
this->OnInvalidateData();
}
virtual void OnPaint()
void OnPaint() override
{
const Company *c = Company::Get((CompanyID)this->window_number);
bool local = this->window_number == _local_company;
@@ -2357,7 +2357,7 @@ struct CompanyWindow : Window
this->DrawWidgets();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_C_FACE: {
@@ -2410,15 +2410,13 @@ struct CompanyWindow : Window
break;
}
#ifdef ENABLE_NETWORK
case WID_C_HAS_PASSWORD:
*size = maxdim(*size, GetSpriteSize(SPR_LOCK));
break;
#endif /* ENABLE_NETWORK */
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
const Company *c = Company::Get((CompanyID)this->window_number);
switch (widget) {
@@ -2521,17 +2519,15 @@ struct CompanyWindow : Window
break;
}
#ifdef ENABLE_NETWORK
case WID_C_HAS_PASSWORD:
if (_networking && NetworkCompanyIsPassworded(c->index)) {
DrawSprite(SPR_LOCK, PAL_NONE, r.left, r.top);
}
break;
#endif /* ENABLE_NETWORK */
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_C_CAPTION:
@@ -2549,7 +2545,7 @@ struct CompanyWindow : Window
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_C_NEW_FACE: DoSelectCompanyManagerFace(this); break;
@@ -2622,7 +2618,6 @@ struct CompanyWindow : Window
DoCommandP(0, this->window_number, 0, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_ERROR_CAN_T_SELL_25_SHARE_IN));
break;
#ifdef ENABLE_NETWORK
case WID_C_COMPANY_PASSWORD:
if (this->window_number == _local_company) ShowNetworkCompanyPasswordWindow(this);
break;
@@ -2642,17 +2637,16 @@ struct CompanyWindow : Window
}
break;
}
#endif /* ENABLE_NETWORK */
}
}
virtual void OnHundredthTick()
void OnHundredthTick() override
{
/* redraw the window every now and then */
this->SetDirty();
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
void OnPlaceObject(Point pt, TileIndex tile) override
{
if (DoCommandP(tile, OBJECT_HQ, 0, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_COMPANY_HEADQUARTERS)) && !_shift_pressed) {
ResetObjectToPlace();
@@ -2660,12 +2654,12 @@ struct CompanyWindow : Window
}
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
this->RaiseButtons();
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
@@ -2684,11 +2678,9 @@ struct CompanyWindow : Window
DoCommandP(0, 0, 0, CMD_RENAME_COMPANY | CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME), NULL, str);
break;
#ifdef ENABLE_NETWORK
case WID_C_COMPANY_JOIN:
NetworkClientRequestMove((CompanyID)this->window_number, str);
break;
#endif /* ENABLE_NETWORK */
}
}
@@ -2698,7 +2690,7 @@ struct CompanyWindow : Window
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (this->window_number == _local_company) return;
@@ -2766,7 +2758,7 @@ struct BuyCompanyWindow : Window {
this->InitNested(window_number);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BC_FACE:
@@ -2782,7 +2774,7 @@ struct BuyCompanyWindow : Window {
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_BC_CAPTION:
@@ -2792,7 +2784,7 @@ struct BuyCompanyWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_BC_FACE: {
@@ -2811,7 +2803,7 @@ struct BuyCompanyWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_BC_NO:

View File

@@ -33,10 +33,8 @@ FILE *_iconsole_output_file;
void IConsoleInit()
{
_iconsole_output_file = NULL;
#ifdef ENABLE_NETWORK /* Initialize network only variables */
_redirect_console_to_client = INVALID_CLIENT_ID;
_redirect_console_to_admin = INVALID_ADMIN_ID;
#endif
IConsoleGUIInit();
@@ -90,7 +88,6 @@ void IConsolePrint(TextColour colour_code, const char *string)
assert(IsValidConsoleColour(colour_code));
char *str;
#ifdef ENABLE_NETWORK
if (_redirect_console_to_client != INVALID_CLIENT_ID) {
/* Redirect the string to the client */
NetworkServerSendRcon(_redirect_console_to_client, colour_code, string);
@@ -101,7 +98,6 @@ void IConsolePrint(TextColour colour_code, const char *string)
NetworkServerSendAdminRcon(_redirect_console_to_admin, colour_code, string);
return;
}
#endif
/* Create a copy of the string, strip if of colours and invalid
* characters and (when applicable) assign it to the console buffer */
@@ -110,9 +106,7 @@ void IConsolePrint(TextColour colour_code, const char *string)
str_validate(str, str + strlen(str));
if (_network_dedicated) {
#ifdef ENABLE_NETWORK
NetworkAdminConsole("console", str);
#endif /* ENABLE_NETWORK */
fprintf(stdout, "%s%s\n", GetLogPrefix(), str);
fflush(stdout);
IConsoleWriteToLogFile(str);

View File

@@ -89,8 +89,6 @@ static ConsoleFileList _console_file_list; ///< File storage cache for the conso
* command hooks
****************/
#ifdef ENABLE_NETWORK
/**
* Check network availability and inform in console about failure of detection.
* @return Network availability.
@@ -162,10 +160,6 @@ DEF_CONSOLE_HOOK(ConHookNoNetwork)
return CHR_ALLOW;
}
#else
# define ConHookNoNetwork NULL
#endif /* ENABLE_NETWORK */
DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
{
if (_settings_client.gui.newgrf_developer_tools) {
@@ -173,11 +167,7 @@ DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
if (echo) IConsoleError("This command is only available in game and editor.");
return CHR_DISALLOW;
}
#ifdef ENABLE_NETWORK
return ConHookNoNetwork(echo);
#else
return CHR_ALLOW;
#endif
}
return CHR_HIDE;
}
@@ -482,7 +472,6 @@ DEF_CONSOLE_CMD(ConClearBuffer)
/**********************************
* Network Core Console Commands
**********************************/
#ifdef ENABLE_NETWORK
static bool ConKickOrBan(const char *argv, bool ban)
{
@@ -566,21 +555,21 @@ DEF_CONSOLE_CMD(ConUnBan)
/* Try by IP. */
uint index;
for (index = 0; index < _network_ban_list.Length(); index++) {
for (index = 0; index < _network_ban_list.size(); index++) {
if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
}
/* Try by index. */
if (index >= _network_ban_list.Length()) {
if (index >= _network_ban_list.size()) {
index = atoi(argv[1]) - 1U; // let it wrap
}
if (index < _network_ban_list.Length()) {
if (index < _network_ban_list.size()) {
char msg[64];
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
IConsolePrint(CC_DEFAULT, msg);
free(_network_ban_list[index]);
_network_ban_list.Erase(_network_ban_list.Get(index));
_network_ban_list.erase(_network_ban_list.begin() + index);
} else {
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
IConsolePrint(CC_DEFAULT, "For a list of banned IP's, see the command 'banlist'");
@@ -599,8 +588,8 @@ DEF_CONSOLE_CMD(ConBanList)
IConsolePrint(CC_DEFAULT, "Banlist: ");
uint i = 1;
for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++, i++) {
IConsolePrintF(CC_DEFAULT, " %d) %s", i, *iter);
for (char *entry : _network_ban_list) {
IConsolePrintF(CC_DEFAULT, " %d) %s", i, entry);
}
return true;
@@ -933,8 +922,6 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
return true;
}
#endif /* ENABLE_NETWORK */
/*********************************
* script file console commands
*********************************/
@@ -1571,12 +1558,9 @@ DEF_CONSOLE_CMD(ConCompanies)
const char *password_state = "";
if (c->is_ai) {
password_state = "AI";
}
#ifdef ENABLE_NETWORK
else if (_network_server) {
} else if (_network_server) {
password_state = StrEmpty(_network_company_states[c->index].password) ? "unprotected" : "protected";
}
#endif
char colour[512];
GetString(colour, STR_COLOUR_DARK_BLUE + _company_colours[c->index], lastof(colour));
@@ -1593,8 +1577,6 @@ DEF_CONSOLE_CMD(ConCompanies)
return true;
}
#ifdef ENABLE_NETWORK
DEF_CONSOLE_CMD(ConSay)
{
if (argc == 0) {
@@ -1836,7 +1818,6 @@ DEF_CONSOLE_CMD(ConContent)
return false;
}
#endif /* defined(WITH_ZLIB) */
#endif /* ENABLE_NETWORK */
DEF_CONSOLE_CMD(ConSetting)
{
@@ -2132,7 +2113,7 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("players", "companies");
/* networking functions */
#ifdef ENABLE_NETWORK
/* Content downloading is only available with ZLIB */
#if defined(WITH_ZLIB)
IConsoleCmdRegister("content", ConContent);
@@ -2190,7 +2171,6 @@ void IConsoleStdLibRegister()
IConsoleAliasRegister("restart_game_year", "setting restart_game_year %+");
IConsoleAliasRegister("min_players", "setting min_active_clients %+");
IConsoleAliasRegister("reload_cfg", "setting reload_cfg %+");
#endif /* ENABLE_NETWORK */
/* debugging stuff */
#ifdef _DEBUG

View File

@@ -201,7 +201,7 @@ struct IConsoleWindow : Window
this->SetDirty();
}
virtual void OnPaint()
void OnPaint() override
{
const int right = this->width - 5;
@@ -229,7 +229,7 @@ struct IConsoleWindow : Window
}
}
virtual void OnHundredthTick()
void OnHundredthTick() override
{
if (IConsoleLine::Truncate() &&
(IConsoleWindow::scroll > IConsoleLine::size)) {
@@ -238,12 +238,12 @@ struct IConsoleWindow : Window
}
}
virtual void OnMouseLoop()
void OnMouseLoop() override
{
if (_iconsole_cmdline.HandleCaret()) this->SetDirty();
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
if (_focused_window != this) return ES_NOT_HANDLED;
@@ -314,7 +314,7 @@ struct IConsoleWindow : Window
return ES_HANDLED;
}
virtual void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
{
if (_iconsole_cmdline.InsertString(str, marked, caret, insert_location, replacement_end)) {
IConsoleWindow::scroll = 0;
@@ -323,17 +323,17 @@ struct IConsoleWindow : Window
}
}
virtual const char *GetFocusedText() const
const char *GetFocusedText() const override
{
return _iconsole_cmdline.buf;
}
virtual const char *GetCaret() const
const char *GetCaret() const override
{
return _iconsole_cmdline.buf + _iconsole_cmdline.caretpos;
}
virtual const char *GetMarkedText(size_t *length) const
const char *GetMarkedText(size_t *length) const override
{
if (_iconsole_cmdline.markend == 0) return NULL;
@@ -341,7 +341,7 @@ struct IConsoleWindow : Window
return _iconsole_cmdline.buf + _iconsole_cmdline.markpos;
}
virtual Point GetCaretPosition() const
Point GetCaretPosition() const override
{
int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
Point pt = {this->line_offset + delta + _iconsole_cmdline.caretxoffs, this->height - this->line_height};
@@ -349,7 +349,7 @@ struct IConsoleWindow : Window
return pt;
}
virtual Rect GetTextBoundingRect(const char *from, const char *to) const
Rect GetTextBoundingRect(const char *from, const char *to) const override
{
int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
@@ -360,7 +360,7 @@ struct IConsoleWindow : Window
return r;
}
virtual const char *GetTextCharacterAtPosition(const Point &pt) const
const char *GetTextCharacterAtPosition(const Point &pt) const override
{
int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
@@ -369,12 +369,12 @@ struct IConsoleWindow : Window
return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
}
virtual void OnMouseWheel(int wheel)
void OnMouseWheel(int wheel) override
{
this->Scroll(-wheel);
}
virtual void OnFocusLost(Window *newly_focused_window)
void OnFocusLost(Window *newly_focused_window) override
{
VideoDriver::GetInstance()->EditBoxLostFocus();
}

View File

@@ -26,7 +26,7 @@
#define TTD_BIG_ENDIAN 1
/* Windows has always LITTLE_ENDIAN */
#if defined(_WIN32) || defined(__OS2__) || defined(__HAIKU__) || defined(__DJGPP__)
#if defined(_WIN32) || defined(__OS2__) || defined(__HAIKU__)
# define TTD_ENDIAN TTD_LITTLE_ENDIAN
#elif defined(OSX)
# include <sys/types.h>

View File

@@ -21,8 +21,8 @@
/* virtual */ PoolBase::~PoolBase()
{
PoolVector *pools = PoolBase::GetPools();
pools->Erase(pools->Find(this));
if (pools->Length() == 0) delete pools;
pools->erase(std::find(pools->begin(), pools->end(), this));
if (pools->size() == 0) delete pools;
}
/**
@@ -31,10 +31,7 @@
*/
/* static */ void PoolBase::Clean(PoolType pt)
{
PoolVector *pools = PoolBase::GetPools();
PoolBase **end = pools->End();
for (PoolBase **ppool = pools->Begin(); ppool != end; ppool++) {
PoolBase *pool = *ppool;
for (PoolBase *pool : *PoolBase::GetPools()) {
if (pool->type & pt) pool->CleanPool();
}
}

View File

@@ -26,7 +26,7 @@ enum PoolType {
};
DECLARE_ENUM_AS_BIT_SET(PoolType)
typedef SmallVector<struct PoolBase *, 4> PoolVector; ///< Vector of pointers to PoolBase
typedef std::vector<struct PoolBase *> PoolVector; ///< Vector of pointers to PoolBase
/** Base class for base of all pools. */
struct PoolBase {
@@ -50,7 +50,7 @@ struct PoolBase {
*/
PoolBase(PoolType pt) : type(pt)
{
*PoolBase::GetPools()->Append() = this;
PoolBase::GetPools()->push_back(this);
}
virtual ~PoolBase();

View File

@@ -27,6 +27,7 @@ struct SmallPair {
/** Initializes this Pair with data */
inline SmallPair(const T &first, const U &second) : first(first), second(second) { }
SmallPair() = default;
};
/**
@@ -38,8 +39,8 @@ struct SmallPair {
*
* @see SmallVector
*/
template <typename T, typename U, uint S = 16>
struct SmallMap : SmallVector<SmallPair<T, U>, S> {
template <typename T, typename U>
struct SmallMap : std::vector<SmallPair<T, U> > {
typedef ::SmallPair<T, U> Pair;
typedef Pair *iterator;
typedef const Pair *const_iterator;
@@ -54,12 +55,13 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
* @param key key to find
* @return &Pair(key, data) if found, this->End() if not
*/
inline const Pair *Find(const T &key) const
inline typename std::vector<Pair>::const_iterator Find(const T &key) const
{
for (uint i = 0; i < this->items; i++) {
if (key == this->data[i].first) return &this->data[i];
typename std::vector<Pair>::const_iterator it;
for (it = std::vector<Pair>::begin(); it != std::vector<Pair>::end(); it++) {
if (key == it->first) return it;
}
return this->End();
return it;
}
/**
@@ -69,12 +71,23 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
inline Pair *Find(const T &key)
{
for (uint i = 0; i < this->items; i++) {
if (key == this->data[i].first) return &this->data[i];
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
if (key == std::vector<Pair>::operator[](i).first) return &std::vector<Pair>::operator[](i);
}
return this->End();
}
inline const Pair *End() const
{
return std::vector<Pair>::data() + std::vector<Pair>::size();
}
inline Pair *End()
{
return std::vector<Pair>::data() + std::vector<Pair>::size();
}
/**
* Tests whether a key is assigned in this map.
* @param key key to test
@@ -85,6 +98,16 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
return this->Find(key) != this->End();
}
/**
* Tests whether a key is assigned in this map.
* @param key key to test
* @return true iff the item is present
*/
inline bool Contains(const T &key)
{
return this->Find(key) != this->End();
}
/**
* Removes given pair from this map
* @param pair pair to remove
@@ -92,8 +115,9 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
inline void Erase(Pair *pair)
{
assert(pair >= this->Begin() && pair < this->End());
*pair = this->data[--this->items];
assert(pair >= std::vector<Pair>::data() && pair < this->End());
auto distance = pair - std::vector<Pair>::data();
std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
}
/**
@@ -104,13 +128,11 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
inline bool Erase(const T &key)
{
for (uint i = 0; i < this->items; i++) {
if (key == this->data[i].first) {
this->data[i] = this->data[--this->items];
return true;
}
}
return false;
Pair *pair = this->Find(key);
if (pair == this->End()) return false;
this->Erase(pair);
return true;
}
/**
@@ -122,9 +144,7 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
inline bool Insert(const T &key, const U &data)
{
if (this->Contains(key)) return false;
Pair *n = this->Append();
n->first = key;
n->second = data;
std::vector<Pair>::emplace_back(key, data);
return true;
}
@@ -136,17 +156,18 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
inline U &operator[](const T &key)
{
for (uint i = 0; i < this->items; i++) {
if (key == this->data[i].first) return this->data[i].second;
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second;
}
Pair *n = this->Append();
n->first = key;
return n->second;
/*C++17: Pair &n = */ std::vector<Pair>::emplace_back();
Pair &n = std::vector<Pair>::back();
n.first = key;
return n.second;
}
inline void SortByKey()
{
QSortT(this->Begin(), this->items, KeySorter);
QSortT(std::vector<Pair>::data(), std::vector<Pair>::size(), KeySorter);
}
static int CDECL KeySorter(const Pair *a, const Pair *b)

View File

@@ -64,8 +64,8 @@ private:
if (!this->data[index].valid) return index;
}
if (index >= this->data.Length() && index < Tmax_size) {
this->data.Resize(index + 1);
if (index >= this->data.size() && index < Tmax_size) {
this->data.resize(index + 1);
}
return index;
}
@@ -77,7 +77,7 @@ private:
Tindex first_unused;
Tindex first_free;
SmallVector<SimplePoolPoolItem, Tgrowth_step> data;
std::vector<SimplePoolPoolItem> data;
};
/**
@@ -96,6 +96,7 @@ struct SmallStackItem {
*/
inline SmallStackItem(const Titem &value, Tindex next) :
next(next), value(value) {}
SmallStackItem() = default;
};
/**

View File

@@ -14,375 +14,60 @@
#include "alloc_func.hpp"
#include "mem_func.hpp"
#include <vector>
#include <algorithm>
/**
* Simple vector template class.
* Helper function to append an item to a vector if it is not already contained
* Consider using std::set, std::unordered_set or std::flat_set in new code
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
* @param vec A reference to the vector to be extended
* @param item Reference to the item to be copy-constructed if not found
*
* @tparam T The type of the items stored
* @tparam S The steps of allocation
* @return Whether the item was already present
*/
template <typename T, uint S>
class SmallVector {
protected:
T *data; ///< The pointer to the first item
uint items; ///< The number of items stored
uint capacity; ///< The available space for storing items
template <typename T>
inline bool include(std::vector<T>& vec, const T &item)
{
const bool is_member = std::find(vec.begin(), vec.end(), item) != vec.end();
if (!is_member) vec.emplace_back(item);
return is_member;
}
public:
SmallVector() : data(NULL), items(0), capacity(0) { }
/**
* Helper function to get the index of an item
* Consider using std::set, std::unordered_set or std::flat_set in new code
*
* @param vec A reference to the vector to be extended
* @param item Reference to the item to be search for
*
* @return Index of element if found, otherwise -1
*/
template <typename T>
int find_index(std::vector<T> const& vec, T const& item)
{
auto const it = std::find(vec.begin(), vec.end(), item);
if (it != vec.end()) return it - vec.begin();
/**
* Copy constructor.
* @param other The other vector to copy.
*/
SmallVector(const SmallVector &other) : data(NULL), items(0), capacity(0)
{
this->Assign(other);
}
/**
* Generic copy constructor.
* @param other The other vector to copy.
*/
template <uint X>
SmallVector(const SmallVector<T, X> &other) : data(NULL), items(0), capacity(0)
{
this->Assign(other);
}
/**
* Assignment.
* @param other The other vector to assign.
*/
SmallVector &operator=(const SmallVector &other)
{
this->Assign(other);
return *this;
}
/**
* Generic assignment.
* @param other The other vector to assign.
*/
template <uint X>
SmallVector &operator=(const SmallVector<T, X> &other)
{
this->Assign(other);
return *this;
}
~SmallVector()
{
free(this->data);
}
/**
* Assign items from other vector.
*/
template <uint X>
inline void Assign(const SmallVector<T, X> &other)
{
if ((const void *)&other == (void *)this) return;
this->Clear();
if (other.Length() > 0) MemCpyT<T>(this->Append(other.Length()), other.Begin(), other.Length());
}
/**
* Remove all items from the list.
*/
inline void Clear()
{
/* In fact we just reset the item counter avoiding the need to
* probably reallocate the same amount of memory the list was
* previously using. */
this->items = 0;
}
/**
* Remove all items from the list and free allocated memory.
*/
inline void Reset()
{
this->items = 0;
this->capacity = 0;
free(data);
data = NULL;
}
/**
* Compact the list down to the smallest block size boundary.
*/
inline void Compact()
{
uint capacity = Align(this->items, S);
if (capacity >= this->capacity) return;
this->capacity = capacity;
this->data = ReallocT(this->data, this->capacity);
}
/**
* Append an item and return it.
* @param to_add the number of items to append
* @return pointer to newly allocated item
*/
inline T *Append(uint to_add = 1)
{
uint begin = this->items;
this->items += to_add;
if (this->items > this->capacity) {
this->capacity = Align(this->items, S);
this->data = ReallocT(this->data, this->capacity);
}
return &this->data[begin];
}
/**
* Set the size of the vector, effectively truncating items from the end or appending uninitialised ones.
* @param num_items Target size.
*/
inline void Resize(uint num_items)
{
this->items = num_items;
if (this->items > this->capacity) {
this->capacity = Align(this->items, S);
this->data = ReallocT(this->data, this->capacity);
}
}
/**
* Insert a new item at a specific position into the vector, moving all following items.
* @param item Position at which the new item should be inserted
* @return pointer to the new item
*/
inline T *Insert(T *item)
{
assert(item >= this->Begin() && item <= this->End());
size_t to_move = this->End() - item;
size_t start = item - this->Begin();
this->Append();
if (to_move > 0) MemMoveT(this->Begin() + start + 1, this->Begin() + start, to_move);
return this->Begin() + start;
}
/**
* Search for the first occurrence of an item.
* The '!=' operator of T is used for comparison.
* @param item Item to search for
* @return The position of the item, or End() when not present
*/
inline const T *Find(const T &item) const
{
const T *pos = this->Begin();
const T *end = this->End();
while (pos != end && *pos != item) pos++;
return pos;
}
/**
* Search for the first occurrence of an item.
* The '!=' operator of T is used for comparison.
* @param item Item to search for
* @return The position of the item, or End() when not present
*/
inline T *Find(const T &item)
{
T *pos = this->Begin();
const T *end = this->End();
while (pos != end && *pos != item) pos++;
return pos;
}
/**
* Search for the first occurrence of an item.
* The '!=' operator of T is used for comparison.
* @param item Item to search for
* @return The position of the item, or -1 when not present
*/
inline int FindIndex(const T &item) const
{
int index = 0;
const T *pos = this->Begin();
const T *end = this->End();
while (pos != end && *pos != item) {
pos++;
index++;
}
return pos == end ? -1 : index;
}
/**
* Tests whether a item is present in the vector.
* The '!=' operator of T is used for comparison.
* @param item Item to test for
* @return true iff the item is present
*/
inline bool Contains(const T &item) const
{
return this->Find(item) != this->End();
}
/**
* Removes given item from this vector
* @param item item to remove
* @note it has to be pointer to item in this map. It is overwritten by the last item.
*/
inline void Erase(T *item)
{
assert(item >= this->Begin() && item < this->End());
*item = this->data[--this->items];
}
/**
* Remove items from the vector while preserving the order of other items.
* @param pos First item to remove.
* @param count Number of consecutive items to remove.
*/
void ErasePreservingOrder(uint pos, uint count = 1)
{
ErasePreservingOrder(this->data + pos, count);
}
/**
* Remove items from the vector while preserving the order of other items.
* @param item First item to remove.
* @param count Number of consecutive items to remove.
*/
inline void ErasePreservingOrder(T *item, uint count = 1)
{
if (count == 0) return;
assert(item >= this->Begin());
assert(item + count <= this->End());
this->items -= count;
ptrdiff_t to_move = this->End() - item;
if (to_move > 0) MemMoveT(item, item + count, to_move);
}
/**
* Tests whether a item is present in the vector, and appends it to the end if not.
* The '!=' operator of T is used for comparison.
* @param item Item to test for
* @return true iff the item is was already present
*/
inline bool Include(const T &item)
{
bool is_member = this->Contains(item);
if (!is_member) *this->Append() = item;
return is_member;
}
/**
* Get the number of items in the list.
*
* @return The number of items in the list.
*/
inline uint Length() const
{
return this->items;
}
/**
* Get the pointer to the first item (const)
*
* @return the pointer to the first item
*/
inline const T *Begin() const
{
return this->data;
}
/**
* Get the pointer to the first item
*
* @return the pointer to the first item
*/
inline T *Begin()
{
return this->data;
}
/**
* Get the pointer behind the last valid item (const)
*
* @return the pointer behind the last valid item
*/
inline const T *End() const
{
return &this->data[this->items];
}
/**
* Get the pointer behind the last valid item
*
* @return the pointer behind the last valid item
*/
inline T *End()
{
return &this->data[this->items];
}
/**
* Get the pointer to item "number" (const)
*
* @param index the position of the item
* @return the pointer to the item
*/
inline const T *Get(uint index) const
{
/* Allow access to the 'first invalid' item */
assert(index <= this->items);
return &this->data[index];
}
/**
* Get the pointer to item "number"
*
* @param index the position of the item
* @return the pointer to the item
*/
inline T *Get(uint index)
{
/* Allow access to the 'first invalid' item */
assert(index <= this->items);
return &this->data[index];
}
/**
* Get item "number" (const)
*
* @param index the position of the item
* @return the item
*/
inline const T &operator[](uint index) const
{
assert(index < this->items);
return this->data[index];
}
/**
* Get item "number"
*
* @param index the position of the item
* @return the item
*/
inline T &operator[](uint index)
{
assert(index < this->items);
return this->data[index];
}
};
return -1;
}
/**
* Helper function to append N default-constructed elements and get a pointer to the first new element
* Consider using std::back_inserter in new code
*
* @param vec A reference to the vector to be extended
* @param num Number of elements to be default-constructed
*
* @return Pointer to the first new element
*/
template <typename T>
T* grow(std::vector<T>& vec, std::size_t num)
{
std::size_t const pos = vec.size();
vec.resize(pos + num);
return vec.data() + pos;
}
/**
* Simple vector template class, with automatic free.
@@ -392,10 +77,9 @@ public:
* inside the list.
*
* @param T The type of the items stored, must be a pointer
* @param S The steps of allocation
*/
template <typename T, uint S>
class AutoFreeSmallVector : public SmallVector<T, S> {
template <typename T>
class AutoFreeSmallVector : public std::vector<T> {
public:
~AutoFreeSmallVector()
{
@@ -407,11 +91,11 @@ public:
*/
inline void Clear()
{
for (uint i = 0; i < this->items; i++) {
free(this->data[i]);
for (T p : *this) {
free(p);
}
this->items = 0;
std::vector<T>::clear();
}
};
@@ -423,10 +107,9 @@ public:
* inside the list.
*
* @param T The type of the items stored, must be a pointer
* @param S The steps of allocation
*/
template <typename T, uint S>
class AutoDeleteSmallVector : public SmallVector<T, S> {
template <typename T>
class AutoDeleteSmallVector : public std::vector<T> {
public:
~AutoDeleteSmallVector()
{
@@ -438,14 +121,14 @@ public:
*/
inline void Clear()
{
for (uint i = 0; i < this->items; i++) {
delete this->data[i];
for (T p : *this) {
delete p;
}
this->items = 0;
std::vector<T>::clear();
}
};
typedef AutoFreeSmallVector<char*, 4> StringList; ///< Type for a list of strings.
typedef AutoFreeSmallVector<char*> StringList; ///< Type for a list of strings.
#endif /* SMALLVEC_TYPE_HPP */

View File

@@ -35,7 +35,7 @@ unsigned __int64 ottd_rdtsc();
#endif
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
#if (defined(__i386__) || defined(__x86_64__)) && !defined(__DJGPP__) && !defined(RDTSC_AVAILABLE)
#if (defined(__i386__) || defined(__x86_64__)) && !defined(RDTSC_AVAILABLE)
uint64 ottd_rdtsc()
{
uint32 high, low;

View File

@@ -210,9 +210,7 @@ static void OnNewYear()
VehiclesYearlyLoop();
TownsYearlyLoop();
InvalidateWindowClassesData(WC_BUILD_STATION);
#ifdef ENABLE_NETWORK
if (_network_server) NetworkServerYearlyLoop();
#endif /* ENABLE_NETWORK */
if (_cur_year == _settings_client.gui.semaphore_build_before) ResetSignalVariant();
@@ -232,11 +230,9 @@ static void OnNewYear()
LinkGraph *lg;
FOR_ALL_LINK_GRAPHS(lg) lg->ShiftDates(-days_this_year);
#ifdef ENABLE_NETWORK
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out
* all of them if the date is set back, else those messages will hang for ever */
NetworkInitChatMessage();
#endif /* ENABLE_NETWORK */
}
if (_settings_client.gui.auto_euro) CheckSwitchToEuro();
@@ -260,9 +256,7 @@ static void OnNewMonth()
IndustryMonthlyLoop();
SubsidyMonthlyLoop();
StationMonthlyLoop();
#ifdef ENABLE_NETWORK
if (_network_server) NetworkServerMonthlyLoop();
#endif /* ENABLE_NETWORK */
IConsoleCmdExec("exec scripts/on_newmonth.scr 0");
}
@@ -271,9 +265,7 @@ static void OnNewMonth()
*/
static void OnNewDay()
{
#ifdef ENABLE_NETWORK
if (_network_server) NetworkServerDailyLoop();
#endif /* ENABLE_NETWORK */
DisasterDailyLoop();
IndustryDailyLoop();

View File

@@ -56,7 +56,7 @@ struct SetDateWindow : Window {
this->date.year = Clamp(this->date.year, min_year, max_year);
}
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
{
Point pt = { this->parent->left + this->parent->width / 2 - sm_width / 2, this->parent->top + this->parent->height / 2 - sm_height / 2 };
return pt;
@@ -76,14 +76,14 @@ struct SetDateWindow : Window {
case WID_SD_DAY:
for (uint i = 0; i < 31; i++) {
*list->Append() = new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false);
list->push_back(new DropDownListStringItem(STR_DAY_NUMBER_1ST + i, i + 1, false));
}
selected = this->date.day;
break;
case WID_SD_MONTH:
for (uint i = 0; i < 12; i++) {
*list->Append() = new DropDownListStringItem(STR_MONTH_JAN + i, i, false);
list->push_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false));
}
selected = this->date.month;
break;
@@ -92,7 +92,7 @@ struct SetDateWindow : Window {
for (Year i = this->min_year; i <= this->max_year; i++) {
DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
item->SetParam(0, i);
*list->Append() = item;
list->push_back(item);
}
selected = this->date.year;
break;
@@ -101,7 +101,7 @@ struct SetDateWindow : Window {
ShowDropDownList(this, list, selected, widget);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
Dimension d = {0, 0};
switch (widget) {
@@ -130,7 +130,7 @@ struct SetDateWindow : Window {
*size = d;
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_SD_DAY: SetDParam(0, this->date.day - 1 + STR_DAY_NUMBER_1ST); break;
@@ -139,7 +139,7 @@ struct SetDateWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_SD_DAY:
@@ -157,7 +157,7 @@ struct SetDateWindow : Window {
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_SD_DAY:
@@ -203,7 +203,7 @@ struct SetMinutesWindow : SetDateWindow
for (uint i = 0; i < 60; i++) {
DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
item->SetParam(0, i);
*list->Append() = item;
list->push_back(item);
}
selected = MINUTES_MINUTE(minutes);
break;
@@ -212,7 +212,7 @@ struct SetMinutesWindow : SetDateWindow
for (uint i = 0; i < 24; i++) {
DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
item->SetParam(0, i);
*list->Append() = item;
list->push_back(item);
}
selected = MINUTES_HOUR(minutes);

View File

@@ -23,10 +23,8 @@
#include <time.h>
#if defined(ENABLE_NETWORK)
#include "network/network_admin.h"
SOCKET _debug_socket = INVALID_SOCKET;
#endif /* ENABLE_NETWORK */
#if defined(RANDOM_DEBUG) && defined(UNIX) && defined(__GLIBC__)
#include <unistd.h>
@@ -121,7 +119,6 @@ char *DumpDebugFacilityNames(char *buf, char *last)
*/
static void debug_print(const char *dbg, const char *buf)
{
#if defined(ENABLE_NETWORK)
if (_debug_socket != INVALID_SOCKET) {
char buf2[1024 + 32];
@@ -131,7 +128,6 @@ static void debug_print(const char *dbg, const char *buf)
send(_debug_socket, buf2, (int)strlen(buf2), 0);
return;
}
#endif /* ENABLE_NETWORK */
if (strcmp(dbg, "desync") == 0) {
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
if (f != NULL) {
@@ -189,9 +185,7 @@ static void debug_print(const char *dbg, const char *buf)
fputs(buffer, stderr);
#endif
#ifdef ENABLE_NETWORK
NetworkAdminConsole(dbg, buf);
#endif /* ENABLE_NETWORK */
IConsoleDebug(dbg, buf);
}

View File

@@ -11,8 +11,6 @@
#include "stdafx.h"
#ifdef ENABLE_NETWORK
char *_log_file = NULL; ///< File to reroute output of a forked OpenTTD to
FILE *_log_fd = NULL; ///< File to reroute output of a forked OpenTTD to
@@ -67,10 +65,3 @@ void DedicatedFork()
}
}
#endif
#else
/** Empty helper function call for NOT(UNIX) systems */
void DedicatedFork() {}
#endif /* ENABLE_NETWORK */

View File

@@ -153,8 +153,8 @@ static void ScheduledDispatchDepartureLocalFix(DepartureList *departure_list)
{
/* Seperate departure by each shared order group */
std::map<uint32, std::vector<Departure*>> separated_departure;
for (Departure** departure = departure_list->Begin(); departure != departure_list->End(); departure++) {
separated_departure[(*departure)->vehicle->orders.list->index].push_back(*departure);
for (Departure* departure : *departure_list) {
separated_departure[departure->vehicle->orders.list->index].push_back(departure);
}
for (auto& pair : separated_departure) {
@@ -190,7 +190,7 @@ static void ScheduledDispatchDepartureLocalFix(DepartureList *departure_list)
}
/* Re-sort the departure list */
QSortT<Departure*>(departure_list->Begin(), departure_list->Length(), [](Departure * const *a, Departure * const *b) -> int {
QSortT<Departure*>(departure_list->data(), departure_list->size(), [](Departure * const *a, Departure * const *b) -> int {
return (*a)->scheduled_date - (*b)->scheduled_date;
});
}
@@ -215,12 +215,12 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
/* Having written that, it's not exactly slow at the moment. */
/* The list of departures which will be returned as a result. */
SmallVector<Departure*, 32> *result = new SmallVector<Departure*, 32>();
std::vector<Departure*> *result = new std::vector<Departure*>();
if (!show_pax && !show_freight) return result;
/* A list of the next scheduled orders to be considered for inclusion in the departure list. */
SmallVector<OrderDate*, 32> next_orders;
std::vector<OrderDate*> next_orders;
/* The maximum possible date for departures to be scheduled to occur. */
DateTicksScaled max_date = _settings_client.gui.max_departure_time * DAY_TICKS * _settings_game.economy.day_length_factor;
@@ -254,11 +254,11 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
/* Get the first order for each vehicle for the station we're interested in that doesn't have No Loading set. */
/* We find the least order while we're at it. */
for (const Vehicle **v = vehicles.Begin(); v != vehicles.End(); v++) {
for (const Vehicle *v : vehicles) {
if (show_pax != show_freight) {
bool carries_passengers = false;
const Vehicle *u = *v;
const Vehicle *u = v;
while (u != NULL) {
if (u->cargo_cap > 0 && IsCargoInClass(u->cargo_type, CC_PASSENGERS)) {
carries_passengers = true;
@@ -272,12 +272,12 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
}
const Order *order = (*v)->GetOrder((*v)->cur_implicit_order_index % (*v)->GetNumOrders());
DateTicks start_date = date_fract_scaled - (*v)->current_order_time;
if ((*v)->cur_timetable_order_index != INVALID_VEH_ORDER_ID && (*v)->cur_timetable_order_index != (*v)->cur_real_order_index) {
const Order *order = v->GetOrder(v->cur_implicit_order_index % v->GetNumOrders());
DateTicks start_date = date_fract_scaled - v->current_order_time;
if (v->cur_timetable_order_index != INVALID_VEH_ORDER_ID && v->cur_timetable_order_index != v->cur_real_order_index) {
/* vehicle is taking a conditional order branch, adjust start time to compensate */
const Order *real_current_order = (*v)->GetOrder((*v)->cur_real_order_index);
const Order *real_timetable_order = (*v)->GetOrder((*v)->cur_timetable_order_index);
const Order *real_current_order = v->GetOrder(v->cur_real_order_index);
const Order *real_timetable_order = v->GetOrder(v->cur_timetable_order_index);
assert(real_timetable_order->IsType(OT_CONDITIONAL));
start_date += (real_timetable_order->GetWaitTime() - real_current_order->GetTravelTime());
}
@@ -286,30 +286,30 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
uint waiting_time = 0;
/* If the vehicle is stopped in a depot, ignore it. */
if ((*v)->IsStoppedInDepot()) {
if (v->IsStoppedInDepot()) {
continue;
}
/* If the vehicle is heading for a depot to stop there, then its departures are cancelled. */
if ((*v)->current_order.IsType(OT_GOTO_DEPOT) && (*v)->current_order.GetDepotActionType() & ODATFB_HALT) {
if (v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDepotActionType() & ODATFB_HALT) {
status = D_CANCELLED;
}
if ((*v)->current_order.IsAnyLoadingType()) {
if (v->current_order.IsAnyLoadingType()) {
/* Account for the vehicle having reached the current order and being in the loading phase. */
status = D_ARRIVED;
start_date -= order->GetTravelTime() + (((*v)->lateness_counter < 0) ? (*v)->lateness_counter : 0);
start_date -= order->GetTravelTime() + ((v->lateness_counter < 0) ? v->lateness_counter : 0);
}
/* Loop through the vehicle's orders until we've found a suitable order or we've determined that no such order exists. */
/* We only need to consider each order at most once. */
for (int i = (*v)->GetNumOrders(); i > 0; --i) {
if (VehicleSetNextDepartureTime(&start_date, &waiting_time, date_only_scaled, *v, order, status == D_ARRIVED, schdispatch_last_planned_dispatch)) {
for (int i = v->GetNumOrders(); i > 0; --i) {
if (VehicleSetNextDepartureTime(&start_date, &waiting_time, date_only_scaled, v, order, status == D_ARRIVED, schdispatch_last_planned_dispatch)) {
should_reset_lateness = true;
}
/* If the scheduled departure date is too far in the future, stop. */
if (start_date - (*v)->lateness_counter > max_date) {
if (start_date - v->lateness_counter > max_date) {
break;
}
@@ -325,7 +325,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
if (status != D_CANCELLED) {
status = D_TRAVELLING;
}
order = (*v)->GetOrder(order->GetConditionSkipToOrder());
order = v->GetOrder(order->GetConditionSkipToOrder());
if (order == NULL) {
break;
}
@@ -339,7 +339,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
if (status != D_CANCELLED) {
status = D_TRAVELLING;
}
order = (order->next == NULL) ? (*v)->GetFirstOrder() : order->next;
order = (order->next == NULL) ? v->GetFirstOrder() : order->next;
continue;
}
}
@@ -347,7 +347,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
/* Skip it if it's an automatic order. */
if (order->IsType(OT_IMPLICIT)) {
order = (order->next == NULL) ? (*v)->GetFirstOrder() : order->next;
order = (order->next == NULL) ? v->GetFirstOrder() : order->next;
continue;
}
@@ -368,10 +368,10 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
OrderDate *od = new OrderDate();
od->order = order;
od->v = *v;
od->v = v;
/* We store the expected date for now, so that vehicles will be shown in order of expected time. */
od->expected_date = start_date;
od->lateness = (*v)->lateness_counter > 0 ? (*v)->lateness_counter : 0;
od->lateness = v->lateness_counter > 0 ? v->lateness_counter : 0;
od->status = status;
od->scheduled_waiting_time = waiting_time;
@@ -381,8 +381,8 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
/* If we are early, use the scheduled date as the expected date. We also take lateness to be zero. */
if (!should_reset_lateness && (*v)->lateness_counter < 0 && !(*v)->current_order.IsAnyLoadingType()) {
od->expected_date -= (*v)->lateness_counter;
if (!should_reset_lateness && v->lateness_counter < 0 && !v->current_order.IsAnyLoadingType()) {
od->expected_date -= v->lateness_counter;
}
/* Update least_order if this is the current least order. */
@@ -393,7 +393,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
least_order = od;
}
*(next_orders.Append(1)) = od;
next_orders.push_back(od);
/* We're done with this vehicle. */
break;
@@ -402,14 +402,14 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
if (status != D_CANCELLED) {
status = D_TRAVELLING;
}
order = (order->next == NULL) ? (*v)->GetFirstOrder() : order->next;
order = (order->next == NULL) ? v->GetFirstOrder() : order->next;
}
}
}
}
/* No suitable orders found? Then stop. */
if (next_orders.Length() == 0) {
if (next_orders.size() == 0) {
return result;
}
@@ -418,15 +418,15 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
for(int i = 10000; i > 0; --i) {
/* I should probably try to convince you that this loop always terminates regardless of the safeguard. */
/* 1. next_orders contains at least one element. */
/* 2. The loop terminates if result->Length() exceeds a fixed (for this loop) value, or if the least order's scheduled date is later than max_date. */
/* 2. The loop terminates if result->size() exceeds a fixed (for this loop) value, or if the least order's scheduled date is later than max_date. */
/* (We ignore the case that the least order's scheduled date has overflown, as it is a relative rather than absolute date.) */
/* 3. Every time we loop round, either result->Length() will have increased -OR- we will have increased the expected_date of one of the elements of next_orders. */
/* 3. Every time we loop round, either result->size() will have increased -OR- we will have increased the expected_date of one of the elements of next_orders. */
/* 4. Therefore the loop must eventually terminate. */
/* least_order is the best candidate for the next departure. */
/* First, we check if we can stop looking for departures yet. */
if (result->Length() >= _settings_client.gui.max_departures ||
if (result->size() >= _settings_client.gui.max_departures ||
least_order->expected_date - least_order->lateness > max_date) {
break;
}
@@ -469,7 +469,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
/* If we reach the order at which the departure occurs again, then use the departure station as the terminus. */
if (order == least_order->order) {
/* If we're not calling anywhere, then skip this departure. */
found_terminus = (d->calling_at.Length() > 0);
found_terminus = (d->calling_at.size() > 0);
break;
}
@@ -504,7 +504,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
order->GetNonStopType() != ONSF_NO_STOP_AT_ANY_STATION &&
order->GetNonStopType() != ONSF_NO_STOP_AT_DESTINATION_STATION) {
/* If we're not calling anywhere, then skip this departure. */
found_terminus = (d->calling_at.Length() > 0);
found_terminus = (d->calling_at.size() > 0);
break;
}
@@ -537,7 +537,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
/* If this order's station is already in the calling, then the previous called at station is the terminus. */
if (d->calling_at.Contains(c)) {
if (std::find(d->calling_at.begin(), d->calling_at.end(), c) != d->calling_at.end()) {
found_terminus = true;
break;
}
@@ -551,13 +551,13 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
d->via = (StationID)order->GetDestination();
}
d->terminus = c;
*(d->calling_at.Append(1)) = c;
d->calling_at.push_back(c);
}
/* If we unload all at this station, then it is the terminus. */
if (order->GetType() == OT_GOTO_STATION &&
order->GetUnloadType() == OUFB_UNLOAD) {
if (d->calling_at.Length() > 0) {
if (d->calling_at.size() > 0) {
found_terminus = true;
}
break;
@@ -574,8 +574,8 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
bool duplicate = false;
if (_settings_client.gui.departure_merge_identical) {
for (uint i = 0; i < result->Length(); ++i) {
if (*d == **(result->Get(i))) {
for (uint i = 0; i < result->size(); ++i) {
if (*d == *((*result)[i])) {
duplicate = true;
break;
}
@@ -583,17 +583,17 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
if (!duplicate) {
*(result->Append(1)) = d;
result->push_back(d);
if (_settings_client.gui.departure_smart_terminus && type == D_DEPARTURE) {
for (uint i = 0; i < result->Length()-1; ++i) {
Departure *d_first = *(result->Get(i));
uint k = d_first->calling_at.Length()-2;
for (uint j = d->calling_at.Length(); j > 0; --j) {
CallAt c = CallAt(*(d->calling_at.Get(j-1)));
for (uint i = 0; i < result->size() - 1; ++i) {
Departure *d_first = (*result)[i];
uint k = d_first->calling_at.size() - 2;
for (uint j = d->calling_at.size(); j > 0; --j) {
CallAt c = CallAt(d->calling_at[j - 1]);
if (d_first->terminus >= c && d_first->calling_at.Length() >= 2) {
d_first->terminus = CallAt(*(d_first->calling_at.Get(k)));
if (d_first->terminus >= c && d_first->calling_at.size() >= 2) {
d_first->terminus = CallAt(d_first->calling_at[k]);
if (k == 0) break;
@@ -666,7 +666,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
if (order->GetType() == OT_GOTO_STATION &&
(order->GetLoadType() != OLFB_NO_LOAD ||
_settings_client.gui.departure_show_all_stops)) {
*(d->calling_at.Append(1)) = CallAt((StationID)order->GetDestination());
d->calling_at.push_back(CallAt((StationID)order->GetDestination()));
}
order = (order->next == NULL) ? least_order->v->GetFirstOrder() : order->next;
@@ -678,8 +678,8 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
bool duplicate = false;
if (_settings_client.gui.departure_merge_identical) {
for (uint i = 0; i < result->Length(); ++i) {
if (*d == **(result->Get(i))) {
for (uint i = 0; i < result->size(); ++i) {
if (*d == *((*result)[i])) {
duplicate = true;
break;
}
@@ -687,7 +687,7 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
if (!duplicate) {
*(result->Append(1)) = d;
result->push_back(d);
}
}
}
@@ -784,8 +784,8 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
/* Find the new least order. */
for (uint i = 0; i < next_orders.Length(); ++i) {
OrderDate *od = *(next_orders.Get(i));
for (uint i = 0; i < next_orders.size(); ++i) {
OrderDate *od = next_orders[i];
DateTicks lod = least_order->expected_date - least_order->lateness;
DateTicks odd = od->expected_date - od->lateness;
@@ -802,8 +802,8 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
}
/* Avoid leaking OrderDate structs */
for (uint i = 0; i < next_orders.Length(); ++i) {
OrderDate *od = *(next_orders.Get(i));
for (uint i = 0; i < next_orders.size(); ++i) {
OrderDate *od = next_orders[i];
delete od;
}

View File

@@ -274,7 +274,7 @@ public:
id_v += this->vscroll->GetPosition();
if (id_v >= (this->departures->Length() + this->arrivals->Length())) return; // click out of list bound
if (id_v >= (this->departures->size() + this->arrivals->size())) return; // click out of list bound
uint departure = 0;
uint arrival = 0;
@@ -283,9 +283,9 @@ public:
for (uint i = 0; i <= id_v; ++i) {
const Departure *d;
if (arrival == this->arrivals->Length()) {
if (arrival == this->arrivals->size()) {
d = (*(this->departures))[departure++];
} else if (departure == this->departures->Length()) {
} else if (departure == this->departures->size()) {
d = (*(this->arrivals))[arrival++];
} else {
d = (*(this->departures))[departure];
@@ -384,7 +384,7 @@ public:
this->EnableWidget(WID_DB_SHOW_DEPS);
}
this->vscroll->SetCount(min(_settings_client.gui.max_departures, this->departures->Length() + this->arrivals->Length()));
this->vscroll->SetCount(min(_settings_client.gui.max_departures, this->departures->size() + this->arrivals->size()));
this->DrawWidgets();
}
@@ -485,18 +485,18 @@ uint DeparturesWindow<Twaypoint>::GetMinWidth() const
continue;
}
for (const Vehicle **v = vehicles.Begin(); v != vehicles.End(); v++) {
SetDParam(0, (uint64)((*v)->index));
for (const Vehicle *v : vehicles) {
SetDParam(0, (uint64)(v->index));
int width = (GetStringBoundingBox(STR_DEPARTURES_VEH)).width;
if (_settings_client.gui.departure_show_vehicle && width > veh_width) veh_width = width;
if ((*v)->group_id != INVALID_GROUP && (*v)->group_id != DEFAULT_GROUP) {
SetDParam(0, (uint64)((*v)->group_id));
if (v->group_id != INVALID_GROUP && v->group_id != DEFAULT_GROUP) {
SetDParam(0, (uint64)(v->group_id));
width = (GetStringBoundingBox(STR_DEPARTURES_GROUP)).width;
if (_settings_client.gui.departure_show_group && width > group_width) group_width = width;
}
SetDParam(0, (uint64)((*v)->owner));
SetDParam(0, (uint64)(v->owner));
width = (GetStringBoundingBox(STR_DEPARTURES_TOC)).width;
if (_settings_client.gui.departure_show_company && width > toc_width) toc_width = width;
}
@@ -515,13 +515,12 @@ template<bool Twaypoint>
void DeparturesWindow<Twaypoint>::DeleteDeparturesList(DepartureList *list)
{
/* SmallVector uses free rather than delete on its contents (which doesn't invoke the destructor), so we need to delete each departure manually. */
for (uint i = 0; i < list->Length(); ++i) {
Departure **d = list->Get(i);
for (uint i = 0; i < list->size(); ++i) {
Departure **d = &(*list)[i];
delete *d;
/* Make sure a double free doesn't happen. */
*d = NULL;
}
list->Reset();
delete list;
list = NULL;
}
@@ -543,7 +542,7 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
int text_right = right - (rtl ? text_offset : 0);
int y = r.top + 1;
uint max_departures = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->departures->Length() + this->arrivals->Length());
uint max_departures = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->departures->size() + this->arrivals->size());
if (max_departures > _settings_client.gui.max_departures) {
max_departures = _settings_client.gui.max_departures;
@@ -618,18 +617,18 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
continue;
}
for (const Vehicle **v = vehicles.Begin(); v != vehicles.End(); v++) {
SetDParam(0, (uint64)((*v)->index));
for (const Vehicle *v : vehicles) {
SetDParam(0, (uint64)(v->index));
int width = (GetStringBoundingBox(STR_DEPARTURES_VEH)).width;
if (_settings_client.gui.departure_show_vehicle && width > veh_width) veh_width = width;
if ((*v)->group_id != INVALID_GROUP && (*v)->group_id != DEFAULT_GROUP) {
SetDParam(0, (uint64)((*v)->group_id));
if (v->group_id != INVALID_GROUP && v->group_id != DEFAULT_GROUP) {
SetDParam(0, (uint64)(v->group_id));
width = (GetStringBoundingBox(STR_DEPARTURES_GROUP)).width;
if (_settings_client.gui.departure_show_group && width > group_width) group_width = width;
}
SetDParam(0, (uint64)((*v)->owner));
SetDParam(0, (uint64)(v->owner));
width = (GetStringBoundingBox(STR_DEPARTURES_TOC)).width;
if (_settings_client.gui.departure_show_company && width > toc_width) toc_width = width;
}
@@ -646,9 +645,9 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
for (uint i = 0; i < max_departures; ++i) {
const Departure *d;
if (arrival == this->arrivals->Length()) {
if (arrival == this->arrivals->size()) {
d = (*(this->departures))[departure++];
} else if (departure == this->departures->Length()) {
} else if (departure == this->departures->size()) {
d = (*(this->arrivals))[arrival++];
} else {
d = (*(this->departures))[departure];
@@ -851,23 +850,23 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
/* STR_DEPARTURES_CALLING_AT_LAST_STATION :{STATION} & {RAW_STRING}*/
char buffer[512], scratch[512];
if (d->calling_at.Length() != 0) {
SetDParam(0, (uint64)(*d->calling_at.Get(0)).station);
if (d->calling_at.size() != 0) {
SetDParam(0, (uint64)(d->calling_at[0]).station);
GetString(scratch, STR_DEPARTURES_CALLING_AT_FIRST_STATION, lastof(scratch));
StationID continuesTo = INVALID_STATION;
if (d->calling_at.Get(0)->station == d->terminus.station && d->calling_at.Length() > 1) {
continuesTo = d->calling_at.Get(d->calling_at.Length() - 1)->station;
} else if (d->calling_at.Length() > 1) {
if (d->calling_at[0].station == d->terminus.station && d->calling_at.size() > 1) {
continuesTo = d->calling_at[d->calling_at.size() - 1].station;
} else if (d->calling_at.size() > 1) {
/* There's more than one stop. */
uint i;
/* For all but the last station, write out ", <station>". */
for (i = 1; i < d->calling_at.Length() - 1; ++i) {
StationID s = d->calling_at.Get(i)->station;
for (i = 1; i < d->calling_at.size() - 1; ++i) {
StationID s = d->calling_at[i].station;
if (s == d->terminus.station) {
continuesTo = d->calling_at.Get(d->calling_at.Length() - 1)->station;
continuesTo = d->calling_at[d->calling_at.size() - 1].station;
break;
}
SetDParam(0, (uint64)scratch);
@@ -878,7 +877,7 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
/* Finally, finish off with " and <station>". */
SetDParam(0, (uint64)scratch);
SetDParam(1, (uint64)d->calling_at.Get(i)->station);
SetDParam(1, (uint64)d->calling_at[i].station);
GetString(buffer, STR_DEPARTURES_CALLING_AT_LAST_STATION, lastof(buffer));
strncpy(scratch, buffer, sizeof(scratch));
}

View File

@@ -29,7 +29,7 @@ typedef enum {
D_ARRIVAL = 1,
} DepartureType;
typedef struct CallAt {
struct CallAt {
StationID station;
DateTicks scheduled_date;
@@ -61,31 +61,27 @@ typedef struct CallAt {
inline bool operator==(StationID s) const {
return this->station == s;
}
} CallAt;
};
/** A scheduled departure. */
typedef struct Departure {
struct Departure {
DateTicksScaled scheduled_date; ///< The date this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
Ticks lateness; ///< How delayed the departure is expected to be
CallAt terminus; ///< The station at which the vehicle will terminate following this departure
StationID via; ///< The station the departure should list as going via
SmallVector<CallAt, 32> calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates
std::vector<CallAt> calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates
DepartureStatus status; ///< Whether the vehicle has arrived yet for this departure
DepartureType type; ///< The type of the departure (departure or arrival)
const Vehicle *vehicle; ///< The vehicle performing this departure
const Order *order; ///< The order corresponding to this departure
uint scheduled_waiting_time; ///< Scheduled waiting time if scheduled dispatch is used
Departure() : terminus(INVALID_STATION), via(INVALID_STATION), calling_at(), vehicle(NULL) { }
~Departure()
{
calling_at.Reset();
}
Departure() : terminus(INVALID_STATION), via(INVALID_STATION), vehicle(NULL), order(NULL) { }
inline bool operator==(const Departure& d) const {
if (this->calling_at.Length() != d.calling_at.Length()) return false;
if (this->calling_at.size() != d.calling_at.size()) return false;
for (uint i = 0; i < this->calling_at.Length(); ++i) {
if (*(this->calling_at.Get(i)) != *(d.calling_at.Get(i))) return false;
for (uint i = 0; i < this->calling_at.size(); ++i) {
if (this->calling_at[i] != d.calling_at[i]) return false;
}
return
@@ -95,8 +91,8 @@ typedef struct Departure {
this->type == d.type
;
}
} Departure;
};
typedef SmallVector<Departure*, 32> DepartureList;
typedef std::vector<Departure*> DepartureList;
#endif /* DEPARTURES_TYPE_H */

View File

@@ -366,7 +366,7 @@ struct DepotWindow : Window {
}
}
void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_D_MATRIX) return;
@@ -400,7 +400,7 @@ struct DepotWindow : Window {
uint16 rows_in_display = wid->current_y / wid->resize_y;
uint16 num = this->vscroll->GetPosition() * this->num_columns;
int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * this->num_columns));
int maxval = min(this->vehicle_list.size(), num + (rows_in_display * this->num_columns));
int y;
for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
for (byte i = 0; i < this->num_columns && num < maxval; i++, num++) {
@@ -415,16 +415,16 @@ struct DepotWindow : Window {
}
}
maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns));
maxval = min(this->vehicle_list.size() + this->wagon_list.size(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns));
/* Draw the train wagons without an engine in front. */
for (; num < maxval; num++, y += this->resize.step_height) {
const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
const Vehicle *v = this->wagon_list[num - this->vehicle_list.size()];
this->DrawVehicleInDepot(v, r.left, r.right, y);
}
}
void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget != WID_D_CAPTION) return;
@@ -467,7 +467,7 @@ struct DepotWindow : Window {
uint pos = ((row + this->vscroll->GetPosition()) * this->num_columns) + xt;
if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
if (this->vehicle_list.size() + this->wagon_list.size() <= pos) {
/* Clicking on 'line' / 'block' without a vehicle */
if (this->type == VEH_TRAIN) {
/* End the dragging */
@@ -480,12 +480,12 @@ struct DepotWindow : Window {
}
bool wagon = false;
if (this->vehicle_list.Length() > pos) {
if (this->vehicle_list.size() > pos) {
*veh = this->vehicle_list[pos];
/* Skip vehicles that are scrolled off the list */
if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
} else {
pos -= this->vehicle_list.Length();
pos -= this->vehicle_list.size();
*veh = this->wagon_list[pos];
/* free wagons don't have an initial loco. */
x -= ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
@@ -652,7 +652,7 @@ struct DepotWindow : Window {
uint flag_width;
uint flag_height;
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_D_MATRIX: {
@@ -703,12 +703,12 @@ struct DepotWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
this->generate_list = true;
}
virtual void OnPaint()
void OnPaint() override
{
if (this->generate_list) {
/* Generate the vehicle list
@@ -728,7 +728,7 @@ struct DepotWindow : Window {
/* determine amount of items for scroller */
if (this->type == VEH_TRAIN) {
uint max_width = ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
for (uint num = 0; num < this->vehicle_list.Length(); num++) {
for (uint num = 0; num < this->vehicle_list.size(); num++) {
uint width = 0;
for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
width += v->GetDisplayImageWidth();
@@ -736,11 +736,11 @@ struct DepotWindow : Window {
max_width = max(max_width, width);
}
/* Always have 1 empty row, so people can change the setting of the train */
this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
this->vscroll->SetCount(this->vehicle_list.size() + this->wagon_list.size() + 1);
/* Always make it longer than the longest train, so you can attach vehicles at the end, and also see the next vertical tile separator line */
this->hscroll->SetCount(max_width + ScaleGUITrad(2 * VEHICLEINFO_FULL_VEHICLE_WIDTH + 1));
} else {
this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->num_columns));
this->vscroll->SetCount(CeilDiv(this->vehicle_list.size(), this->num_columns));
}
/* Setup disabled buttons. */
@@ -760,7 +760,7 @@ struct DepotWindow : Window {
this->DrawWidgets();
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_D_MATRIX: { // List
@@ -813,7 +813,7 @@ struct DepotWindow : Window {
case WID_D_SELL_ALL:
/* Only open the confirmation window if there are anything to sell */
if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) {
if (this->vehicle_list.size() != 0 || this->wagon_list.size() != 0) {
TileIndex tile = this->window_number;
byte vehtype = this->type;
@@ -839,7 +839,7 @@ struct DepotWindow : Window {
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str == NULL) return;
@@ -847,7 +847,7 @@ struct DepotWindow : Window {
DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
}
virtual bool OnRightClick(Point pt, int widget)
bool OnRightClick(Point pt, int widget) override
{
if (widget != WID_D_MATRIX) return false;
@@ -908,7 +908,7 @@ struct DepotWindow : Window {
* @param v the original vehicle to clone
* @return Always true.
*/
virtual bool OnVehicleSelect(const Vehicle *v)
bool OnVehicleSelect(const Vehicle *v) override
{
if (_ctrl_pressed) {
/* Share-clone, do not open new viewport, and keep tool active */
@@ -924,7 +924,7 @@ struct DepotWindow : Window {
return true;
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
/* abort clone */
this->RaiseWidget(WID_D_CLONE);
@@ -942,7 +942,7 @@ struct DepotWindow : Window {
}
}
virtual void OnMouseDrag(Point pt, int widget)
void OnMouseDrag(Point pt, int widget) override
{
if (this->sel == INVALID_VEHICLE) return;
if (widget != this->hovered_widget) {
@@ -994,7 +994,7 @@ struct DepotWindow : Window {
this->SetWidgetDirty(widget);
}
virtual void OnDragDrop(Point pt, int widget)
void OnDragDrop(Point pt, int widget) override
{
switch (widget) {
case WID_D_MATRIX: {
@@ -1049,7 +1049,7 @@ struct DepotWindow : Window {
_cursor.vehchain = false;
}
virtual void OnTimeout()
void OnTimeout() override
{
if (!this->IsWidgetDisabled(WID_D_SELL)) {
this->RaiseWidget(WID_D_SELL);
@@ -1061,7 +1061,7 @@ struct DepotWindow : Window {
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_D_MATRIX);
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
@@ -1072,7 +1072,7 @@ struct DepotWindow : Window {
}
}
virtual EventState OnCTRLStateChange()
EventState OnCTRLStateChange() override
{
if (this->sel != INVALID_VEHICLE) {
_cursor.vehchain = _ctrl_pressed;

View File

@@ -114,7 +114,7 @@ struct BuildDocksToolbarWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -130,7 +130,7 @@ struct BuildDocksToolbarWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_DT_CANAL: // Build canal button
@@ -174,7 +174,7 @@ struct BuildDocksToolbarWindow : Window {
this->last_clicked_widget = (DockToolbarWidgets)widget;
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
void OnPlaceObject(Point pt, TileIndex tile) override
{
switch (this->last_clicked_widget) {
case WID_DT_CANAL: // Build canal button
@@ -223,12 +223,12 @@ struct BuildDocksToolbarWindow : Window {
}
}
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
{
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
{
if (pt.x != -1) {
switch (select_proc) {
@@ -247,7 +247,7 @@ struct BuildDocksToolbarWindow : Window {
}
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
this->RaiseButtons();
@@ -257,7 +257,7 @@ struct BuildDocksToolbarWindow : Window {
DeleteWindowByClass(WC_BUILD_BRIDGE);
}
virtual void OnPlacePresize(Point pt, TileIndex tile_from)
void OnPlacePresize(Point pt, TileIndex tile_from) override
{
TileIndex tile_to = tile_from;
@@ -412,7 +412,7 @@ public:
DeleteWindowById(WC_SELECT_STATION, 0);
}
virtual void OnPaint()
void OnPaint() override
{
int rad = (_settings_game.station.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
rad += _settings_game.station.catchment_increase;
@@ -440,7 +440,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case BDSW_LT_OFF:
@@ -454,7 +454,7 @@ public:
}
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
CheckRedrawStationCoverage(this);
}
@@ -508,7 +508,7 @@ public:
UpdateDocksDirection();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_BDD_X:
@@ -519,7 +519,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
this->DrawWidgets();
@@ -534,7 +534,7 @@ public:
DrawShipDepotSprite(this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_x + x1, this->GetWidget<NWidgetBase>(WID_BDD_Y)->pos_y + y2, AXIS_Y, DEPOT_PART_SOUTH);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_BDD_X:

View File

@@ -81,7 +81,7 @@ static inline int32 BigMulS(const int32 a, const int32 b, const uint8 shift)
return (int32)((int64)a * (int64)b >> shift);
}
typedef SmallVector<Industry *, 16> SmallIndustryList;
typedef std::vector<Industry *> SmallIndustryList;
/**
* Score info, values used for computing the detailed performance rating.
@@ -264,7 +264,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
/* Skip the total */
if (i == SCORE_TOTAL) continue;
/* Check the score */
s = Clamp(_score_part[owner][i], 0, _score_info[i].needed) * _score_info[i].score / _score_info[i].needed;
s = Clamp<int64>(_score_part[owner][i], 0, _score_info[i].needed) * _score_info[i].score / _score_info[i].needed;
score += s;
total_score += _score_info[i].score;
}
@@ -296,10 +296,8 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
* the client. This is needed as it needs to know whether "you" really
* are the current local company. */
Backup<CompanyByte> cur_company(_current_company, old_owner, FILE_LINE);
#ifdef ENABLE_NETWORK
/* In all cases, make spectators of clients connected to that company */
if (_networking) NetworkClientsToSpectators(old_owner);
#endif /* ENABLE_NETWORK */
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. */
@@ -1092,7 +1090,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue;
/* Insert the industry into _cargo_delivery_destinations, if not yet contained */
_cargo_delivery_destinations.Include(ind);
include(_cargo_delivery_destinations, ind);
uint amount = min(num_pieces, 0xFFFFU - ind->incoming_cargo_waiting[cargo_index]);
ind->incoming_cargo_waiting[cargo_index] += amount;
@@ -2166,11 +2164,10 @@ void LoadUnloadStation(Station *st)
}
/* Call the production machinery of industries */
const Industry * const *isend = _cargo_delivery_destinations.End();
for (Industry **iid = _cargo_delivery_destinations.Begin(); iid != isend; iid++) {
TriggerIndustryProduction(*iid);
for (Industry *iid : _cargo_delivery_destinations) {
TriggerIndustryProduction(iid);
}
_cargo_delivery_destinations.Clear();
_cargo_delivery_destinations.clear();
}
/**

View File

@@ -497,14 +497,15 @@ StringID Engine::GetAircraftTypeText() const
*/
void EngineOverrideManager::ResetToDefaultMapping()
{
this->Clear();
this->clear();
for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
EngineIDMapping *eid = this->Append();
eid->type = type;
eid->grfid = INVALID_GRFID;
eid->internal_id = internal_id;
eid->substitute_id = internal_id;
/*C++17: EngineIDMapping &eid = */ this->emplace_back();
EngineIDMapping &eid = this->back();
eid.type = type;
eid.grfid = INVALID_GRFID;
eid.internal_id = internal_id;
eid.substitute_id = internal_id;
}
}
}
@@ -520,12 +521,12 @@ void EngineOverrideManager::ResetToDefaultMapping()
*/
EngineID EngineOverrideManager::GetID(VehicleType type, uint16 grf_local_id, uint32 grfid)
{
const EngineIDMapping *end = this->End();
EngineID index = 0;
for (const EngineIDMapping *eid = this->Begin(); eid != end; eid++, index++) {
if (eid->type == type && eid->grfid == grfid && eid->internal_id == grf_local_id) {
for (const EngineIDMapping &eid : *this) {
if (eid.type == type && eid.grfid == grfid && eid.internal_id == grf_local_id) {
return index;
}
index++;
}
return INVALID_ENGINE;
}
@@ -557,15 +558,15 @@ void SetupEngines()
DeleteWindowByClass(WC_ENGINE_PREVIEW);
_engine_pool.CleanPool();
assert(_engine_mngr.Length() >= _engine_mngr.NUM_DEFAULT_ENGINES);
const EngineIDMapping *end = _engine_mngr.End();
assert(_engine_mngr.size() >= _engine_mngr.NUM_DEFAULT_ENGINES);
uint index = 0;
for (const EngineIDMapping *eid = _engine_mngr.Begin(); eid != end; eid++, index++) {
for (const EngineIDMapping &eid : _engine_mngr) {
/* Assert is safe; there won't be more than 256 original vehicles
* in any case, and we just cleaned the pool. */
assert(Engine::CanAllocateItem());
const Engine *e = new Engine(eid->type, eid->internal_id);
const Engine *e = new Engine(eid.type, eid.internal_id);
assert(e->index == index);
index++;
}
}

View File

@@ -157,7 +157,7 @@ struct EngineIDMapping {
* Stores the mapping of EngineID to the internal id of newgrfs.
* Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get resetted in different cases.
*/
struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
struct EngineOverrideManager : std::vector<EngineIDMapping> {
static const uint NUM_DEFAULT_ENGINES; ///< Number of default entries
void ResetToDefaultMapping();

View File

@@ -26,7 +26,7 @@ extern const uint8 _engine_offsets[4];
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
bool IsEngineRefittable(EngineID engine);
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits);
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint16 cargo_capacity);
void SetYearEngineAgingStops();
void StartupOneEngine(Engine *e, Date aging_date);

View File

@@ -75,7 +75,7 @@ struct EnginePreviewWindow : Window {
this->flags |= WF_STICKY;
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_EP_QUESTION) return;
@@ -102,7 +102,7 @@ struct EnginePreviewWindow : Window {
size->height += GetStringHeight(GetEngineInfoString(engine), size->width);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_EP_QUESTION) return;
@@ -121,7 +121,7 @@ struct EnginePreviewWindow : Window {
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_EP_YES:
@@ -133,7 +133,7 @@ struct EnginePreviewWindow : Window {
}
}
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -325,11 +325,11 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng
*/
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
{
uint size = el->Length();
uint size = el->size();
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
* generally, do not sort if there are less than 2 items */
if (size < 2) return;
QSortT(el->Begin(), size, compare);
QSortT(el->data(), size, compare);
}
/**
@@ -342,8 +342,8 @@ void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
{
if (num_items < 2) return;
assert(begin < el->Length());
assert(begin + num_items <= el->Length());
QSortT(el->Get(begin), num_items, compare);
assert(begin < el->size());
assert(begin + num_items <= el->size());
QSortT(el->data() + begin, num_items, compare);
}

View File

@@ -183,7 +183,7 @@ public:
this->InitNested();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_EM_MESSAGE: {
@@ -213,7 +213,7 @@ public:
}
}
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
{
/* Position (0, 0) given, center the window. */
if (this->position.x == 0 && this->position.y == 0) {
@@ -249,18 +249,18 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
/* If company gets shut down, while displaying an error about it, remove the error message. */
if (this->face != INVALID_COMPANY && !Company::IsValidID(this->face)) delete this;
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_EM_CAPTION) CopyInDParam(0, this->decode_params, lengthof(this->decode_params));
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_EM_FACE: {
@@ -312,13 +312,13 @@ public:
}
}
virtual void OnMouseLoop()
void OnMouseLoop() override
{
/* Disallow closing the window too easily, if timeout is disabled */
if (_right_button_down && this->duration != 0) delete this;
}
virtual void OnHundredthTick()
void OnHundredthTick() override
{
/* Timeout enabled? */
if (this->duration != 0) {
@@ -333,7 +333,7 @@ public:
if (_window_system_initialized) ShowFirstError();
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
if (keycode != WKC_SPACE) return ES_NOT_HANDLED;
delete this;

View File

@@ -1000,10 +1000,6 @@ static bool ChangeWorkingDirectoryToExecutable(const char *exe)
char *s = strrchr(tmp, PATHSEPCHAR);
if (s != NULL) {
*s = '\0';
#if defined(__DJGPP__)
/* If we want to go to the root, we can't use cd C:, but we must use '/' */
if (s > tmp && *(s - 1) == ':') chdir("/");
#endif
if (chdir(tmp) != 0) {
DEBUG(misc, 0, "Directory with the binary does not exist?");
} else {
@@ -1056,7 +1052,7 @@ void DetermineBasePaths(const char *exe)
AppendPathSeparator(tmp, lastof(tmp));
_searchpaths[SP_PERSONAL_DIR_XDG] = stredup(tmp);
#endif
#if defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR)
#if defined(OS2) || !defined(WITH_PERSONAL_DIR)
_searchpaths[SP_PERSONAL_DIR] = NULL;
#else
#ifdef __HAIKU__
@@ -1244,7 +1240,6 @@ void DeterminePaths(const char *exe)
/* If we have network we make a directory for the autodownloading of content */
_searchpaths[SP_AUTODOWNLOAD_DIR] = str_fmt("%s%s", _personal_dir, "content_download" PATHSEP);
#ifdef ENABLE_NETWORK
FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR]);
/* Create the directory for each of the types of content */
@@ -1257,14 +1252,6 @@ void DeterminePaths(const char *exe)
extern char *_log_file;
_log_file = str_fmt("%sopenttd.log", _personal_dir);
#else /* ENABLE_NETWORK */
/* If we don't have networking, we don't need to make the directory. But
* if it exists we keep it, otherwise remove it from the search paths. */
if (!FileExists(_searchpaths[SP_AUTODOWNLOAD_DIR])) {
free(_searchpaths[SP_AUTODOWNLOAD_DIR]);
_searchpaths[SP_AUTODOWNLOAD_DIR] = NULL;
}
#endif /* ENABLE_NETWORK */
}
/**

View File

@@ -107,7 +107,7 @@ public:
ALL = BASESET | NEWGRF | AI | SCENARIO | GAME, ///< Scan for everything.
};
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL);
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL) override;
bool AddFile(Subdirectory sd, const char *filename);

View File

@@ -13,11 +13,13 @@
*/
#include "stdafx.h"
#include "fios.h"
#include "3rdparty/md5/md5.h"
#include "fileio_func.h"
#include "tar_type.h"
#include "fios.h"
#include "network/network_content.h"
#include "screenshot.h"
#include "string_func.h"
#include "tar_type.h"
#include <sys/stat.h>
#ifndef _WIN32
@@ -274,7 +276,7 @@ public:
fop(fop), callback_proc(callback_proc), file_list(file_list)
{}
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename);
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override;
};
/**
@@ -378,7 +380,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
{
SortingBits order = _savegame_sort_order;
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
QSortT(file_list.files.Begin(), file_list.files.Length(), CompareFiosItems);
QSortT(file_list.files.data(), file_list.files.size(), CompareFiosItems);
_savegame_sort_order = order;
}
@@ -632,10 +634,6 @@ const char *FiosGetScreenshotDir()
return fios_screenshot_path;
}
#if defined(ENABLE_NETWORK)
#include "network/network_content.h"
#include "3rdparty/md5/md5.h"
/** Basic data to distinguish a scenario. Used in the server list window */
struct ScenarioIdentifier {
uint32 scenid; ///< ID for the scenario (generated by content).
@@ -657,7 +655,7 @@ struct ScenarioIdentifier {
/**
* Scanner to find the unique IDs of scenarios
*/
class ScenarioScanner : protected FileScanner, public SmallVector<ScenarioIdentifier, 8> {
class ScenarioScanner : protected FileScanner, public std::vector<ScenarioIdentifier> {
bool scanned; ///< Whether we've already scanned
public:
/** Initialise */
@@ -675,7 +673,7 @@ public:
this->scanned = true;
}
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override
{
FILE *f = FioFOpenFile(filename, "r", SCENARIO_DIR);
if (f == NULL) return false;
@@ -708,7 +706,7 @@ public:
FioFCloseFile(f);
this->Include(id);
include(*this, id);
return true;
}
};
@@ -726,10 +724,10 @@ const char *FindScenario(const ContentInfo *ci, bool md5sum)
{
_scanner.Scan(false);
for (ScenarioIdentifier *id = _scanner.Begin(); id != _scanner.End(); id++) {
if (md5sum ? (memcmp(id->md5sum, ci->md5sum, sizeof(id->md5sum)) == 0)
: (id->scenid == ci->unique_id)) {
return id->filename;
for (ScenarioIdentifier &id : _scanner) {
if (md5sum ? (memcmp(id.md5sum, ci->md5sum, sizeof(id.md5sum)) == 0)
: (id.scenid == ci->unique_id)) {
return id.filename;
}
}
@@ -754,5 +752,3 @@ void ScanScenarios()
{
_scanner.Scan(true);
}
#endif /* ENABLE_NETWORK */

View File

@@ -122,7 +122,8 @@ public:
*/
inline FiosItem *Append()
{
return this->files.Append();
/*C++17: return &*/ this->files.emplace_back();
return &this->files.back();
}
/**
@@ -131,7 +132,7 @@ public:
*/
inline uint Length() const
{
return this->files.Length();
return this->files.size();
}
/**
@@ -140,7 +141,7 @@ public:
*/
inline const FiosItem *Begin() const
{
return this->files.Begin();
return this->files.data();
}
/**
@@ -149,7 +150,7 @@ public:
*/
inline const FiosItem *End() const
{
return this->files.End();
return this->Begin() + this->Length();
}
/**
@@ -158,7 +159,7 @@ public:
*/
inline const FiosItem *Get(uint index) const
{
return this->files.Get(index);
return this->files.data() + index;
}
/**
@@ -167,7 +168,7 @@ public:
*/
inline FiosItem *Get(uint index)
{
return this->files.Get(index);
return this->files.data() + index;
}
inline const FiosItem &operator[](uint index) const
@@ -187,19 +188,19 @@ public:
/** Remove all items from the list. */
inline void Clear()
{
this->files.Clear();
this->files.clear();
}
/** Compact the list down to the smallest block size boundary. */
inline void Compact()
{
this->files.Compact();
this->files.shrink_to_fit();
}
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
const FiosItem *FindItem(const char *file);
SmallVector<FiosItem, 32> files; ///< The list of files.
std::vector<FiosItem> files; ///< The list of files.
};
enum SortingBits {

View File

@@ -57,11 +57,10 @@ void LoadCheckData::Clear()
this->current_date = 0;
memset(&this->settings, 0, sizeof(this->settings));
const CompanyPropertiesMap::iterator end = this->companies.End();
for (CompanyPropertiesMap::iterator it = this->companies.Begin(); it != end; it++) {
delete it->second;
for (auto &pair : this->companies) {
delete pair.second;
}
companies.Clear();
companies.clear();
GamelogFree(this->gamelog_action, this->gamelog_actions);
this->gamelog_action = NULL;
@@ -281,7 +280,7 @@ private:
StringFilter string_filter; ///< Filter for available games.
QueryString filter_editbox; ///< Filter editbox;
SmallVector<bool, 32> fios_items_shown; ///< Map of the filtered out fios items
std::vector<bool> fios_items_shown; ///< Map of the filtered out fios items
static void SaveGameConfirmationCallback(Window *w, bool confirmed)
{
@@ -409,7 +408,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_SL_SORT_BYNAME:
@@ -439,12 +438,15 @@ public:
GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, PC_BLACK);
uint y = r.top + WD_FRAMERECT_TOP;
for (uint pos = this->vscroll->GetPosition(); pos < this->fios_items.Length(); pos++) {
if (!this->fios_items_shown[pos]) {
uint scroll_pos = this->vscroll->GetPosition();
for (uint row = 0; row < this->fios_items.Length(); row++) {
if (!this->fios_items_shown[row]) {
/* The current item is filtered out : we do not show it */
scroll_pos++;
continue;
}
const FiosItem *item = this->fios_items.Get(pos);
if (row < scroll_pos) continue;
const FiosItem *item = this->fios_items.Get(row);
if (item == this->selected) {
GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE);
@@ -541,10 +543,9 @@ public:
if (y > y_max) break;
/* Companies / AIs */
CompanyPropertiesMap::const_iterator end = _load_check_data.companies.End();
for (CompanyPropertiesMap::const_iterator it = _load_check_data.companies.Begin(); it != end; it++) {
SetDParam(0, it->first + 1);
const CompanyProperties &c = *it->second;
for (auto &pair : _load_check_data.companies) {
SetDParam(0, pair.first + 1);
const CompanyProperties &c = *pair.second;
if (c.name != NULL) {
SetDParam(1, STR_JUST_RAW_STRING);
SetDParamStr(2, c.name);
@@ -563,7 +564,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_SL_BACKGROUND:
@@ -585,7 +586,7 @@ public:
}
}
virtual void OnPaint()
void OnPaint() override
{
if (_savegame_sort_dirty) {
_savegame_sort_dirty = false;
@@ -596,7 +597,7 @@ public:
this->DrawWidgets();
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_SL_SORT_BYNAME: // Sort save names by name
@@ -647,9 +648,7 @@ public:
if (!_network_available) {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
} else if (_load_check_data.HasNewGrfs()) {
#if defined(ENABLE_NETWORK)
ShowMissingContentWindow(_load_check_data.grfconfig);
#endif
}
break;
@@ -711,14 +710,12 @@ public:
if (!_network_available) {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
} else {
#if defined(ENABLE_NETWORK)
assert(this->fop == SLO_LOAD);
switch (this->abstract_filetype) {
default: NOT_REACHED();
case FT_SCENARIO: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO); break;
case FT_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break;
}
#endif
}
break;
@@ -732,7 +729,7 @@ public:
}
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
if (keycode == WKC_ESC) {
delete this;
@@ -742,7 +739,7 @@ public:
return ES_NOT_HANDLED;
}
virtual void OnTimeout()
void OnTimeout() override
{
/* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */
if (this->fop != SLO_SAVE) return;
@@ -783,7 +780,7 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_SL_DRIVES_DIRECTORIES_LIST);
}
@@ -793,7 +790,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
switch (data) {
case SLIWD_RESCAN_FILES:
@@ -844,7 +841,7 @@ public:
case SLIWD_FILTER_CHANGES:
/* Filter changes */
this->fios_items_shown.Resize(this->fios_items.Length());
this->fios_items_shown.resize(this->fios_items.Length());
uint items_shown_count = 0; ///< The number of items shown in the list
/* We pass through every fios item */
for (uint i = 0; i < this->fios_items.Length(); i++) {
@@ -871,7 +868,7 @@ public:
}
}
virtual void OnEditboxChanged(int wid)
void OnEditboxChanged(int wid) override
{
if (wid == WID_SL_FILTER) {
this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);

View File

@@ -417,8 +417,8 @@ FreeTypeFontCache::~FreeTypeFontCache()
this->face = NULL;
this->ClearFontCache();
for (FontTable::iterator iter = this->font_tables.Begin(); iter != this->font_tables.End(); iter++) {
free(iter->second.second);
for (auto &iter : this->font_tables) {
free(iter.second.second);
}
}
@@ -639,7 +639,7 @@ GlyphID FreeTypeFontCache::MapCharToGlyph(WChar key)
const void *FreeTypeFontCache::GetFontTable(uint32 tag, size_t &length)
{
const FontTable::iterator iter = this->font_tables.Find(tag);
if (iter != this->font_tables.End()) {
if (iter != this->font_tables.data() + this->font_tables.size()) {
length = iter->second.first;
return iter->second.second;
}

View File

@@ -432,7 +432,7 @@ struct FramerateWindow : Window {
ResizeWindow(this, 0, (max(MIN_ELEMENTS, this->num_displayed) - MIN_ELEMENTS) * FONT_HEIGHT_NORMAL);
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
bool elapsed = this->next_update.Elapsed(delta_ms);
@@ -475,7 +475,7 @@ struct FramerateWindow : Window {
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_FRW_CAPTION:
@@ -503,7 +503,7 @@ struct FramerateWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_FRW_RATE_GAMELOOP:
@@ -582,7 +582,7 @@ struct FramerateWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_FRW_TIMES_NAMES: {
@@ -621,7 +621,7 @@ struct FramerateWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_FRW_TIMES_NAMES:
@@ -646,7 +646,7 @@ struct FramerateWindow : Window {
}
}
virtual void OnResize()
void OnResize() override
{
auto *wid = this->GetWidget<NWidgetResizeBase>(WID_FRW_TIMES_NAMES);
this->num_displayed = (wid->current_y - wid->min_y - VSPACING) / FONT_HEIGHT_NORMAL - 1; // subtract 1 for headings
@@ -694,7 +694,7 @@ struct FrametimeGraphWindow : Window {
this->InitNested(number);
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_FGW_CAPTION:
@@ -709,7 +709,7 @@ struct FrametimeGraphWindow : Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_FGW_GRAPH) {
SetDParam(0, 100);
@@ -807,7 +807,7 @@ struct FrametimeGraphWindow : Window {
this->SelectVerticalScale(peak_value);
}
virtual void OnRealtimeTick(uint delta_ms)
void OnRealtimeTick(uint delta_ms) override
{
this->SetDirty();
@@ -826,7 +826,7 @@ struct FrametimeGraphWindow : Window {
return (value - src_min) * dst_diff / src_diff + dst_min;
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget == WID_FGW_GRAPH) {
const TimingMeasurement *durations = _pf_data[this->element].durations;

View File

@@ -112,11 +112,9 @@ public:
*/
static class GameInstance *GetInstance() { return Game::instance; }
#if defined(ENABLE_NETWORK)
/** Wrapper function for GameScanner::HasGame */
static bool HasGame(const struct ContentInfo *ci, bool md5sum);
static bool HasGameLibrary(const ContentInfo *ci, bool md5sum);
#endif
/** Gets the ScriptScanner instance that is used to find Game scripts */
static GameScannerInfo *GetScannerInfo();
/** Gets the ScriptScanner instance that is used to find Game Libraries */

View File

@@ -42,7 +42,7 @@ public:
bool ResetInfo(bool force_exact_match);
protected:
/* virtual */ ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match);
ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) override;
};
#endif /* GAME_CONFIG_HPP */

View File

@@ -257,8 +257,6 @@
return Game::scanner_library->FindLibrary(library, version);
}
#if defined(ENABLE_NETWORK)
/**
* Check whether we have an Game (library) with the exact characteristics as ci.
* @param ci the characteristics to search on (shortname and md5sum)
@@ -275,8 +273,6 @@
return Game::scanner_library->HasScript(ci, md5sum);
}
#endif /* defined(ENABLE_NETWORK) */
/* static */ GameScannerInfo *Game::GetScannerInfo()
{
return Game::scanner_info;

View File

@@ -40,7 +40,7 @@ public:
*/
const char *GetAPIVersion() const { return this->api_version; }
/* virtual */ bool IsDeveloperOnly() const { return this->is_developer_only; }
bool IsDeveloperOnly() const override { return this->is_developer_only; }
private:
int min_loadable_version; ///< The Game can load savegame data if the version is equal or greater than this.

View File

@@ -25,14 +25,14 @@ public:
*/
void Initialize(class GameInfo *info);
/* virtual */ int GetSetting(const char *name);
/* virtual */ ScriptInfo *FindLibrary(const char *library, int version);
int GetSetting(const char *name) override;
ScriptInfo *FindLibrary(const char *library, int version) override;
private:
/* virtual */ void RegisterAPI();
/* virtual */ void Died();
/* virtual */ CommandCallback *GetDoCommandCallback();
/* virtual */ void LoadDummyScript() {}
void RegisterAPI() override;
void Died() override;
CommandCallback *GetDoCommandCallback() override;
void LoadDummyScript() override {}
};
#endif /* GAME_INSTANCE_HPP */

View File

@@ -16,7 +16,7 @@
class GameScannerInfo : public ScriptScanner {
public:
/* virtual */ void Initialize();
void Initialize() override;
/**
* Check if we have a game by name and version available in our list.
@@ -28,17 +28,17 @@ public:
class GameInfo *FindInfo(const char *nameParam, int versionParam, bool force_exact_match);
protected:
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, const char *last);
/* virtual */ const char *GetFileName() const { return PATHSEP "info.nut"; }
/* virtual */ Subdirectory GetDirectory() const { return GAME_DIR; }
/* virtual */ const char *GetScannerName() const { return "Game Scripts"; }
/* virtual */ void RegisterAPI(class Squirrel *engine);
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
const char *GetFileName() const override { return PATHSEP "info.nut"; }
Subdirectory GetDirectory() const override { return GAME_DIR; }
const char *GetScannerName() const override { return "Game Scripts"; }
void RegisterAPI(class Squirrel *engine) override;
};
class GameScannerLibrary : public ScriptScanner {
public:
/* virtual */ void Initialize();
void Initialize() override;
/**
* Find a library in the pool.
@@ -49,11 +49,11 @@ public:
class GameLibrary *FindLibrary(const char *library, int version);
protected:
/* virtual */ void GetScriptName(ScriptInfo *info, char *name, const char *last);
/* virtual */ const char *GetFileName() const { return PATHSEP "library.nut"; }
/* virtual */ Subdirectory GetDirectory() const { return GAME_LIBRARY_DIR; }
/* virtual */ const char *GetScannerName() const { return "GS Libraries"; }
/* virtual */ void RegisterAPI(class Squirrel *engine);
void GetScriptName(ScriptInfo *info, char *name, const char *last) override;
const char *GetFileName() const override { return PATHSEP "library.nut"; }
Subdirectory GetDirectory() const override { return GAME_LIBRARY_DIR; }
const char *GetScannerName() const override { return "GS Libraries"; }
void RegisterAPI(class Squirrel *engine) override;
};
#endif /* GAME_SCANNER_HPP */

View File

@@ -115,7 +115,7 @@ LanguageStrings *ReadRawLanguageStrings(const char *file)
while (i > 0 && (buffer[i - 1] == '\r' || buffer[i - 1] == '\n' || buffer[i - 1] == ' ')) i--;
buffer[i] = '\0';
*ret->lines.Append() = stredup(buffer, buffer + to_read - 1);
ret->lines.push_back(stredup(buffer, buffer + to_read - 1));
if (len > to_read) {
to_read = 0;
@@ -147,11 +147,11 @@ struct StringListReader : StringReader {
* @param translation Are we reading a translation?
*/
StringListReader(StringData &data, const LanguageStrings *strings, bool master, bool translation) :
StringReader(data, strings->language, master, translation), p(strings->lines.Begin()), end(strings->lines.End())
StringReader(data, strings->language, master, translation), p(strings->lines.data()), end(p + strings->lines.size())
{
}
/* virtual */ char *ReadLine(char *buffer, const char *last)
char *ReadLine(char *buffer, const char *last) override
{
if (this->p == this->end) return NULL;
@@ -194,7 +194,7 @@ struct TranslationWriter : LanguageWriter {
char *dest = MallocT<char>(length + 1);
memcpy(dest, buffer, length);
dest[length] = '\0';
*this->strings->Append() = dest;
this->strings->push_back(dest);
}
};
@@ -212,7 +212,7 @@ struct StringNameWriter : HeaderWriter {
void WriteStringID(const char *name, int stringid)
{
if (stringid == (int)this->strings->Length()) *this->strings->Append() = stredup(name);
if (stringid == (int)this->strings->size()) this->strings->push_back(stredup(name));
}
void Finalise(const StringData &data)
@@ -242,11 +242,11 @@ public:
this->FileScanner::Scan(".txt", directory, false);
}
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override
{
if (strcmp(filename, exclude) == 0) return true;
*gs->raw_strings.Append() = ReadRawLanguageStrings(filename);
gs->raw_strings.push_back(ReadRawLanguageStrings(filename));
return true;
}
};
@@ -269,7 +269,7 @@ GameStrings *LoadTranslations()
GameStrings *gs = new GameStrings();
try {
*gs->raw_strings.Append() = ReadRawLanguageStrings(filename);
gs->raw_strings.push_back(ReadRawLanguageStrings(filename));
/* Scan for other language files */
LanguageScanner scanner(gs, filename);
@@ -318,14 +318,14 @@ void GameStrings::Compile()
StringNameWriter id_writer(&this->string_names);
id_writer.WriteHeader(data);
for (LanguageStrings **p = this->raw_strings.Begin(); p != this->raw_strings.End(); p++) {
for (LanguageStrings *p : this->raw_strings) {
data.FreeTranslation();
StringListReader translation_reader(data, *p, false, strcmp((*p)->language, "english") != 0);
StringListReader translation_reader(data, p, false, strcmp(p->language, "english") != 0);
translation_reader.ParseFile();
if (_errors != 0) throw std::exception();
LanguageStrings *compiled = *this->compiled_strings.Append() = new LanguageStrings((*p)->language);
TranslationWriter writer(&compiled->lines);
this->compiled_strings.push_back(new LanguageStrings(p->language));
TranslationWriter writer(&this->compiled_strings.back()->lines);
writer.WriteLang(data);
}
}
@@ -340,7 +340,7 @@ GameStrings *_current_data = NULL;
*/
const char *GetGameStringPtr(uint id)
{
if (id >= _current_data->cur_language->lines.Length()) return GetStringPtr(STR_UNDEFINED);
if (id >= _current_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
return _current_data->cur_language->lines[id];
}
@@ -360,10 +360,11 @@ void RegisterGameTranslation(Squirrel *engine)
if (SQ_FAILED(sq_get(vm, -2))) return;
int idx = 0;
for (const char * const *p = _current_data->string_names.Begin(); p != _current_data->string_names.End(); p++, idx++) {
sq_pushstring(vm, *p, -1);
for (const char * const p : _current_data->string_names) {
sq_pushstring(vm, p, -1);
sq_pushinteger(vm, idx);
sq_rawset(vm, -3);
idx++;
}
sq_pop(vm, 2);
@@ -391,9 +392,9 @@ void ReconsiderGameScriptLanguage()
assert(language != NULL);
language++;
for (LanguageStrings **p = _current_data->compiled_strings.Begin(); p != _current_data->compiled_strings.End(); p++) {
if (strcmp((*p)->language, language) == 0) {
_current_data->cur_language = *p;
for (LanguageStrings *p : _current_data->compiled_strings) {
if (strcmp(p->language, language) == 0) {
_current_data->cur_language = p;
return;
}
}

View File

@@ -32,9 +32,9 @@ struct GameStrings {
uint version; ///< The version of the language strings.
LanguageStrings *cur_language; ///< The current (compiled) language.
AutoDeleteSmallVector<LanguageStrings *, 4> raw_strings; ///< The raw strings per language, first must be English/the master language!.
AutoDeleteSmallVector<LanguageStrings *, 4> compiled_strings; ///< The compiled strings per language, first must be English/the master language!.
StringList string_names; ///< The names of the compiled strings.
AutoDeleteSmallVector<LanguageStrings *> raw_strings; ///< The raw strings per language, first must be English/the master language!.
AutoDeleteSmallVector<LanguageStrings *> compiled_strings; ///< The compiled strings per language, first must be English/the master language!.
StringList string_names; ///< The names of the compiled strings.
void Compile();
};

View File

@@ -155,6 +155,7 @@ struct GRFPresence{
bool was_missing; ///< Grf was missing during some gameload in the past
GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {}
GRFPresence() = default;
};
typedef SmallMap<uint32, GRFPresence> GrfIDMapping;

View File

@@ -315,7 +315,7 @@ static DropDownList *BuildMapsizeDropDown(int other_dimension)
for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
DropDownListParamStringItem *item = new DropDownListParamStringItem((i + other_dimension > MAX_MAP_TILES_BITS) ? STR_RED_INT : STR_JUST_INT, i, false);
item->SetParam(0, 1LL << i);
*list->Append() = item;
list->push_back(item);
}
return list;
@@ -368,7 +368,7 @@ struct GenerateLandscapeWindow : public Window {
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_GL_START_DATE_TEXT: SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
@@ -429,7 +429,7 @@ struct GenerateLandscapeWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
/* Update the climate buttons */
@@ -476,7 +476,7 @@ struct GenerateLandscapeWindow : public Window {
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
const StringID *strs = NULL;
switch (widget) {
@@ -554,7 +554,7 @@ struct GenerateLandscapeWindow : public Window {
size->height = max(size->height, (uint)(FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM));
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_GL_HEIGHTMAP_NAME_TEXT: {
@@ -564,7 +564,7 @@ struct GenerateLandscapeWindow : public Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_GL_TEMPERATE:
@@ -740,7 +740,7 @@ struct GenerateLandscapeWindow : public Window {
}
}
virtual void OnTimeout()
void OnTimeout() override
{
static const int raise_widgets[] = {WID_GL_MAX_HEIGHTLEVEL_DOWN, WID_GL_MAX_HEIGHTLEVEL_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_LEVEL_UP, WID_GL_SNOW_LEVEL_DOWN, WIDGET_LIST_END};
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
@@ -751,7 +751,7 @@ struct GenerateLandscapeWindow : public Window {
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_GL_MAPSIZE_X_PULLDOWN:
@@ -801,7 +801,7 @@ struct GenerateLandscapeWindow : public Window {
this->InvalidateData();
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
/* Was 'cancel' pressed? */
if (str == NULL) return;
@@ -940,7 +940,7 @@ struct CreateScenarioWindow : public Window
SetDropDownColor();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_CS_START_DATE_TEXT:
@@ -961,9 +961,7 @@ struct CreateScenarioWindow : public Window
}
}
virtual void OnPaint()
void OnPaint() override
{
this->SetWidgetDisabledState(WID_CS_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= MIN_YEAR);
this->SetWidgetDisabledState(WID_CS_START_DATE_UP, _settings_newgame.game_creation.starting_year >= MAX_YEAR);
@@ -978,7 +976,7 @@ struct CreateScenarioWindow : public Window
this->DrawWidgets();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
StringID str = STR_JUST_INT;
switch (widget) {
@@ -1004,7 +1002,7 @@ struct CreateScenarioWindow : public Window
size->height += padding.height;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_CS_TEMPERATE:
@@ -1071,7 +1069,7 @@ struct CreateScenarioWindow : public Window
}
}
virtual void OnTimeout()
void OnTimeout() override
{
static const int raise_widgets[] = {WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP, WIDGET_LIST_END};
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
@@ -1082,7 +1080,7 @@ struct CreateScenarioWindow : public Window
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_CS_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
@@ -1093,7 +1091,7 @@ struct CreateScenarioWindow : public Window
this->SetDirty();
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (!StrEmpty(str)) {
int32 value = atoi(str);
@@ -1245,7 +1243,7 @@ struct GenerateProgressWindow : public Window {
this->InitNested();
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_GP_ABORT:
@@ -1260,7 +1258,7 @@ struct GenerateProgressWindow : public Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_GP_PROGRESS_BAR: {
@@ -1281,7 +1279,7 @@ struct GenerateProgressWindow : public Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_GP_PROGRESS_BAR:

View File

@@ -86,9 +86,7 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
if (_cursor.visible) UndrawMouseCursor();
#ifdef ENABLE_NETWORK
if (_networking) NetworkUndrawChatMessage();
#endif /* ENABLE_NETWORK */
blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
/* This part of the screen is now dirty. */
@@ -511,9 +509,9 @@ int DrawString(int left, int right, int top, const char *str, TextColour colour,
}
Layouter layout(str, INT32_MAX, colour, fontsize);
if (layout.Length() == 0) return 0;
if (layout.size() == 0) return 0;
return DrawLayoutLine(*layout.Begin(), top, left, right, align, underline, true);
return DrawLayoutLine(layout.front(), top, left, right, align, underline, true);
}
/**
@@ -576,7 +574,7 @@ int GetStringLineCount(StringID str, int maxw)
GetString(buffer, str, lastof(buffer));
Layouter layout(buffer, maxw);
return layout.Length();
return layout.size();
}
/**
@@ -649,8 +647,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, const char *st
int last_line = top;
int first_line = bottom;
for (const ParagraphLayouter::Line **iter = layout.Begin(); iter != layout.End(); iter++) {
const ParagraphLayouter::Line *line = *iter;
for (const ParagraphLayouter::Line *line : layout) {
int line_height = line->GetLeading();
if (y >= top && y < bottom) {
@@ -970,7 +967,7 @@ static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mo
if (topleft <= clicked && clicked <= bottomright) {
uint offset = (((size_t)clicked - (size_t)topleft) / (blitter->GetScreenDepth() / 8)) % bp.pitch;
if (offset < (uint)bp.width) {
_newgrf_debug_sprite_picker.sprites.Include(sprite_id);
include(_newgrf_debug_sprite_picker.sprites, sprite_id);
}
}
}
@@ -1291,9 +1288,7 @@ void RedrawScreenRect(int left, int top, int right, int bottom)
}
}
#ifdef ENABLE_NETWORK
if (_networking) NetworkUndrawChatMessage();
#endif /* ENABLE_NETWORK */
DrawOverlappedWindowForAll(left, top, right, bottom);

View File

@@ -124,7 +124,7 @@ le_bool Font::getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &poin
/**
* Wrapper for doing layouts with ICU.
*/
class ICUParagraphLayout : public AutoDeleteSmallVector<ParagraphLayouter::Line *, 4>, public ParagraphLayouter {
class ICUParagraphLayout : public AutoDeleteSmallVector<ParagraphLayouter::Line *>, public ParagraphLayouter {
icu::ParagraphLayout *p; ///< The actual ICU paragraph layout.
public:
/** Visual run contains data about the bit of text with the same font. */
@@ -143,14 +143,14 @@ public:
};
/** A single line worth of VisualRuns. */
class ICULine : public AutoDeleteSmallVector<ICUVisualRun *, 4>, public ParagraphLayouter::Line {
class ICULine : public AutoDeleteSmallVector<ICUVisualRun *>, public ParagraphLayouter::Line {
icu::ParagraphLayout::Line *l; ///< The actual ICU line.
public:
ICULine(icu::ParagraphLayout::Line *l) : l(l)
{
for (int i = 0; i < l->countRuns(); i++) {
*this->Append() = new ICUVisualRun(l->getVisualRun(i));
this->push_back(new ICUVisualRun(l->getVisualRun(i)));
}
}
~ICULine() { delete l; }
@@ -158,7 +158,7 @@ public:
int GetLeading() const { return l->getLeading(); }
int GetWidth() const { return l->getWidth(); }
int CountRuns() const { return l->countRuns(); }
const ParagraphLayouter::VisualRun *GetVisualRun(int run) const { return *this->Get(run); }
const ParagraphLayouter::VisualRun *GetVisualRun(int run) const { return this->at(run); }
int GetInternalCharLength(WChar c) const
{
@@ -196,13 +196,13 @@ public:
/* ICU's ParagraphLayout cannot handle empty strings, so fake one. */
buff[0] = ' ';
length = 1;
fontMapping.End()[-1].first++;
fontMapping.back().first++;
}
/* Fill ICU's FontRuns with the right data. */
icu::FontRuns runs(fontMapping.Length());
for (FontMap::iterator iter = fontMapping.Begin(); iter != fontMapping.End(); iter++) {
runs.add(iter->second, iter->first);
icu::FontRuns runs(fontMapping.size());
for (auto &pair : fontMapping) {
runs.add(pair.second, pair.first);
}
LEErrorCode status = LE_NO_ERROR;
@@ -269,7 +269,7 @@ public:
};
/** A single line worth of VisualRuns. */
class FallbackLine : public AutoDeleteSmallVector<FallbackVisualRun *, 4>, public ParagraphLayouter::Line {
class FallbackLine : public AutoDeleteSmallVector<FallbackVisualRun *>, public ParagraphLayouter::Line {
public:
int GetLeading() const;
int GetWidth() const;
@@ -419,8 +419,8 @@ int FallbackParagraphLayout::FallbackVisualRun::GetLeading() const
int FallbackParagraphLayout::FallbackLine::GetLeading() const
{
int leading = 0;
for (const FallbackVisualRun * const *run = this->Begin(); run != this->End(); run++) {
leading = max(leading, (*run)->GetLeading());
for (const FallbackVisualRun * const &run : *this) {
leading = max(leading, run->GetLeading());
}
return leading;
@@ -432,7 +432,7 @@ int FallbackParagraphLayout::FallbackLine::GetLeading() const
*/
int FallbackParagraphLayout::FallbackLine::GetWidth() const
{
if (this->Length() == 0) return 0;
if (this->size() == 0) return 0;
/*
* The last X position of a run contains is the end of that run.
@@ -449,7 +449,7 @@ int FallbackParagraphLayout::FallbackLine::GetWidth() const
*/
int FallbackParagraphLayout::FallbackLine::CountRuns() const
{
return this->Length();
return this->size();
}
/**
@@ -458,7 +458,7 @@ int FallbackParagraphLayout::FallbackLine::CountRuns() const
*/
const ParagraphLayouter::VisualRun *FallbackParagraphLayout::FallbackLine::GetVisualRun(int run) const
{
return *this->Get(run);
return this->at(run);
}
/**
@@ -498,12 +498,12 @@ const ParagraphLayouter::Line *FallbackParagraphLayout::NextLine(int max_width)
if (*this->buffer == '\0') {
/* Only a newline. */
this->buffer = NULL;
*l->Append() = new FallbackVisualRun(this->runs.Begin()->second, this->buffer, 0, 0);
l->push_back(new FallbackVisualRun(this->runs.front().second, this->buffer, 0, 0));
return l;
}
int offset = this->buffer - this->buffer_begin;
FontMap::iterator iter = this->runs.Begin();
FontMap::iterator iter = this->runs.data();
while (iter->first <= offset) {
iter++;
assert(iter != this->runs.End());
@@ -527,7 +527,7 @@ const ParagraphLayouter::Line *FallbackParagraphLayout::NextLine(int max_width)
if (this->buffer == next_run) {
int w = l->GetWidth();
*l->Append() = new FallbackVisualRun(iter->second, begin, this->buffer - begin, w);
l->push_back(new FallbackVisualRun(iter->second, begin, this->buffer - begin, w));
iter++;
assert(iter != this->runs.End());
@@ -572,9 +572,9 @@ const ParagraphLayouter::Line *FallbackParagraphLayout::NextLine(int max_width)
this->buffer++;
}
if (l->Length() == 0 || last_char - begin != 0) {
if (l->size() == 0 || last_char - begin != 0) {
int w = l->GetWidth();
*l->Append() = new FallbackVisualRun(iter->second, begin, last_char - begin, w);
l->push_back(new FallbackVisualRun(iter->second, begin, last_char - begin, w));
}
return l;
}
@@ -600,7 +600,7 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, const char *&str,
Font *f = Layouter::GetFont(state.fontsize, state.cur_colour);
line.buffer = buff_begin;
fontMapping.Clear();
fontMapping.clear();
/*
* Go through the whole string while adding Font instances to the font map
@@ -720,7 +720,7 @@ Layouter::Layouter(const char *str, int maxw, TextColour colour, FontSize fontsi
/* Copy all lines into a local cache so we can reuse them later on more easily. */
const ParagraphLayouter::Line *l;
while ((l = line.layout->NextLine(maxw)) != NULL) {
*this->Append() = l;
this->push_back(l);
}
} while (c != '\0');
@@ -733,9 +733,9 @@ Layouter::Layouter(const char *str, int maxw, TextColour colour, FontSize fontsi
Dimension Layouter::GetBounds()
{
Dimension d = { 0, 0 };
for (const ParagraphLayouter::Line **l = this->Begin(); l != this->End(); l++) {
d.width = max<uint>(d.width, (*l)->GetWidth());
d.height += (*l)->GetLeading();
for (const ParagraphLayouter::Line *l : *this) {
d.width = max<uint>(d.width, l->GetWidth());
d.height += l->GetLeading();
}
return d;
}
@@ -757,12 +757,12 @@ Point Layouter::GetCharPosition(const char *ch) const
size_t len = Utf8Decode(&c, str);
if (c == '\0' || c == '\n') break;
str += len;
index += (*this->Begin())->GetInternalCharLength(c);
index += this->front()->GetInternalCharLength(c);
}
if (str == ch) {
/* Valid character. */
const ParagraphLayouter::Line *line = *this->Begin();
const ParagraphLayouter::Line *line = this->front();
/* Pointer to the end-of-string/line marker? Return total line width. */
if (*ch == '\0' || *ch == '\n') {
@@ -795,7 +795,7 @@ Point Layouter::GetCharPosition(const char *ch) const
*/
const char *Layouter::GetCharAtPosition(int x) const
{
const ParagraphLayouter::Line *line = *this->Begin();
const ParagraphLayouter::Line *line = this->front();
for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
const ParagraphLayouter::VisualRun *run = line->GetVisualRun(run_index);
@@ -834,7 +834,7 @@ Font *Layouter::GetFont(FontSize size, TextColour colour)
if (it != fonts[size].End()) return it->second;
Font *f = new Font(size, colour);
*fonts[size].Append() = FontColourMap::Pair(colour, f);
fonts[size].emplace_back(colour, f);
return f;
}
@@ -844,10 +844,10 @@ Font *Layouter::GetFont(FontSize size, TextColour colour)
*/
void Layouter::ResetFontCache(FontSize size)
{
for (FontColourMap::iterator it = fonts[size].Begin(); it != fonts[size].End(); ++it) {
delete it->second;
for (auto &pair : fonts[size]) {
delete pair.second;
}
fonts[size].Clear();
fonts[size].clear();
/* We must reset the linecache since it references the just freed fonts */
ResetLineCache();

View File

@@ -150,7 +150,7 @@ public:
*
* It also accounts for the memory allocations and frees.
*/
class Layouter : public AutoDeleteSmallVector<const ParagraphLayouter::Line *, 4> {
class Layouter : public AutoDeleteSmallVector<const ParagraphLayouter::Line *> {
const char *string; ///< Pointer to the original string.
/** Key into the linecache */

View File

@@ -247,20 +247,14 @@ CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
{
uint16 uniqueid = (GoalType)GB(p1, 0, 16);
CompanyID company = (CompanyID)GB(p1, 16, 8);
#ifdef ENABLE_NETWORK
ClientIndex client = (ClientIndex)GB(p1, 16, 8);
#endif
byte type = GB(p1, 24, 2);
bool is_client = HasBit(p1, 31);
if (_current_company != OWNER_DEITY) return CMD_ERROR;
if (StrEmpty(text)) return CMD_ERROR;
if (is_client) {
#ifdef ENABLE_NETWORK
if (!NetworkClientInfo::IsValidID(client)) return CMD_ERROR;
#else
return CMD_ERROR;
#endif
} else {
if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR;
}
@@ -270,9 +264,7 @@ CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (flags & DC_EXEC) {
if (is_client) {
#ifdef ENABLE_NETWORK
if (NetworkClientInfo::Get(client)->client_id != _network_own_client_id) return CommandCost();
#endif
} else {
if (company == INVALID_COMPANY && !Company::IsValidID(_local_company)) return CommandCost();
if (company != INVALID_COMPANY && company != _local_company) return CommandCost();

View File

@@ -50,7 +50,7 @@ struct GoalListWindow : public Window {
this->OnInvalidateData(0);
}
/* virtual */ void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget != WID_GOAL_CAPTION) return;
@@ -62,7 +62,7 @@ struct GoalListWindow : public Window {
}
}
/* virtual */ void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget != WID_GOAL_LIST) return;
@@ -177,7 +177,7 @@ struct GoalListWindow : public Window {
return 3 + num_global + num_company;
}
/* virtual */ void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_GOAL_LIST) return;
Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
@@ -272,7 +272,7 @@ struct GoalListWindow : public Window {
DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, false, column);
}
/* virtual */ void OnPaint()
void OnPaint() override
{
this->DrawWidgets();
@@ -299,7 +299,7 @@ struct GoalListWindow : public Window {
}
/* virtual */ void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
}
@@ -309,7 +309,7 @@ struct GoalListWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
/* virtual */ void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->vscroll->SetCount(this->CountLines());
@@ -388,7 +388,7 @@ struct GoalQuestionWindow : public Window {
free(this->question);
}
/* virtual */ void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_GQ_CAPTION:
@@ -409,7 +409,7 @@ struct GoalQuestionWindow : public Window {
}
}
/* virtual */ void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_GQ_BUTTON_1:
@@ -429,7 +429,7 @@ struct GoalQuestionWindow : public Window {
}
}
/* virtual */ void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_GQ_QUESTION) return;
@@ -437,7 +437,7 @@ struct GoalQuestionWindow : public Window {
size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WD_PAR_VSEP_WIDE;
}
/* virtual */ void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_GQ_QUESTION) return;

View File

@@ -56,7 +56,7 @@ struct GraphLegendWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (!IsInsideMM(widget, WID_GL_FIRST_COMPANY, MAX_COMPANIES + WID_GL_FIRST_COMPANY)) return;
@@ -74,7 +74,7 @@ struct GraphLegendWindow : Window {
DrawString(r.left + (rtl ? (uint)WD_FRAMERECT_LEFT : (d.width + 4)), r.right - (rtl ? (d.width + 4) : (uint)WD_FRAMERECT_RIGHT), r.top + (r.bottom - r.top + 1 - FONT_HEIGHT_NORMAL) / 2, STR_COMPANY_NAME_COMPANY_NUM, HasBit(_legend_excluded_companies, cid) ? TC_BLACK : TC_WHITE);
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (!IsInsideMM(widget, WID_GL_FIRST_COMPANY, MAX_COMPANIES + WID_GL_FIRST_COMPANY)) return;
@@ -93,7 +93,7 @@ struct GraphLegendWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
if (Company::IsValidID(data)) return;
@@ -485,7 +485,7 @@ protected:
}
public:
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != this->graph_widget) return;
@@ -521,7 +521,7 @@ public:
size->height = max<uint>(size->height, size->width / 3);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != this->graph_widget) return;
@@ -533,13 +533,13 @@ public:
return INVALID_DATAPOINT;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
/* Clicked on legend? */
if (widget == WID_CV_KEY_BUTTON) ShowGraphLegend();
}
virtual void OnGameTick()
void OnGameTick() override
{
this->UpdateStatistics(false);
}
@@ -549,7 +549,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->UpdateStatistics(true);
@@ -621,7 +621,7 @@ struct OperatingProfitGraphWindow : BaseGraphWindow {
this->InitializeWindow(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
{
return c->old_economy[j].income + c->old_economy[j].expenses;
}
@@ -672,7 +672,7 @@ struct IncomeGraphWindow : BaseGraphWindow {
this->InitializeWindow(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
{
return c->old_economy[j].income;
}
@@ -721,7 +721,7 @@ struct DeliveredCargoGraphWindow : BaseGraphWindow {
this->InitializeWindow(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
{
return c->old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
}
@@ -770,12 +770,12 @@ struct PerformanceHistoryGraphWindow : BaseGraphWindow {
this->InitializeWindow(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
{
return c->old_economy[j].performance_history;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
if (widget == WID_PHG_DETAILED_PERFORMANCE) ShowPerformanceRatingDetail();
this->BaseGraphWindow::OnClick(pt, widget, click_count);
@@ -826,7 +826,7 @@ struct CompanyValueGraphWindow : BaseGraphWindow {
this->InitializeWindow(window_number);
}
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
OverflowSafeInt64 GetGraphData(const Company *c, int j) override
{
return c->old_economy[j].company_value;
}
@@ -903,7 +903,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
@@ -926,7 +926,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
resize->height = this->line_height;
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::DrawWidget(r, widget);
@@ -963,7 +963,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_CPR_ENABLE_CARGOES:
@@ -1004,12 +1004,12 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_CPR_MATRIX);
}
virtual void OnGameTick()
void OnGameTick() override
{
/* Override default OnGameTick */
}
@@ -1019,13 +1019,13 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->OnHundredthTick();
}
virtual void OnHundredthTick()
void OnHundredthTick() override
{
this->UpdateExcludedData();
@@ -1136,14 +1136,14 @@ private:
{
if (!this->companies.NeedRebuild()) return;
this->companies.Clear();
this->companies.clear();
const Company *c;
FOR_ALL_COMPANIES(c) {
*this->companies.Append() = c;
this->companies.push_back(c);
}
this->companies.Compact();
this->companies.shrink_to_fit();
this->companies.RebuildDone();
}
@@ -1161,7 +1161,7 @@ public:
this->companies.NeedResort();
}
virtual void OnPaint()
void OnPaint() override
{
this->BuildCompanyList();
this->companies.Sort(&PerformanceSorter);
@@ -1169,7 +1169,7 @@ public:
this->DrawWidgets();
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_CL_BACKGROUND) return;
@@ -1183,7 +1183,7 @@ public:
uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_LEFT - this->text_width;
uint text_right = rtl ? r.left + WD_FRAMERECT_LEFT + this->text_width : r.right - WD_FRAMERECT_LEFT;
for (uint i = 0; i != this->companies.Length(); i++) {
for (uint i = 0; i != this->companies.size(); i++) {
const Company *c = this->companies[i];
DrawString(ordinal_left, ordinal_right, y, i + STR_ORDINAL_NUMBER_1ST, i == 0 ? TC_WHITE : TC_YELLOW);
@@ -1197,7 +1197,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_CL_BACKGROUND) return;
@@ -1236,7 +1236,7 @@ public:
}
virtual void OnGameTick()
void OnGameTick() override
{
if (this->companies.NeedResort()) {
this->SetDirty();
@@ -1248,7 +1248,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
@@ -1318,7 +1318,7 @@ struct PerformanceRatingDetailWindow : Window {
uint score_detail_left;
uint score_detail_right;
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_PRD_SCORE_FIRST:
@@ -1376,7 +1376,7 @@ struct PerformanceRatingDetailWindow : Window {
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
/* No need to draw when there's nothing to draw */
if (this->company == INVALID_COMPANY) return;
@@ -1455,7 +1455,7 @@ struct PerformanceRatingDetailWindow : Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
/* Check which button is clicked */
if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) {
@@ -1469,7 +1469,7 @@ struct PerformanceRatingDetailWindow : Window {
}
}
virtual void OnGameTick()
void OnGameTick() override
{
/* Update the company score every 5 days */
if (--this->timeout == 0) {
@@ -1483,7 +1483,7 @@ struct PerformanceRatingDetailWindow : Window {
* @param data the company ID of the company that is going to be removed
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
/* Disable the companies who are not active */

View File

@@ -93,7 +93,7 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
void PowerChanged();
void CargoChanged();
bool IsChainInDepot() const;
bool IsChainInDepot() const override;
void CalculatePower(uint32& power, uint32& max_te, bool breakdowns) const;
@@ -104,7 +104,7 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
* @param flooded was this vehicle flooded?
* @return number of victims
*/
/* virtual */ uint Crash(bool flooded)
uint Crash(bool flooded) override
{
/* Crashed vehicles aren't going up or down */
for (T *v = T::From(this); v != NULL; v = v->Next()) {

View File

@@ -73,6 +73,8 @@ struct Group : GroupPool::PoolItem<&_group_pool> {
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?
GroupID parent; ///< Parent group
Group(CompanyID owner = INVALID_COMPANY);
@@ -105,6 +107,9 @@ static inline bool IsTopLevelGroupID(GroupID index)
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type);
uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type);
Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type);
void SetTrainGroupID(Train *v, GroupID grp);
void UpdateTrainGroupID(Train *v);

View File

@@ -306,6 +306,7 @@ void PropagateChildLivery(const Group *g)
Group::Group(Owner owner)
{
this->owner = owner;
this->folded = false;
}
Group::~Group()
@@ -463,7 +464,7 @@ CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Ensure request parent isn't child of group.
* This is the only place that infinite loops are prevented. */
if (GroupIsInGroup(pg->index, g->index)) return CMD_ERROR;
if (GroupIsInGroup(pg->index, g->index)) return_cmd_error(STR_ERROR_GROUP_CAN_T_SET_PARENT_RECURSION);
}
if (flags & DC_EXEC) {
@@ -522,7 +523,7 @@ CommandCost CmdCreateGroupFromList(TileIndex tile, DoCommandFlag flags, uint32 p
DoCommand(tile, g->index, 0, flags, CMD_ALTER_GROUP, text);
}
for (uint i = 0; i < list.Length(); i++) {
for (uint i = 0; i < list.size(); i++) {
const Vehicle *v = list[i];
/* Just try and don't care if some vehicle's can't be added. */
@@ -867,6 +868,60 @@ uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
return count + GroupStatistics::Get(company, id_g, e->type).num_engines[id_e];
}
/**
* Get the number of vehicles in the group with GroupID
* id_g and its sub-groups.
* @param company The company the group belongs to
* @param id_g The GroupID of the group used
* @param type The vehicle type of the group
* @return The number of vehicles in the group
*/
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
{
uint count = 0;
const Group *g;
FOR_ALL_GROUPS(g) {
if (g->parent == id_g) count += GetGroupNumVehicle(company, g->index, type);
}
return count + GroupStatistics::Get(company, id_g, type).num_vehicle;
}
/**
* Get the number of vehicles above profit minimum age in the group with GroupID
* id_g and its sub-groups.
* @param company The company the group belongs to
* @param id_g The GroupID of the group used
* @param type The vehicle type of the group
* @return The number of vehicles above profit minimum age in the group
*/
uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type)
{
uint count = 0;
const Group *g;
FOR_ALL_GROUPS(g) {
if (g->parent == id_g) count += GetGroupNumProfitVehicle(company, g->index, type);
}
return count + GroupStatistics::Get(company, id_g, type).num_profit_vehicle;
}
/**
* Get last year's profit for the group with GroupID
* id_g and its sub-groups.
* @param company The company the group belongs to
* @param id_g The GroupID of the group used
* @param type The vehicle type of the group
* @return Last year's profit for the group
*/
Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
{
Money sum = 0;
const Group *g;
FOR_ALL_GROUPS(g) {
if (g->parent == id_g) sum += GetGroupProfitLastYear(company, g->index, type);
}
return sum + GroupStatistics::Get(company, id_g, type).profit_last_year;
}
void RemoveAllGroupsForCompany(const CompanyID company)
{
Group *g;

View File

@@ -68,11 +68,6 @@ static const NWidgetPart _nested_group_widgets[] = {
SetDataTip(SPR_GROUP_RENAME_TRAIN, STR_GROUP_RENAME_TOOLTIP),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_LIVERY_GROUP), SetFill(0, 1),
SetDataTip(SPR_GROUP_LIVERY_TRAIN, STR_GROUP_LIVERY_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_COLLAPSE_EXPAND_GROUP), SetFill(0, 1),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_COLLAPSE_ALL_GROUPS), SetFill(0, 1),
SetDataTip(STR_GROUP_COLLAPSE_ALL, STR_GROUP_COLLAPSE_ALL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GL_EXPAND_ALL_GROUPS), SetFill(0, 1),
SetDataTip(STR_GROUP_EXPAND_ALL, STR_GROUP_EXPAND_ALL),
NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GL_REPLACE_PROTECTION), SetFill(0, 1),
SetDataTip(SPR_GROUP_REPLACE_OFF_TRAIN, STR_GROUP_REPLACE_PROTECTION_TOOLTIP),
@@ -136,8 +131,8 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
private:
/* Columns in the group list */
enum ListColumns {
VGC_FOLD, ///< Fold / Unfold button.
VGC_NAME, ///< Group name.
VGC_COLLAPSED, ///< Collapsed icon
VGC_PROTECT, ///< Autoreplace protect icon.
VGC_AUTOREPLACE, ///< Autoreplace active icon.
VGC_PROFIT, ///< Profit icon.
@@ -153,46 +148,27 @@ private:
GUIGroupList groups; ///< List of groups
uint tiny_step_height; ///< Step height for the group list
Scrollbar *group_sb;
SmallVector<GroupID, 16> all_groups; ///< List of all groups, including hidden ones
SmallVector<GroupID, 16> collapsed_groups; ///< List of collapsed groups
SmallVector<GroupID, 16> collapsable_groups; ///< List of collapsable groups
SmallVector<int, 16> indents; ///< Indentation levels
std::vector<int> indents; ///< Indentation levels
Dimension column_size[VGC_END]; ///< Size of the columns in the group list.
/** return true if group has children */
bool AddChildren(GUIGroupList *source, GroupID parent, int indent, bool parent_collapsed)
void AddChildren(GUIGroupList *source, GroupID parent, int indent)
{
bool is_collapsed = this->collapsed_groups.Contains(parent);
bool overall_collapsed = is_collapsed || parent_collapsed;
bool has_children = false;
for (const Group **g = source->Begin(); g != source->End(); g++) {
if ((*g)->parent == parent) {
has_children = true;
*this->all_groups.Append() = (*g)->index;
if (!overall_collapsed) {
*this->groups.Append() = *g;
*this->indents.Append() = indent;
}
bool child_has_children = AddChildren(source, (*g)->index, indent + 1, overall_collapsed);
if (child_has_children) *this->collapsable_groups.Append() = (*g)->index;
for (const Group *g : *source) {
if (g->parent != parent) continue;
this->groups.push_back(g);
this->indents.push_back(indent);
if (g->folded) {
/* Test if this group has children at all. If not, the folded flag should be cleared to avoid lingering unfold buttons in the list. */
auto child = std::find_if(source->begin(), source->end(), [g](const Group *child){ return child->parent == g->index; });
bool has_children = child != source->end();
Group::Get(g->index)->folded = has_children;
} else {
AddChildren(source, g->index, indent + 1);
}
}
return has_children;
}
void ToogleGroupCollapse(GroupID group)
{
GroupID *item = this->collapsed_groups.Find(group);
if (item == this->collapsed_groups.End()) {
if (this->collapsable_groups.Find(group) != this->collapsable_groups.End()) {
*(this->collapsed_groups.Append()) = group;
}
} else {
this->collapsed_groups.Erase(item);
}
}
/**
@@ -204,26 +180,24 @@ private:
{
if (!this->groups.NeedRebuild()) return;
this->all_groups.Clear();
this->groups.Clear();
this->indents.Clear();
this->collapsable_groups.Clear();
this->groups.clear();
this->indents.clear();
GUIGroupList list;
const Group *g;
FOR_ALL_GROUPS(g) {
if (g->owner == owner && g->vehicle_type == this->vli.vtype) {
*list.Append() = g;
list.push_back(g);
}
}
list.ForceResort();
list.Sort(&GroupNameSorter);
AddChildren(&list, INVALID_GROUP, 0, false);
AddChildren(&list, INVALID_GROUP, 0);
this->groups.Compact();
this->groups.shrink_to_fit();
this->groups.RebuildDone();
}
@@ -233,12 +207,12 @@ private:
*/
uint ComputeGroupInfoSize()
{
this->column_size[VGC_FOLD] = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
this->tiny_step_height = this->column_size[VGC_FOLD].height;
this->column_size[VGC_NAME] = maxdim(GetStringBoundingBox(STR_GROUP_DEFAULT_TRAINS + this->vli.vtype), GetStringBoundingBox(STR_GROUP_ALL_TRAINS + this->vli.vtype));
this->column_size[VGC_NAME].width = max((170u * FONT_HEIGHT_NORMAL) / 10u, this->column_size[VGC_NAME].width);
this->tiny_step_height = this->column_size[VGC_NAME].height;
this->column_size[VGC_COLLAPSED] = GetSpriteSize(SPR_WINDOW_UNSHADE);
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_COLLAPSED].height);
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_NAME].height);
this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
@@ -255,15 +229,17 @@ private:
}
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROFIT].height);
SetDParamMaxValue(0, GroupStatistics::Get(this->vli.company, ALL_GROUP, this->vli.vtype).num_vehicle, 3, FS_SMALL);
this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_TINY_COMMA);
int num_vehicle = GetGroupNumVehicle(this->vli.company, ALL_GROUP, this->vli.vtype);
SetDParamMaxValue(0, num_vehicle, 3, FS_SMALL);
SetDParamMaxValue(1, num_vehicle, 3, FS_SMALL);
this->column_size[VGC_NUMBER] = GetStringBoundingBox(STR_GROUP_COUNT_WITH_SUBGROUP);
this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_NUMBER].height);
this->tiny_step_height += WD_MATRIX_TOP;
return WD_FRAMERECT_LEFT + 8 +
this->column_size[VGC_FOLD].width + 2 +
this->column_size[VGC_NAME].width + 8 +
this->column_size[VGC_COLLAPSED].width + 2 +
this->column_size[VGC_PROTECT].width + 2 +
this->column_size[VGC_AUTOREPLACE].width + 2 +
this->column_size[VGC_PROFIT].width + 2 +
@@ -279,8 +255,9 @@ private:
* @param g_id Group to list.
* @param indent Indentation level.
* @param protection Whether autoreplace protection is set.
* @param has_children Whether the group has children and should have a fold / unfold button.
*/
void DrawGroupInfo(int y, int left, int right, GroupID g_id, int indent = 0, bool protection = false) const
void DrawGroupInfo(int y, int left, int right, GroupID g_id, int indent = 0, bool protection = false, bool has_children = false) const
{
/* Highlight the group if a vehicle is dragged over it */
if (g_id == this->group_over) {
@@ -294,6 +271,12 @@ private:
const GroupStatistics &stats = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype);
bool rtl = _current_text_dir == TD_RTL;
/* draw fold / unfold button */
int x = rtl ? right - WD_FRAMERECT_RIGHT - 8 - this->column_size[VGC_FOLD].width + 1 : left + WD_FRAMERECT_LEFT + 8;
if (has_children) {
DrawSprite(Group::Get(g_id)->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, rtl ? x - indent : x + indent, y + (this->tiny_step_height - this->column_size[VGC_FOLD].height) / 2);
}
/* draw group name */
StringID str;
if (IsAllGroupID(g_id)) {
@@ -304,15 +287,11 @@ private:
SetDParam(0, g_id);
str = STR_GROUP_NAME;
}
int x = rtl ? right - WD_FRAMERECT_RIGHT - 8 - this->column_size[VGC_NAME].width + 1 : left + WD_FRAMERECT_LEFT + 8;
x = rtl ? x - 2 - this->column_size[VGC_NAME].width : x + 2 + this->column_size[VGC_FOLD].width;
DrawString(x + (rtl ? 0 : indent), x + this->column_size[VGC_NAME].width - 1 - (rtl ? indent : 0), y + (this->tiny_step_height - this->column_size[VGC_NAME].height) / 2, str, colour);
/* draw collapse state */
x = rtl ? x - 8 - this->column_size[VGC_COLLAPSED].width : x + 8 + this->column_size[VGC_NAME].width;
if (this->collapsed_groups.Contains(g_id)) DrawSprite(SPR_WINDOW_UNSHADE, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_COLLAPSED].height) / 2);
/* draw autoreplace protection */
x = rtl ? x - 2 - this->column_size[VGC_PROTECT].width : x + 2 + this->column_size[VGC_COLLAPSED].width;
x = rtl ? x - 2 - this->column_size[VGC_PROTECT].width : x + 2 + this->column_size[VGC_NAME].width;
if (protection) DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROTECT].height) / 2);
/* draw autoreplace status */
@@ -322,11 +301,13 @@ private:
/* draw the profit icon */
x = rtl ? x - 2 - this->column_size[VGC_PROFIT].width : x + 2 + this->column_size[VGC_AUTOREPLACE].width;
SpriteID spr;
if (stats.num_profit_vehicle == 0) {
uint num_profit_vehicle = GetGroupNumProfitVehicle(this->vli.company, g_id, this->vli.vtype);
Money profit_last_year = GetGroupProfitLastYear(this->vli.company, g_id, this->vli.vtype);
if (num_profit_vehicle == 0) {
spr = SPR_PROFIT_NA;
} else if (stats.profit_last_year < 0) {
} else if (profit_last_year < 0) {
spr = SPR_PROFIT_NEGATIVE;
} else if (stats.profit_last_year < 10000 * stats.num_profit_vehicle) { // TODO magic number
} else if (profit_last_year < (Money)10000 * num_profit_vehicle) { // TODO magic number
spr = SPR_PROFIT_SOME;
} else {
spr = SPR_PROFIT_LOT;
@@ -335,8 +316,16 @@ private:
/* draw the number of vehicles of the group */
x = rtl ? x - 2 - this->column_size[VGC_NUMBER].width : x + 2 + this->column_size[VGC_PROFIT].width;
SetDParam(0, stats.num_vehicle);
DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, STR_TINY_COMMA, colour, SA_RIGHT | SA_FORCE);
int num_vehicle_with_subgroups = GetGroupNumVehicle(this->vli.company, g_id, this->vli.vtype);
int num_vehicle = GroupStatistics::Get(this->vli.company, g_id, this->vli.vtype).num_vehicle;
if (IsAllGroupID(g_id) || IsDefaultGroupID(g_id) || num_vehicle_with_subgroups == num_vehicle) {
SetDParam(0, num_vehicle);
DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, STR_TINY_COMMA, colour, SA_RIGHT | SA_FORCE);
} else {
SetDParam(0, num_vehicle);
SetDParam(1, num_vehicle_with_subgroups - num_vehicle);
DrawString(x, x + this->column_size[VGC_NUMBER].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NUMBER].height) / 2, STR_GROUP_COUNT_WITH_SUBGROUP, colour, SA_RIGHT | SA_FORCE);
}
}
/**
@@ -392,9 +381,6 @@ public:
this->GetWidget<NWidgetCore>(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype;
this->GetWidget<NWidgetCore>(WID_GL_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype;
this->GetWidget<NWidgetCore>(WID_GL_COLLAPSE_EXPAND_GROUP)->widget_data = STR_GROUP_COLLAPSE;
this->GetWidget<NWidgetCore>(WID_GL_COLLAPSE_EXPAND_GROUP)->tool_tip = STR_GROUP_COLLAPSE_TOOLTIP;
this->GetWidget<NWidgetCore>(WID_GL_CREATE_GROUP)->widget_data += this->vli.vtype;
this->GetWidget<NWidgetCore>(WID_GL_RENAME_GROUP)->widget_data += this->vli.vtype;
this->GetWidget<NWidgetCore>(WID_GL_DELETE_GROUP)->widget_data += this->vli.vtype;
@@ -410,7 +396,7 @@ public:
*this->sorting = this->vehicles.GetListing();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_GL_LIST_GROUP: {
@@ -474,7 +460,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
@@ -501,7 +487,7 @@ public:
this->SetDirty();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
@@ -518,21 +504,21 @@ public:
if (IsDefaultGroupID(this->vli.index) || IsAllGroupID(this->vli.index)) {
SetDParam(0, STR_COMPANY_NAME);
SetDParam(1, this->vli.company);
SetDParam(2, this->vehicles.Length());
SetDParam(3, this->vehicles.Length());
SetDParam(2, this->vehicles.size());
SetDParam(3, this->vehicles.size());
} else {
const Group *g = Group::Get(this->vli.index);
uint num_vehicle = GetGroupNumVehicle(this->vli.company, this->vli.index, this->vli.vtype);
SetDParam(0, STR_GROUP_NAME);
SetDParam(1, g->index);
SetDParam(2, g->statistics.num_vehicle);
SetDParam(3, g->statistics.num_vehicle);
SetDParam(1, this->vli.index);
SetDParam(2, num_vehicle);
SetDParam(3, num_vehicle);
}
break;
}
}
virtual void OnPaint()
void OnPaint() override
{
/* If we select the all vehicles, this->list will contain all vehicles of the owner
* else this->list will contain all vehicles which belong to the selected group */
@@ -541,8 +527,8 @@ public:
this->BuildGroupList(this->owner);
this->group_sb->SetCount(this->groups.Length());
this->vscroll->SetCount(this->vehicles.Length());
this->group_sb->SetCount(this->groups.size());
this->vscroll->SetCount(this->vehicles.size());
/* The drop down menu is out, *but* it may not be used, retract it. */
if (!this->ShouldShowActionDropdownList() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) {
@@ -552,7 +538,7 @@ public:
/* Disable all lists management button when the list is empty */
this->SetWidgetDisabledState(WID_GL_MANAGE_VEHICLES_DROPDOWN, !this->ShouldShowActionDropdownList() || _local_company != this->vli.company);
this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_company != this->vli.company || (IsTopLevelGroupID(this->vli.index) && _settings_client.gui.disable_top_veh_list_mass_actions),
this->SetWidgetsDisabledState(this->vehicles.size() == 0 || _local_company != this->vli.company || (IsTopLevelGroupID(this->vli.index) && _settings_client.gui.disable_top_veh_list_mass_actions),
WID_GL_STOP_ALL,
WID_GL_START_ALL,
WIDGET_LIST_END);
@@ -586,29 +572,10 @@ public:
this->GetWidget<NWidgetCore>(WID_GL_FILTER_BY_CARGO)->widget_data = this->cargo_filter_texts[this->cargo_filter_criteria];
bool is_non_collapsable_group = (this->vli.index == ALL_GROUP) || (this->vli.index == DEFAULT_GROUP)
|| (this->vli.index == INVALID_GROUP) || !this->collapsable_groups.Contains(this->vli.index);
this->SetWidgetDisabledState(WID_GL_COLLAPSE_EXPAND_GROUP, is_non_collapsable_group);
NWidgetCore *collapse_widget = this->GetWidget<NWidgetCore>(WID_GL_COLLAPSE_EXPAND_GROUP);
if (is_non_collapsable_group || !this->collapsed_groups.Contains(this->vli.index)) {
collapse_widget->widget_data = STR_GROUP_COLLAPSE;
collapse_widget->tool_tip = STR_GROUP_COLLAPSE_TOOLTIP;
} else {
collapse_widget->widget_data = STR_GROUP_EXPAND;
collapse_widget->tool_tip = STR_GROUP_EXPAND_TOOLTIP;
}
this->SetWidgetDisabledState(WID_GL_EXPAND_ALL_GROUPS, this->collapsed_groups.Length() == 0);
this->SetWidgetDisabledState(WID_GL_COLLAPSE_ALL_GROUPS, this->collapsable_groups.Length() == 0 || this->collapsed_groups.Length() == this->collapsable_groups.Length());
this->DrawWidgets();
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_GL_ALL_VEHICLES:
@@ -623,7 +590,7 @@ public:
Money this_year = 0;
Money last_year = 0;
uint32 occupancy = 0;
uint32 vehicle_count = this->vehicles.Length();
uint32 vehicle_count = this->vehicles.size();
for (uint i = 0; i < vehicle_count; i++) {
const Vehicle *v = this->vehicles[i];
@@ -659,17 +626,17 @@ public:
case WID_GL_LIST_GROUP: {
int y1 = r.top + WD_FRAMERECT_TOP;
int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.Length());
int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.size());
for (int i = this->group_sb->GetPosition(); i < max; ++i) {
const Group *g = this->groups[i];
assert(g->owner == this->owner);
DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * LEVEL_WIDTH, g->replace_protection);
DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * LEVEL_WIDTH, g->replace_protection, g->folded || (i + 1 < (int)this->groups.size() && indents[i + 1] > this->indents[i]));
y1 += this->tiny_step_height;
}
if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.Length()) {
if ((uint)this->group_sb->GetPosition() + this->group_sb->GetCapacity() > this->groups.size()) {
DrawGroupInfo(y1, r.left, r.right, NEW_GROUP);
}
break;
@@ -683,7 +650,7 @@ public:
if (this->vli.index != ALL_GROUP) {
/* Mark vehicles which are in sub-groups */
int y = r.top;
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehicles.Length());
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehicles.size());
for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
const Vehicle *v = this->vehicles[i];
if (v->group_id != this->vli.index) {
@@ -707,7 +674,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_GL_SORT_BY_ORDER: // Flip sorting method ascending/descending
@@ -742,15 +709,37 @@ public:
case WID_GL_LIST_GROUP: { // Matrix Group
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
if (id_g >= this->groups.Length()) return;
if (id_g >= this->groups.size()) return;
if (groups[id_g]->folded || (id_g + 1 < this->groups.size() && this->indents[id_g + 1] > this->indents[id_g])) {
/* The group has children, check if the user clicked the fold / unfold button. */
NWidgetCore *group_display = this->GetWidget<NWidgetCore>(widget);
int x = _current_text_dir == TD_RTL ?
group_display->pos_x + group_display->current_x - WD_FRAMERECT_RIGHT - 8 - this->indents[id_g] * LEVEL_WIDTH - this->column_size[VGC_FOLD].width :
group_display->pos_x + WD_FRAMERECT_LEFT + 8 + this->indents[id_g] * LEVEL_WIDTH;
if (click_count > 1 || (pt.x >= x && pt.x < (int)(x + this->column_size[VGC_FOLD].width))) {
GroupID g = this->vli.index;
if (!IsAllGroupID(g) && !IsDefaultGroupID(g)) {
do {
g = Group::Get(g)->parent;
if (g == groups[id_g]->index) {
this->vli.index = g;
break;
}
} while (g != INVALID_GROUP);
}
Group::Get(groups[id_g]->index)->folded = !groups[id_g]->folded;
this->groups.ForceRebuild();
this->SetDirty();
break;
}
}
this->group_sel = this->vli.index = this->groups[id_g]->index;
if (click_count % 2 == 0) {
this->ToogleGroupCollapse(this->vli.index);
OnInvalidateData();
}
SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
this->vehicles.ForceRebuild();
@@ -760,7 +749,7 @@ public:
case WID_GL_LIST_VEHICLE: { // Matrix Vehicle
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
if (id_v >= this->vehicles.Length()) return; // click out of list bound
if (id_v >= this->vehicles.size()) return; // click out of list bound
const Vehicle *v = this->vehicles[id_v];
if (VehicleClicked(v)) break;
@@ -791,32 +780,6 @@ public:
this->ShowRenameGroupWindow(this->vli.index, false);
break;
case WID_GL_COLLAPSE_EXPAND_GROUP: // Toggle collapse/expand
this->ToogleGroupCollapse(this->vli.index);
OnInvalidateData();
this->SetDirty();
break;
case WID_GL_COLLAPSE_ALL_GROUPS: {
this->collapsed_groups.Clear();
for (const GroupID *gid = this->all_groups.Begin(); gid != this->all_groups.End(); ++gid) {
GroupID id = *gid;
if (id != ALL_GROUP && id != DEFAULT_GROUP && id != INVALID_GROUP && this->collapsable_groups.Contains(id)) {
*this->collapsed_groups.Append() = id;
}
}
OnInvalidateData();
this->SetDirty();
break;
}
case WID_GL_EXPAND_ALL_GROUPS: {
this->collapsed_groups.Clear();
OnInvalidateData();
this->SetDirty();
break;
}
case WID_GL_LIVERY_GROUP: // Set group livery
ShowCompanyLiveryWindow(this->owner, this->vli.index);
break;
@@ -866,12 +829,10 @@ public:
case WID_GL_LIST_GROUP: { // Matrix group
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
GroupID new_g = id_g >= this->groups.Length() ? INVALID_GROUP : this->groups[id_g]->index;
GroupID new_g = id_g >= this->groups.size() ? INVALID_GROUP : this->groups[id_g]->index;
if (this->group_sel != new_g && g->parent != new_g) {
DoCommandP(0, this->group_sel | (1 << 16), new_g, CMD_ALTER_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_SET_PARENT));
GroupID *group = this->collapsed_groups.Find(new_g);
if (group != this->collapsed_groups.End()) this->collapsed_groups.Erase(group);
}
this->group_sel = INVALID_GROUP;
@@ -901,7 +862,7 @@ public:
this->SetDirty();
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
GroupID new_g = id_g >= this->groups.Length() ? NEW_GROUP : this->groups[id_g]->index;
GroupID new_g = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
DoCommandP(0, new_g, vindex | (_ctrl_pressed ? 1 << 31 : 0), CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE), new_g == NEW_GROUP ? CcAddVehicleNewGroup : NULL);
break;
@@ -914,7 +875,7 @@ public:
this->SetDirty();
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_VEHICLE);
if (id_v >= this->vehicles.Length()) return; // click out of list bound
if (id_v >= this->vehicles.size()) return; // click out of list bound
const Vehicle *v = this->vehicles[id_v];
if (!VehicleClicked(v) && vindex == v->index) {
@@ -925,7 +886,7 @@ public:
}
}
virtual void OnDragDrop(Point pt, int widget)
void OnDragDrop(Point pt, int widget) override
{
if (this->vehicle_sel != INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget);
if (this->group_sel != INVALID_GROUP) OnDragDrop_Group(pt, widget);
@@ -933,20 +894,20 @@ public:
_cursor.vehchain = false;
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str != NULL) DoCommandP(0, this->group_rename, 0, CMD_ALTER_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_RENAME), NULL, str);
InvalidateWindowData(WC_TEMPLATEGUI_MAIN, 0, 0, 0);
this->group_rename = INVALID_GROUP;
}
virtual void OnResize()
void OnResize() override
{
this->group_sb->SetCapacityFromWidget(this, WID_GL_LIST_GROUP);
this->vscroll->SetCapacityFromWidget(this, WID_GL_LIST_VEHICLE);
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
switch (widget) {
case WID_GL_SORT_BY_DROPDOWN:
@@ -1006,14 +967,14 @@ public:
this->SetDirty();
}
virtual void OnGameTick()
void OnGameTick() override
{
if (this->groups.NeedResort() || this->vehicles.NeedResort()) {
this->SetDirty();
}
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
/* abort drag & drop */
this->vehicle_sel = INVALID_VEHICLE;
@@ -1022,7 +983,7 @@ public:
this->SetWidgetDirty(WID_GL_LIST_VEHICLE);
}
virtual void OnMouseDrag(Point pt, int widget)
void OnMouseDrag(Point pt, int widget) override
{
if (this->vehicle_sel == INVALID_VEHICLE && this->group_sel == INVALID_GROUP) return;
@@ -1035,7 +996,7 @@ public:
case WID_GL_LIST_GROUP: { // ... the list of custom groups.
uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, WID_GL_LIST_GROUP, 0, this->tiny_step_height);
new_group_over = id_g >= this->groups.Length() ? NEW_GROUP : this->groups[id_g]->index;
new_group_over = id_g >= this->groups.size() ? NEW_GROUP : this->groups[id_g]->index;
break;
}
}

View File

@@ -63,12 +63,12 @@ struct EndGameHighScoreBaseWindow : Window {
return pt;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
delete this;
}
virtual EventState OnKeyPress(WChar key, uint16 keycode)
EventState OnKeyPress(WChar key, uint16 keycode) override
{
/* All keys are 'handled' by this window but we want to make
* sure that 'quit' still works correctly. Not handling the
@@ -129,7 +129,7 @@ struct EndGameWindow : EndGameHighScoreBaseWindow {
ShowHighscoreTable(this->window_number, this->rank);
}
virtual void OnPaint()
void OnPaint() override
{
this->SetupHighScoreEndWindow();
Point pt = this->GetTopLeft(640, 480);
@@ -177,7 +177,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow {
if (!_networking && !this->game_paused_by_player) DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE); // unpause
}
virtual void OnPaint()
void OnPaint() override
{
const HighScore *hs = _highscore_table[this->window_number];

View File

@@ -24,7 +24,7 @@ char *_hotkeys_file;
* List of all HotkeyLists.
* This is a pointer to ensure initialisation order with the various static HotkeyList instances.
*/
static SmallVector<HotkeyList*, 16> *_hotkey_lists = NULL;
static std::vector<HotkeyList*> *_hotkey_lists = NULL;
/** String representation of a keycode */
struct KeycodeNames {
@@ -205,7 +205,7 @@ const char *SaveKeycodes(const Hotkey *hotkey)
{
static char buf[128];
buf[0] = '\0';
for (uint i = 0; i < hotkey->keycodes.Length(); i++) {
for (uint i = 0; i < hotkey->keycodes.size(); i++) {
const char *str = KeycodeToString(hotkey->keycodes[i]);
if (i > 0) strecat(buf, ",", lastof(buf));
strecat(buf, str, lastof(buf));
@@ -250,19 +250,19 @@ Hotkey::Hotkey(const uint16 *default_keycodes, const char *name, int num) :
*/
void Hotkey::AddKeycode(uint16 keycode)
{
this->keycodes.Include(keycode);
include(this->keycodes, keycode);
}
HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
{
if (_hotkey_lists == NULL) _hotkey_lists = new SmallVector<HotkeyList*, 16>();
*_hotkey_lists->Append() = this;
if (_hotkey_lists == NULL) _hotkey_lists = new std::vector<HotkeyList*>();
_hotkey_lists->push_back(this);
}
HotkeyList::~HotkeyList()
{
_hotkey_lists->Erase(_hotkey_lists->Find(this));
_hotkey_lists->erase(std::find(_hotkey_lists->begin(), _hotkey_lists->end(), this));
}
/**
@@ -275,7 +275,7 @@ void HotkeyList::Load(IniFile *ini)
for (Hotkey *hotkey = this->items; hotkey->name != NULL; ++hotkey) {
IniItem *item = group->GetItem(hotkey->name, false);
if (item != NULL) {
hotkey->keycodes.Clear();
hotkey->keycodes.clear();
if (item->value != NULL) ParseHotkeys(hotkey, item->value);
}
}
@@ -303,7 +303,9 @@ void HotkeyList::Save(IniFile *ini) const
int HotkeyList::CheckMatch(uint16 keycode, bool global_only) const
{
for (const Hotkey *list = this->items; list->name != NULL; ++list) {
if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
auto begin = list->keycodes.begin();
auto end = list->keycodes.end();
if (std::find(begin, end, keycode | WKC_GLOBAL_HOTKEY) != end || (!global_only && std::find(begin, end, keycode) != end)) {
return list->num;
}
}
@@ -316,11 +318,11 @@ static void SaveLoadHotkeys(bool save)
IniFile *ini = new IniFile();
ini->LoadFromDisk(_hotkeys_file, NO_DIRECTORY);
for (HotkeyList **list = _hotkey_lists->Begin(); list != _hotkey_lists->End(); ++list) {
for (HotkeyList *list : *_hotkey_lists) {
if (save) {
(*list)->Save(ini);
list->Save(ini);
} else {
(*list)->Load(ini);
list->Load(ini);
}
}
@@ -343,11 +345,11 @@ void SaveHotkeysToConfig()
void HandleGlobalHotkeys(WChar key, uint16 keycode)
{
for (HotkeyList **list = _hotkey_lists->Begin(); list != _hotkey_lists->End(); ++list) {
if ((*list)->global_hotkey_handler == NULL) continue;
for (HotkeyList *list : *_hotkey_lists) {
if (list->global_hotkey_handler == NULL) continue;
int hotkey = (*list)->CheckMatch(keycode, true);
if (hotkey >= 0 && ((*list)->global_hotkey_handler(hotkey) == ES_HANDLED)) return;
int hotkey = list->CheckMatch(keycode, true);
if (hotkey >= 0 && (list->global_hotkey_handler(hotkey) == ES_HANDLED)) return;
}
}

View File

@@ -29,7 +29,7 @@ struct Hotkey {
const char *name;
int num;
SmallVector<uint16, 1> keycodes;
std::vector<uint16> keycodes;
};
#define HOTKEY_LIST_END Hotkey((uint16)0, NULL, -1)

View File

@@ -1759,8 +1759,16 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
}
if (_generating_world) {
if (HasBit(indspec->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
IndustryProductionCallback(i, 1);
for (size_t ci = 0; ci < lengthof(i->last_month_production); ci++) {
i->last_month_production[ci] = i->produced_cargo_waiting[ci] * 8;
i->produced_cargo_waiting[ci] = 0;
}
}
for (size_t ci = 0; ci < lengthof(i->last_month_production); ci++) {
i->last_month_production[ci] = i->production_rate[ci] * 8;
i->last_month_production[ci] += i->production_rate[ci] * 8;
}
}
@@ -1884,7 +1892,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
*ip = NULL;
SmallVector<ClearedObjectArea, 1> object_areas(_cleared_object_areas);
std::vector<ClearedObjectArea> object_areas(_cleared_object_areas);
CommandCost ret = CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, random_initial_bits, founder, creation_type, &custom_shape_check);
_cleared_object_areas = object_areas;
if (ret.Failed()) return ret;

View File

@@ -403,12 +403,12 @@ public:
this->SetButtons();
}
virtual void OnInit()
void OnInit() override
{
this->SetupArrays();
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_DPI_MATRIX_WIDGET: {
@@ -477,7 +477,7 @@ public:
}
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_DPI_FUND_WIDGET:
@@ -494,7 +494,7 @@ public:
}
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_DPI_MATRIX_WIDGET: {
@@ -581,7 +581,7 @@ public:
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_DPI_MATRIX_WIDGET: {
@@ -635,13 +635,13 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
/* Adjust the number of items in the matrix depending of the resize */
this->vscroll->SetCapacityFromWidget(this, WID_DPI_MATRIX_WIDGET);
}
virtual void OnPlaceObject(Point pt, TileIndex tile)
void OnPlaceObject(Point pt, TileIndex tile) override
{
bool success = true;
/* We do not need to protect ourselves against "Random Many Industries" in this mode */
@@ -674,7 +674,7 @@ public:
if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
}
virtual void OnGameTick()
void OnGameTick() override
{
if (!this->timer_enabled) return;
if (--this->callback_timer == 0) {
@@ -697,12 +697,12 @@ public:
}
}
virtual void OnTimeout()
void OnTimeout() override
{
this->RaiseButtons();
}
virtual void OnPlaceObjectAbort()
void OnPlaceObjectAbort() override
{
this->RaiseButtons();
}
@@ -712,7 +712,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->SetupArrays();
@@ -787,7 +787,7 @@ public:
this->InvalidateData();
}
virtual void OnPaint()
void OnPaint() override
{
this->DrawWidgets();
@@ -924,17 +924,17 @@ public:
return y + WD_FRAMERECT_BOTTOM;
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget == WID_IV_INFO) size->height = this->info_height;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_IV_INFO: {
@@ -1039,14 +1039,14 @@ public:
}
}
virtual void OnTimeout()
void OnTimeout() override
{
this->clicked_line = IL_NONE;
this->clicked_button = 0;
this->SetDirty();
}
virtual void OnResize()
void OnResize() override
{
if (this->viewport != NULL) {
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
@@ -1056,7 +1056,7 @@ public:
}
}
virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (StrEmpty(str)) return;
@@ -1082,7 +1082,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
const Industry *i = Industry::Get(this->window_number);
@@ -1094,12 +1094,12 @@ public:
}
}
virtual bool IsNewGRFInspectable() const
bool IsNewGRFInspectable() const override
{
return ::IsNewGRFInspectable(GSF_INDUSTRIES, this->window_number);
}
virtual void ShowNewGRFInspectWindow() const
void ShowNewGRFInspectWindow() const override
{
::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->window_number);
}
@@ -1202,16 +1202,16 @@ protected:
void BuildSortIndustriesList()
{
if (this->industries.NeedRebuild()) {
this->industries.Clear();
this->industries.clear();
const Industry *i;
FOR_ALL_INDUSTRIES(i) {
*this->industries.Append() = i;
this->industries.push_back(i);
}
this->industries.Compact();
this->industries.shrink_to_fit();
this->industries.RebuildDone();
this->vscroll->SetCount(this->industries.Length()); // Update scrollbar as well.
this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well.
}
if (!this->industries.Sort()) return;
@@ -1357,12 +1357,12 @@ public:
this->last_sorting = this->industries.GetListing();
}
virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_ID_DROPDOWN_CRITERIA) SetDParam(0, IndustryDirectoryWindow::sorter_names[this->industries.SortType()]);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_ID_DROPDOWN_ORDER:
@@ -1372,11 +1372,11 @@ public:
case WID_ID_INDUSTRY_LIST: {
int n = 0;
int y = r.top + WD_FRAMERECT_TOP;
if (this->industries.Length() == 0) {
if (this->industries.size() == 0) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_DIRECTORY_NONE);
break;
}
for (uint i = this->vscroll->GetPosition(); i < this->industries.Length(); i++) {
for (uint i = this->vscroll->GetPosition(); i < this->industries.size(); i++) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, this->GetIndustryString(this->industries[i]));
y += this->resize.step_height;
@@ -1387,7 +1387,7 @@ public:
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_ID_DROPDOWN_ORDER: {
@@ -1411,7 +1411,7 @@ public:
case WID_ID_INDUSTRY_LIST: {
Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
for (uint i = 0; i < this->industries.Length(); i++) {
for (uint i = 0; i < this->industries.size(); i++) {
d = maxdim(d, GetStringBoundingBox(this->GetIndustryString(this->industries[i])));
}
resize->height = d.height;
@@ -1425,7 +1425,7 @@ public:
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_ID_DROPDOWN_ORDER:
@@ -1439,7 +1439,7 @@ public:
case WID_ID_INDUSTRY_LIST: {
uint p = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ID_INDUSTRY_LIST, WD_FRAMERECT_TOP);
if (p < this->industries.Length()) {
if (p < this->industries.size()) {
if (_ctrl_pressed) {
ShowExtraViewPortWindow(this->industries[p]->location.tile);
} else {
@@ -1451,7 +1451,7 @@ public:
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
if (this->industries.SortType() != index) {
this->industries.SetSortType(index);
@@ -1459,18 +1459,18 @@ public:
}
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
}
virtual void OnPaint()
void OnPaint() override
{
if (this->industries.NeedRebuild()) this->BuildSortIndustriesList();
this->DrawWidgets();
}
virtual void OnHundredthTick()
void OnHundredthTick() override
{
this->industries.ForceResort();
this->BuildSortIndustriesList();
@@ -1481,7 +1481,7 @@ public:
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (data == 0) {
/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
@@ -2155,7 +2155,7 @@ next_cargo: ;
struct IndustryCargoesWindow : public Window {
static const int HOR_TEXT_PADDING, VERT_TEXT_PADDING;
typedef SmallVector<CargoesRow, 4> Fields;
typedef std::vector<CargoesRow> Fields;
Fields fields; ///< Fields to display in the #WID_IC_PANEL.
uint ind_cargo; ///< If less than #NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
@@ -2172,7 +2172,7 @@ struct IndustryCargoesWindow : public Window {
this->OnInvalidateData(id);
}
virtual void OnInit()
void OnInit() override
{
/* Initialize static CargoesField size variables. */
Dimension d = GetStringBoundingBox(STR_INDUSTRY_CARGOES_PRODUCERS);
@@ -2219,7 +2219,7 @@ struct IndustryCargoesWindow : public Window {
CargoesField::cargo_field_width = CargoesField::HOR_CARGO_BORDER_SPACE * 2 + CargoesField::HOR_CARGO_WIDTH * CargoesField::max_cargoes + CargoesField::HOR_CARGO_SPACE * (CargoesField::max_cargoes - 1);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_IC_PANEL:
@@ -2238,7 +2238,7 @@ struct IndustryCargoesWindow : public Window {
CargoesFieldType type; ///< Type of field.
virtual void SetStringParameters (int widget) const
void SetStringParameters (int widget) const override
{
if (widget != WID_IC_CAPTION) return;
@@ -2422,13 +2422,14 @@ struct IndustryCargoesWindow : public Window {
_displayed_industries.reset();
_displayed_industries.set(it);
this->fields.Clear();
CargoesRow *row = this->fields.Append();
row->columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row->columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row->columns[2].MakeEmpty(CFT_SMALL_EMPTY);
row->columns[3].MakeEmpty(CFT_SMALL_EMPTY);
row->columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
this->fields.clear();
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[2].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
const IndustrySpec *central_sp = GetIndustrySpec(it);
bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
@@ -2438,12 +2439,13 @@ struct IndustryCargoesWindow : public Window {
int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
int num_indrows = max(3, max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
for (int i = 0; i < num_indrows; i++) {
CargoesRow *row = this->fields.Append();
row->columns[0].MakeEmpty(CFT_EMPTY);
row->columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
row->columns[2].MakeEmpty(CFT_EMPTY);
row->columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
row->columns[4].MakeEmpty(CFT_EMPTY);
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeEmpty(CFT_EMPTY);
row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
row.columns[2].MakeEmpty(CFT_EMPTY);
row.columns[3].MakeCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo));
row.columns[4].MakeEmpty(CFT_EMPTY);
}
/* Add central industry. */
int central_row = 1 + num_indrows / 2;
@@ -2500,13 +2502,14 @@ struct IndustryCargoesWindow : public Window {
this->ind_cargo = cid + NUM_INDUSTRYTYPES;
_displayed_industries.reset();
this->fields.Clear();
CargoesRow *row = this->fields.Append();
row->columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row->columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row->columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
row->columns[3].MakeEmpty(CFT_SMALL_EMPTY);
row->columns[4].MakeEmpty(CFT_SMALL_EMPTY);
this->fields.clear();
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
row.columns[3].MakeEmpty(CFT_SMALL_EMPTY);
row.columns[4].MakeEmpty(CFT_SMALL_EMPTY);
bool houses_supply = HousesCanSupply(&cid, 1);
bool houses_accept = HousesCanAccept(&cid, 1);
@@ -2514,12 +2517,13 @@ struct IndustryCargoesWindow : public Window {
int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
int num_indrows = max(num_supp, num_cust);
for (int i = 0; i < num_indrows; i++) {
CargoesRow *row = this->fields.Append();
row->columns[0].MakeEmpty(CFT_EMPTY);
row->columns[1].MakeCargo(&cid, 1);
row->columns[2].MakeEmpty(CFT_EMPTY);
row->columns[3].MakeEmpty(CFT_EMPTY);
row->columns[4].MakeEmpty(CFT_EMPTY);
/*C++17: CargoesRow &row = */ this->fields.emplace_back();
CargoesRow &row = this->fields.back();
row.columns[0].MakeEmpty(CFT_EMPTY);
row.columns[1].MakeCargo(&cid, 1);
row.columns[2].MakeEmpty(CFT_EMPTY);
row.columns[3].MakeEmpty(CFT_EMPTY);
row.columns[4].MakeEmpty(CFT_EMPTY);
}
this->fields[num_indrows].MakeCargoLabel(0, false); // Add cargo labels at the left bottom.
@@ -2565,7 +2569,7 @@ struct IndustryCargoesWindow : public Window {
* - data = NUM_INDUSTRYTYPES: Stop sending updates to the smallmap window.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
if (data == NUM_INDUSTRYTYPES) {
@@ -2580,7 +2584,7 @@ struct IndustryCargoesWindow : public Window {
this->ComputeIndustryDisplay(data);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_IC_PANEL) return;
@@ -2597,7 +2601,7 @@ struct IndustryCargoesWindow : public Window {
const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
int vpos = -this->vscroll->GetPosition() * nwp->resize_y;
for (uint i = 0; i < this->fields.Length(); i++) {
for (uint i = 0; i < this->fields.size(); i++) {
int row_height = (i == 0) ? CargoesField::small_height : CargoesField::normal_height;
if (vpos + row_height >= 0) {
int xpos = left_pos;
@@ -2639,7 +2643,7 @@ struct IndustryCargoesWindow : public Window {
if (pt.y < vpos) return false;
int row = (pt.y - vpos) / CargoesField::normal_height; // row is relative to row 1.
if (row + 1 >= (int)this->fields.Length()) return false;
if (row + 1 >= (int)this->fields.size()) return false;
vpos = pt.y - vpos - row * CargoesField::normal_height; // Position in the row + 1 field
row++; // rebase row to match index of this->fields.
@@ -2668,7 +2672,7 @@ struct IndustryCargoesWindow : public Window {
return true;
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_IC_PANEL: {
@@ -2716,9 +2720,9 @@ struct IndustryCargoesWindow : public Window {
DropDownList *lst = new DropDownList;
const CargoSpec *cs;
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
*lst->Append() = new DropDownListStringItem(cs->name, cs->Index(), false);
lst->push_back(new DropDownListStringItem(cs->name, cs->Index(), false));
}
if (lst->Length() == 0) {
if (lst->size() == 0) {
delete lst;
break;
}
@@ -2733,9 +2737,9 @@ struct IndustryCargoesWindow : public Window {
IndustryType ind = _sorted_industry_types[i];
const IndustrySpec *indsp = GetIndustrySpec(ind);
if (!indsp->enabled) continue;
*lst->Append() = new DropDownListStringItem(indsp->name, ind, false);
lst->push_back(new DropDownListStringItem(indsp->name, ind, false));
}
if (lst->Length() == 0) {
if (lst->size() == 0) {
delete lst;
break;
}
@@ -2746,7 +2750,7 @@ struct IndustryCargoesWindow : public Window {
}
}
virtual void OnDropdownSelect(int widget, int index)
void OnDropdownSelect(int widget, int index) override
{
if (index < 0) return;
@@ -2761,12 +2765,12 @@ struct IndustryCargoesWindow : public Window {
}
}
virtual void OnHover(Point pt, int widget)
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
{
if (widget != WID_IC_PANEL) return;
if (widget != WID_IC_PANEL) return false;
Point fieldxy, xy;
if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return;
if (!CalculatePositionInWidget(pt, &fieldxy, &xy)) return false;
const CargoesField *fld = this->fields[fieldxy.y].columns + fieldxy.x;
CargoID cid = INVALID_CARGO;
@@ -2785,9 +2789,9 @@ struct IndustryCargoesWindow : public Window {
case CFT_INDUSTRY:
if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0, NULL, TCC_HOVER);
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0, NULL, close_cond);
}
return;
return true;
default:
break;
@@ -2796,11 +2800,14 @@ struct IndustryCargoesWindow : public Window {
const CargoSpec *csp = CargoSpec::Get(cid);
uint64 params[5];
params[0] = csp->name;
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, TCC_HOVER);
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, close_cond);
return true;
}
return false;
}
virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL);
}

View File

@@ -49,7 +49,7 @@ struct SelectGameWindow : public Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->SetWidgetLoweredState(WID_SGI_TEMPERATE_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
@@ -58,7 +58,7 @@ struct SelectGameWindow : public Window {
this->SetWidgetLoweredState(WID_SGI_TOYLAND_LANDSCAPE, _settings_newgame.game_creation.landscape == LT_TOYLAND);
}
virtual void OnInit()
void OnInit() override
{
bool missing_sprites = _missing_extra_graphics > 0 && !IsReleasedVersion();
this->GetWidget<NWidgetStacked>(WID_SGI_BASESET_SELECTION)->SetDisplayedPlane(missing_sprites ? 0 : SZSP_NONE);
@@ -67,7 +67,7 @@ struct SelectGameWindow : public Window {
this->GetWidget<NWidgetStacked>(WID_SGI_TRANSLATION_SELECTION)->SetDisplayedPlane(missing_lang ? 0 : SZSP_NONE);
}
virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_SGI_BASESET:
@@ -82,7 +82,7 @@ struct SelectGameWindow : public Window {
}
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
StringID str = 0;
switch (widget) {
@@ -111,13 +111,11 @@ struct SelectGameWindow : public Window {
}
}
virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
#ifdef ENABLE_NETWORK
/* Do not create a network server when you (just) have closed one of the game
* creation/load windows for the network server. */
if (IsInsideMM(widget, WID_SGI_GENERATE_GAME, WID_SGI_EDIT_SCENARIO + 1)) _is_network_server = false;
#endif /* ENABLE_NETWORK */
switch (widget) {
case WID_SGI_GENERATE_GAME:
@@ -299,8 +297,6 @@ void AskExitGame()
SetDParam(0, STR_OSNAME_OS2);
#elif defined(SUNOS)
SetDParam(0, STR_OSNAME_SUNOS);
#elif defined(DOS)
SetDParam(0, STR_OSNAME_DOS);
#else
SetDParam(0, STR_OSNAME_UNIX);
#endif

View File

@@ -1685,7 +1685,6 @@ STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST :{ORANGE}Vragver
STR_CONFIG_SETTING_AI :{ORANGE}Mededingers
STR_CONFIG_SETTING_AI_NPC :{ORANGE}Rekenaar spelers
STR_CONFIG_SETTING_PATHFINDER_OPF :Oorspronklik
STR_CONFIG_SETTING_PATHFINDER_NPF :NPF
STR_CONFIG_SETTING_PATHFINDER_YAPF_RECOMMENDED :YAPF {BLUE}(Aanbevole)
@@ -1768,7 +1767,6 @@ STR_QUIT_NO :{BLACK}Nee
# Supported OSes
STR_OSNAME_WINDOWS :Windows
STR_OSNAME_DOS :DOS
STR_OSNAME_UNIX :Unix
STR_OSNAME_OSX :OS{NBSP}X
STR_OSNAME_HAIKU :Haiku
@@ -3389,11 +3387,13 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Koop Voe
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}Bou skip
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_BUTTON :{BLACK}Koop vliegtuig
STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP :{BLACK}Koop die gekose lokomotief/wa. Shift+klik vir kwotasie
STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Koop die gekose voertuig. Shift+klik vir kwotasie
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}Koop die gekose skip. Shift+klik vir kwotasie
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}Koop die gekose vliegtuig. Shift+klik vir kwotasie
STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}Hernoem
STR_BUY_VEHICLE_ROAD_VEHICLE_RENAME_BUTTON :{BLACK}Hernoem
STR_BUY_VEHICLE_SHIP_RENAME_BUTTON :{BLACK}Hernoem

View File

@@ -1369,7 +1369,6 @@ STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST :توزيع ال
STR_CONFIG_SETTING_AI :{ORANGE}المتنافسين
STR_CONFIG_SETTING_AI_NPC :{ORANGE} لاعبين الحاسوب
STR_CONFIG_SETTING_PATHFINDER_OPF :اصلي
STR_CONFIG_SETTING_PATHFINDER_NPF :NPF
STR_CONFIG_SETTING_PATHFINDER_YAPF_RECOMMENDED :YAPF {BLUE}(مفضل)
@@ -1440,7 +1439,6 @@ STR_QUIT_NO :{BLACK}لا
# Supported OSes
STR_OSNAME_WINDOWS :ويندوز
STR_OSNAME_DOS :دوس
STR_OSNAME_UNIX :يونكس
STR_OSNAME_OSX :OS{NBSP}X
STR_OSNAME_HAIKU :هايكو
@@ -2917,11 +2915,13 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}شراء
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}شراء سفينة
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_BUTTON :{BLACK}شراء طائرة
STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP :{BLACK}شراء العربة الموضحة
STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}شراء العربة
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}شراء السفينة المختارة
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}اشتر الطائرة المختارة
STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}اعادة تسمية
STR_BUY_VEHICLE_ROAD_VEHICLE_RENAME_BUTTON :{BLACK}أعد التسمية
STR_BUY_VEHICLE_SHIP_RENAME_BUTTON :{BLACK}تسمية

View File

@@ -1598,7 +1598,6 @@ STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST :{ORANGE}Zama ba
STR_CONFIG_SETTING_AI :{ORANGE}Lehiakideak
STR_CONFIG_SETTING_AI_NPC :{ORANGE}Ordenagailu jokalariak
STR_CONFIG_SETTING_PATHFINDER_OPF :Jatorrizkoa
STR_CONFIG_SETTING_PATHFINDER_NPF :NPF
STR_CONFIG_SETTING_PATHFINDER_YAPF_RECOMMENDED :YAPF {BLUE}(Gomendatua)
@@ -1680,7 +1679,6 @@ STR_QUIT_NO :{BLACK}Ez
# Supported OSes
STR_OSNAME_WINDOWS :Windows
STR_OSNAME_DOS :DOS
STR_OSNAME_UNIX :Unix
STR_OSNAME_OSX :OS{NBSP}X
STR_OSNAME_HAIKU :Haiku
@@ -3276,11 +3274,13 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Ibilgail
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}Itsasontia erosi
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_BUTTON :{BLACK}Hegazkina erosi
STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP :{BLACK}Aukeratuta dagoen ibilgailua erosi. Shift+Klik gutxi gora beherako kostea erakutsi
STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Aukeratuta dagoen ibilgailua erosi. Shift+Klik gutxi gora beherako kostea erakutsi
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}Aukeratuta dagoen itsasontzia erosi. Shift+Klik gutxi gora beherako kostea erakutsi
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}Aukeratuta dagoen hegazkina erosi. Shift+Klik gutxi gora beherako kostea erakutsi
STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}Berrizendatu
STR_BUY_VEHICLE_ROAD_VEHICLE_RENAME_BUTTON :{BLACK}Berrizendatu
STR_BUY_VEHICLE_SHIP_RENAME_BUTTON :{BLACK}Berrizendatu

View File

@@ -2009,7 +2009,6 @@ STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST :{ORANGE}Раз
STR_CONFIG_SETTING_AI :{ORANGE}Канкурэнты
STR_CONFIG_SETTING_AI_NPC :{ORANGE}Кампутарныя гульцы
STR_CONFIG_SETTING_PATHFINDER_OPF :арыґінальны
STR_CONFIG_SETTING_PATHFINDER_NPF :NPF
STR_CONFIG_SETTING_PATHFINDER_YAPF_RECOMMENDED :YAPF {BLUE}(рэкамэндуецца)
@@ -2093,7 +2092,6 @@ STR_QUIT_NO :{BLACK}Не
# Supported OSes
STR_OSNAME_WINDOWS :Windows
STR_OSNAME_DOS :DOS
STR_OSNAME_UNIX :Unix
STR_OSNAME_OSX :OS{NBSP}X
STR_OSNAME_HAIKU :Haiku
@@ -3746,11 +3744,13 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Купі
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}Купіць
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_BUTTON :{BLACK}Купіць
STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP :{BLACK}Набыць абраны лякаматыў/ваґон. Shift+пстрычка — ацэнка кошту набыцьця.
STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Набыць абраны аўтамабіль. Shift+пстрычка — ацэнка кошту набыцьця.
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}Набыць абраны карабель. Shift+пстрычка — ацэнка кошту набыцьця.
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}Набыць абраны авіятранспарт. Shift+пстрычка — ацэнка кошту набыцьця.
STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}Перайменаваць
STR_BUY_VEHICLE_ROAD_VEHICLE_RENAME_BUTTON :{BLACK}Перайменаваць
STR_BUY_VEHICLE_SHIP_RENAME_BUTTON :{BLACK}Перайменаваць

View File

@@ -1700,7 +1700,6 @@ STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST :{ORANGE}Distrib
STR_CONFIG_SETTING_AI :{ORANGE}Oponentes
STR_CONFIG_SETTING_AI_NPC :{ORANGE}Computadores
STR_CONFIG_SETTING_PATHFINDER_OPF :Original
STR_CONFIG_SETTING_PATHFINDER_NPF :NPF
STR_CONFIG_SETTING_PATHFINDER_YAPF_RECOMMENDED :YAPF {BLUE}(Recomendado)
@@ -1784,7 +1783,6 @@ STR_QUIT_NO :{BLACK}Não
# Supported OSes
STR_OSNAME_WINDOWS :Windows
STR_OSNAME_DOS :DOS
STR_OSNAME_UNIX :Unix
STR_OSNAME_OSX :OS{NBSP}X
STR_OSNAME_HAIKU :Haiku
@@ -3456,11 +3454,13 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_BUTTON :{BLACK}Comprar
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_BUTTON :{BLACK}Comprar Embarcação
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_BUTTON :{BLACK}Comprar Aeronave
STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP :{BLACK}Compra o veículo ferroviário selecionado. Shift+Clique mostra preço estimado sem a compra
STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Compra o veículo selecionado. Shift+Clique mostra preço estimado sem a compra
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}Compra a embarcação selecionada. Shift+Clique mostra preço estimado sem a compra
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}Compra a aeronave selecionada. Shift+Clique mostra o preço estimado sem a compra
STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}Renomear
STR_BUY_VEHICLE_ROAD_VEHICLE_RENAME_BUTTON :{BLACK}Renomear
STR_BUY_VEHICLE_SHIP_RENAME_BUTTON :{BLACK}Renomear

Some files were not shown because too many files have changed in this diff Show More