diff --git a/src/blitter/32bpp_anim_sse4.hpp b/src/blitter/32bpp_anim_sse4.hpp index dacd4105b7..f84e55d0b6 100644 --- a/src/blitter/32bpp_anim_sse4.hpp +++ b/src/blitter/32bpp_anim_sse4.hpp @@ -39,7 +39,7 @@ public: template void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override; - Sprite *Encode(const SpriteLoader::SpriteCollection *sprite, AllocatorProc *allocator) override { + Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override { return Blitter_32bppSSE2::Encode(sprite, allocator); // CM FIXME 14.0-beta1 why SSE -> SSE2 } const char *GetName() override { return "32bpp-sse4-anim"; } diff --git a/src/blitter/32bpp_sse2.cpp b/src/blitter/32bpp_sse2.cpp index b21640b874..bd6c61cc5c 100644 --- a/src/blitter/32bpp_sse2.cpp +++ b/src/blitter/32bpp_sse2.cpp @@ -20,7 +20,7 @@ /** Instantiation of the SSE2 32bpp blitter factory. */ static FBlitter_32bppSSE2 iFBlitter_32bppSSE2; -Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection *sprite, AllocatorProc *allocator, Blitter_32bppSimple *base_blitter) +Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator, Blitter_32bppSimple *base_blitter) { /* First uint32_t of a line = the number of transparent pixels from the left. * Second uint32_t of a line = the number of transparent pixels from the right. diff --git a/src/blitter/32bpp_sse2.hpp b/src/blitter/32bpp_sse2.hpp index d60dfed87d..d6d44fea4a 100644 --- a/src/blitter/32bpp_sse2.hpp +++ b/src/blitter/32bpp_sse2.hpp @@ -76,7 +76,7 @@ public: byte data[]; ///< Data, all zoomlevels. }; - Sprite *Encode(const SpriteLoader::SpriteCollection *sprite, AllocatorProc *allocator, Blitter_32bppSimple *base_blitter); + Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator, Blitter_32bppSimple *base_blitter); }; DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags); @@ -88,7 +88,7 @@ public: template void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); - Sprite *Encode(const SpriteLoader::SpriteCollection *sprite, AllocatorProc *allocator) override { + Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override { return Blitter_32bppSSE_Base::Encode(sprite, allocator, this); } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index eaf812fdd8..10477803bd 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -926,7 +926,7 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, SetDParam(0, e->index); SetDParam(1, e->grf_prop.local_id); DrawString(left, right, y, CM_STR_PURCHASE_ENGINE_ID); - y += FONT_HEIGHT_NORMAL; + y += GetCharacterHeight(FS_NORMAL); } switch (e->type) { @@ -1910,7 +1910,6 @@ struct BuildVehicleWindow : Window { Hotkey('R', "cm_build_vehicle", WID_BV_BUILD), }}; }; -HotkeyList BuildVehicleWindow::hotkeys("build_vehicle", build_vehicle_hotkeys); static WindowDesc _build_vehicle_desc(__FILE__, __LINE__, WDP_AUTO, "build_vehicle", 240, 268, diff --git a/src/citymania/cm_blueprint.cpp b/src/citymania/cm_blueprint.cpp index 9d234d4524..d9926b3507 100644 --- a/src/citymania/cm_blueprint.cpp +++ b/src/citymania/cm_blueprint.cpp @@ -198,8 +198,8 @@ up GetBlueprintCommand(TileIndex start, const Blueprint::Item &item) { false, // convert_signal true, // skip_existing_signals false, // ctrl_pressed - SIGTYPE_NORMAL, // cycle_start - SIGTYPE_NORMAL, // cycle_stop + SIGTYPE_BLOCK, // cycle_start + SIGTYPE_BLOCK, // cycle_stop SIGNAL_POS_NUM[item.u.rail.signal.pos] + (item.u.rail.signal.type <= SIGTYPE_LAST_NOPBS && !item.u.rail.signal.twoway ? 1 : 0), false // signals_copy @@ -214,7 +214,7 @@ std::multimap Blueprint::GetTiles(TileIndex tile std::multimap res; if (tile == INVALID_TILE) return res; auto add_tile = [&res](TileIndex tile, const ObjectTileHighlight &ohl) { - if (tile >= MapSize()) return; + if (tile >= Map::Size()) return; res.emplace(tile, ohl); }; @@ -256,7 +256,8 @@ std::multimap Blueprint::GetTiles(TileIndex tile add_tile(otile, ObjectTileHighlight::make_rail_depot(palette, o.u.rail.depot.ddir)); break; case Item::Type::RAIL_STATION_PART: { - auto layout_ptr = AllocaM(byte, (int)o.u.rail.station_part.numtracks * o.u.rail.station_part.plat_len); + std::vector layouts(o.u.rail.station_part.numtracks * o.u.rail.station_part.plat_len); + byte *layout_ptr = layouts.data(); GetStationLayout(layout_ptr, o.u.rail.station_part.numtracks, o.u.rail.station_part.plat_len, nullptr); if (palette == CM_PALETTE_TINT_WHITE && can_build_station_sign.find(o.u.rail.station_part.id) == can_build_station_sign.end()) palette = CM_PALETTE_TINT_ORANGE_DEEP; @@ -454,7 +455,7 @@ void BlueprintCopyArea(TileIndex start, TileIndex end) { } case RAIL_TILE_SIGNALS: BlueprintAddSignals(blueprint, tile, td); - FALLTHROUGH; + [[fallthrough]]; case RAIL_TILE_NORMAL: BlueprintAddTracks(blueprint, tile, td, ta, track_tiles); break; diff --git a/src/citymania/cm_cargo_table_gui.cpp b/src/citymania/cm_cargo_table_gui.cpp index c1955dd38e..ed671f6b3d 100644 --- a/src/citymania/cm_cargo_table_gui.cpp +++ b/src/citymania/cm_cargo_table_gui.cpp @@ -8,6 +8,7 @@ #include "../company_func.h" #include "../company_base.h" #include "../table/strings.h" +#include "../table/sprites.h" #include "../textbuf_gui.h" #include "../cargotype.h" #include "../zoom_func.h" @@ -65,7 +66,7 @@ struct CargosWindow : Window { void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { Dimension icon_size = this->GetMaxIconSize(); - int line_height = std::max(FONT_HEIGHT_NORMAL, (int)icon_size.height); + int line_height = std::max(GetCharacterHeight(FS_NORMAL), (int)icon_size.height); int icon_space = icon_size.width + ScaleGUITrad(CT_ICON_MARGIN); switch(widget) { case WID_CT_HEADER_AMOUNT: @@ -86,14 +87,14 @@ struct CargosWindow : Window { switch(widget) { case WID_CT_HEADER_AMOUNT: case WID_CT_HEADER_INCOME: - size->height = FONT_HEIGHT_NORMAL; + size->height = GetCharacterHeight(FS_NORMAL); break; case WID_CT_HEADER_CARGO: break; case WID_CT_AMOUNT: case WID_CT_INCOME: case WID_CT_LIST: { - size->height = _sorted_standard_cargo_specs.size() * line_height + CT_LINESPACE + FONT_HEIGHT_NORMAL; + size->height = _sorted_standard_cargo_specs.size() * line_height + CT_LINESPACE + GetCharacterHeight(FS_NORMAL); break; } } @@ -117,9 +118,9 @@ struct CargosWindow : Window { Money sum_cargo_income = 0; int y = r.top; Dimension max_icon_size = this->GetMaxIconSize(); - int line_height = std::max(FONT_HEIGHT_NORMAL, (int)(max_icon_size.height)); + int line_height = std::max(GetCharacterHeight(FS_NORMAL), (int)(max_icon_size.height)); int icon_space = max_icon_size.width + ScaleGUITrad(CT_ICON_MARGIN); - int text_y_ofs = (line_height - FONT_HEIGHT_NORMAL); + int text_y_ofs = (line_height - GetCharacterHeight(FS_NORMAL)); switch(widget){ case WID_CT_HEADER_CARGO: @@ -210,11 +211,11 @@ static const NWidgetPart _nested_cargos_widgets[] = { EndContainer(), }; -static WindowDesc _cargos_desc( - WDP_AUTO, NULL, 0, 0, +static WindowDesc _cargos_desc(__FILE__, __LINE__, + WDP_AUTO, nullptr, 0, 0, WC_CARGOS, WC_NONE, WDF_CONSTRUCTION, - _nested_cargos_widgets, lengthof(_nested_cargos_widgets) + std::begin(_nested_cargos_widgets), std::end(_nested_cargos_widgets) ); void ShowCompanyCargos(CompanyID company) diff --git a/src/citymania/cm_client_list_gui.cpp b/src/citymania/cm_client_list_gui.cpp index d9d8ae6ba2..cbbf2ab27e 100644 --- a/src/citymania/cm_client_list_gui.cpp +++ b/src/citymania/cm_client_list_gui.cpp @@ -13,6 +13,7 @@ #include "../network/network.h" #include "../network/network_base.h" #include "../network/network_func.h" +#include "../sprite.h" #include "../strings_func.h" #include "../table/sprites.h" #include "../video/video_driver.hpp" @@ -49,8 +50,7 @@ protected: bool drawn = false; bool dirty = true; PointDimension backup_box; - uint8 *backup = nullptr; - int backup_size = -1; + ReusableBuffer backup; int padding; int line_height; int text_offset_y; @@ -63,9 +63,9 @@ public: void UpdateSize() { this->padding = ScaleGUITrad(3); auto icon_size = GetSpriteSize(CM_SPR_COMPANY_ICON); - auto common_height = std::max(icon_size.height, FONT_HEIGHT_NORMAL); + auto common_height = std::max(icon_size.height, GetCharacterHeight(FS_NORMAL)); this->line_height = common_height + this->padding; - this->text_offset_y = (common_height - FONT_HEIGHT_NORMAL) / 2; + this->text_offset_y = (common_height - GetCharacterHeight(FS_NORMAL)) / 2; this->icon_offset_y = (common_height - icon_size.height) / 2; this->box.height = this->padding; this->box.width = 0; @@ -100,7 +100,7 @@ public: Blitter *blitter = BlitterFactory::GetCurrentBlitter(); /* Put our 'shot' back to the screen */ - blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, box.x, box.y), this->backup, box.width, box.height); + blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, box.x, box.y), this->backup.GetBuffer(), box.width, box.height); /* And make sure it is updated next time */ VideoDriver::GetInstance()->MakeDirty(box.x, box.y, box.width, box.height); @@ -118,7 +118,7 @@ public: if (this->drawn) { /* Put our 'shot' back to the screen */ - blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, this->backup_box.x, this->backup_box.y), this->backup, this->backup_box.width, this->backup_box.height); + blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, this->backup_box.x, this->backup_box.y), this->backup.GetBuffer(), this->backup_box.width, this->backup_box.height); /* And make sure it is updated next time */ VideoDriver::GetInstance()->MakeDirty(this->backup_box.x, this->backup_box.y, this->backup_box.width, this->backup_box.height); @@ -138,12 +138,8 @@ public: this->box.y != this->backup_box.y || this->box.width != this->backup_box.width || this->box.height != this->backup_box.height) { - auto size = this->box.width * this->box.height * BlitterFactory::GetCurrentBlitter()->GetBytesPerPixel(); - if (size > this->backup_size) { - this->backup = ReallocT(this->backup, size); - this->backup_size = size; - } - blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, this->box.x, this->box.y), this->backup, this->box.width, this->box.height); + uint8_t *buffer = this->backup.Allocate(BlitterFactory::GetCurrentBlitter()->BufferSize(this->box.width, this->box.height)); + blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, this->box.x, this->box.y), buffer, this->box.width, this->box.height); this->backup_box = this->box; } diff --git a/src/citymania/cm_command_log.cpp b/src/citymania/cm_command_log.cpp index 3b4e0c0773..54513f2467 100644 --- a/src/citymania/cm_command_log.cpp +++ b/src/citymania/cm_command_log.cpp @@ -20,8 +20,7 @@ namespace citymania { struct FakeCommand { - Date date; - DateFract date_fract; + TimerGameTick::TickCounter counter; uint res; uint8 seed; uint16 client_id; @@ -31,33 +30,29 @@ struct FakeCommand { static std::queue _fake_commands; bool _replay_started = false; -bool DatePredate(Date date1, DateFract date_fract1, Date date2, DateFract date_fract2) { - return date1 < date2 || (date1 == date2 && date_fract1 < date_fract2); -} - -void SkipFakeCommands(Date date, DateFract date_fract) { +void SkipFakeCommands(TimerGameTick::TickCounter counter) { uint commands_skipped = 0; - while (!_fake_commands.empty() && DatePredate(_fake_commands.front().date, _fake_commands.front().date_fract, date, date_fract)) { + while (!_fake_commands.empty() && _fake_commands.front().counter < counter) { _fake_commands.pop(); commands_skipped++; } if (commands_skipped) { - fprintf(stderr, "Skipped %u commands that predate the current date (%d/%hu)\n", commands_skipped, date, date_fract); + fprintf(stderr, "Skipped %u commands that predate the current counter (%lu)\n", commands_skipped, counter); } } extern CommandCost ExecuteCommand(CommandPacket *cp); -void ExecuteFakeCommands(Date date, DateFract date_fract) { +void ExecuteFakeCommands(TimerGameTick::TickCounter counter) { if (!_replay_started) { - SkipFakeCommands(_date, _date_fract); + SkipFakeCommands(counter); _replay_started = true; } auto backup_company = _current_company; - while (!_fake_commands.empty() && !DatePredate(date, date_fract, _fake_commands.front().date, _fake_commands.front().date_fract)) { + while (!_fake_commands.empty() && _fake_commands.front().counter <= counter) { auto &x = _fake_commands.front(); fprintf(stderr, "Executing command: %s(%u) company=%u ... ", GetCommandName(x.cp.cmd), x.cp.cmd, x.cp.company); @@ -85,9 +80,8 @@ void ExecuteFakeCommands(Date date, DateFract date_fract) { if (!res.Failed()) { fprintf(stderr, "FAIL (Failing command succeeded)\n"); } else if (res.GetErrorMessage() != INVALID_STRING_ID) { - char buf[DRAW_STRING_BUFFER]; - GetString(buf, res.GetErrorMessage(), lastof(buf)); - fprintf(stderr, "FAIL (Successful command failed: %s)\n", buf); + auto buf = GetString(res.GetErrorMessage()); + fprintf(stderr, "FAIL (Successful command failed: %s)\n", buf.c_str()); } else { fprintf(stderr, "FAIL (Successful command failed)\n"); } @@ -181,9 +175,7 @@ void load_replay_commands(const std::string &filename, std::function= '0' && *url <= '9') || (*url >= 'A' && *url <= 'Z') || (*url >= 'a' && *url <= 'z') - || *url == '-' || *url == '_' || *url == '.' || *url == '~' - ){ - *buf++ = *url++; - } - else{ - buf += seprintf(buf, buflast, "%%%02X", *url++); - } - } - *buf = '\0'; -} +// void UrlEncode(char * buf, const char * buflast, const char * url){ +// while(*url != '\0' && buf < buflast){ +// if((*url >= '0' && *url <= '9') || (*url >= 'A' && *url <= 'Z') || (*url >= 'a' && *url <= 'z') +// || *url == '-' || *url == '_' || *url == '.' || *url == '~' +// ){ +// *buf++ = *url++; +// } +// else{ +// buf += seprintf(buf, buflast, "%%%02X", *url++); +// } +// } +// *buf = '\0'; +// } //ini login hadling void IniLoginInitiate(){ - static const char * const list_login[] = { - CFG_LOGIN_KEY, - NULL - }; - if(_inilogin != NULL) return; //it was already set - _inilogin = new IniFile(list_login); + _inilogin = new IniFile({CFG_LOGIN_KEY}); _inilogin->LoadFromDisk(CFG_LOGIN_FILE, BASE_DIR); IniReloadLogin(); } -std::string GetLoginItem(const char *itemname){ - IniGroup *group = _inilogin->GetGroup(CFG_LOGIN_KEY); - if(group == NULL) return ""; - IniItem *item = group->GetItem(itemname, true); - if(item == NULL) return ""; - return item->value.value_or(""); +std::string GetLoginItem(const std::string& itemname){ + IniGroup &group = _inilogin->GetOrCreateGroup(CFG_LOGIN_KEY); + IniItem &item = group.GetOrCreateItem(itemname); + return item.value.value_or(""); } void IniReloadLogin(){ - char str[MAX_COMMUNITY_STRING_LEN * 2]; for(int i = 0, len = lengthof(INI_LOGIN_KEYS); i < len; i++){ - auto itemvalue = GetLoginItem(INI_LOGIN_KEYS[i]); - if (itemvalue.empty()){ - GetString(str, CM_STR_LOGIN_WINDOW_NOT_SET, lastof(str)); + auto str = GetLoginItem(INI_LOGIN_KEYS[i]); + if (str.empty()){ + str = GetString(CM_STR_LOGIN_WINDOW_NOT_SET); } - else{ - strecpy(str, itemvalue.c_str(), lastof(str)); - } - strecpy(_inilogindata[i], str, lastof(_inilogindata[i])); + strecpy(_inilogindata[i], str.c_str(), lastof(_inilogindata[i])); } } -void SetLoginItem(const char * itemname, const char * value){ - IniGroup *group = _inilogin->GetGroup(CFG_LOGIN_KEY); - if(group == NULL) return; - IniItem *item = group->GetItem(itemname, true); - if(item == NULL) return; - item->SetValue(value); - _inilogin->SaveToDisk(str_fmt("%s%s", _personal_dir.c_str(), CFG_LOGIN_FILE)); +void SetLoginItem(const std::string& itemname, const std::string& value){ + IniGroup &group = _inilogin->GetOrCreateGroup(CFG_LOGIN_KEY); + IniItem &item = group.GetOrCreateItem(itemname); + item.SetValue(value); + _inilogin->SaveToDisk(fmt::format("{}{}", _personal_dir, CFG_LOGIN_FILE)); IniReloadLogin(); } @@ -592,7 +579,7 @@ void ShowCommandsToolbar() // login window class GetHTTPContent: public HTTPCallback { public: - GetHTTPContent(char *uri): uri(uri) { + GetHTTPContent(const std::string &uri): uri{uri} { this->proccessing = false; this->buf_last = lastof(buf); } @@ -605,30 +592,30 @@ public: NetworkHTTPSocketHandler::Connect(this->uri, this); } - virtual void OnReceiveData(const char *data, size_t length) { - if (data == NULL) { - this->cursor = NULL; + void OnReceiveData(std::unique_ptr data, size_t length) override { + if (data.get() == nullptr) { + this->cursor = nullptr; this->LoginAlready(); - } - else { - for(size_t i=0; icursor < this->buf_last; i++, data++, this->cursor++) { - *(this->cursor) = *data; + } else { + for(size_t i = 0; i < length && this->cursor < this->buf_last; i++, this->cursor++) { + *(this->cursor) = data.get()[i]; } *(this->cursor) = '\0'; } } - virtual void OnFailure() { + void OnFailure() override { ShowErrorMessage(CM_STR_LOGIN_ERROR_SIGN_IN_FAILED, INVALID_STRING_ID, WL_ERROR); } + bool IsCancelled() const override { + return false; + } + void LoginAlready(){ if(strlen(this->buf) == 4 && _networking){ - char msg[32]; - seprintf(msg, lastof(msg), "!login %s", this->buf); - NetworkClientSendChatToServer(msg); - } - else{ + NetworkClientSendChatToServer(fmt::format("!login {}", this->buf)); + } else{ ShowErrorMessage(CM_STR_LOGIN_ERROR_BAD_INPUT, INVALID_STRING_ID, WL_ERROR); } this->proccessing = false; @@ -637,11 +624,10 @@ public: virtual ~GetHTTPContent() { } private: - NetworkHTTPContentConnecter *conn; char buf[HTTPBUFLEN]; char *buf_last; char *cursor; - char *uri; + std::string uri; }; std::string urlencode(const std::string &s) { @@ -674,19 +660,18 @@ std::string btpro_encode(const char *value) { //send login void AccountLogin(CommunityName community){ - char uri[MAX_COMMUNITY_STRING_LEN * 2 + 32]; + std::string uri; switch(community){ case CITYMANIA: - seprintf(uri, lastof(uri), "!login %s %s", _inilogindata[NOVAPOLISUSER], _inilogindata[NOVAPOLISPW]); - NetworkClientSendChatToServer(uri); + NetworkClientSendChatToServer(fmt::format("!login {} {}", _inilogindata[NOVAPOLISUSER], _inilogindata[NOVAPOLISPW])); return; case NICE: - seprintf(uri, lastof(uri), NICE_HTTP_LOGIN, GetLoginItem(NICE_LOGIN).c_str(), GetLoginItem(NICE_PW).c_str()); + uri = fmt::format("http://n-ice.org/openttd/gettoken.php?user={}&password={}", GetLoginItem(NICE_LOGIN), GetLoginItem(NICE_PW)); break; case BTPRO: { - seprintf(uri, lastof(uri), BTPRO_HTTP_LOGIN, - btpro_encode(GetLoginItem(BTPRO_LOGIN).c_str()).c_str(), - btpro_encode(GetLoginItem(BTPRO_PW).c_str()).c_str()); + uri = fmt::format(BTPRO_HTTP_LOGIN, + btpro_encode(GetLoginItem(BTPRO_LOGIN).c_str()), + btpro_encode(GetLoginItem(BTPRO_PW).c_str())); break; } default: @@ -764,7 +749,6 @@ struct LoginWindow : Window { void OnQueryTextFinished(char * str) { if (str == NULL) return; - char item[128]; switch(this->query_widget){ case LQW_NOVAPOLIS_LOGIN: { SetLoginItem(NOVAPOLIS_LOGIN, str); @@ -777,10 +761,11 @@ struct LoginWindow : Window { case LQW_NICE_LOGIN: case LQW_NICE_PW: case LQW_BTPRO_LOGIN: - case LQW_BTPRO_PW: - UrlEncode(item, lastof(item), str); + case LQW_BTPRO_PW: { + auto item = urlencode(str); SetLoginItem(INI_LOGIN_KEYS[this->query_widget - 3], item); // - LWW_NICE_LOGIN + NICE_LOGIN break; + } default: return; } this->SetDirty(); @@ -843,17 +828,17 @@ static const NWidgetPart _nested_login_window_widgets[] = { EndContainer(), }; -static WindowDesc _login_window_desc( +static WindowDesc _login_window_desc(__FILE__, __LINE__, WDP_CENTER, NULL, 0, 0, - WC_LOGIN_WINDOW, WC_NONE, + CM_WC_LOGIN_WINDOW, WC_NONE, WDF_CONSTRUCTION, - _nested_login_window_widgets, lengthof(_nested_login_window_widgets) + std::begin(_nested_login_window_widgets), std::end(_nested_login_window_widgets) ); void ShowLoginWindow() { IniLoginInitiate(); - CloseWindowByClass(WC_LOGIN_WINDOW); + CloseWindowByClass(CM_WC_LOGIN_WINDOW); AllocateWindowDescFront(&_login_window_desc, 0); } diff --git a/src/citymania/cm_console_cmds.cpp b/src/citymania/cm_console_cmds.cpp index 0046a9b39e..e26303588e 100644 --- a/src/citymania/cm_console_cmds.cpp +++ b/src/citymania/cm_console_cmds.cpp @@ -10,7 +10,6 @@ #include "../command_func.h" #include "../console_func.h" #include "../console_type.h" -#include "../date_func.h" #include "../fileio_type.h" #include "../map_type.h" #include "../map_func.h" @@ -122,9 +121,9 @@ bool ConTreeMap(byte argc, char *argv[]) { return true; } - for (TileIndex tile = 0; tile < MapSize(); tile++) { - auto mx = x - x * TileX(tile) / MapSizeX() - 1; - auto my = y * TileY(tile) / MapSizeY(); + for (TileIndex tile = 0; tile < Map::Size(); tile++) { + auto mx = x - x * TileX(tile) / Map::SizeX() - 1; + auto my = y * TileY(tile) / Map::SizeY(); auto t = map[mx + my * x]; auto tree_count = std::min(t / 51, 4); // auto tree_growth = (uint)(t % 51) * 7 / 50; diff --git a/src/citymania/cm_console_cmds.hpp b/src/citymania/cm_console_cmds.hpp index 30478f9cf7..d1de0a712e 100644 --- a/src/citymania/cm_console_cmds.hpp +++ b/src/citymania/cm_console_cmds.hpp @@ -1,11 +1,11 @@ #ifndef CM_CONSOLE_CMDS_HPP #define CM_CONSOLE_CMDS_HPP -#include "../date_type.h" +#include "../timer/timer_game_tick.h" namespace citymania { -void SkipFakeCommands(Date date, DateFract date_fract); +void SkipFakeCommands(TimerGameTick::TickCounter counter); void SetReplaySaveInterval(uint32 interval); void CheckIntervalSave(); bool IsReplayingCommands(); @@ -16,7 +16,7 @@ bool ConExport(byte argc, char *argv[]); bool ConTreeMap(byte argc, char *argv[]); bool ConResetTownGrowth(byte argc, char *argv[]); bool ConLoadCommands(byte argc, char *argv[]); -void ExecuteFakeCommands(Date date, DateFract date_fract); +void ExecuteFakeCommands(TimerGameTick::TickCounter counter); bool ConStartRecord(byte argc, char *argv[]); bool ConStopRecord(byte argc, char *argv[]); diff --git a/src/citymania/cm_export.cpp b/src/citymania/cm_export.cpp index 60422cd882..9b74a5ff00 100644 --- a/src/citymania/cm_export.cpp +++ b/src/citymania/cm_export.cpp @@ -4,7 +4,6 @@ #include "../cargotype.h" #include "../debug.h" -#include "../date_func.h" #include "../house.h" #include "../gfx_func.h" #include "../gfx_type.h" @@ -19,6 +18,7 @@ #include "../table/strings.h" #include "../table/town_land.h" #include "../table/train_sprites.h" +#include "../timer/timer_game_tick.h" #include "../viewport_sprite_sorter.h" #include "../viewport_type.h" #include "../window_func.h" @@ -191,8 +191,8 @@ void WriteHouseSpecInfo(JsonWriter &j) { for (uint i = 0; i < NUM_HOUSES; i++) { const HouseSpec *hs = HouseSpec::Get(i); j.begin_dict(); - j.kv("min_year", hs->min_year); - j.kv("max_year", hs->max_year); + j.kv("min_year", hs->min_year.base()); + j.kv("max_year", hs->max_year.base()); j.kv("population", hs->population); j.kv("removal_cost", hs->removal_cost); j.kv("name", hs->building_name); @@ -364,11 +364,11 @@ extern ChildScreenSpriteToDrawVector &ViewportExportGetChildSprites(); void ViewportExportJson(const Viewport *vp, int left, int top, int right, int bottom) { ViewportExportDrawBegin(vp, left, top, right, bottom); - auto fname = fmt::format("snaps/tick_{}.json", _tick_counter); - Debug(misc, 0, "Exporting tick {} into {} box ({},{})-({},{}) ", _tick_counter, fname, left, top, right, bottom); + auto fname = fmt::format("snaps/tick_{}.json", TimerGameTick::counter); + Debug(misc, 0, "Exporting tick {} into {} box ({},{})-({},{}) ", TimerGameTick::counter, fname, left, top, right, bottom); data_export::JsonWriter j(fname); j.begin_dict(); - j.kv("tick", _tick_counter); + j.kv("tick", TimerGameTick::counter); j.begin_list_with_key("tile_sprites"); for (auto &ts : ViewportExportGetTileSprites()) { j.begin_dict(); @@ -463,7 +463,7 @@ void ExportSprite(SpriteID sprite, SpriteType type) { std::ofstream f(fname, std::ios::binary); uint size; void *raw = GetRawSprite(sprite, type); - if (type == ST_RECOLOUR) size = 257; + if (type == SpriteType::Recolour) size = 257; else size = *(((size_t *)raw) - 1); f.write((char *)raw, size); exported.insert(sprite); @@ -472,25 +472,25 @@ void ExportSprite(SpriteID sprite, SpriteType type) { void ExportSpriteAndPal(SpriteID img, SpriteID pal) { SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH); if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) { - ExportSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR); - ExportSprite(real_sprite, ST_NORMAL); + ExportSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour); + ExportSprite(real_sprite, SpriteType::Normal); } else if (pal != PAL_NONE) { if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) { //SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH)); } else { - ExportSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR); + ExportSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour); } - ExportSprite(real_sprite, ST_NORMAL); + ExportSprite(real_sprite, SpriteType::Normal); } else { - ExportSprite(real_sprite, ST_NORMAL); + ExportSprite(real_sprite, SpriteType::Normal); } } void ViewportExport(const Viewport *vp, int left, int top, int right, int bottom) { ViewportExportDrawBegin(vp, left, top, right, bottom); - auto fname = fmt::format("snaps/tick_{}.bin", _tick_counter); - Debug(misc, 0, "Exporting tick {} into {} box ({},{})-({},{}) ", _tick_counter, fname, left, top, right, bottom); + auto fname = fmt::format("snaps/tick_{}.bin", TimerGameTick::counter); + Debug(misc, 0, "Exporting tick {} into {} box ({},{})-({},{}) ", TimerGameTick::counter, fname, left, top, right, bottom); std::ofstream f(fname, std::ios::binary); auto &tile_sprites = ViewportExportGetTileSprites(); uint64 n = tile_sprites.size(); diff --git a/src/citymania/cm_highlight.cpp b/src/citymania/cm_highlight.cpp index e7784d1cba..c247c162c3 100644 --- a/src/citymania/cm_highlight.cpp +++ b/src/citymania/cm_highlight.cpp @@ -62,7 +62,7 @@ extern uint32 _realtime_tick; extern uint32 _cm_funding_layout; extern IndustryType _cm_funding_type; extern void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec); -extern void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage, IndustryGfx gfx); +extern void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, byte rnd_colour, byte stage); struct RailStationGUISettings { Axis orientation; ///< Currently selected rail station orientation @@ -74,6 +74,16 @@ struct RailStationGUISettings { }; extern RailStationGUISettings _railstation; ///< Settings of the station builder GUI +struct RoadStopGUISettings { + DiagDirection orientation; + + RoadStopClassID roadstop_class; + uint16_t roadstop_type; + uint16_t roadstop_count; +}; +extern RoadStopGUISettings _roadstop_gui_settings; + + namespace citymania { extern void (*DrawTileSelectionRect)(const TileInfo *ti, PaletteID pal); @@ -96,6 +106,7 @@ extern const Station *_station_to_join; extern const Station *_highlight_station_to_join; extern TileArea _highlight_join_area; + std::set, std::greater>> _town_cache; // struct { // int w; @@ -158,11 +169,13 @@ ObjectTileHighlight ObjectTileHighlight::make_rail_tunnel_head(SpriteID palette, return oh; } -ObjectTileHighlight ObjectTileHighlight::make_road_stop(SpriteID palette, RoadType roadtype, DiagDirection ddir, bool is_truck) { +ObjectTileHighlight ObjectTileHighlight::make_road_stop(SpriteID palette, RoadType roadtype, DiagDirection ddir, bool is_truck, RoadStopClassID spec_class, uint16_t spec_index) { auto oh = ObjectTileHighlight(Type::ROAD_STOP, palette); oh.u.road.stop.roadtype = roadtype; oh.u.road.stop.ddir = ddir; oh.u.road.stop.is_truck = is_truck; + oh.u.road.stop.spec_class = spec_class; + oh.u.road.stop.spec_index = spec_index; return oh; } @@ -246,13 +259,15 @@ ObjectHighlight ObjectHighlight::make_rail_station(TileIndex start_tile, TileInd return oh; } -ObjectHighlight ObjectHighlight::make_road_stop(TileIndex start_tile, TileIndex end_tile, RoadType roadtype, DiagDirection orientation, bool is_truck) { +ObjectHighlight ObjectHighlight::make_road_stop(TileIndex start_tile, TileIndex end_tile, RoadType roadtype, DiagDirection orientation, bool is_truck, RoadStopClassID spec_class, uint16_t spec_index) { auto oh = ObjectHighlight{ObjectHighlight::Type::ROAD_STOP}; oh.tile = start_tile; oh.end_tile = end_tile; oh.ddir = orientation; oh.roadtype = roadtype; oh.is_truck = is_truck; + oh.road_stop_spec_class = spec_class; + oh.road_stop_spec_index = spec_index; return oh; } @@ -329,7 +344,7 @@ static const DiagDirection _place_depot_extra_dir[12] = { }; void ObjectHighlight::AddTile(TileIndex tile, ObjectTileHighlight &&oh) { - if (tile >= MapSize()) return; + if (tile >= Map::Size()) return; this->tiles.insert(std::make_pair(tile, std::move(oh))); } @@ -379,7 +394,8 @@ void ObjectHighlight::UpdateTiles() { ).test(); auto palette = (this->cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); - auto layout_ptr = AllocaM(byte, (int)numtracks * plat_len); + std::vector layouts(numtracks * plat_len); + auto layout_ptr = layouts.data(); GetStationLayout(layout_ptr, numtracks, plat_len, nullptr); // TODO statspec auto tile_delta = (this->axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); @@ -407,12 +423,14 @@ void ObjectHighlight::UpdateTiles() { (this->ddir >= DIAGDIR_END), // is_drive_through (DiagDirection)(this->ddir % 4), this->roadtype, + this->road_stop_spec_class, + this->road_stop_spec_index, NEW_STATION, true ).test(); auto palette = (this->cost.Succeeded() ? CM_PALETTE_TINT_WHITE : CM_PALETTE_TINT_RED_DEEP); for (TileIndex tile : ta) { - this->AddTile(tile, ObjectTileHighlight::make_road_stop(palette, this->roadtype, this->ddir, this->is_truck)); + this->AddTile(tile, ObjectTileHighlight::make_road_stop(palette, this->roadtype, this->ddir, this->is_truck, this->road_stop_spec_class, this->road_stop_spec_index)); } break; } @@ -496,7 +514,7 @@ void ObjectHighlight::UpdateTiles() { auto add_track = [this, z](TileIndex tile, TileIndex end_tile, Trackdir trackdir, SpriteID palette, TileIndex point1, TileIndex point2) { if (trackdir == INVALID_TRACKDIR) return; - while(tile <= MapSize()) { + while(tile <= Map::Size()) { this->sprites.emplace_back( RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, z * TILE_HEIGHT + 7 /* z_offset */), SPR_AUTORAIL_BASE + _AutorailTilehSprite[0][TrackdirToTrack(trackdir)], @@ -571,7 +589,7 @@ void ObjectHighlight::MarkDirty() { MarkTileDirtyByTile(kv.first); } for (const auto &s: this->sprites) { - auto sprite = GetSprite(GB(s.sprite_id, 0, SPRITE_WIDTH), ST_NORMAL); + auto sprite = GetSprite(GB(s.sprite_id, 0, SPRITE_WIDTH), SpriteType::Normal); auto left = s.pt.x + sprite->x_offs; auto top = s.pt.y + sprite->y_offs; MarkAllViewportsDirty( @@ -630,7 +648,7 @@ SpriteID GetSelectionColourByTint(SpriteID colour) { void DrawTrainDepotSprite(SpriteID palette, const TileInfo *ti, RailType railtype, DiagDirection ddir) { const DrawTileSprites *dts = &_depot_gfx_table[ddir]; - const RailtypeInfo *rti = GetRailTypeInfo(railtype); + const RailTypeInfo *rti = GetRailTypeInfo(railtype); SpriteID image = rti->UsesOverlay() ? SPR_FLAT_GRASS_TILE : dts->ground.sprite; uint32 offset = rti->GetRailtypeSpriteOffset(); @@ -662,7 +680,7 @@ void DrawTrainDepotSprite(SpriteID palette, const TileInfo *ti, RailType railtyp void DrawTrainStationSprite(SpriteID palette, const TileInfo *ti, RailType railtype, Axis axis, byte section) { int32 total_offset = 0; const DrawTileSprites *t = GetStationTileLayout(STATION_RAIL, section + (axis == AXIS_X ? 0 : 1)); - const RailtypeInfo *rti = nullptr; + const RailTypeInfo *rti = nullptr; if (railtype != INVALID_RAILTYPE) { rti = GetRailTypeInfo(railtype); @@ -979,7 +997,7 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus /* Limit the building stage to the number of stages supplied. */ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group; - IndustryDrawTileLayout(ti, tlgroup, i->random_colour, INDUSTRY_COMPLETED, gfx); + IndustryDrawTileLayout(ti, tlgroup, i->random_colour, INDUSTRY_COMPLETED); return true; } @@ -1115,7 +1133,7 @@ void DrawSignal(SpriteID palette, const TileInfo *ti, RailType railtype, uint po sprite += image; } else { /* Normal electric signals are stored in a different sprite block than all other signals. */ - sprite = (type == SIGTYPE_NORMAL && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16; + sprite = (type == SIGTYPE_BLOCK && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16; sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0); } @@ -1182,7 +1200,7 @@ void DrawSelectionPoint(SpriteID palette, const TileInfo *ti) { if (IsSteepSlope(ti->tileh)) z -= TILE_HEIGHT; } } - DrawSelectionSprite(_cur_dpi->zoom <= ZOOM_LVL_DETAIL ? SPR_DOT : SPR_DOT_SMALL, palette, ti, z, foundation_part); + DrawSelectionSprite(SPR_DOT, palette, ti, z, foundation_part); } TileHighlight ObjectHighlight::GetTileHighlight(const TileInfo *ti) { @@ -1260,16 +1278,16 @@ void ObjectHighlight::Draw(const TileInfo *ti) { auto string_id = oth.u.numbered_rect.number ? CM_STR_LAYOUT_NUM : CM_STR_LAYOUT_RANDOM; SetDParam(0, oth.u.numbered_rect.number); - char buffer[DRAW_STRING_BUFFER]; - GetString(buffer, string_id, lastof(buffer)); + std::string buffer = GetString(string_id); auto bb = GetStringBoundingBox(buffer); sign.width_normal = WidgetDimensions::scaled.fullbevel.left + Align(bb.width, 2) + WidgetDimensions::scaled.fullbevel.right; Point pt = RemapCoords2(TileX(ti->tile) * TILE_SIZE + TILE_SIZE / 2, TileY(ti->tile) * TILE_SIZE + TILE_SIZE / 2); sign.center = pt.x; sign.top = pt.y - bb.height / 2; - ViewportAddString(_cur_dpi, ZOOM_LVL_OUT_8X, &sign, - string_id, STR_NULL, STR_NULL, oth.u.numbered_rect.number, 0, COLOUR_WHITE); + // TODO NUMBERED_RECT should be used atm anyway + // ViewportAddString(_cur_dpi, ZOOM_LVL_OUT_8X, &sign, + // string_id, STR_NULL, STR_NULL, oth.u.numbered_rect.number, 0, COLOUR_WHITE); break; } default: @@ -1330,7 +1348,7 @@ void ObjectHighlight::DrawOverlay(DrawPixelInfo *dpi) { template uint8 Get(uint32 x, uint32 y, F getter) { - if (x >= MapSizeX() || y >= MapSizeY()) return 0; + if (x >= Map::SizeX() || y >= Map::SizeY()) return 0; return getter(TileXY(x, y)); } @@ -1364,14 +1382,14 @@ void UpdateIndustryHighlight() { bool CanBuildIndustryOnTileCached(IndustryType type, TileIndex tile) { // if (_mz[tile].industry_fund_type != type || !_mz[tile].industry_fund_result) { - if (_mz[tile].industry_fund_update != _industry_highlight_hash || !_mz[tile].industry_fund_result) { + if (_mz[tile.base()].industry_fund_update != _industry_highlight_hash || !_mz[tile.base()].industry_fund_result) { bool res = CanBuildIndustryOnTile(type, tile); // _mz[tile].industry_fund_type = type; - _mz[tile].industry_fund_update = _industry_highlight_hash; - _mz[tile].industry_fund_result = res ? 2 : 1; + _mz[tile.base()].industry_fund_update = _industry_highlight_hash; + _mz[tile.base()].industry_fund_result = res ? 2 : 1; return res; } - return (_mz[tile].industry_fund_result == 2); + return (_mz[tile.base()].industry_fund_result == 2); } void DrawBorderSprites(const TileInfo *ti, ZoningBorder border, SpriteID color) { @@ -1396,10 +1414,10 @@ SpriteID GetIndustryZoningPalette(TileIndex tile) { auto n_produced = 0; auto n_serviced = 0; for (auto j = 0; j < INDUSTRY_NUM_OUTPUTS; j++) { - if (ind->produced_cargo[j] == CT_INVALID) continue; - if (ind->last_month_production[j] == 0 && ind->this_month_production[j] == 0) continue; + if (ind->produced[j].cargo == CT_INVALID) continue; + if (ind->produced[j].history[LAST_MONTH].production == 0 && ind->produced[j].history[THIS_MONTH].production == 0) continue; n_produced++; - if (ind->last_month_transported[j] > 0 || ind->last_month_transported[j] > 0) + if (ind->produced[j].history[LAST_MONTH].transported > 0 || ind->produced[j].history[THIS_MONTH].transported > 0) n_serviced++; } if (n_serviced < n_produced) @@ -1479,8 +1497,8 @@ void CalcCBAcceptanceBorders(TileHighlight &th, TileIndex tile, SpriteID border_ _town_kdtree.FindContained( (uint16)std::max(0, tx - radius), (uint16)std::max(0, ty - radius), - (uint16)std::min(tx + radius + 1, MapSizeX()), - (uint16)std::min(ty + radius + 1, MapSizeY()), + (uint16)std::min(tx + radius + 1, Map::SizeX()), + (uint16)std::min(ty + radius + 1, Map::SizeY()), [tx, ty, radius, &in_zone, &border] (TownID tid) { Town *town = Town::GetIfValid(tid); if (!town || town->larger_town) @@ -1517,7 +1535,7 @@ void CalcCBTownLimitBorder(TileHighlight &th, TileIndex tile, SpriteID border_pa bool in_zone = false; for (auto &p : _town_cache) { sq = p.second->cache.squared_town_zone_radius[0] + 30; - if (4 * sq * n < MapSize() * i) break; + if (4 * sq * n < Map::Size() * i) break; AddTownCBLimitBorder(tile, p.second, border, in_zone); i++; } @@ -1526,8 +1544,8 @@ void CalcCBTownLimitBorder(TileHighlight &th, TileIndex tile, SpriteID border_pa _town_kdtree.FindContained( (uint16)std::max(0, tx - radius), (uint16)std::max(0, ty - radius), - (uint16)std::min(tx + radius + 1, MapSizeX()), - (uint16)std::min(ty + radius + 1, MapSizeY()), + (uint16)std::min(tx + radius + 1, Map::SizeX()), + (uint16)std::min(ty + radius + 1, Map::SizeY()), [tile, &in_zone, &border] (TownID tid) { Town *town = Town::GetIfValid(tid); if (!town || town->larger_town) @@ -1599,7 +1617,7 @@ TileHighlight GetTileHighlight(const TileInfo *ti, TileType tile_type) { auto pal = GetIndustryZoningPalette(ti->tile); if (pal) th.ground_pal = th.structure_pal = CM_PALETTE_TINT_RED_DEEP; } else if (_zoning.outer == CHECKTOWNADZONES) { - auto getter = [](TileIndex t) { return _mz[t].advertisement_zone; }; + auto getter = [](TileIndex t) { return _mz[t.base()].advertisement_zone; }; auto b = CalcTileBorders(ti->tile, getter); const SpriteID pal[] = {PAL_NONE, CM_SPR_PALETTE_ZONING_YELLOW, CM_SPR_PALETTE_ZONING_ORANGE, CM_SPR_PALETTE_ZONING_RED}; th.add_border(b.first, pal[b.second]); @@ -1757,8 +1775,8 @@ HighLightStyle UpdateTileSelection(HighLightStyle new_drawstyle) { if (_thd.size.x >= (int)TILE_SIZE && _thd.size.y >= (int)TILE_SIZE) { auto start_tile = TileXY(_thd.new_pos.x / TILE_SIZE, _thd.new_pos.y / TILE_SIZE); auto end_tile = TileXY( - std::min((_thd.new_pos.x + _thd.new_size.x) / TILE_SIZE, MapSizeX()) - 1, - std::min((_thd.new_pos.y + _thd.new_size.y) / TILE_SIZE, MapSizeY()) - 1 + std::min((_thd.new_pos.x + _thd.new_size.x) / TILE_SIZE, Map::SizeX()) - 1, + std::min((_thd.new_pos.y + _thd.new_size.y) / TILE_SIZE, Map::SizeY()) - 1 ); if (_thd.select_proc == DDSP_BUILD_STATION) _thd.cm_new = ObjectHighlight::make_rail_station(start_tile, end_tile, _railstation.orientation); @@ -1781,7 +1799,15 @@ HighLightStyle UpdateTileSelection(HighLightStyle new_drawstyle) { ddir = AddAutodetectionRotation(AutodetectDriveThroughRoadStopDirection(ta, pt, _cur_roadtype)); } } - _thd.cm_new = ObjectHighlight::make_road_stop(start_tile, end_tile, _cur_roadtype, ddir, _thd.select_proc == DDSP_BUILD_TRUCKSTOP); + _thd.cm_new = ObjectHighlight::make_road_stop( + start_tile, + end_tile, + _cur_roadtype, + ddir, + _thd.select_proc == DDSP_BUILD_TRUCKSTOP, + _roadstop_gui_settings.roadstop_class, + _roadstop_gui_settings.roadstop_type + ); } } new_drawstyle = HT_RECT; @@ -1857,17 +1883,17 @@ void UpdateTownZoning(Town *town, uint32 prev_edge) { for(TileIndex tile : area) { uint8 group = GetTownZone(town, tile); - if (_mz[tile].town_zone != group) - _mz[tile].industry_fund_result = 0; + if (_mz[tile.base()].town_zone != group) + _mz[tile.base()].industry_fund_result = 0; - if (_mz[tile].town_zone > group) { + if (_mz[tile.base()].town_zone > group) { if (recalc) { - _mz[tile].town_zone = GetAnyTownZone(tile); + _mz[tile.base()].town_zone = GetAnyTownZone(tile); if (_zoning.outer == CHECKTOWNZONES) MarkTileDirtyByTile(tile); } - } else if (_mz[tile].town_zone < group) { - _mz[tile].town_zone = group; + } else if (_mz[tile.base()].town_zone < group) { + _mz[tile.base()].town_zone = group; if (_zoning.outer == CHECKTOWNZONES) MarkTileDirtyByTile(tile); } @@ -1877,14 +1903,14 @@ void UpdateTownZoning(Town *town, uint32 prev_edge) { void UpdateAdvertisementZoning(TileIndex center, uint radius, uint8 zone) { uint16 x1, y1, x2, y2; x1 = (uint16)std::max(0, TileX(center) - radius); - x2 = (uint16)std::min(TileX(center) + radius + 1, MapSizeX()); + x2 = (uint16)std::min(TileX(center) + radius + 1, Map::SizeX()); y1 = (uint16)std::max(0, TileY(center) - radius); - y2 = (uint16)std::min(TileY(center) + radius + 1, MapSizeY()); + y2 = (uint16)std::min(TileY(center) + radius + 1, Map::SizeY()); for (uint16 y = y1; y < y2; y++) { for (uint16 x = x1; x < x2; x++) { auto tile = TileXY(x, y); if (DistanceManhattan(tile, center) > radius) continue; - _mz[tile].advertisement_zone = std::max(_mz[tile].advertisement_zone, zone); + _mz[tile.base()].advertisement_zone = std::max(_mz[tile.base()].advertisement_zone, zone); } } } @@ -1910,7 +1936,7 @@ void InitializeZoningMap() { } std::pair GetTownZoneBorder(TileIndex tile) { - return CalcTileBorders(tile, [](TileIndex t) { return _mz[t].town_zone; }); + return CalcTileBorders(tile, [](TileIndex t) { return _mz[t.base()].town_zone; }); } ZoningBorder GetAnyStationCatchmentBorder(TileIndex tile) { diff --git a/src/citymania/cm_highlight_type.hpp b/src/citymania/cm_highlight_type.hpp index a9b480d4b5..33573bf2da 100644 --- a/src/citymania/cm_highlight_type.hpp +++ b/src/citymania/cm_highlight_type.hpp @@ -4,6 +4,7 @@ #include "../bridge.h" #include "../direction_type.h" #include "../map_func.h" +#include "../newgrf_roadstop.h" #include "../road_type.h" #include "../signal_type.h" #include "../station_map.h" @@ -130,6 +131,8 @@ public: RoadType roadtype; DiagDirection ddir; bool is_truck; + RoadStopClassID spec_class; + uint16_t spec_index; } stop; struct { RoadType roadtype; @@ -143,7 +146,7 @@ public: IndustryType ind_type; byte ind_layout; TileIndexDiff tile_diff; - IndustryGfx gfx; + IndustryGfx gfx; // TODO remove? } industry_tile; struct { uint32 number; @@ -158,7 +161,7 @@ public: static ObjectTileHighlight make_rail_bridge_head(SpriteID palette, DiagDirection ddir, BridgeType type); static ObjectTileHighlight make_rail_tunnel_head(SpriteID palette, DiagDirection ddir); - static ObjectTileHighlight make_road_stop(SpriteID palette, RoadType roadtype, DiagDirection ddir, bool is_truck); + static ObjectTileHighlight make_road_stop(SpriteID palette, RoadType roadtype, DiagDirection ddir, bool is_truck, RoadStopClassID spec_class, uint16_t spec_index); static ObjectTileHighlight make_road_depot(SpriteID palette, RoadType roadtype, DiagDirection ddir); static ObjectTileHighlight make_airport_tile(SpriteID palette, StationGfx gfx); static ObjectTileHighlight make_industry_tile(SpriteID palette, IndustryType ind_type, byte ind_layout, TileIndexDiff tile_diff, IndustryGfx gfx); @@ -301,6 +304,8 @@ public: DiagDirection ddir = INVALID_DIAGDIR; RoadType roadtype = INVALID_ROADTYPE; bool is_truck = false; + RoadStopClassID road_stop_spec_class; + uint16_t road_stop_spec_index; int airport_type = 0; byte airport_layout = 0; sp blueprint = nullptr; @@ -324,7 +329,7 @@ public: static ObjectHighlight make_rail_depot(TileIndex tile, DiagDirection ddir); static ObjectHighlight make_rail_station(TileIndex start_tile, TileIndex end_tile, Axis axis); - static ObjectHighlight make_road_stop(TileIndex start_tile, TileIndex end_tile, RoadType roadtype, DiagDirection orientation, bool is_truck); + static ObjectHighlight make_road_stop(TileIndex start_tile, TileIndex end_tile, RoadType roadtype, DiagDirection orientation, bool is_truck, RoadStopClassID spec_class, uint16_t spec_index); static ObjectHighlight make_road_depot(TileIndex tile, RoadType roadtype, DiagDirection orientation); static ObjectHighlight make_airport(TileIndex start_tile, int airport_type, byte airport_layout); static ObjectHighlight make_blueprint(TileIndex tile, sp blueprint); diff --git a/src/citymania/cm_hotkeys.cpp b/src/citymania/cm_hotkeys.cpp index 7a030b77cf..7b54cf82b6 100644 --- a/src/citymania/cm_hotkeys.cpp +++ b/src/citymania/cm_hotkeys.cpp @@ -194,7 +194,7 @@ ToolRemoveMode RoadToolbar_GetRemoveMode(int widget) { switch(widget) { case WID_ROT_ROAD_X: case WID_ROT_ROAD_Y: - case WID_ROT_AUTOROAD: + case CM_WID_ROT_AUTOROAD: return ToolRemoveMode::MOD; case WID_ROT_BUS_STATION: @@ -220,7 +220,7 @@ void RoadToolbar_UpdateOptionWidgetStatus(Window *w, int widget, bool remove_act case WID_ROT_ROAD_X: case WID_ROT_ROAD_Y: - case WID_ROT_AUTOROAD: + case CM_WID_ROT_AUTOROAD: if (is_road) w->SetWidgetDisabledState(WID_ROT_ONE_WAY, !w->IsWidgetLowered(widget)); break; diff --git a/src/citymania/cm_minimap.cpp b/src/citymania/cm_minimap.cpp index 7a81a10f3f..1d18ee48ca 100644 --- a/src/citymania/cm_minimap.cpp +++ b/src/citymania/cm_minimap.cpp @@ -9,15 +9,17 @@ #include "../tree_map.h" #include "../viewport_func.h" #include "../town.h" +#include "../blitter/factory.hpp" +#include "../linkgraph/linkgraph_gui.h" #include "../tunnelbridge_map.h" #include "../core/endian_func.hpp" #include "../core/geometry_func.hpp" +#include "../widgets/smallmap_widget.h" #include "../core/kdtree.hpp" #include "../vehicle_base.h" #include "../sound_func.h" #include "../window_func.h" #include "../company_base.h" -#include "../guitimer_func.h" #include "../zoom_func.h" #include "../smallmap_gui.h" @@ -238,7 +240,7 @@ uint _max_industry_outputs = 0; bool is_cached_industry(const Industry *ind) { for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) - if (ind->produced_cargo[i] != INVALID_CARGO) + if (ind->produced[i].cargo != INVALID_CARGO) return true; return false; } @@ -248,7 +250,7 @@ MinimapIndustryKdtreeEntry get_industry_entry(const Industry *ind) { auto y = TileY(ind->location.tile) * TILE_SIZE + ind->location.h * TILE_SIZE / 2; uint num_outputs = 0; for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) - if (ind->produced_cargo[i] != INVALID_CARGO) + if (ind->produced[i].cargo != INVALID_CARGO) num_outputs++; _max_industry_outputs = std::max(_max_industry_outputs, num_outputs); return {(int16)((y - x) / 8), (int16)((y + x) / 8), ind->index}; @@ -604,7 +606,7 @@ static inline uint32 GetSmallMapRoutesPixels(TileIndex tile, TileType t) const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour]; return ApplyMask(cs->default_colour, &andor); } - FALLTHROUGH; + [[ fallthrough ]]; } default: @@ -717,7 +719,7 @@ static inline uint32 CM_GetSmallMapIMBAPixels(TileIndex tile, TileType t) } // if (IsClearGround(tile, CLEAR_SNOW)) // return _vegetation_clear_bits[GetClearGround(tile)]; - FALLTHROUGH; + [[ fallthrough ]]; default: const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour]; @@ -928,7 +930,7 @@ void SmallMapWindow::DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int hidden_mod = hidden_x % this->ui_zoom; do { /* Check if the tile (xc,yc) is within the map range */ - if (xc >= MapMaxX() || yc >= MapMaxY()) continue; + if (xc >= Map::MaxX() || yc >= Map::MaxY()) continue; /* Check if the dst pointer points to a pixel inside the screen buffer */ if (dst < _screen.dst_ptr) continue; @@ -1035,8 +1037,8 @@ void SmallMapWindow::DrawIndustryProduction(const DrawPixelInfo *dpi) const IconTextSizeHelper its{SPR_CARGO_COAL, WidgetDimensions::scaled.framerect}; for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) { - if (ind->produced_cargo[i] == INVALID_CARGO) continue; - SetDParam(0, ind->last_month_production[i]); + if (ind->produced[i].cargo == INVALID_CARGO) continue; + SetDParam(0, ind->produced[i].history[LAST_MONTH].production); its.add(STR_JUST_INT, FS_SMALL); } its.calculate(); @@ -1044,9 +1046,9 @@ void SmallMapWindow::DrawIndustryProduction(const DrawPixelInfo *dpi) const auto [r, ir] = its.make_rects(pt.x, pt.y); GfxFillRect(r, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR); for (auto i = 0; i < INDUSTRY_NUM_OUTPUTS; i++) { - if (ind->produced_cargo[i] == INVALID_CARGO) continue; - DrawSprite(CargoSpec::Get(ind->produced_cargo[i])->GetCargoIcon(), PAL_NONE, ir.left, ir.top + its.icon_ofs_y); - SetDParam(0, ind->last_month_production[i]); + if (ind->produced[i].cargo == INVALID_CARGO) continue; + DrawSprite(CargoSpec::Get(ind->produced[i].cargo)->GetCargoIcon(), PAL_NONE, ir.left, ir.top + its.icon_ofs_y); + SetDParam(0, ind->produced[i].history[LAST_MONTH].production); DrawString(ir.left + its.text_ofs_x, ir.right, ir.top + its.text_ofs_y, STR_JUST_INT, TC_WHITE, SA_LEFT, false, FS_SMALL); ir.top += its.line_height; } @@ -1063,12 +1065,12 @@ void SmallMapWindow::DrawTowns(const DrawPixelInfo *dpi) const for (auto &[t, population, width] : this->town_cache.towns) { Point pt = this->TileToPixel(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE); int x = pt.x - width / 2; - int y = pt.y - FONT_HEIGHT_SMALL / 2; + int y = pt.y - GetCharacterHeight(FS_SMALL) / 2; /* Check if the town sign is within bounds */ if ((int)(x + width) > dpi->left && x < dpi->left + dpi->width && - y + FONT_HEIGHT_SMALL > dpi->top && + y + GetCharacterHeight(FS_SMALL) > dpi->top && y < dpi->top + dpi->height) { if (this->map_type == CM_SMT_IMBA) { /* And draw it. */ @@ -1230,7 +1232,7 @@ void SmallMapWindow::SetupWidgetData() } -SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc), refresh(GUITimer(FORCE_REFRESH_PERIOD)) +SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc) { _smallmap_industry_highlight = INVALID_INDUSTRYTYPE; this->overlay = new LinkGraphOverlay(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1); @@ -1337,7 +1339,7 @@ void SmallMapWindow::RebuildColourIndexIfNecessary() } /* Width of the legend blob. */ - this->legend_width = (FONT_HEIGHT_SMALL - ScaleGUITrad(1)) * 8 / 5; + this->legend_width = (GetCharacterHeight(FS_SMALL) - ScaleGUITrad(1)) * 8 / 5; /* The width of a column is the minimum width of all texts + the size of the blob + some spacing */ this->column_width = min_width + this->legend_width + WidgetDimensions::scaled.framerect.Horizontal(); @@ -1386,7 +1388,7 @@ void SmallMapWindow::RebuildColourIndexIfNecessary() uint number_of_rows = this->GetNumberRowsLegend(columns); bool rtl = _current_text_dir == TD_RTL; uint i = 0; // Row counter for industry legend. - uint row_height = FONT_HEIGHT_SMALL; + uint row_height = GetCharacterHeight(FS_SMALL); int padding = WidgetDimensions::scaled.hsep_normal; @@ -1433,11 +1435,11 @@ void SmallMapWindow::RebuildColourIndexIfNecessary() if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) { legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK; } - FALLTHROUGH; + [[ fallthrough ]]; case SMT_LINKSTATS: SetDParam(0, tbl->legend); - FALLTHROUGH; + [[ fallthrough ]]; case SMT_OWNER: if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) { @@ -1452,7 +1454,7 @@ void SmallMapWindow::RebuildColourIndexIfNecessary() } break; } - FALLTHROUGH; + [[ fallthrough ]]; default: if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP); @@ -1567,7 +1569,7 @@ void SmallMapWindow::SetOverlayCargoMask() int SmallMapWindow::GetPositionOnLegend(Point pt) { const NWidgetBase *wi = this->GetWidget(WID_SM_LEGEND); - uint line = (pt.y - wi->pos_y - WidgetDimensions::scaled.framerect.top) / FONT_HEIGHT_SMALL; + uint line = (pt.y - wi->pos_y - WidgetDimensions::scaled.framerect.top) / GetCharacterHeight(FS_SMALL); uint columns = this->GetNumberColumnsLegend(wi->current_x); uint number_of_rows = this->GetNumberRowsLegend(columns); if (line >= number_of_rows) return -1; @@ -1591,7 +1593,6 @@ int SmallMapWindow::GetPositionOnLegend(Point pt) } if (new_highlight != _smallmap_industry_highlight) { _smallmap_industry_highlight = new_highlight; - this->refresh.SetInterval(_smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD); _smallmap_industry_highlight_state = true; this->SetDirty(); } @@ -1765,9 +1766,7 @@ int SmallMapWindow::GetPositionOnLegend(Point pt) /* virtual */ void SmallMapWindow::OnRealtimeTick(uint delta_ms) { /* Update the window every now and then */ - if (!this->refresh.Elapsed(delta_ms)) return; - - if (this->map_type == SMT_LINKSTATS) { + if (this->map_type == SmallMapWindow::SMT_LINKSTATS) { uint32 company_mask = this->GetOverlayCompanyMask(); if (this->overlay->GetCompanyMask() != company_mask) { this->overlay->SetCompanyMask(company_mask); @@ -1777,18 +1776,51 @@ int SmallMapWindow::GetPositionOnLegend(Point pt) } _smallmap_industry_highlight_state = !_smallmap_industry_highlight_state; - this->refresh.SetInterval(_smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD); this->SetDirty(); } -/* virtual */ void SmallMapWindow::OnHundredthTick() +// /* virtual */ void SmallMapWindow::OnHundredthTick() +// { +// if (this->show_towns) { +// this->UpdateTownCache(true); +// this->SetDirty(); +// } +// } + +/** Update all the links on the map. */ +void SmallMapWindow::UpdateLinks() { - if (this->show_towns) { - this->UpdateTownCache(true); - this->SetDirty(); + if (this->map_type == SMT_LINKSTATS) { + CompanyMask company_mask = this->GetOverlayCompanyMask(); + if (this->overlay->GetCompanyMask() != company_mask) { + this->overlay->SetCompanyMask(company_mask); + } else { + this->overlay->SetDirty(); + } } } +/** Blink the industries (if hover over an industry). */ +void SmallMapWindow::Blink() +{ + if (_smallmap_industry_highlight == INVALID_INDUSTRYTYPE) return; + + _smallmap_industry_highlight_state = !_smallmap_industry_highlight_state; + + this->UpdateLinks(); + this->SetDirty(); +} + +/** Force a full refresh of the map. */ +void SmallMapWindow::ForceRefresh() +{ + if (_smallmap_industry_highlight != INVALID_INDUSTRYTYPE) return; + + this->UpdateLinks(); + this->SetDirty(); +} + + /* virtual */ void SmallMapWindow::OnScroll(Point delta) { if (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED || _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED) _cursor.fix_at = true; @@ -1883,7 +1915,7 @@ void SmallMapWindow::UpdateTownCache(bool force) { this->town_cache.towns.push_back(std::make_tuple(t, t->cache.population, dim.width)); } else { - if (!IsSignVisible(rect, pt, t->cache.sign.width_small, FONT_HEIGHT_SMALL)) continue; + if (!IsSignVisible(rect, pt, t->cache.sign.width_small, GetCharacterHeight(FS_SMALL))) continue; this->town_cache.towns.push_back(std::make_tuple(t, t->cache.population, t->cache.sign.width_small)); } } @@ -1909,13 +1941,14 @@ public: this->smallmap_window = nullptr; } - void SetupSmallestSize(Window *w, bool init_array) override + void SetupSmallestSize(Window *w) override { - NWidgetBase *display = this->head; - NWidgetBase *bar = display->next; + assert(this->children.size() == 2); + NWidgetBase *display = this->children.front().get(); + NWidgetBase *bar = this->children.back().get(); - display->SetupSmallestSize(w, init_array); - bar->SetupSmallestSize(w, init_array); + display->SetupSmallestSize(w); + bar->SetupSmallestSize(w); this->smallmap_window = dynamic_cast(w); assert(this->smallmap_window != nullptr); @@ -1927,15 +1960,16 @@ public: this->resize_y = std::min(display->resize_y, bar->resize_y); } - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override { this->pos_x = x; this->pos_y = y; this->current_x = given_width; this->current_y = given_height; - NWidgetBase *display = this->head; - NWidgetBase *bar = display->next; + assert(this->children.size() == 2); + NWidgetBase *display = this->children.front().get(); + NWidgetBase *bar = this->children.back().get(); if (sizing == ST_SMALLEST) { this->smallest_x = given_width; @@ -1951,29 +1985,29 @@ public: bar->AssignSizePosition(ST_RESIZE, x, y + display_height, given_width, bar_height, rtl); } - NWidgetCore *GetWidgetFromPos(int x, int y) override - { - if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr; - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { - NWidgetCore *widget = child_wid->GetWidgetFromPos(x, y); - if (widget != nullptr) return widget; - } - return nullptr; - } + // NWidgetCore *GetWidgetFromPos(int x, int y) override + // { + // if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr; + // for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { + // NWidgetCore *widget = child_wid->GetWidgetFromPos(x, y); + // if (widget != nullptr) return widget; + // } + // return nullptr; + // } - void Draw(const Window *w) override - { - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) child_wid->Draw(w); - } + // void Draw(const Window *w) override + // { + // for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) child_wid->Draw(w); + // } - void FillDirtyWidgets(std::vector &dirty_widgets) override - { - if (this->base_flags & WBF_DIRTY) { - dirty_widgets.push_back(this); - } else { - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) child_wid->FillDirtyWidgets(dirty_widgets); - } - } + // void FillDirtyWidgets(std::vector &dirty_widgets) override + // { + // if (this->base_flags & WBF_DIRTY) { + // dirty_widgets.push_back(this); + // } else { + // for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) child_wid->FillDirtyWidgets(dirty_widgets); + // } + // } }; /** Widget parts of the smallmap display. */ @@ -2025,12 +2059,12 @@ static const NWidgetPart _nested_smallmap_bar[] = { EndContainer(), }; -static NWidgetBase *SmallMapDisplay(int *biggest_index) +static std::unique_ptr SmallMapDisplay() { - NWidgetContainer *map_display = new NWidgetSmallmapDisplay; + std::unique_ptr map_display = std::make_unique(); - MakeNWidgets(_nested_smallmap_display, lengthof(_nested_smallmap_display), biggest_index, map_display); - MakeNWidgets(_nested_smallmap_bar, lengthof(_nested_smallmap_bar), biggest_index, map_display); + map_display = MakeNWidgets(std::begin(_nested_smallmap_display), std::end(_nested_smallmap_display), std::move(map_display)); + map_display = MakeNWidgets(std::begin(_nested_smallmap_bar), std::end(_nested_smallmap_bar), std::move(map_display)); return map_display; } @@ -2061,11 +2095,11 @@ static const NWidgetPart _nested_smallmap_widgets[] = { EndContainer(), }; -static WindowDesc _smallmap_desc( +static WindowDesc _smallmap_desc(__FILE__, __LINE__, WDP_AUTO, "smallmap", 484, 314, WC_SMALLMAP, WC_NONE, 0, - _nested_smallmap_widgets, lengthof(_nested_smallmap_widgets) + std::begin(_nested_smallmap_widgets), std::end(_nested_smallmap_widgets) ); /** diff --git a/src/citymania/cm_minimap.hpp b/src/citymania/cm_minimap.hpp index b86b19393d..d0a82883d2 100644 --- a/src/citymania/cm_minimap.hpp +++ b/src/citymania/cm_minimap.hpp @@ -3,7 +3,12 @@ #include "../smallmap_gui.h" #include "../core/endian_func.hpp" +#include "../timer/timer.h" +#include "../timer/timer_window.h" +#include "../blitter/base.hpp" +#include "../industry.h" +extern CompanyID _local_company; namespace citymania { @@ -51,6 +56,17 @@ void minimap_init_industries(); class NWidgetSmallmapDisplay; +struct LegendAndColour { + uint8_t colour; ///< Colour of the item on the map. + StringID legend; ///< String corresponding to the coloured item. + IndustryType type; ///< Type of industry. Only valid for industry entries. + uint8_t height; ///< Height in tiles. Only valid for height legend entries. + CompanyID company; ///< Company to display. Only valid for company entries of the owner legend. + bool show_on_map; ///< For filtering industries, if \c true, industry is shown on the map in colour. + bool end; ///< This is the end of the list. + bool col_break; ///< Perform a column break and go further at the next column. +}; + /** Class managing the smallmap window. */ class SmallMapWindow : public Window { protected: @@ -94,7 +110,6 @@ protected: int ui_zoom; ///< Zoom level. Bigger number means more zoom-out (further away). int zoom = 1; ///< Zoom level. Bigger number means more zoom-out (further away). - GUITimer refresh; ///< Refresh timer. LinkGraphOverlay *overlay; struct { @@ -161,7 +176,7 @@ protected: inline uint GetLegendHeight(uint num_columns) const { return WidgetDimensions::scaled.framerect.Vertical() + - this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL; + this->GetNumberRowsLegend(num_columns) * GetCharacterHeight(FS_SMALL); } /** @@ -174,6 +189,19 @@ protected: return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff; } + /** Blink the industries (if selected) on a regular interval. */ + IntervalTimer blink_interval = {std::chrono::milliseconds(450), [this](auto) { + Blink(); + }}; + + /** Update the whole map on a regular interval. */ + IntervalTimer refresh_interval = {std::chrono::milliseconds(930), [this](auto) { + ForceRefresh(); + }}; + + void UpdateLinks(); + void Blink(); + void ForceRefresh(); void RebuildColourIndexIfNecessary(); uint GetNumberRowsLegend(uint columns) const; void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0); @@ -216,7 +244,7 @@ public: bool OnRightClick(Point pt, int widget) override; void OnMouseWheel(int wheel) override; void OnRealtimeTick(uint delta_ms) override; - void OnHundredthTick() override; + // void OnHundredthTick() override; void OnScroll(Point delta) override; void OnMouseOver(Point pt, int widget) override; }; diff --git a/src/citymania/cm_misc_gui.cpp b/src/citymania/cm_misc_gui.cpp index dc2a5a9b9a..4d5b6e87c7 100644 --- a/src/citymania/cm_misc_gui.cpp +++ b/src/citymania/cm_misc_gui.cpp @@ -26,11 +26,11 @@ static const NWidgetPart _nested_land_info_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY, WID_LI_BACKGROUND), SetMinimalSize(64, 32), EndContainer(), }; -static WindowDesc _land_info_desc( +static WindowDesc _land_info_desc(__FILE__, __LINE__, WDP_MANUAL, "land_info", 0, 0, WC_LAND_INFO, WC_NONE, 0, - _nested_land_info_widgets, lengthof(_nested_land_info_widgets) + std::begin(_nested_land_info_widgets), std::end(_nested_land_info_widgets) ); class LandInfoWindow : public Window { @@ -43,7 +43,8 @@ class LandInfoWindow : public Window { static const uint LAND_INFO_LINE_BUFF_SIZE = 512; public: - char landinfo_data[LAND_INFO_LINE_END][LAND_INFO_LINE_BUFF_SIZE]; + StringList landinfo_data; ///< Info lines to show. + std::string cargo_acceptance; ///< Centered multi-line string for cargo acceptance. TileIndex tile; TileIndex end_tile; ///< For use in ruler(dragdrop) mode @@ -58,7 +59,7 @@ public: return pt; } - void DrawWidget(const Rect &r, int widget) const override + void DrawWidget(const Rect &r, WidgetID widget) const override { if (widget != WID_LI_BACKGROUND) return; @@ -68,43 +69,38 @@ public: GfxDrawLine(r.right, r.top, r.right, r.bottom, PC_BLACK); Rect ir = r.Shrink(WidgetDimensions::scaled.frametext); - for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) { - if (StrEmpty(this->landinfo_data[i])) break; - + for (size_t i = 0; i < this->landinfo_data.size(); i++) { DrawString(ir, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER); - ir.top += FONT_HEIGHT_NORMAL + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); + ir.top += GetCharacterHeight(FS_NORMAL) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); } - if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) { - SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]); + if (!this->cargo_acceptance.empty()) { + SetDParamStr(0, this->cargo_acceptance); DrawStringMultiLine(ir, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER); } } - void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override { if (widget != WID_LI_BACKGROUND) return; size->height = WidgetDimensions::scaled.frametext.Vertical(); - for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) { - if (StrEmpty(this->landinfo_data[i])) break; - + for (size_t i = 0; i < this->landinfo_data.size(); i++) { uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WidgetDimensions::scaled.frametext.Horizontal(); size->width = std::max(size->width, width); - size->height += FONT_HEIGHT_NORMAL + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); + size->height += GetCharacterHeight(FS_NORMAL) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); } - if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) { - uint width = GetStringBoundingBox(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]).width + WidgetDimensions::scaled.frametext.Horizontal(); - size->width = std::max(size->width, std::min(ScaleGUITrad(300), width)); - SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]); + if (!this->cargo_acceptance.empty()) { + uint width = GetStringBoundingBox(this->cargo_acceptance).width + WidgetDimensions::scaled.frametext.Horizontal(); + size->width = std::max(size->width, std::min(static_cast(ScaleGUITrad(300)), width)); + SetDParamStr(0, cargo_acceptance); size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.frametext.Horizontal()); } } - LandInfoWindow(TileIndex tile, TileIndex end_tile=INVALID_TILE) : - Window(&_land_info_desc), tile(tile), end_tile(end_tile) + LandInfoWindow(Tile tile, Tile end_tile) : Window(&_land_info_desc), tile(tile), end_tile(end_tile) { this->InitNested(); CLRBITS(this->flags, WF_WHITE_BORDER); @@ -114,28 +110,28 @@ public: #else # define LANDINFOD_LEVEL 1 #endif - Debug(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile)); - Debug(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type); - Debug(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height); - Debug(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1); - Debug(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2); - Debug(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3); - Debug(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4); - Debug(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5); - Debug(misc, LANDINFOD_LEVEL, "m6 = %#x", _me[tile].m6); - Debug(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); - Debug(misc, LANDINFOD_LEVEL, "m8 = %#x", _me[tile].m8); + Debug(misc, LANDINFOD_LEVEL, "TILE: 0x{:x} ({},{})", (TileIndex)tile, TileX(tile), TileY(tile)); + Debug(misc, LANDINFOD_LEVEL, "type = 0x{:x}", tile.type()); + Debug(misc, LANDINFOD_LEVEL, "height = 0x{:x}", tile.height()); + Debug(misc, LANDINFOD_LEVEL, "m1 = 0x{:x}", tile.m1()); + Debug(misc, LANDINFOD_LEVEL, "m2 = 0x{:x}", tile.m2()); + Debug(misc, LANDINFOD_LEVEL, "m3 = 0x{:x}", tile.m3()); + Debug(misc, LANDINFOD_LEVEL, "m4 = 0x{:x}", tile.m4()); + Debug(misc, LANDINFOD_LEVEL, "m5 = 0x{:x}", tile.m5()); + Debug(misc, LANDINFOD_LEVEL, "m6 = 0x{:x}", tile.m6()); + Debug(misc, LANDINFOD_LEVEL, "m7 = 0x{:x}", tile.m7()); + Debug(misc, LANDINFOD_LEVEL, "m8 = 0x{:x}", tile.m8()); #undef LANDINFOD_LEVEL } void OnInit() override { - Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); + Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); /* Because build_date is not set yet in every TileDesc, we make sure it is empty */ TileDesc td; - td.build_date = INVALID_DATE; + td.build_date = CalendarTime::INVALID_DATE; /* Most tiles have only one owner, but * - drivethrough roadstops can be build on town owned roads (up to 2 owners) and @@ -161,29 +157,27 @@ public: td.road_speed = 0; td.tramtype = STR_NULL; td.tram_speed = 0; - td.population = 0; + td.cm_population = 0; td.grf = nullptr; - CargoArray acceptance; + CargoArray acceptance{}; AddAcceptedCargo(tile, acceptance, nullptr); GetTileDesc(tile, &td); - uint line_nr = 0; + this->landinfo_data.clear(); /* Tiletype */ - SetDParam(0, td.dparam[0]); - GetString(this->landinfo_data[line_nr], td.str, lastof(this->landinfo_data[line_nr])); - line_nr++; + SetDParam(0, td.dparam); + this->landinfo_data.push_back(GetString(td.str)); /* Up to four owners */ for (uint i = 0; i < 4; i++) { if (td.owner_type[i] == STR_NULL) continue; SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A); - if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) GetNameOfOwner(td.owner[i], tile); - GetString(this->landinfo_data[line_nr], td.owner_type[i], lastof(this->landinfo_data[line_nr])); - line_nr++; + if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) SetDParamsForOwnedBy(td.owner[i], tile); + this->landinfo_data.push_back(GetString(td.owner_type[i])); } /* Cost to clear/revenue when cleared */ @@ -191,7 +185,7 @@ public: Company *c = Company::GetIfValid(_local_company); if (c != nullptr) { assert(_current_company == _local_company); - CommandCost costclear = ::Command::Do(DC_QUERY_COST, tile); + CommandCost costclear = Command::Do(DC_QUERY_COST, tile); if (costclear.Succeeded()) { Money cost = costclear.GetCost(); if (cost < 0) { @@ -203,20 +197,17 @@ public: SetDParam(0, cost); } } - GetString(this->landinfo_data[line_nr], str, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(str)); /* Location */ std::stringstream tile_ss; - tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << tile; // 0x%.4X - std::string tile_str = tile_ss.str(); // Can't pass it directly to SetDParamStr as the string is only a temporary and would be destructed before the GetString call. + tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << tile.base(); // 0x%.4X SetDParam(0, TileX(tile)); SetDParam(1, TileY(tile)); SetDParam(2, GetTileZ(tile)); - SetDParamStr(3, tile_str); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, lastof(this->landinfo_data[line_nr])); - line_nr++; + SetDParamStr(3, tile_ss.str()); + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_COORDS)); /* Local authority */ SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE); @@ -224,143 +215,130 @@ public: SetDParam(0, STR_TOWN_NAME); SetDParam(1, t->index); } - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY)); /* Build date */ - if (td.build_date != INVALID_DATE) { + if (td.build_date != CalendarTime::INVALID_DATE) { SetDParam(0, td.build_date); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_BUILD_DATE, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_BUILD_DATE)); } /* Station class */ if (td.station_class != STR_NULL) { SetDParam(0, td.station_class); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_CLASS, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_STATION_CLASS)); } /* Station type name */ if (td.station_name != STR_NULL) { SetDParam(0, td.station_name); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_TYPE, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_STATION_TYPE)); } /* Airport class */ if (td.airport_class != STR_NULL) { SetDParam(0, td.airport_class); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_CLASS, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORT_CLASS)); } /* Airport name */ if (td.airport_name != STR_NULL) { SetDParam(0, td.airport_name); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_NAME, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORT_NAME)); } /* Airport tile name */ if (td.airport_tile_name != STR_NULL) { SetDParam(0, td.airport_tile_name); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME)); } /* Rail type name */ if (td.railtype != STR_NULL) { SetDParam(0, td.railtype); - GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_TYPE, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_TYPE)); } /* Rail speed limit */ if (td.rail_speed != 0) { - SetDParam(0, td.rail_speed); - GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, lastof(this->landinfo_data[line_nr])); - line_nr++; + SetDParam(0, PackVelocity(td.rail_speed, VEH_TRAIN)); + this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT)); } /* Road type name */ if (td.roadtype != STR_NULL) { SetDParam(0, td.roadtype); - GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_ROAD_TYPE, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_TYPE)); } /* Road speed limit */ if (td.road_speed != 0) { - SetDParam(0, td.road_speed); - GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, lastof(this->landinfo_data[line_nr])); - line_nr++; + SetDParam(0, PackVelocity(td.road_speed, VEH_ROAD)); + this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT)); } /* Tram type name */ if (td.tramtype != STR_NULL) { SetDParam(0, td.tramtype); - GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_TRAM_TYPE, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_TYPE)); } /* Tram speed limit */ if (td.tram_speed != 0) { - SetDParam(0, td.tram_speed); - GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_TRAM_SPEED_LIMIT, lastof(this->landinfo_data[line_nr])); - line_nr++; + SetDParam(0, PackVelocity(td.tram_speed, VEH_ROAD)); + this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_SPEED_LIMIT)); } /* NewGRF name */ if (td.grf != nullptr) { SetDParamStr(0, td.grf); - GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_NEWGRF_NAME, lastof(this->landinfo_data[line_nr])); - line_nr++; + this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_NEWGRF_NAME)); } - /* House pop */ - if (td.population != 0) { - SetDParam(0, td.population); - GetString(this->landinfo_data[line_nr], CM_STR_LAND_AREA_INFORMATION_POP, lastof(this->landinfo_data[line_nr])); - line_nr++; + /* CityMania code start (House pop) */ + if (td.cm_population != 0) { + SetDParam(0, td.cm_population); + this->landinfo_data.push_back(GetString(CM_STR_LAND_AREA_INFORMATION_POP)); } - - assert(line_nr < LAND_INFO_CENTERED_LINES); - - /* Mark last line empty */ - this->landinfo_data[line_nr][0] = '\0'; + /* CityMania code end */ /* Cargo acceptance is displayed in a extra multiline */ - char *strp = GetString(this->landinfo_data[LAND_INFO_MULTICENTER_LINE], STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])); - bool found = false; + std::stringstream line; + line << GetString(STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED); - for (CargoID i = 0; i < NUM_CARGO; ++i) { - if (acceptance[i] > 0) { + bool found = false; + for (const CargoSpec *cs : _sorted_cargo_specs) { + CargoID cid = cs->Index(); + if (acceptance[cid] > 0) { /* Add a comma between each item. */ - if (found) strp = strecpy(strp, ", ", lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])); + if (found) line << ", "; found = true; /* If the accepted value is less than 8, show it in 1/8:ths */ - if (acceptance[i] < 8) { - SetDParam(0, acceptance[i]); - SetDParam(1, CargoSpec::Get(i)->name); - strp = GetString(strp, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])); + if (acceptance[cid] < 8) { + SetDParam(0, acceptance[cid]); + SetDParam(1, cs->name); + line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS); } else { - strp = GetString(strp, CargoSpec::Get(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])); + line << GetString(cs->name); } } } - if (!found) this->landinfo_data[LAND_INFO_MULTICENTER_LINE][0] = '\0'; + if (found) { + this->cargo_acceptance = line.str(); + } else { + this->cargo_acceptance.clear(); + } } bool IsNewGRFInspectable() const override { - return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile); + return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile.base()); } void ShowNewGRFInspectWindow() const override { - ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile); + ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile.base()); } /** @@ -368,15 +346,12 @@ 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. */ - void OnInvalidateData(int data = 0, bool gui_scope = true) override + void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override { if (!gui_scope) return; - switch (data) { - case 1: - /* ReInit, "debug" sprite might have changed */ - this->ReInit(); - break; - } + + /* ReInit, "debug" sprite might have changed */ + if (data == 1) this->ReInit(); } }; diff --git a/src/citymania/cm_station_gui.cpp b/src/citymania/cm_station_gui.cpp index 733875b762..56d26fae03 100644 --- a/src/citymania/cm_station_gui.cpp +++ b/src/citymania/cm_station_gui.cpp @@ -54,6 +54,15 @@ struct RailStationGUISettings { }; extern RailStationGUISettings _railstation; //rail_gui.cpp +struct RoadStopGUISettings { + DiagDirection orientation; + + RoadStopClassID roadstop_class; + uint16_t roadstop_type; + uint16_t roadstop_count; +}; +extern RoadStopGUISettings _roadstop_gui_settings; + namespace citymania { StationBuildingStatus _station_building_status = StationBuildingStatus::NEW; @@ -106,8 +115,8 @@ static void UpdateHiglightJoinArea(const Station *station) { TileArea ta( TileXY(std::max(r.right - d, 0), std::max(r.bottom - d, 0)), - TileXY(std::min(r.left + d, MapSizeX() - 1), - std::min(r.top + d, MapSizeY() - 1)) + TileXY(std::min(r.left + d, Map::SizeX() - 1), + std::min(r.top + d, Map::SizeY() - 1)) ); if (_highlight_join_area.tile == ta.tile && _highlight_join_area.w == ta.w && @@ -344,6 +353,8 @@ void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_t bool drive_through = (ddir >= DIAGDIR_END); if (drive_through) ddir = static_cast(ddir - DIAGDIR_END); // Adjust picker result to actual direction. + RoadStopClassID spec_class = _roadstop_gui_settings.roadstop_class; + uint16_t spec_index = _roadstop_gui_settings.roadstop_type; auto c = cmd::BuildRoadStop( ta.tile, @@ -353,6 +364,8 @@ void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_t drive_through, static_cast(ddir), rt, + spec_class, + spec_index, INVALID_STATION, adjacent ); @@ -439,7 +452,7 @@ static void FindStationsAroundSelection(const TileArea &location) int x = TileX(location.tile); int y = TileY(location.tile); - TileArea ta(TileXY(std::max(0, x - 1), std::max(0, y - 1)), TileXY(std::min(MapMaxX() - 1, x + location.w + 1), std::min(MapMaxY() - 1, y + location.h + 1))); + TileArea ta(TileXY(std::max(0, x - 1), std::max(0, y - 1)), TileXY(std::min(Map::MaxX() - 1, x + location.w + 1), std::min(Map::MaxY() - 1, y + location.h + 1))); Station *adjacent = nullptr; @@ -512,7 +525,7 @@ void AbortStationPlacement() { uint GetMonthlyFrom256Tick(uint amount) { - return ((amount * DAY_TICKS * 30) >> 8); + return ((amount * Ticks::DAY_TICKS * EconomyTime::DAYS_IN_ECONOMY_MONTH) >> 8); } uint GetAverageHouseProduction(byte amount) { @@ -604,9 +617,9 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad) /* Skip industry with neutral station */ if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) continue; - for (uint j = 0; j < lengthof(i->produced_cargo); j++) { - CargoID cargo = i->produced_cargo[j]; - if (cargo != CT_INVALID) produced[cargo] += ((uint)i->last_month_production[j]) << 8; + for (auto &p : i->produced) { + CargoID cargo = p.cargo; + if (cargo != CT_INVALID) produced[p.cargo] += ((uint)p.history[LAST_MONTH].production) << 8; } } @@ -617,9 +630,7 @@ std::string GetStationCoverageProductionText(TileIndex tile, int w, int h, int r auto production = citymania::GetProductionAroundTiles(tile, w, h, rad); std::ostringstream s; - char buffer[DRAW_STRING_BUFFER]; - GetString(buffer, CM_STR_STATION_BUILD_SUPPLIES, lastof(buffer)); - s << buffer; + s << GetString(CM_STR_STATION_BUILD_SUPPLIES); bool first = true; for (CargoID i = 0; i < NUM_CARGO; i++) { switch (sct) { @@ -634,8 +645,7 @@ std::string GetStationCoverageProductionText(TileIndex tile, int w, int h, int r SetDParam(0, i); SetDParam(1, production[i] >> 8); // GetString(buffer, CM_STR_STATION_BUILD_SUPPLIES_CARGO, lastof(buffer)); - GetString(buffer, STR_JUST_CARGO, lastof(buffer)); - s << buffer; + s << GetString(STR_JUST_CARGO); } return s.str(); } diff --git a/src/citymania/cm_tooltips.cpp b/src/citymania/cm_tooltips.cpp index b37d9e88d4..235df1872a 100644 --- a/src/citymania/cm_tooltips.cpp +++ b/src/citymania/cm_tooltips.cpp @@ -28,11 +28,11 @@ static const NWidgetPart _nested_land_tooltips_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY, 0), SetMinimalSize(64, 32), EndContainer(), }; -static WindowDesc _land_tooltips_desc( - WDP_MANUAL, NULL, 0, 0, +static WindowDesc _land_tooltips_desc(__FILE__, __LINE__, + WDP_MANUAL, nullptr, 0, 0, CM_WC_LAND_TOOLTIPS, WC_NONE, 0, - _nested_land_tooltips_widgets, lengthof(_nested_land_tooltips_widgets) + std::begin(_nested_land_tooltips_widgets), std::end(_nested_land_tooltips_widgets) ); @@ -66,11 +66,11 @@ struct LandTooltipsWindow : public Window virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { uint icon_size = ScaleGUITrad(10); - uint line_height = std::max((uint)FONT_HEIGHT_NORMAL, icon_size) + WidgetDimensions::scaled.hsep_normal; - uint text_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.hsep_normal; + uint line_height = std::max((uint)GetCharacterHeight(FS_NORMAL), icon_size) + WidgetDimensions::scaled.hsep_normal; + uint text_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.hsep_normal; uint icons_width = icon_size * 3 + WidgetDimensions::scaled.vsep_normal; size->width = ScaleGUITrad(194); - size->height = FONT_HEIGHT_NORMAL; + size->height = GetCharacterHeight(FS_NORMAL); switch(this->tiletype) { case MP_HOUSE: { const HouseSpec *hs = HouseSpec::Get((HouseID)this->objIndex); @@ -89,15 +89,15 @@ struct LandTooltipsWindow : public Window SetDParam(0, ind->index); size->width = std::max(GetStringBoundingBox(CM_STR_LAND_TOOLTIPS_INDUSTRY_NAME).width, size->width); - for (CargoID i = 0; i < lengthof(ind->produced_cargo); i++) { - if (ind->produced_cargo[i] == CT_INVALID) continue; - const CargoSpec *cs = CargoSpec::Get(ind->produced_cargo[i]); + for (auto &p : ind->produced) { + if (p.cargo == CT_INVALID) continue; + const CargoSpec *cs = CargoSpec::Get(p.cargo); if(cs == NULL) continue; size->height += line_height; SetDParam(0, cs->name); SetDParam(1, cs->Index()); - SetDParam(2, ind->last_month_production[i]); - SetDParam(3, ToPercent8(ind->last_month_pct_transported[i])); + SetDParam(2, p.history[LAST_MONTH].production); + SetDParam(3, ToPercent8(p.history[LAST_MONTH].PctTransported())); size->width = std::max(GetStringBoundingBox(CM_STR_LAND_TOOLTIPS_INDUSTRY_CARGO).width + icons_width, size->width); } break; @@ -132,10 +132,10 @@ struct LandTooltipsWindow : public Window virtual void DrawWidget(const Rect &r, int widget) const { uint icon_size = ScaleGUITrad(10); - uint line_height = std::max((uint)FONT_HEIGHT_NORMAL, icon_size) + WidgetDimensions::scaled.hsep_normal; - uint text_height = FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.hsep_normal; + uint line_height = std::max((uint)GetCharacterHeight(FS_NORMAL), icon_size) + WidgetDimensions::scaled.hsep_normal; + uint text_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.hsep_normal; uint icons_width = icon_size * 3 + WidgetDimensions::scaled.vsep_normal; - uint text_ofs = (line_height - FONT_HEIGHT_NORMAL) >> 1; + uint text_ofs = (line_height - GetCharacterHeight(FS_NORMAL)) >> 1; uint icon_ofs = (line_height - icon_size) >> 1; GfxFillRect(r.left, r.top, r.right, r.top + WidgetDimensions::scaled.bevel.top - 1, PC_BLACK); @@ -164,14 +164,14 @@ struct LandTooltipsWindow : public Window DrawString(ir, CM_STR_LAND_TOOLTIPS_INDUSTRY_NAME, TC_BLACK, SA_CENTER); ir.top += text_height; - for (CargoID i = 0; i < lengthof(ind->produced_cargo); i++) { - if (ind->produced_cargo[i] == CT_INVALID) continue; - const CargoSpec *cs = CargoSpec::Get(ind->produced_cargo[i]); + for (auto &p : ind->produced) { + if (p.cargo == CT_INVALID) continue; + const CargoSpec *cs = CargoSpec::Get(p.cargo); if(cs == NULL) continue; SetDParam(0, cs->name); SetDParam(1, cs->Index()); - SetDParam(2, ind->last_month_production[i]); - SetDParam(3, ToPercent8(ind->last_month_pct_transported[i])); + SetDParam(2, p.history[LAST_MONTH].production); + SetDParam(3, ToPercent8(p.history[LAST_MONTH].PctTransported())); this->DrawSpriteIcons(cs->GetCargoIcon(), ir.left, ir.top + icon_ofs); DrawString(ir.left + icons_width, ir.right, ir.top + text_ofs, CM_STR_LAND_TOOLTIPS_INDUSTRY_CARGO); @@ -264,11 +264,11 @@ static const NWidgetPart _nested_station_rating_tooltip_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY, 0), SetMinimalSize(64, 32), EndContainer(), }; -static WindowDesc _station_rating_tooltip_desc( +static WindowDesc _station_rating_tooltip_desc(__FILE__, __LINE__, WDP_MANUAL, NULL, 0, 0, WC_STATION_RATING_TOOLTIP, WC_NONE, 0, - _nested_station_rating_tooltip_widgets, lengthof(_nested_station_rating_tooltip_widgets) + std::begin(_nested_station_rating_tooltip_widgets), std::end(_nested_station_rating_tooltip_widgets) ); static const int STATION_RATING_AGE[] = {0, 10, 20, 33}; @@ -285,12 +285,10 @@ struct StationRatingTooltipWindow : public Window const CargoSpec *cs; bool newgrf_rating_used; - static const uint RATING_TOOLTIP_LINE_BUFF_SIZE = 512; - static const uint RATING_TOOLTIP_MAX_LINES = 8; static const uint RATING_TOOLTIP_NEWGRF_INDENT = 20; public: - char data[RATING_TOOLTIP_MAX_LINES + 1][RATING_TOOLTIP_LINE_BUFF_SIZE]; + std::vector data; StationRatingTooltipWindow(Window *parent, const Station *st, const CargoSpec *cs, TooltipCloseCondition close_cond) : Window(&_station_rating_tooltip_desc) { @@ -318,14 +316,12 @@ public: } void OnInit() override { + this->data.clear(); const GoodsEntry *ge = &this->st->goods[this->cs->Index()]; SetDParam(0, this->cs->name); - GetString(this->data[0], CM_STR_STATION_RATING_TOOLTIP_RATING_DETAILS, lastof(this->data[0])); - if (!ge->HasRating()) { - this->data[1][0] = '\0'; - return; - } + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_RATING_DETAILS)); + if (!ge->HasRating()) { return; } uint line_nr = 1; int total_rating = 0; @@ -349,20 +345,16 @@ public: SetDParam(0, CM_STR_STATION_RATING_TOOLTIP_NEWGRF_RATING_0 + (newgrf_rating <= 0 ? 0 : 1)); SetDParam(1, newgrf_rating); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_NEWGRF_RATING, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_NEWGRF_RATING)); SetDParam(0, std::min(last_speed, 0xFF)); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_NEWGRF_SPEED, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_NEWGRF_SPEED)); SetDParam(0, std::min(ge->max_waiting_cargo, 0xFFFF)); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_NEWGRF_WAITUNITS, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_NEWGRF_WAITUNITS)); SetDParam(0, (std::min(ge->time_since_pickup, 0xFF) * 5 + 1) / 2); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_NEWGRF_WAITTIME, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_NEWGRF_WAITTIME)); } } @@ -381,8 +373,7 @@ public: SetDParam(0, CM_STR_STATION_RATING_TOOLTIP_WAITTIME_0 + waittime_stage); SetDParam(1, (ge->time_since_pickup * 5 + 1) / 2); SetDParam(2, this->RoundRating(STATION_RATING_WAITTIME[waittime_stage])); - GetString(this->data[line_nr], this->st->last_vehicle_type == VEH_SHIP ? CM_STR_STATION_RATING_TOOLTIP_WAITTIME_SHIP : CM_STR_STATION_RATING_TOOLTIP_WAITTIME, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(this->st->last_vehicle_type == VEH_SHIP ? CM_STR_STATION_RATING_TOOLTIP_WAITTIME_SHIP : CM_STR_STATION_RATING_TOOLTIP_WAITTIME)); uint waitunits = ge->max_waiting_cargo; int waitunits_stage = 0; @@ -397,8 +388,7 @@ public: SetDParam(0, CM_STR_STATION_RATING_TOOLTIP_WAITUNITS_0 + waitunits_stage); SetDParam(1, ge->max_waiting_cargo); SetDParam(2, this->RoundRating(STATION_RATING_WAITUNITS[waitunits_stage])); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_WAITUNITS, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_WAITUNITS)); int b = ge->last_speed - 85; int r_speed = b >= 0 ? b >> 2 : 0; @@ -414,8 +404,7 @@ public: SetDParam(0, ge->last_speed == 255 ? CM_STR_STATION_RATING_TOOLTIP_SPEED_MAX : CM_STR_STATION_RATING_TOOLTIP_SPEED_0 + r_speed / 11); SetDParam(1, ge->last_speed); SetDParam(2, r_speed_round); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_SPEED, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_SPEED)); } int age_stage = (ge->last_age >= 3 ? 0 : 3 - ge->last_age); @@ -423,8 +412,7 @@ public: SetDParam(0, CM_STR_STATION_RATING_TOOLTIP_AGE_0 + age_stage); SetDParam(1, ge->last_age); SetDParam(2, this->RoundRating(STATION_RATING_AGE[age_stage])); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_AGE, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_AGE)); if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) { SetDParam(0, CM_STR_STATION_RATING_TOOLTIP_STATUE_YES); @@ -432,27 +420,21 @@ public: } else { SetDParam(0, CM_STR_STATION_RATING_TOOLTIP_STATUE_NO); } - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_STATUE, lastof(this->data[line_nr])); - line_nr++; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_STATUE)); SetDParam(0, ToPercent8(Clamp(total_rating, 0, 255))); - GetString(this->data[line_nr], CM_STR_STATION_RATING_TOOLTIP_TOTAL_RATING, lastof(this->data[line_nr])); - line_nr++; - - this->data[line_nr][0] = '\0'; + this->data.push_back(GetString(CM_STR_STATION_RATING_TOOLTIP_TOTAL_RATING)); } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override { size->height = WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.fullbevel.Vertical(); - for (uint i = 0; i <= RATING_TOOLTIP_MAX_LINES; i++) { - if (StrEmpty(this->data[i])) break; - + for (uint i = 0; i < data.size(); i++) { uint width = GetStringBoundingBox(this->data[i]).width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.fullbevel.Horizontal(); if (this->newgrf_rating_used && i >= 2 && i <= 4) width += RATING_TOOLTIP_NEWGRF_INDENT; size->width = std::max(size->width, width); - size->height += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.hsep_normal; + size->height += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.hsep_normal; } size->height -= WidgetDimensions::scaled.hsep_normal; } @@ -467,12 +449,11 @@ public: auto ir = r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.bevel); DrawString(ir, this->data[0], TC_LIGHT_BLUE, SA_CENTER); - ir.top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal; - for (uint i = 1; i <= RATING_TOOLTIP_MAX_LINES; i++) { - if (StrEmpty(this->data[i])) break; + ir.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; + for (uint i = 1; i < data.size(); i++) { auto indent = (this->newgrf_rating_used && i >= 2 && i <= 4 ? RATING_TOOLTIP_NEWGRF_INDENT : 0); DrawString(ir.Indent(indent, _current_text_dir == TD_RTL), this->data[i], TC_BLACK); - ir.top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal; + ir.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; } } diff --git a/src/citymania/cm_watch_gui.cpp b/src/citymania/cm_watch_gui.cpp index aeccc0403b..5b9891b096 100644 --- a/src/citymania/cm_watch_gui.cpp +++ b/src/citymania/cm_watch_gui.cpp @@ -40,56 +40,55 @@ namespace citymania { * @return Horizontal container with butons columns. * @post \c *biggest_index contains the largest used index in the tree. */ -static NWidgetBase *MakeCompanyButtons(int *biggest_index) -{ - NWidgetHorizontal *widget_container_horiz = NULL; // Storage for all cols. - NWidgetVertical *widget_container_company = NULL; // Storage for company Col. - NWidgetVertical *widget_container_hasclient = NULL; // Storage for Has Client Blot. - // NWidgetVertical *widget_container_activity = NULL; // Storage for Activity Blot. +// static static std::unique_ptr MakeCompanyButtons() +// { +// NWidgetHorizontal *widget_container_horiz = NULL; +// NWidgetVertical *widget_container_company = NULL; +// NWidgetVertical *widget_container_hasclient = NULL; - widget_container_horiz = new NWidgetHorizontal( ); - widget_container_company = new NWidgetVertical( ); - widget_container_hasclient = new NWidgetVertical( ); - // widget_container_activity = new NWidgetVertical( ); +// auto widget_container_horiz = std::make_unique(); // Storage for all cols. +// auto widget_container_company = std::make_unique(); // Storage for company Col. +// auto widget_container_hasclient = std::make_unique(); // Storage for Has Client Blot. +// // NWidgetVertical *widget_container_activity = NULL; // Storage for Activity Blot. +// // widget_container_activity = new NWidgetVertical( ); - Dimension company_sprite_size = GetSpriteSize( SPR_COMPANY_ICON ); - company_sprite_size.width += WidgetDimensions::scaled.matrix.Horizontal(); - company_sprite_size.height += WidgetDimensions::scaled.matrix.Vertical() + 1; // 1 for the 'offset' of being pressed +// Dimension company_sprite_size = GetSpriteSize( SPR_COMPANY_ICON ); +// company_sprite_size.width += WidgetDimensions::scaled.matrix.Horizontal(); +// company_sprite_size.height += WidgetDimensions::scaled.matrix.Vertical() + 1; // 1 for the 'offset' of being pressed - Dimension blot_sprite_size = GetSpriteSize( SPR_BLOT ); - blot_sprite_size.width += WidgetDimensions::scaled.matrix.Horizontal(); - blot_sprite_size.height += WidgetDimensions::scaled.matrix.Vertical() + 1; // 1 for the 'offset' of being pressed +// Dimension blot_sprite_size = GetSpriteSize( SPR_BLOT ); +// blot_sprite_size.width += WidgetDimensions::scaled.matrix.Horizontal(); +// blot_sprite_size.height += WidgetDimensions::scaled.matrix.Vertical() + 1; // 1 for the 'offset' of being pressed - for (int company_num = COMPANY_FIRST; company_num < MAX_COMPANIES; company_num++ ) { - /* Manage Company Buttons */ - NWidgetBackground *company_panel = new NWidgetBackground( WWT_PANEL, COLOUR_GREY, EWW_PB_COMPANY_FIRST + company_num ); - company_panel->SetMinimalSizeAbsolute( company_sprite_size.width, company_sprite_size.height ); - company_panel->SetResize( 0, 0 ); - company_panel->SetFill( 1, 0 ); - company_panel->SetDataTip( 0x0, CM_STR_WATCH_CLICK_TO_WATCH_COMPANY ); - widget_container_company->Add( company_panel ); +// for (int company_num = COMPANY_FIRST; company_num < MAX_COMPANIES; company_num++ ) { +// /* Manage Company Buttons */ +// auto company_panel = std::make_unique( WWT_PANEL, COLOUR_GREY, EWW_PB_COMPANY_FIRST + company_num ); +// company_panel->SetMinimalSizeAbsolute(company_sprite_size.width, company_sprite_size.height); +// company_panel->SetResize( 0, 0 ); +// company_panel->SetFill( 1, 0 ); +// company_panel->SetDataTip( 0x0, CM_STR_WATCH_CLICK_TO_WATCH_COMPANY ); +// widget_container_company->Add(std::move(company_panel)); - /* Manage Has Client Blot */ +// /* Manage Has Client Blot */ - NWidgetBackground *hasclient_panel = new NWidgetBackground( WWT_PANEL, COLOUR_GREY, EWW_HAS_CLIENT_FIRST + company_num ); - company_panel->SetMinimalSizeAbsolute( blot_sprite_size.width, blot_sprite_size.height ); - company_panel->SetResize( 0, 0 ); - company_panel->SetFill( 1, 0 ); - widget_container_hasclient->Add( hasclient_panel ); - } +// auto hasclient_panel = std::make_unique(WWT_PANEL, COLOUR_GREY, EWW_HAS_CLIENT_FIRST + company_num); +// company_panel->SetMinimalSizeAbsolute( blot_sprite_size.width, blot_sprite_size.height ); +// company_panel->SetResize( 0, 0 ); +// company_panel->SetFill( 1, 0 ); +// widget_container_hasclient->Add(std::move(hasclient_panel)); +// } - /* Add the verticals widgets to the horizontal container */ - widget_container_horiz->Add( widget_container_company ); - widget_container_horiz->Add( widget_container_hasclient ); +// /* Add the verticals widgets to the horizontal container */ +// widget_container_horiz->Add(std::move(widget_container_company)); +// widget_container_horiz->Add(std::move(widget_container_hasclient)); - /* return the horizontal widget container */ - return widget_container_horiz; -} +// /* return the horizontal widget container */ +// return widget_container_horiz; +// } -static NWidgetBase *MakeCompanyButtons2(int *biggest_index) -{ - NWidgetHorizontal *widget_container_horiz = new NWidgetHorizontal(); +static std::unique_ptr MakeCompanyButtons2() { + auto widget_container_horiz = std::make_unique(); Dimension company_sprite_size = GetSpriteSize(CM_SPR_COMPANY_ICON); company_sprite_size.width += WidgetDimensions::scaled.matrix.Horizontal(); @@ -97,12 +96,12 @@ static NWidgetBase *MakeCompanyButtons2(int *biggest_index) // for (const Company *c : Company::Iterate()) { for (int widnum = EWW_COMPANY_BEGIN; widnum < EWW_COMPANY_END; widnum++) { - NWidgetBackground *company_panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum); + auto company_panel = std::make_unique(WWT_PANEL, COLOUR_GREY, widnum); company_panel->SetMinimalSizeAbsolute(company_sprite_size.width, company_sprite_size.height); company_panel->SetResize(1, 0); company_panel->SetFill(1, 1); company_panel->SetDataTip(0, CM_STR_WATCH_CLICK_TO_WATCH_COMPANY); - widget_container_horiz->Add(company_panel); + widget_container_horiz->Add(std::move(company_panel)); } // auto filler = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, EWW_COMPANY_FILLER); @@ -113,8 +112,6 @@ static NWidgetBase *MakeCompanyButtons2(int *biggest_index) // filler->SetDataTip(0, 0); // widget_container_horiz->Add(filler); - *biggest_index = EWW_COMPANY_FILLER + 1; - return widget_container_horiz; } @@ -162,11 +159,11 @@ static const NWidgetPart _nested_watch_company_widgets[] = { /** * Watch Company Window Descriptor */ -static WindowDesc _watch_company_desc( +static WindowDesc _watch_company_desc(__FILE__, __LINE__, WDP_AUTO, "watch_gui", 300, 257, WC_WATCH_COMPANY, WC_NONE, WDF_NO_FOCUS, - _nested_watch_company_widgets, lengthof( _nested_watch_company_widgets ) + std::begin(_nested_watch_company_widgets), std::end( _nested_watch_company_widgets ) ); // admin version @@ -226,11 +223,11 @@ static const NWidgetPart _nested_watch_company_widgetsA[] = { /** * Watch Company Window Descriptor */ -static WindowDesc _watch_company_descA( +static WindowDesc _watch_company_descA(__FILE__, __LINE__, WDP_AUTO, "watch_gui_client", 448, 256, WC_WATCH_COMPANYA, WC_NONE, WDF_CONSTRUCTION, - _nested_watch_company_widgetsA, lengthof(_nested_watch_company_widgetsA) + std::begin(_nested_watch_company_widgetsA), std::end(_nested_watch_company_widgetsA) ); static void ResetCallback(Window *w, bool confirmed) @@ -238,9 +235,7 @@ static void ResetCallback(Window *w, bool confirmed) if (confirmed) { NetworkClientInfo *ci = NetworkClientInfo::GetByClientID((ClientID)w->window_number); if (ci && ci->client_playas != INVALID_COMPANY) { - char msg[16]; - seprintf(msg, lastof(msg), "!reset %i", ci->client_playas + 1); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer(fmt::format("!reset {}", ci->client_playas + 1)); } } } @@ -274,7 +269,7 @@ WatchCompany::WatchCompany(WindowDesc *desc, int window_number, CompanyID compan this->company_count_client[i] = 0; } - GetString( this->company_name, STR_JUST_NOTHING, lastof(this->company_name) ); + this->company_name = GetString(STR_JUST_NOTHING); } /* Init the viewport area */ NWidgetViewport *nvp = this->GetWidget(EWW_WATCH); @@ -424,7 +419,7 @@ void WatchCompany::OnClick(Point pt, int widget, int click_count) this->watched_company = c->index; this->LowerWidget(widget); SetDParam(0, c->index); - GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name)); + this->company_name = GetString(STR_COMPANY_NAME); this->ScrollToTile(c->last_build_coordinate); } this->owner = this->watched_company; @@ -446,14 +441,14 @@ void WatchCompany::OnClick(Point pt, int widget, int click_count) if (this->watched_company == (CompanyID)(widget - EWW_PB_COMPANY_FIRST)) { /* Stop watching watched_company */ this->watched_company = INVALID_COMPANY; - GetString( this->company_name, STR_JUST_NOTHING, lastof(this->company_name) ); + this->company_name = GetString(STR_JUST_NOTHING); } else { /* Lower the new watched company button */ this->watched_company = (CompanyID)(widget - EWW_PB_COMPANY_FIRST); this->LowerWidget(this->watched_company + EWW_PB_COMPANY_FIRST); Company *c = Company::Get( this->watched_company ); SetDParam( 0, c->index ); - GetString( this->company_name, STR_COMPANY_NAME, lastof(this->company_name) ); + this->company_name = GetString(STR_COMPANY_NAME); this->ScrollToTile( c->last_build_coordinate ); } @@ -491,20 +486,16 @@ void WatchCompany::OnClick(Point pt, int widget, int click_count) break; case EWW_LOCK: case EWW_UNLOCK: - seprintf(msg, lastof(msg), "!lockp %i", this->watched_company + 1); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer(fmt::format("!lockp {}", this->watched_company + 1)); break; case EWW_KICK: - seprintf(msg, lastof(msg), "!kick %i", this->watched_client); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer(fmt::format("!kick {}", this->watched_client)); break; case EWW_KICKC: - seprintf(msg, lastof(msg), "!move %i %i", this->watched_client, COMPANY_SPECTATOR); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer(fmt::format("!move {} {}", this->watched_client, COMPANY_SPECTATOR)); break; case EWW_JOIN: - seprintf(msg, lastof(msg), "!move %i", this->watched_company + 1); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer(fmt::format("!move {}", this->watched_company + 1)); break; case EWW_BAN: this->query_widget = EWQ_BAN; @@ -522,8 +513,7 @@ void WatchCompany::OnClick(Point pt, int widget, int click_count) ShowNetworkChatQueryWindow(DESTTYPE_TEAM, this->watched_company); break; case EWW_CLIENTS: - seprintf(msg, lastof(msg), "!clients"); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer("!clients"); break; case EWW_COMPANYW: if(this->watched_company != INVALID_COMPANY) ShowCompany(this->watched_company); @@ -544,8 +534,7 @@ void WatchCompany::OnQueryTextFinished(char *str) char msg[128]; switch (this->query_widget) { case EWQ_BAN: - seprintf(msg, lastof(msg), "!ban %i %s", this->watched_client, str); - NetworkClientSendChatToServer(msg); + NetworkClientSendChatToServer(fmt::format("!ban {} {}", this->watched_client, str)); break; default: break; diff --git a/src/citymania/cm_watch_gui.hpp b/src/citymania/cm_watch_gui.hpp index 16926bc649..7b5de51cca 100644 --- a/src/citymania/cm_watch_gui.hpp +++ b/src/citymania/cm_watch_gui.hpp @@ -63,8 +63,8 @@ protected: CompanyID watched_company; // Company ID beeing watched. int company_activity[MAX_COMPANIES]; // int array for activity blot. int company_count_client[MAX_COMPANIES]; // company client count. - char company_name[MAX_LENGTH_COMPANY_NAME_CHARS]; // company name for title display - char client_name[NETWORK_CLIENT_NAME_LENGTH]; + std::string company_name; // company name for title display + std::string client_name; int watched_client; WatchCompanyQuery query_widget; diff --git a/src/citymania/cm_zoning_cmd.cpp b/src/citymania/cm_zoning_cmd.cpp index de55c3a100..8b67f4f542 100644 --- a/src/citymania/cm_zoning_cmd.cpp +++ b/src/citymania/cm_zoning_cmd.cpp @@ -98,7 +98,7 @@ Town *CMClosestTownFromTile(TileIndex tile, uint threshold) return town; } - FALLTHROUGH; + [[ fallthrough ]]; case MP_HOUSE: return Town::GetByTile(tile); @@ -402,7 +402,7 @@ SpriteID GetTownZoneBorderColor(uint8 zone) { void DrawTileZoning(const TileInfo *ti) { if(_zoning.outer == CHECKNOTHING && _zoning.inner == CHECKNOTHING) return; //nothing to do - if (_game_mode != GM_NORMAL || ti->tile >= MapSize() || IsTileType(ti->tile, MP_VOID)) return; //check invalid + if (_game_mode != GM_NORMAL || ti->tile >= Map::Size() || IsTileType(ti->tile, MP_VOID)) return; //check invalid if (_zoning.outer != CHECKNOTHING){ if (_zoning.outer == CHECKTOWNZONES || _zoning.outer == CHECKBULUNSER || diff --git a/src/citymania/cm_zoning_gui.cpp b/src/citymania/cm_zoning_gui.cpp index 15833c8be3..7a70fda1f2 100644 --- a/src/citymania/cm_zoning_gui.cpp +++ b/src/citymania/cm_zoning_gui.cpp @@ -126,57 +126,50 @@ struct ZoningWindow : public Window { return Window::OnHotkey(hotkey); } - static HotkeyList hotkeys; + static EventState ZoningWindowGlobalHotkeys(int hotkey) { + EvaluationMode zoning = (EvaluationMode)(hotkey - ZTW_OUTER_FIRST); // +1:skip CHECKNOTHING + bool deselect = (_zoning.outer == zoning); + _zoning.outer = deselect ? CHECKNOTHING : zoning; + MarkWholeScreenDirty(); + return ES_HANDLED; + } + + static inline HotkeyList hotkeys{"zoning_gui", { + Hotkey(WKC_SHIFT | '1', "authority", ZTW_OUTER_FIRST + CHECKOPINION), + Hotkey(WKC_SHIFT | '2', "build_status", ZTW_OUTER_FIRST + CHECKBUILD), + Hotkey(WKC_SHIFT | '3', "station_catchment", ZTW_OUTER_FIRST + CHECKSTACATCH), + Hotkey(WKC_SHIFT | '4', "unserved_buildings", ZTW_OUTER_FIRST + CHECKBULUNSER), + Hotkey(WKC_SHIFT | '5', "unserved_industries", ZTW_OUTER_FIRST + CHECKINDUNSER), + Hotkey(WKC_SHIFT | '6', "town_zone", ZTW_OUTER_FIRST + CHECKTOWNZONES), + Hotkey(WKC_SHIFT | '7', "cb_acceptance", ZTW_OUTER_FIRST + CHECKCBACCEPTANCE), + Hotkey(WKC_SHIFT | '8', "cb_town_limit", ZTW_OUTER_FIRST + CHECKCBTOWNLIMIT), + Hotkey(WKC_SHIFT | '9', "advertisement", ZTW_OUTER_FIRST + CHECKTOWNADZONES), + Hotkey(WKC_SHIFT | '0', "growth_tiles", ZTW_OUTER_FIRST + CHECKTOWNGROWTHTILES), + Hotkey((uint16)0, "active_stations", ZTW_OUTER_FIRST + CHECKACTIVESTATIONS) + }, ZoningWindowGlobalHotkeys}; }; -static EventState ZoningWindowGlobalHotkeys(int hotkey) { - EvaluationMode zoning = (EvaluationMode)(hotkey - ZTW_OUTER_FIRST); // +1:skip CHECKNOTHING - bool deselect = (_zoning.outer == zoning); - _zoning.outer = deselect ? CHECKNOTHING : zoning; - MarkWholeScreenDirty(); - return ES_HANDLED; -} - -static Hotkey zoning_hotkeys[] = { - Hotkey(WKC_SHIFT | '1', "authority", ZTW_OUTER_FIRST + CHECKOPINION), - Hotkey(WKC_SHIFT | '2', "build_status", ZTW_OUTER_FIRST + CHECKBUILD), - Hotkey(WKC_SHIFT | '3', "station_catchment", ZTW_OUTER_FIRST + CHECKSTACATCH), - Hotkey(WKC_SHIFT | '4', "unserved_buildings", ZTW_OUTER_FIRST + CHECKBULUNSER), - Hotkey(WKC_SHIFT | '5', "unserved_industries", ZTW_OUTER_FIRST + CHECKINDUNSER), - Hotkey(WKC_SHIFT | '6', "town_zone", ZTW_OUTER_FIRST + CHECKTOWNZONES), - Hotkey(WKC_SHIFT | '7', "cb_acceptance", ZTW_OUTER_FIRST + CHECKCBACCEPTANCE), - Hotkey(WKC_SHIFT | '8', "cb_town_limit", ZTW_OUTER_FIRST + CHECKCBTOWNLIMIT), - Hotkey(WKC_SHIFT | '9', "advertisement", ZTW_OUTER_FIRST + CHECKTOWNADZONES), - Hotkey(WKC_SHIFT | '0', "growth_tiles", ZTW_OUTER_FIRST + CHECKTOWNGROWTHTILES), - Hotkey((uint16)0, "active_stations", ZTW_OUTER_FIRST + CHECKACTIVESTATIONS), - HOTKEY_LIST_END -}; - -HotkeyList ZoningWindow::hotkeys("zoning_gui", zoning_hotkeys, ZoningWindowGlobalHotkeys); - - /** Construct the row containing the digit keys. */ -static NWidgetBase *MakeZoningButtons(int *biggest_index) +static std::unique_ptr MakeZoningButtons() { - NWidgetHorizontal *hor = new NWidgetHorizontal(NC_EQUALSIZE); + auto hor = std::make_unique(NC_EQUALSIZE); int zone_types_size = lengthof(_zone_types); hor->SetPadding(1, 1, 1, 1); for(int i = 0; i < 2; i++){ - NWidgetVertical *ver = new NWidgetVertical; + auto vert = std::make_unique(); int offset = (i == 0) ? ZTW_OUTER_FIRST : ZTW_INNER_FIRST; for (int j = 0; j < zone_types_size; j++) { - NWidgetBackground *leaf = new NWidgetBackground(WWT_PANEL, i==0 ? COLOUR_ORANGE : COLOUR_YELLOW, offset + j, NULL); + auto leaf = std::make_unique(WWT_PANEL, i==0 ? COLOUR_ORANGE : COLOUR_YELLOW, offset + j); leaf->SetFill(1, 0); leaf->SetPadding(0, 0, 0, 0); - ver->Add(leaf); + vert->Add(std::move(leaf)); } - hor->Add(ver); + hor->Add(std::move(vert)); } - *biggest_index = ZTW_INNER_END - 1; return hor; } @@ -192,11 +185,11 @@ static const NWidgetPart _nested_zoning_widgets[] = { EndContainer() }; -static WindowDesc _zoning_desc ( +static WindowDesc _zoning_desc (__FILE__, __LINE__, WDP_AUTO, NULL, 0, 0, - WC_ZONING_TOOLBAR, WC_NONE, + CM_WC_ZONING_TOOLBAR, WC_NONE, 0, - _nested_zoning_widgets, lengthof(_nested_zoning_widgets), + std::begin(_nested_zoning_widgets), std::end(_nested_zoning_widgets), &ZoningWindow::hotkeys ); diff --git a/src/citymania/generated/cm_gen_commands.cpp b/src/citymania/generated/cm_gen_commands.cpp index 940bf37e6a..1913792d99 100644 --- a/src/citymania/generated/cm_gen_commands.cpp +++ b/src/citymania/generated/cm_gen_commands.cpp @@ -115,7 +115,7 @@ CommandCost CreateStoryPage::_do(DoCommandFlag flags) { } Commands CreateStoryPageElement::get_command() { return CMD_CREATE_STORY_PAGE_ELEMENT; } -static constexpr auto _CreateStoryPageElement_dispatch = MakeDispatchTable(); +static constexpr auto _CreateStoryPageElement_dispatch = MakeDispatchTable(); bool CreateStoryPageElement::_post(::CommandCallback *callback) { return _CreateStoryPageElement_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->page_id, this->type, this->reference, this->text); } @@ -124,7 +124,7 @@ CommandCost CreateStoryPageElement::_do(DoCommandFlag flags) { } Commands UpdateStoryPageElement::get_command() { return CMD_UPDATE_STORY_PAGE_ELEMENT; } -static constexpr auto _UpdateStoryPageElement_dispatch = MakeDispatchTable(); +static constexpr auto _UpdateStoryPageElement_dispatch = MakeDispatchTable(); bool UpdateStoryPageElement::_post(::CommandCallback *callback) { return _UpdateStoryPageElement_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->page_element_id, this->reference, this->text); } @@ -142,7 +142,7 @@ CommandCost SetStoryPageTitle::_do(DoCommandFlag flags) { } Commands SetStoryPageDate::get_command() { return CMD_SET_STORY_PAGE_DATE; } -static constexpr auto _SetStoryPageDate_dispatch = MakeDispatchTable(); +static constexpr auto _SetStoryPageDate_dispatch = MakeDispatchTable(); bool SetStoryPageDate::_post(::CommandCallback *callback) { return _SetStoryPageDate_dispatch[FindCallbackIndex(callback)](this->error, this->page_id, this->date); } @@ -187,7 +187,7 @@ CommandCost StoryPageButton::_do(DoCommandFlag flags) { } Commands BuildRailWaypoint::get_command() { return CMD_BUILD_RAIL_WAYPOINT; } -static constexpr auto _BuildRailWaypoint_dispatch = MakeDispatchTable(); +static constexpr auto _BuildRailWaypoint_dispatch = MakeDispatchTable(); bool BuildRailWaypoint::_post(::CommandCallback *callback) { return _BuildRailWaypoint_dispatch[FindCallbackIndex(callback)](this->error, this->start_tile, this->axis, this->width, this->height, this->spec_class, this->spec_index, this->station_to_join, this->adjacent); } @@ -241,7 +241,7 @@ CommandCost BuildDock::_do(DoCommandFlag flags) { } Commands BuildRailStation::get_command() { return CMD_BUILD_RAIL_STATION; } -static constexpr auto _BuildRailStation_dispatch = MakeDispatchTable(); +static constexpr auto _BuildRailStation_dispatch = MakeDispatchTable(); bool BuildRailStation::_post(::CommandCallback *callback) { return _BuildRailStation_dispatch[FindCallbackIndex(callback)](this->error, this->tile_org, this->rt, this->axis, this->numtracks, this->plat_len, this->spec_class, this->spec_index, this->station_to_join, this->adjacent); } @@ -259,16 +259,16 @@ CommandCost RemoveFromRailStation::_do(DoCommandFlag flags) { } Commands BuildRoadStop::get_command() { return CMD_BUILD_ROAD_STOP; } -static constexpr auto _BuildRoadStop_dispatch = MakeDispatchTable(); +static constexpr auto _BuildRoadStop_dispatch = MakeDispatchTable(); bool BuildRoadStop::_post(::CommandCallback *callback) { - return _BuildRoadStop_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->width, this->length, this->stop_type, this->is_drive_through, this->ddir, this->rt, this->station_to_join, this->adjacent); + return _BuildRoadStop_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->width, this->length, this->stop_type, this->is_drive_through, this->ddir, this->rt, this->spec_class, this->spec_index, this->station_to_join, this->adjacent); } CommandCost BuildRoadStop::_do(DoCommandFlag flags) { - return (::Command::Do(flags, tile, width, length, stop_type, is_drive_through, ddir, rt, station_to_join, adjacent)); + return (::Command::Do(flags, tile, width, length, stop_type, is_drive_through, ddir, rt, spec_class, spec_index, station_to_join, adjacent)); } Commands RemoveRoadStop::get_command() { return CMD_REMOVE_ROAD_STOP; } -static constexpr auto _RemoveRoadStop_dispatch = MakeDispatchTable(); +static constexpr auto _RemoveRoadStop_dispatch = MakeDispatchTable(); bool RemoveRoadStop::_post(::CommandCallback *callback) { return _RemoveRoadStop_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->width, this->height, this->stop_type, this->remove_road); } @@ -312,6 +312,15 @@ CommandCost RemoveGoal::_do(DoCommandFlag flags) { return (::Command::Do(flags, goal)); } +Commands SetGoalDestination::get_command() { return CMD_SET_GOAL_DESTINATION; } +static constexpr auto _SetGoalDestination_dispatch = MakeDispatchTable(); +bool SetGoalDestination::_post(::CommandCallback *callback) { + return _SetGoalDestination_dispatch[FindCallbackIndex(callback)](this->error, this->goal, this->type, this->dest); +} +CommandCost SetGoalDestination::_do(DoCommandFlag flags) { + return (::Command::Do(flags, goal, type, dest)); +} + Commands SetGoalText::get_command() { return CMD_SET_GOAL_TEXT; } static constexpr auto _SetGoalText_dispatch = MakeDispatchTable(); bool SetGoalText::_post(::CommandCallback *callback) { @@ -340,7 +349,7 @@ CommandCost SetGoalCompleted::_do(DoCommandFlag flags) { } Commands GoalQuestion::get_command() { return CMD_GOAL_QUESTION; } -static constexpr auto _GoalQuestion_dispatch = MakeDispatchTable(); +static constexpr auto _GoalQuestion_dispatch = MakeDispatchTable(); bool GoalQuestion::_post(::CommandCallback *callback) { return _GoalQuestion_dispatch[FindCallbackIndex(callback)](this->error, this->uniqueid, this->target, this->is_client, this->button_mask, this->type, this->text); } @@ -349,7 +358,7 @@ CommandCost GoalQuestion::_do(DoCommandFlag flags) { } Commands GoalQuestionAnswer::get_command() { return CMD_GOAL_QUESTION_ANSWER; } -static constexpr auto _GoalQuestionAnswer_dispatch = MakeDispatchTable(); +static constexpr auto _GoalQuestionAnswer_dispatch = MakeDispatchTable(); bool GoalQuestionAnswer::_post(::CommandCallback *callback) { return _GoalQuestionAnswer_dispatch[FindCallbackIndex(callback)](this->error, this->uniqueid, this->button); } @@ -358,7 +367,7 @@ CommandCost GoalQuestionAnswer::_do(DoCommandFlag flags) { } Commands ChangeSetting::get_command() { return CMD_CHANGE_SETTING; } -static constexpr auto _ChangeSetting_dispatch = MakeDispatchTable(); +static constexpr auto _ChangeSetting_dispatch = MakeDispatchTable(); bool ChangeSetting::_post(::CommandCallback *callback) { return _ChangeSetting_dispatch[FindCallbackIndex(callback)](this->error, this->name, this->value); } @@ -367,7 +376,7 @@ CommandCost ChangeSetting::_do(DoCommandFlag flags) { } Commands ChangeCompanySetting::get_command() { return CMD_CHANGE_COMPANY_SETTING; } -static constexpr auto _ChangeCompanySetting_dispatch = MakeDispatchTable(); +static constexpr auto _ChangeCompanySetting_dispatch = MakeDispatchTable(); bool ChangeCompanySetting::_post(::CommandCallback *callback) { return _ChangeCompanySetting_dispatch[FindCallbackIndex(callback)](this->error, this->name, this->value); } @@ -376,7 +385,7 @@ CommandCost ChangeCompanySetting::_do(DoCommandFlag flags) { } Commands CustomNewsItem::get_command() { return CMD_CUSTOM_NEWS_ITEM; } -static constexpr auto _CustomNewsItem_dispatch = MakeDispatchTable(); +static constexpr auto _CustomNewsItem_dispatch = MakeDispatchTable(); bool CustomNewsItem::_post(::CommandCallback *callback) { return _CustomNewsItem_dispatch[FindCallbackIndex(callback)](this->error, this->type, this->reftype1, this->company, this->reference, this->text); } @@ -385,7 +394,7 @@ CommandCost CustomNewsItem::_do(DoCommandFlag flags) { } Commands BuildObject::get_command() { return CMD_BUILD_OBJECT; } -static constexpr auto _BuildObject_dispatch = MakeDispatchTable(); +static constexpr auto _BuildObject_dispatch = MakeDispatchTable(); bool BuildObject::_post(::CommandCallback *callback) { return _BuildObject_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->type, this->view); } @@ -394,7 +403,7 @@ CommandCost BuildObject::_do(DoCommandFlag flags) { } Commands BuildObjectArea::get_command() { return CMD_BUILD_OBJECT_AREA; } -static constexpr auto _BuildObjectArea_dispatch = MakeDispatchTable(); +static constexpr auto _BuildObjectArea_dispatch = MakeDispatchTable(); bool BuildObjectArea::_post(::CommandCallback *callback) { return _BuildObjectArea_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->start_tile, this->type, this->view, this->diagonal); } @@ -474,31 +483,13 @@ CommandCost ConvertRoad::_do(DoCommandFlag flags) { return (::Command::Do(flags, tile, area_start, to_type)); } -Commands BuyShareInCompany::get_command() { return CMD_BUY_SHARE_IN_COMPANY; } -static constexpr auto _BuyShareInCompany_dispatch = MakeDispatchTable(); -bool BuyShareInCompany::_post(::CommandCallback *callback) { - return _BuyShareInCompany_dispatch[FindCallbackIndex(callback)](this->error, this->target_company); -} -CommandCost BuyShareInCompany::_do(DoCommandFlag flags) { - return (::Command::Do(flags, target_company)); -} - -Commands SellShareInCompany::get_command() { return CMD_SELL_SHARE_IN_COMPANY; } -static constexpr auto _SellShareInCompany_dispatch = MakeDispatchTable(); -bool SellShareInCompany::_post(::CommandCallback *callback) { - return _SellShareInCompany_dispatch[FindCallbackIndex(callback)](this->error, this->target_company); -} -CommandCost SellShareInCompany::_do(DoCommandFlag flags) { - return (::Command::Do(flags, target_company)); -} - Commands BuyCompany::get_command() { return CMD_BUY_COMPANY; } -static constexpr auto _BuyCompany_dispatch = MakeDispatchTable(); +static constexpr auto _BuyCompany_dispatch = MakeDispatchTable(); bool BuyCompany::_post(::CommandCallback *callback) { - return _BuyCompany_dispatch[FindCallbackIndex(callback)](this->error, this->target_company); + return _BuyCompany_dispatch[FindCallbackIndex(callback)](this->error, this->target_company, this->hostile_takeover); } CommandCost BuyCompany::_do(DoCommandFlag flags) { - return (::Command::Do(flags, target_company)); + return (::Command::Do(flags, target_company, hostile_takeover)); } Commands LandscapeClear::get_command() { return CMD_LANDSCAPE_CLEAR; } @@ -556,7 +547,7 @@ CommandCost CreateSubsidy::_do(DoCommandFlag flags) { } Commands ScrollViewport::get_command() { return CMD_SCROLL_VIEWPORT; } -static constexpr auto _ScrollViewport_dispatch = MakeDispatchTable(); +static constexpr auto _ScrollViewport_dispatch = MakeDispatchTable(); bool ScrollViewport::_post(::CommandCallback *callback) { return _ScrollViewport_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->target, this->ref); } @@ -565,7 +556,7 @@ CommandCost ScrollViewport::_do(DoCommandFlag flags) { } Commands ChangeTimetable::get_command() { return CMD_CHANGE_TIMETABLE; } -static constexpr auto _ChangeTimetable_dispatch = MakeDispatchTable(); +static constexpr auto _ChangeTimetable_dispatch = MakeDispatchTable(); bool ChangeTimetable::_post(::CommandCallback *callback) { return _ChangeTimetable_dispatch[FindCallbackIndex(callback)](this->error, this->veh, this->order_number, this->mtf, this->data); } @@ -574,7 +565,7 @@ CommandCost ChangeTimetable::_do(DoCommandFlag flags) { } Commands BulkChangeTimetable::get_command() { return CMD_BULK_CHANGE_TIMETABLE; } -static constexpr auto _BulkChangeTimetable_dispatch = MakeDispatchTable(); +static constexpr auto _BulkChangeTimetable_dispatch = MakeDispatchTable(); bool BulkChangeTimetable::_post(::CommandCallback *callback) { return _BulkChangeTimetable_dispatch[FindCallbackIndex(callback)](this->error, this->veh, this->mtf, this->data); } @@ -583,12 +574,12 @@ CommandCost BulkChangeTimetable::_do(DoCommandFlag flags) { } Commands SetVehicleOnTime::get_command() { return CMD_SET_VEHICLE_ON_TIME; } -static constexpr auto _SetVehicleOnTime_dispatch = MakeDispatchTable(); +static constexpr auto _SetVehicleOnTime_dispatch = MakeDispatchTable(); bool SetVehicleOnTime::_post(::CommandCallback *callback) { - return _SetVehicleOnTime_dispatch[FindCallbackIndex(callback)](this->error, this->veh); + return _SetVehicleOnTime_dispatch[FindCallbackIndex(callback)](this->error, this->veh, this->apply_to_group); } CommandCost SetVehicleOnTime::_do(DoCommandFlag flags) { - return (::Command::Do(flags, veh)); + return (::Command::Do(flags, veh, apply_to_group)); } Commands AutofillTimetable::get_command() { return CMD_AUTOFILL_TIMETABLE; } @@ -601,12 +592,12 @@ CommandCost AutofillTimetable::_do(DoCommandFlag flags) { } Commands SetTimetableStart::get_command() { return CMD_SET_TIMETABLE_START; } -static constexpr auto _SetTimetableStart_dispatch = MakeDispatchTable(); +static constexpr auto _SetTimetableStart_dispatch = MakeDispatchTable(); bool SetTimetableStart::_post(::CommandCallback *callback) { - return _SetTimetableStart_dispatch[FindCallbackIndex(callback)](this->error, this->veh_id, this->timetable_all, this->start_date); + return _SetTimetableStart_dispatch[FindCallbackIndex(callback)](this->error, this->veh_id, this->timetable_all, this->start_tick); } CommandCost SetTimetableStart::_do(DoCommandFlag flags) { - return (::Command::Do(flags, veh_id, timetable_all, start_date)); + return (::Command::Do(flags, veh_id, timetable_all, start_tick)); } Commands PlantTree::get_command() { return CMD_PLANT_TREE; } @@ -628,7 +619,7 @@ CommandCost CreateLeagueTable::_do(DoCommandFlag flags) { } Commands CreateLeagueTableElement::get_command() { return CMD_CREATE_LEAGUE_TABLE_ELEMENT; } -static constexpr auto _CreateLeagueTableElement_dispatch = MakeDispatchTable(); +static constexpr auto _CreateLeagueTableElement_dispatch = MakeDispatchTable(); bool CreateLeagueTableElement::_post(::CommandCallback *callback) { return _CreateLeagueTableElement_dispatch[FindCallbackIndex(callback)](this->error, this->table, this->rating, this->company, this->text, this->score, this->link_type, this->link_target); } @@ -646,7 +637,7 @@ CommandCost UpdateLeagueTableElementData::_do(DoCommandFlag flags) { } Commands UpdateLeagueTableElementScore::get_command() { return CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE; } -static constexpr auto _UpdateLeagueTableElementScore_dispatch = MakeDispatchTable(); +static constexpr auto _UpdateLeagueTableElementScore_dispatch = MakeDispatchTable(); bool UpdateLeagueTableElementScore::_post(::CommandCallback *callback) { return _UpdateLeagueTableElementScore_dispatch[FindCallbackIndex(callback)](this->error, this->element, this->rating, this->score); } @@ -700,7 +691,7 @@ CommandCost SellVehicle::_do(DoCommandFlag flags) { } Commands RefitVehicle::get_command() { return CMD_REFIT_VEHICLE; } -static constexpr auto _RefitVehicle_dispatch = MakeDispatchTable(); +static constexpr auto _RefitVehicle_dispatch = MakeDispatchTable(); bool RefitVehicle::_post(::CommandCallback *callback) { return _RefitVehicle_dispatch[FindCallbackIndex(callback)](this->error, this->location, this->veh_id, this->new_cid, this->new_subtype, this->auto_refit, this->only_this, this->num_vehicles); } @@ -718,7 +709,7 @@ CommandCost SendVehicleToDepot::_do(DoCommandFlag flags) { } Commands ChangeServiceInt::get_command() { return CMD_CHANGE_SERVICE_INT; } -static constexpr auto _ChangeServiceInt_dispatch = MakeDispatchTable(); +static constexpr auto _ChangeServiceInt_dispatch = MakeDispatchTable(); bool ChangeServiceInt::_post(::CommandCallback *callback) { return _ChangeServiceInt_dispatch[FindCallbackIndex(callback)](this->error, this->veh_id, this->serv_int, this->is_custom, this->is_percent); } @@ -852,22 +843,22 @@ CommandCost BuildTrainDepot::_do(DoCommandFlag flags) { return (::Command::Do(flags, tile, railtype, dir)); } -Commands BuildSingleSignal::get_command() { return CMD_BUILD_SIGNALS; } -static constexpr auto _BuildSingleSignal_dispatch = MakeDispatchTable(); +Commands BuildSingleSignal::get_command() { return CMD_BUILD_SINGLE_SIGNAL; } +static constexpr auto _BuildSingleSignal_dispatch = MakeDispatchTable(); bool BuildSingleSignal::_post(::CommandCallback *callback) { return _BuildSingleSignal_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->track, this->sigtype, this->sigvar, this->convert_signal, this->skip_existing_signals, this->ctrl_pressed, this->cycle_start, this->cycle_stop, this->num_dir_cycle, this->signals_copy); } CommandCost BuildSingleSignal::_do(DoCommandFlag flags) { - return (::Command::Do(flags, tile, track, sigtype, sigvar, convert_signal, skip_existing_signals, ctrl_pressed, cycle_start, cycle_stop, num_dir_cycle, signals_copy)); + return (::Command::Do(flags, tile, track, sigtype, sigvar, convert_signal, skip_existing_signals, ctrl_pressed, cycle_start, cycle_stop, num_dir_cycle, signals_copy)); } -Commands RemoveSingleSignal::get_command() { return CMD_REMOVE_SIGNALS; } -static constexpr auto _RemoveSingleSignal_dispatch = MakeDispatchTable(); +Commands RemoveSingleSignal::get_command() { return CMD_REMOVE_SINGLE_SIGNAL; } +static constexpr auto _RemoveSingleSignal_dispatch = MakeDispatchTable(); bool RemoveSingleSignal::_post(::CommandCallback *callback) { return _RemoveSingleSignal_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->track); } CommandCost RemoveSingleSignal::_do(DoCommandFlag flags) { - return (::Command::Do(flags, tile, track)); + return (::Command::Do(flags, tile, track)); } Commands ConvertRail::get_command() { return CMD_CONVERT_RAIL; } @@ -907,7 +898,7 @@ CommandCost CompanyCtrl::_do(DoCommandFlag flags) { } Commands GiveMoney::get_command() { return CMD_GIVE_MONEY; } -static constexpr auto _GiveMoney_dispatch = MakeDispatchTable(); +static constexpr auto _GiveMoney_dispatch = MakeDispatchTable(); bool GiveMoney::_post(::CommandCallback *callback) { return _GiveMoney_dispatch[FindCallbackIndex(callback)](this->error, this->money, this->dest_company); } @@ -970,7 +961,7 @@ CommandCost SetAutoReplace::_do(DoCommandFlag flags) { } Commands FoundTown::get_command() { return CMD_FOUND_TOWN; } -static constexpr auto _FoundTown_dispatch = MakeDispatchTable(); +static constexpr auto _FoundTown_dispatch = MakeDispatchTable(); bool FoundTown::_post(::CommandCallback *callback) { return _FoundTown_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->size, this->city, this->layout, this->random_location, this->townnameparts, this->text); } @@ -988,7 +979,7 @@ CommandCost RenameTown::_do(DoCommandFlag flags) { } Commands DoTownAction::get_command() { return CMD_DO_TOWN_ACTION; } -static constexpr auto _DoTownAction_dispatch = MakeDispatchTable(); +static constexpr auto _DoTownAction_dispatch = MakeDispatchTable(); bool DoTownAction::_post(::CommandCallback *callback) { return _DoTownAction_dispatch[FindCallbackIndex(callback)](this->error, this->location, this->town_id, this->action); } @@ -997,7 +988,7 @@ CommandCost DoTownAction::_do(DoCommandFlag flags) { } Commands TownGrowthRate::get_command() { return CMD_TOWN_GROWTH_RATE; } -static constexpr auto _TownGrowthRate_dispatch = MakeDispatchTable(); +static constexpr auto _TownGrowthRate_dispatch = MakeDispatchTable(); bool TownGrowthRate::_post(::CommandCallback *callback) { return _TownGrowthRate_dispatch[FindCallbackIndex(callback)](this->error, this->town_id, this->growth_rate); } @@ -1006,7 +997,7 @@ CommandCost TownGrowthRate::_do(DoCommandFlag flags) { } Commands TownRating::get_command() { return CMD_TOWN_RATING; } -static constexpr auto _TownRating_dispatch = MakeDispatchTable(); +static constexpr auto _TownRating_dispatch = MakeDispatchTable(); bool TownRating::_post(::CommandCallback *callback) { return _TownRating_dispatch[FindCallbackIndex(callback)](this->error, this->town_id, this->company_id, this->rating); } @@ -1015,12 +1006,12 @@ CommandCost TownRating::_do(DoCommandFlag flags) { } Commands TownCargoGoal::get_command() { return CMD_TOWN_CARGO_GOAL; } -static constexpr auto _TownCargoGoal_dispatch = MakeDispatchTable(); +static constexpr auto _TownCargoGoal_dispatch = MakeDispatchTable(); bool TownCargoGoal::_post(::CommandCallback *callback) { - return _TownCargoGoal_dispatch[FindCallbackIndex(callback)](this->error, this->town_id, this->te, this->goal); + return _TownCargoGoal_dispatch[FindCallbackIndex(callback)](this->error, this->town_id, this->tae, this->goal); } CommandCost TownCargoGoal::_do(DoCommandFlag flags) { - return (::Command::Do(flags, town_id, te, goal)); + return (::Command::Do(flags, town_id, tae, goal)); } Commands TownSetText::get_command() { return CMD_TOWN_SET_TEXT; } @@ -1033,7 +1024,7 @@ CommandCost TownSetText::_do(DoCommandFlag flags) { } Commands ExpandTown::get_command() { return CMD_EXPAND_TOWN; } -static constexpr auto _ExpandTown_dispatch = MakeDispatchTable(); +static constexpr auto _ExpandTown_dispatch = MakeDispatchTable(); bool ExpandTown::_post(::CommandCallback *callback) { return _ExpandTown_dispatch[FindCallbackIndex(callback)](this->error, this->town_id, this->grow_amount); } @@ -1060,7 +1051,7 @@ CommandCost TurnRoadVeh::_do(DoCommandFlag flags) { } Commands BuildIndustry::get_command() { return CMD_BUILD_INDUSTRY; } -static constexpr auto _BuildIndustry_dispatch = MakeDispatchTable(); +static constexpr auto _BuildIndustry_dispatch = MakeDispatchTable(); bool BuildIndustry::_post(::CommandCallback *callback) { return _BuildIndustry_dispatch[FindCallbackIndex(callback)](this->error, this->tile, this->it, this->first_layout, this->fund, this->seed); } @@ -1068,17 +1059,44 @@ CommandCost BuildIndustry::_do(DoCommandFlag flags) { return (::Command::Do(flags, tile, it, first_layout, fund, seed)); } -Commands IndustryCtrl::get_command() { return CMD_INDUSTRY_CTRL; } -static constexpr auto _IndustryCtrl_dispatch = MakeDispatchTable(); -bool IndustryCtrl::_post(::CommandCallback *callback) { - return _IndustryCtrl_dispatch[FindCallbackIndex(callback)](this->error, this->ind_id, this->action, this->ctlflags, this->company_id, this->text); +Commands IndustrySetFlags::get_command() { return CMD_INDUSTRY_SET_FLAGS; } +static constexpr auto _IndustrySetFlags_dispatch = MakeDispatchTable(); +bool IndustrySetFlags::_post(::CommandCallback *callback) { + return _IndustrySetFlags_dispatch[FindCallbackIndex(callback)](this->error, this->ind_id, this->ctlflags); } -CommandCost IndustryCtrl::_do(DoCommandFlag flags) { - return (::Command::Do(flags, ind_id, action, ctlflags, company_id, text)); +CommandCost IndustrySetFlags::_do(DoCommandFlag flags) { + return (::Command::Do(flags, ind_id, ctlflags)); +} + +Commands IndustrySetExclusivity::get_command() { return CMD_INDUSTRY_SET_EXCLUSIVITY; } +static constexpr auto _IndustrySetExclusivity_dispatch = MakeDispatchTable(); +bool IndustrySetExclusivity::_post(::CommandCallback *callback) { + return _IndustrySetExclusivity_dispatch[FindCallbackIndex(callback)](this->error, this->ind_id, this->company_id, this->consumer); +} +CommandCost IndustrySetExclusivity::_do(DoCommandFlag flags) { + return (::Command::Do(flags, ind_id, company_id, consumer)); +} + +Commands IndustrySetText::get_command() { return CMD_INDUSTRY_SET_TEXT; } +static constexpr auto _IndustrySetText_dispatch = MakeDispatchTable(); +bool IndustrySetText::_post(::CommandCallback *callback) { + return _IndustrySetText_dispatch[FindCallbackIndex(callback)](this->error, this->ind_id, this->text); +} +CommandCost IndustrySetText::_do(DoCommandFlag flags) { + return (::Command::Do(flags, ind_id, text)); +} + +Commands IndustrySetProduction::get_command() { return CMD_INDUSTRY_SET_PRODUCTION; } +static constexpr auto _IndustrySetProduction_dispatch = MakeDispatchTable(); +bool IndustrySetProduction::_post(::CommandCallback *callback) { + return _IndustrySetProduction_dispatch[FindCallbackIndex(callback)](this->error, this->ind_id, this->prod_level, this->show_news, this->text); +} +CommandCost IndustrySetProduction::_do(DoCommandFlag flags) { + return (::Command::Do(flags, ind_id, prod_level, show_news, text)); } Commands ModifyOrder::get_command() { return CMD_MODIFY_ORDER; } -static constexpr auto _ModifyOrder_dispatch = MakeDispatchTable(); +static constexpr auto _ModifyOrder_dispatch = MakeDispatchTable(); bool ModifyOrder::_post(::CommandCallback *callback) { return _ModifyOrder_dispatch[FindCallbackIndex(callback)](this->error, this->location, this->veh, this->sel_ord, this->mof, this->data); } @@ -1185,6 +1203,15 @@ CommandCost DecreaseLoan::_do(DoCommandFlag flags) { return (::Command::Do(flags, cmd, amount)); } +Commands SetCompanyMaxLoan::get_command() { return CMD_SET_COMPANY_MAX_LOAN; } +static constexpr auto _SetCompanyMaxLoan_dispatch = MakeDispatchTable(); +bool SetCompanyMaxLoan::_post(::CommandCallback *callback) { + return _SetCompanyMaxLoan_dispatch[FindCallbackIndex(callback)](this->error, this->company, this->amount); +} +CommandCost SetCompanyMaxLoan::_do(DoCommandFlag flags) { + return (::Command::Do(flags, company, amount)); +} + Commands Pause::get_command() { return CMD_PAUSE; } static constexpr auto _Pause_dispatch = MakeDispatchTable(); bool Pause::_post(::CommandCallback *callback) { @@ -1276,12 +1303,12 @@ CommandCost DeleteGroup::_do(DoCommandFlag flags) { } Commands AddVehicleGroup::get_command() { return CMD_ADD_VEHICLE_GROUP; } -static constexpr auto _AddVehicleGroup_dispatch = MakeDispatchTable(); +static constexpr auto _AddVehicleGroup_dispatch = MakeDispatchTable(); bool AddVehicleGroup::_post(::CommandCallback *callback) { - return _AddVehicleGroup_dispatch[FindCallbackIndex(callback)](this->error, this->group_id, this->veh_id, this->add_shared); + return _AddVehicleGroup_dispatch[FindCallbackIndex(callback)](this->error, this->group_id, this->veh_id, this->add_shared, this->vli); } CommandCost AddVehicleGroup::_do(DoCommandFlag flags) { - return std::get<0>(::Command::Do(flags, group_id, veh_id, add_shared)); + return std::get<0>(::Command::Do(flags, group_id, veh_id, add_shared, vli)); } Commands AddSharedVehicleGroup::get_command() { return CMD_ADD_SHARED_VEHICLE_GROUP; } diff --git a/src/citymania/generated/cm_gen_commands.hpp b/src/citymania/generated/cm_gen_commands.hpp index f4dcee5531..9352b3377b 100644 --- a/src/citymania/generated/cm_gen_commands.hpp +++ b/src/citymania/generated/cm_gen_commands.hpp @@ -35,6 +35,7 @@ #include "../../town_cmd.h" #include "../../roadveh_cmd.h" #include "../../industry_cmd.h" +#include "../../vehiclelist_cmd.h" #include "../../order_cmd.h" #include "../../misc_cmd.h" #include "../../engine_cmd.h" @@ -63,10 +64,10 @@ public: TileIndex tile; StoryPageID page_id; StoryPageElementType type; - uint32 reference; + uint32_t reference; const std::string & text; - CreateStoryPageElement(TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32 reference, const std::string & text) + CreateStoryPageElement(TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32_t reference, const std::string & text) :tile{tile}, page_id{page_id}, type{type}, reference{reference}, text{text} {} ~CreateStoryPageElement() override {} @@ -79,10 +80,10 @@ class UpdateStoryPageElement: public Command { public: TileIndex tile; StoryPageElementID page_element_id; - uint32 reference; + uint32_t reference; const std::string & text; - UpdateStoryPageElement(TileIndex tile, StoryPageElementID page_element_id, uint32 reference, const std::string & text) + UpdateStoryPageElement(TileIndex tile, StoryPageElementID page_element_id, uint32_t reference, const std::string & text) :tile{tile}, page_element_id{page_element_id}, reference{reference}, text{text} {} ~UpdateStoryPageElement() override {} @@ -108,9 +109,9 @@ public: class SetStoryPageDate: public Command { public: StoryPageID page_id; - Date date; + TimerGameCalendar::Date date; - SetStoryPageDate(StoryPageID page_id, Date date) + SetStoryPageDate(StoryPageID page_id, TimerGameCalendar::Date date) :page_id{page_id}, date{date} {} ~SetStoryPageDate() override {} @@ -180,11 +181,11 @@ public: byte width; byte height; StationClassID spec_class; - byte spec_index; + uint16_t spec_index; StationID station_to_join; bool adjacent; - BuildRailWaypoint(TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent) + BuildRailWaypoint(TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent) :start_tile{start_tile}, axis{axis}, width{width}, height{height}, spec_class{spec_class}, spec_index{spec_index}, station_to_join{station_to_join}, adjacent{adjacent} {} ~BuildRailWaypoint() override {} @@ -275,11 +276,11 @@ public: byte numtracks; byte plat_len; StationClassID spec_class; - byte spec_index; + uint16_t spec_index; StationID station_to_join; bool adjacent; - BuildRailStation(TileIndex tile_org, RailType rt, Axis axis, byte numtracks, byte plat_len, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent) + BuildRailStation(TileIndex tile_org, RailType rt, Axis axis, byte numtracks, byte plat_len, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent) :tile_org{tile_org}, rt{rt}, axis{axis}, numtracks{numtracks}, plat_len{plat_len}, spec_class{spec_class}, spec_index{spec_index}, station_to_join{station_to_join}, adjacent{adjacent} {} ~BuildRailStation() override {} @@ -306,17 +307,19 @@ public: class BuildRoadStop: public Command { public: TileIndex tile; - uint8 width; - uint8 length; + uint8_t width; + uint8_t length; RoadStopType stop_type; bool is_drive_through; DiagDirection ddir; RoadType rt; + RoadStopClassID spec_class; + uint16_t spec_index; StationID station_to_join; bool adjacent; - BuildRoadStop(TileIndex tile, uint8 width, uint8 length, RoadStopType stop_type, bool is_drive_through, DiagDirection ddir, RoadType rt, StationID station_to_join, bool adjacent) - :tile{tile}, width{width}, length{length}, stop_type{stop_type}, is_drive_through{is_drive_through}, ddir{ddir}, rt{rt}, station_to_join{station_to_join}, adjacent{adjacent} {} + BuildRoadStop(TileIndex tile, uint8_t width, uint8_t length, RoadStopType stop_type, bool is_drive_through, DiagDirection ddir, RoadType rt, RoadStopClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent) + :tile{tile}, width{width}, length{length}, stop_type{stop_type}, is_drive_through{is_drive_through}, ddir{ddir}, rt{rt}, spec_class{spec_class}, spec_index{spec_index}, station_to_join{station_to_join}, adjacent{adjacent} {} ~BuildRoadStop() override {} bool _post(::CommandCallback * callback) override; @@ -327,12 +330,12 @@ public: class RemoveRoadStop: public Command { public: TileIndex tile; - uint8 width; - uint8 height; + uint8_t width; + uint8_t height; RoadStopType stop_type; bool remove_road; - RemoveRoadStop(TileIndex tile, uint8 width, uint8 height, RoadStopType stop_type, bool remove_road) + RemoveRoadStop(TileIndex tile, uint8_t width, uint8_t height, RoadStopType stop_type, bool remove_road) :tile{tile}, width{width}, height{height}, stop_type{stop_type}, remove_road{remove_road} {} ~RemoveRoadStop() override {} @@ -397,6 +400,21 @@ public: Commands get_command() override; }; +class SetGoalDestination: public Command { +public: + ::GoalID goal; + ::GoalType type; + ::GoalTypeID dest; + + SetGoalDestination(::GoalID goal, ::GoalType type, ::GoalTypeID dest) + :goal{goal}, type{type}, dest{dest} {} + ~SetGoalDestination() override {} + + bool _post(::CommandCallback * callback) override; + CommandCost _do(DoCommandFlag flags) override; + Commands get_command() override; +}; + class SetGoalText: public Command { public: ::GoalID goal; @@ -441,14 +459,14 @@ public: class GoalQuestion: public Command { public: - uint16 uniqueid; - uint16 target; + uint16_t uniqueid; + uint32_t target; bool is_client; - uint32 button_mask; + uint32_t button_mask; GoalQuestionType type; const std::string & text; - GoalQuestion(uint16 uniqueid, uint16 target, bool is_client, uint32 button_mask, GoalQuestionType type, const std::string & text) + GoalQuestion(uint16_t uniqueid, uint32_t target, bool is_client, uint32_t button_mask, GoalQuestionType type, const std::string & text) :uniqueid{uniqueid}, target{target}, is_client{is_client}, button_mask{button_mask}, type{type}, text{text} {} ~GoalQuestion() override {} @@ -459,10 +477,10 @@ public: class GoalQuestionAnswer: public Command { public: - uint16 uniqueid; - uint8 button; + uint16_t uniqueid; + uint8_t button; - GoalQuestionAnswer(uint16 uniqueid, uint8 button) + GoalQuestionAnswer(uint16_t uniqueid, uint8_t button) :uniqueid{uniqueid}, button{button} {} ~GoalQuestionAnswer() override {} @@ -474,9 +492,9 @@ public: class ChangeSetting: public Command { public: const std::string & name; - int32 value; + int32_t value; - ChangeSetting(const std::string & name, int32 value) + ChangeSetting(const std::string & name, int32_t value) :name{name}, value{value} {} ~ChangeSetting() override {} @@ -488,9 +506,9 @@ public: class ChangeCompanySetting: public Command { public: const std::string & name; - int32 value; + int32_t value; - ChangeCompanySetting(const std::string & name, int32 value) + ChangeCompanySetting(const std::string & name, int32_t value) :name{name}, value{value} {} ~ChangeCompanySetting() override {} @@ -504,10 +522,10 @@ public: NewsType type; NewsReferenceType reftype1; CompanyID company; - uint32 reference; + uint32_t reference; const std::string & text; - CustomNewsItem(NewsType type, NewsReferenceType reftype1, CompanyID company, uint32 reference, const std::string & text) + CustomNewsItem(NewsType type, NewsReferenceType reftype1, CompanyID company, uint32_t reference, const std::string & text) :type{type}, reftype1{reftype1}, company{company}, reference{reference}, text{text} {} ~CustomNewsItem() override {} @@ -520,9 +538,9 @@ class BuildObject: public Command { public: TileIndex tile; ObjectType type; - uint8 view; + uint8_t view; - BuildObject(TileIndex tile, ObjectType type, uint8 view) + BuildObject(TileIndex tile, ObjectType type, uint8_t view) :tile{tile}, type{type}, view{view} {} ~BuildObject() override {} @@ -536,10 +554,10 @@ public: TileIndex tile; TileIndex start_tile; ObjectType type; - uint8 view; + uint8_t view; bool diagonal; - BuildObjectArea(TileIndex tile, TileIndex start_tile, ObjectType type, uint8 view, bool diagonal) + BuildObjectArea(TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal) :tile{tile}, start_tile{start_tile}, type{type}, view{view}, diagonal{diagonal} {} ~BuildObjectArea() override {} @@ -676,38 +694,13 @@ public: Commands get_command() override; }; -class BuyShareInCompany: public Command { -public: - CompanyID target_company; - - BuyShareInCompany(CompanyID target_company) - :target_company{target_company} {} - ~BuyShareInCompany() override {} - - bool _post(::CommandCallback * callback) override; - CommandCost _do(DoCommandFlag flags) override; - Commands get_command() override; -}; - -class SellShareInCompany: public Command { -public: - CompanyID target_company; - - SellShareInCompany(CompanyID target_company) - :target_company{target_company} {} - ~SellShareInCompany() override {} - - bool _post(::CommandCallback * callback) override; - CommandCost _do(DoCommandFlag flags) override; - Commands get_command() override; -}; - class BuyCompany: public Command { public: CompanyID target_company; + bool hostile_takeover; - BuyCompany(CompanyID target_company) - :target_company{target_company} {} + BuyCompany(CompanyID target_company, bool hostile_takeover) + :target_company{target_company}, hostile_takeover{hostile_takeover} {} ~BuyCompany() override {} bool _post(::CommandCallback * callback) override; @@ -809,9 +802,9 @@ class ScrollViewport: public Command { public: TileIndex tile; ViewportScrollTarget target; - uint32 ref; + uint32_t ref; - ScrollViewport(TileIndex tile, ViewportScrollTarget target, uint32 ref) + ScrollViewport(TileIndex tile, ViewportScrollTarget target, uint32_t ref) :tile{tile}, target{target}, ref{ref} {} ~ScrollViewport() override {} @@ -825,9 +818,9 @@ public: VehicleID veh; VehicleOrderID order_number; ModifyTimetableFlags mtf; - uint16 data; + uint16_t data; - ChangeTimetable(VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16 data) + ChangeTimetable(VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16_t data) :veh{veh}, order_number{order_number}, mtf{mtf}, data{data} {} ~ChangeTimetable() override {} @@ -840,9 +833,9 @@ class BulkChangeTimetable: public Command { public: VehicleID veh; ModifyTimetableFlags mtf; - uint16 data; + uint16_t data; - BulkChangeTimetable(VehicleID veh, ModifyTimetableFlags mtf, uint16 data) + BulkChangeTimetable(VehicleID veh, ModifyTimetableFlags mtf, uint16_t data) :veh{veh}, mtf{mtf}, data{data} {} ~BulkChangeTimetable() override {} @@ -854,9 +847,10 @@ public: class SetVehicleOnTime: public Command { public: VehicleID veh; + bool apply_to_group; - SetVehicleOnTime(VehicleID veh) - :veh{veh} {} + SetVehicleOnTime(VehicleID veh, bool apply_to_group) + :veh{veh}, apply_to_group{apply_to_group} {} ~SetVehicleOnTime() override {} bool _post(::CommandCallback * callback) override; @@ -883,10 +877,10 @@ class SetTimetableStart: public Command { public: VehicleID veh_id; bool timetable_all; - Date start_date; + TimerGameTick::TickCounter start_tick; - SetTimetableStart(VehicleID veh_id, bool timetable_all, Date start_date) - :veh_id{veh_id}, timetable_all{timetable_all}, start_date{start_date} {} + SetTimetableStart(VehicleID veh_id, bool timetable_all, TimerGameTick::TickCounter start_tick) + :veh_id{veh_id}, timetable_all{timetable_all}, start_tick{start_tick} {} ~SetTimetableStart() override {} bool _post(::CommandCallback * callback) override; @@ -928,14 +922,14 @@ public: class CreateLeagueTableElement: public Command { public: LeagueTableID table; - int64 rating; + int64_t rating; CompanyID company; const std::string & text; const std::string & score; LinkType link_type; LinkTargetID link_target; - CreateLeagueTableElement(LeagueTableID table, int64 rating, CompanyID company, const std::string & text, const std::string & score, LinkType link_type, LinkTargetID link_target) + CreateLeagueTableElement(LeagueTableID table, int64_t rating, CompanyID company, const std::string & text, const std::string & score, LinkType link_type, LinkTargetID link_target) :table{table}, rating{rating}, company{company}, text{text}, score{score}, link_type{link_type}, link_target{link_target} {} ~CreateLeagueTableElement() override {} @@ -964,10 +958,10 @@ public: class UpdateLeagueTableElementScore: public Command { public: LeagueTableElementID element; - int64 rating; + int64_t rating; const std::string & score; - UpdateLeagueTableElementScore(LeagueTableElementID element, int64 rating, const std::string & score) + UpdateLeagueTableElementScore(LeagueTableElementID element, int64_t rating, const std::string & score) :element{element}, rating{rating}, score{score} {} ~UpdateLeagueTableElementScore() override {} @@ -1059,9 +1053,9 @@ public: byte new_subtype; bool auto_refit; bool only_this; - uint8 num_vehicles; + uint8_t num_vehicles; - RefitVehicle(TileIndex location, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8 num_vehicles) + RefitVehicle(TileIndex location, VehicleID veh_id, CargoID new_cid, byte new_subtype, bool auto_refit, bool only_this, uint8_t num_vehicles) :location{location}, veh_id{veh_id}, new_cid{new_cid}, new_subtype{new_subtype}, auto_refit{auto_refit}, only_this{only_this}, num_vehicles{num_vehicles} {} ~RefitVehicle() override {} @@ -1088,11 +1082,11 @@ public: class ChangeServiceInt: public Command { public: VehicleID veh_id; - uint16 serv_int; + uint16_t serv_int; bool is_custom; bool is_percent; - ChangeServiceInt(VehicleID veh_id, uint16 serv_int, bool is_custom, bool is_percent) + ChangeServiceInt(VehicleID veh_id, uint16_t serv_int, bool is_custom, bool is_percent) :veh_id{veh_id}, serv_int{serv_int}, is_custom{is_custom}, is_percent{is_percent} {} ~ChangeServiceInt() override {} @@ -1323,10 +1317,10 @@ public: bool ctrl_pressed; SignalType cycle_start; SignalType cycle_stop; - uint8 num_dir_cycle; + uint8_t num_dir_cycle; byte signals_copy; - BuildSingleSignal(TileIndex tile, Track track, SignalType sigtype, SignalVariant sigvar, bool convert_signal, bool skip_existing_signals, bool ctrl_pressed, SignalType cycle_start, SignalType cycle_stop, uint8 num_dir_cycle, byte signals_copy) + BuildSingleSignal(TileIndex tile, Track track, SignalType sigtype, SignalVariant sigvar, bool convert_signal, bool skip_existing_signals, bool ctrl_pressed, SignalType cycle_start, SignalType cycle_stop, uint8_t num_dir_cycle, byte signals_copy) :tile{tile}, track{track}, sigtype{sigtype}, sigvar{sigvar}, convert_signal{convert_signal}, skip_existing_signals{skip_existing_signals}, ctrl_pressed{ctrl_pressed}, cycle_start{cycle_start}, cycle_stop{cycle_stop}, num_dir_cycle{num_dir_cycle}, signals_copy{signals_copy} {} ~BuildSingleSignal() override {} @@ -1420,10 +1414,10 @@ public: class GiveMoney: public Command { public: - uint32 money; + Money money; CompanyID dest_company; - GiveMoney(uint32 money, CompanyID dest_company) + GiveMoney(Money money, CompanyID dest_company) :money{money}, dest_company{dest_company} {} ~GiveMoney() override {} @@ -1522,10 +1516,10 @@ public: bool city; TownLayout layout; bool random_location; - uint32 townnameparts; + uint32_t townnameparts; const std::string & text; - FoundTown(TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32 townnameparts, const std::string & text) + FoundTown(TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32_t townnameparts, const std::string & text) :tile{tile}, size{size}, city{city}, layout{layout}, random_location{random_location}, townnameparts{townnameparts}, text{text} {} ~FoundTown() override {} @@ -1552,9 +1546,9 @@ class DoTownAction: public Command { public: TileIndex location; TownID town_id; - uint8 action; + uint8_t action; - DoTownAction(TileIndex location, TownID town_id, uint8 action) + DoTownAction(TileIndex location, TownID town_id, uint8_t action) :location{location}, town_id{town_id}, action{action} {} ~DoTownAction() override {} @@ -1566,9 +1560,9 @@ public: class TownGrowthRate: public Command { public: TownID town_id; - uint16 growth_rate; + uint16_t growth_rate; - TownGrowthRate(TownID town_id, uint16 growth_rate) + TownGrowthRate(TownID town_id, uint16_t growth_rate) :town_id{town_id}, growth_rate{growth_rate} {} ~TownGrowthRate() override {} @@ -1581,9 +1575,9 @@ class TownRating: public Command { public: TownID town_id; CompanyID company_id; - int16 rating; + int16_t rating; - TownRating(TownID town_id, CompanyID company_id, int16 rating) + TownRating(TownID town_id, CompanyID company_id, int16_t rating) :town_id{town_id}, company_id{company_id}, rating{rating} {} ~TownRating() override {} @@ -1595,11 +1589,11 @@ public: class TownCargoGoal: public Command { public: TownID town_id; - TownEffect te; - uint32 goal; + TownAcceptanceEffect tae; + uint32_t goal; - TownCargoGoal(TownID town_id, TownEffect te, uint32 goal) - :town_id{town_id}, te{te}, goal{goal} {} + TownCargoGoal(TownID town_id, TownAcceptanceEffect tae, uint32_t goal) + :town_id{town_id}, tae{tae}, goal{goal} {} ~TownCargoGoal() override {} bool _post(::CommandCallback * callback) override; @@ -1624,9 +1618,9 @@ public: class ExpandTown: public Command { public: TownID town_id; - uint32 grow_amount; + uint32_t grow_amount; - ExpandTown(TownID town_id, uint32 grow_amount) + ExpandTown(TownID town_id, uint32_t grow_amount) :town_id{town_id}, grow_amount{grow_amount} {} ~ExpandTown() override {} @@ -1666,11 +1660,11 @@ class BuildIndustry: public Command { public: TileIndex tile; IndustryType it; - uint32 first_layout; + uint32_t first_layout; bool fund; - uint32 seed; + uint32_t seed; - BuildIndustry(TileIndex tile, IndustryType it, uint32 first_layout, bool fund, uint32 seed) + BuildIndustry(TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed) :tile{tile}, it{it}, first_layout{first_layout}, fund{fund}, seed{seed} {} ~BuildIndustry() override {} @@ -1679,17 +1673,59 @@ public: Commands get_command() override; }; -class IndustryCtrl: public Command { +class IndustrySetFlags: public Command { public: IndustryID ind_id; - IndustryAction action; IndustryControlFlags ctlflags; + + IndustrySetFlags(IndustryID ind_id, IndustryControlFlags ctlflags) + :ind_id{ind_id}, ctlflags{ctlflags} {} + ~IndustrySetFlags() override {} + + bool _post(::CommandCallback * callback) override; + CommandCost _do(DoCommandFlag flags) override; + Commands get_command() override; +}; + +class IndustrySetExclusivity: public Command { +public: + IndustryID ind_id; Owner company_id; + bool consumer; + + IndustrySetExclusivity(IndustryID ind_id, Owner company_id, bool consumer) + :ind_id{ind_id}, company_id{company_id}, consumer{consumer} {} + ~IndustrySetExclusivity() override {} + + bool _post(::CommandCallback * callback) override; + CommandCost _do(DoCommandFlag flags) override; + Commands get_command() override; +}; + +class IndustrySetText: public Command { +public: + IndustryID ind_id; const std::string & text; - IndustryCtrl(IndustryID ind_id, IndustryAction action, IndustryControlFlags ctlflags, Owner company_id, const std::string & text) - :ind_id{ind_id}, action{action}, ctlflags{ctlflags}, company_id{company_id}, text{text} {} - ~IndustryCtrl() override {} + IndustrySetText(IndustryID ind_id, const std::string & text) + :ind_id{ind_id}, text{text} {} + ~IndustrySetText() override {} + + bool _post(::CommandCallback * callback) override; + CommandCost _do(DoCommandFlag flags) override; + Commands get_command() override; +}; + +class IndustrySetProduction: public Command { +public: + IndustryID ind_id; + byte prod_level; + bool show_news; + const std::string & text; + + IndustrySetProduction(IndustryID ind_id, byte prod_level, bool show_news, const std::string & text) + :ind_id{ind_id}, prod_level{prod_level}, show_news{show_news}, text{text} {} + ~IndustrySetProduction() override {} bool _post(::CommandCallback * callback) override; CommandCost _do(DoCommandFlag flags) override; @@ -1702,9 +1738,9 @@ public: VehicleID veh; VehicleOrderID sel_ord; ModifyOrderFlags mof; - uint16 data; + uint16_t data; - ModifyOrder(TileIndex location, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16 data) + ModifyOrder(TileIndex location, VehicleID veh, VehicleOrderID sel_ord, ModifyOrderFlags mof, uint16_t data) :location{location}, veh{veh}, sel_ord{sel_ord}, mof{mof}, data{data} {} ~ModifyOrder() override {} @@ -1878,6 +1914,20 @@ public: Commands get_command() override; }; +class SetCompanyMaxLoan: public Command { +public: + CompanyID company; + Money amount; + + SetCompanyMaxLoan(CompanyID company, Money amount) + :company{company}, amount{amount} {} + ~SetCompanyMaxLoan() override {} + + bool _post(::CommandCallback * callback) override; + CommandCost _do(DoCommandFlag flags) override; + Commands get_command() override; +}; + class Pause: public Command { public: PauseMode mode; @@ -2028,9 +2078,10 @@ public: GroupID group_id; VehicleID veh_id; bool add_shared; + const VehicleListIdentifier & vli; - AddVehicleGroup(GroupID group_id, VehicleID veh_id, bool add_shared) - :group_id{group_id}, veh_id{veh_id}, add_shared{add_shared} {} + AddVehicleGroup(GroupID group_id, VehicleID veh_id, bool add_shared, const VehicleListIdentifier & vli) + :group_id{group_id}, veh_id{veh_id}, add_shared{add_shared}, vli{vli} {} ~AddVehicleGroup() override {} bool _post(::CommandCallback * callback) override; diff --git a/src/command_func.h b/src/command_func.h index ce2c0c18d3..5b65827810 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -177,7 +177,7 @@ public: /* Execute the command here. All cost-relevant functions set the expenses type * themselves to the cost object at some point. */ InternalDoBefore(counter.IsTopLevel(), false); - Debug(misc, 0, "DO {}/{} {} {}({}) seed={} company={}", _date, _date_fract, _frame_counter, GetCommandName(Tcmd), Tcmd, _random.state[0] & 0xFF, (int)_current_company); + // Debug(misc, 0, "DO {}/{} {} {}({}) seed={} company={}", _date, _date_fract, _frame_counter, GetCommandName(Tcmd), Tcmd, _random.state[0] & 0xFF, (int)_current_company); Tret res = CommandTraits::proc(flags, args...); InternalDoAfter(ExtractCommandCost(res), flags, counter.IsTopLevel(), false); @@ -417,7 +417,7 @@ protected: if (desync_log) LogCommandExecution(Tcmd, err_message, EndianBufferWriter::FromValue(args), false); - Debug(misc, 0, "EXEC {}/{} {} {}({}) seed={} company={} tile={}", _date, _date_fract, _frame_counter, GetCommandName(Tcmd), Tcmd, _random.state[0] & 0xFF, (int)_current_company, tile); + // Debug(misc, 0, "EXEC {}/{} {} {}({}) seed={} company={} tile={}", _date, _date_fract, _frame_counter, GetCommandName(Tcmd), Tcmd, _random.state[0] & 0xFF, (int)_current_company, tile); /* Actually try and execute the command. */ Tret res2 = std::apply(CommandTraits::proc, std::tuple_cat(std::make_tuple(flags | DC_EXEC), args)); diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 3c6edbf297..f20e7a95e6 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -2258,9 +2258,7 @@ static void ResetCallback(Window *w, bool confirmed) { if (confirmed) { CompanyID company2 = (CompanyID)w->window_number; - char msg[128]; - seprintf(msg, lastof(msg), "!reset %i", company2 + 1); - citymania::NetworkClientSendChatToServer(msg); + citymania::NetworkClientSendChatToServer(fmt::format("!reset {}", company2 + 1)); } } @@ -2620,9 +2618,7 @@ struct CompanyWindow : Window if (!_novarole) return; CompanyID company2 = (CompanyID)this->window_number; // this->query_widget = WID_C_MOD_COMPANY_JOIN; - char msg[128]; - seprintf(msg, lastof(msg), "!move %i", company2 + 1); - citymania::NetworkClientSendChatToServer(msg); + citymania::NetworkClientSendChatToServer(fmt::format("!move {}", company2 + 1)); MarkWholeScreenDirty(); break; } @@ -2636,9 +2632,7 @@ struct CompanyWindow : Window case WID_C_MOD_COMPANY_TOGGLE_LOCK: { if (!_novarole) return; CompanyID company2 = (CompanyID)this->window_number; - char msg[128]; - seprintf(msg, lastof(msg), "!lockp %i", company2 + 1); - citymania::NetworkClientSendChatToServer(msg); + citymania::NetworkClientSendChatToServer(fmt::format("!lockp {}", company2 + 1)); MarkWholeScreenDirty(); break; } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 6a4b94e3b2..b4600fb360 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -328,7 +328,7 @@ struct DepotWindow : Window { } else { /* Arrange unitnumber and flag vertically */ diff_x = 0; - diff_y = WidgetDimensions::scaled.matrix.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; + diff_y = WidgetDimensions::scaled.matrix.top + 'GetCharacterHeight(FS_NORMAL)' + WidgetDimensions::scaled.vsep_normal; } text = text.WithWidth(this->header_width - WidgetDimensions::scaled.hsep_normal, rtl).WithHeight(GetCharacterHeight(FS_NORMAL)).Indent(diff_x, rtl); @@ -1116,17 +1116,13 @@ struct DepotWindow : Window { return Window::OnHotkey(hotkey); } - static HotkeyList hotkeys; + static inline HotkeyList hotkeys{"cm_depot_view", { + Hotkey(WKC_CTRL | 'F', "depot_go_all", WID_D_START_ALL), + Hotkey('R', "depot_build_vehicle", WID_D_BUILD), + Hotkey(WKC_NONE, "depot_clone_vehicle", WID_D_CLONE), + }}; }; -static Hotkey depot_hotkeys[] = { - Hotkey(WKC_CTRL | 'F', "depot_go_all", WID_D_START_ALL), - Hotkey('R', "depot_build_vehicle", WID_D_BUILD), - Hotkey(WKC_NONE, "depot_clone_vehicle", WID_D_CLONE), - HOTKEY_LIST_END -}; -HotkeyList DepotWindow::hotkeys("depot_gui", depot_hotkeys); - static void DepotSellAllConfirmationCallback(Window *win, bool confirmed) { if (confirmed) { @@ -1137,34 +1133,36 @@ static void DepotSellAllConfirmationCallback(Window *win, bool confirmed) } } -TODO depot Hotkeys - static WindowDesc _train_depot_desc(__FILE__, __LINE__, WDP_AUTO, "depot_train", 362, 123, WC_VEHICLE_DEPOT, WC_NONE, 0, - std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets) + std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets), + &DepotWindow::hotkeys ); static WindowDesc _road_depot_desc(__FILE__, __LINE__, WDP_AUTO, "depot_roadveh", 316, 97, WC_VEHICLE_DEPOT, WC_NONE, 0, - std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets) + std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets), + &DepotWindow::hotkeys ); static WindowDesc _ship_depot_desc(__FILE__, __LINE__, WDP_AUTO, "depot_ship", 306, 99, WC_VEHICLE_DEPOT, WC_NONE, 0, - std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets) + std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets), + &DepotWindow::hotkeys ); static WindowDesc _aircraft_depot_desc(__FILE__, __LINE__, WDP_AUTO, "depot_aircraft", 332, 99, WC_VEHICLE_DEPOT, WC_NONE, 0, - std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets) + std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets), + &DepotWindow::hotkeys ); /** diff --git a/src/economy.cpp b/src/economy.cpp index 2a7f1d03db..bd55acda61 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1150,7 +1150,7 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, ui if(CB_Enabled()){ if (_settings_game.citymania.cb.acceptance_range == 0 || (DistanceManhattan(st->town->xy, st->xy) <= _settings_game.citymania.cb.acceptance_range)) { st->town->cb.delivered[cargo_type] += accepted_total; - InvalidateWindowData(WC_CB_TOWN, st->town->index); + InvalidateWindowData(CM_WC_CB_TOWN, st->town->index); } } diff --git a/src/gfx.cpp b/src/gfx.cpp index 5c32ad0db6..6c9b99353f 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1526,7 +1526,7 @@ void DrawDirtyBlocks() if (w->flags & WF_DIRTY) { clear_overlays(); DrawOverlappedWindowFlags flags = DOWF_MARK_DIRTY; - if (unlikely(HasBit(_gfx_debug_flags, GDF_SHOW_WINDOW_DIRTY))) { + if (HasBit(_gfx_debug_flags, GDF_SHOW_WINDOW_DIRTY)) [[ unlikely ]] { flags |= DOWF_SHOW_DEBUG; } DrawOverlappedWindowWithClipping(w, w->left, w->top, w->left + w->width, w->top + w->height, flags); @@ -1537,7 +1537,7 @@ void DrawDirtyBlocks() w->nested_root->FillDirtyWidgets(dirty_widgets); for (NWidgetBase *widget : dirty_widgets) { DrawOverlappedWindowFlags flags = DOWF_MARK_DIRTY; - if (unlikely(HasBit(_gfx_debug_flags, GDF_SHOW_WIDGET_DIRTY))) { + if (HasBit(_gfx_debug_flags, GDF_SHOW_WIDGET_DIRTY)) [[ unlikely ]] { flags |= DOWF_SHOW_DEBUG; } DrawOverlappedWindowWithClipping(w, w->left + widget->pos_x, w->top + widget->pos_y, w->left + widget->pos_x + widget->current_x, w->top + widget->pos_y + widget->current_y, flags); @@ -1566,7 +1566,7 @@ void DrawDirtyBlocks() _dirty_viewport_disp_flags = w->viewport_widget->disp_flags; TransparencyOptionBits to_backup = _transparency_opt; if (_dirty_viewport_disp_flags & ND_NO_TRANSPARENCY) { - _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff + _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_TEXT); // Disable all transparency, except textual stuff } { @@ -1670,7 +1670,7 @@ void DrawDirtyBlocks() for (const Rect &r : _dirty_blocks) { RedrawScreenRect(r.left, r.top, r.right, r.bottom); } - if (unlikely(HasBit(_gfx_debug_flags, GDF_SHOW_RECT_DIRTY))) { + if (HasBit(_gfx_debug_flags, GDF_SHOW_RECT_DIRTY)) [[ unlikely ]] { for (const Rect &r : _dirty_blocks) { GfxFillRect(r.left, r.top, r.right, r.bottom, _string_colourmap[++_dirty_block_colour & 0xF], FILLRECT_CHECKER); } diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 85a082bede..1423ea9ab9 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -150,7 +150,7 @@ static constexpr NWidgetPart _nested_graph_legend_widgets1[] = { EndContainer(), }; -static constexpr NWidgetPart _nested_graph_legend_widgets[] = { +static constexpr NWidgetPart _nested_graph_legend_widgets2[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, WINDOW_BG2), NWidget(WWT_CAPTION, WINDOW_BG2), SetDataTip(STR_GRAPH_KEY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), @@ -354,7 +354,7 @@ protected: r.left += ScaleGUITrad(9); r.right -= ScaleGUITrad(5); - int grid_size_y = std::max(ScaleGUITrad(MIN_GRID_PIXEL_SIZE), FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal); + int grid_size_y = std::max(ScaleGUITrad(MIN_GRID_PIXEL_SIZE), GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal); /* Initial number of horizontal lines. */ int num_hori_lines = ScaleGUITrad(160) / grid_size_y; /* For the rest of the height, the number of horizontal lines will increase more slowly. */ @@ -491,7 +491,7 @@ protected: OverflowSafeInt64 datapoint = this->cost[i][j]; if (datapoint != INVALID_DATAPOINT) { - int mult_range = FindLastBit(x_axis_offset) + FindLastBit(abs(datapoint)); + int mult_range = FindLastBit((uint)x_axis_offset) + FindLastBit((uint)abs(datapoint)); int reduce_range = std::max(mult_range - 31, 0); if (datapoint < 0) { @@ -738,14 +738,14 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { bool show_cargo_colors; uint64 excluded_cargo; - ExcludingCargoBaseGraphWindow(WindowDesc *desc, int widget, StringID format_str_y_axis, bool show_cargo_colors): - BaseGraphWindow(desc, widget, format_str_y_axis), show_cargo_colors{show_cargo_colors} + ExcludingCargoBaseGraphWindow(WindowDesc *desc, StringID format_str_y_axis, bool show_cargo_colors): + BaseGraphWindow(desc, format_str_y_axis), show_cargo_colors{show_cargo_colors} {} void OnInit() override { /* Width of the legend blob. */ - this->legend_width = (FONT_HEIGHT_SMALL - ScaleGUITrad(1)) * 8 / 5; + this->legend_width = (GetCharacterHeight(FS_SMALL) - ScaleGUITrad(1)) * 8 / 5; } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) @@ -797,7 +797,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { /* Redraw frame if lowered */ if (lowered) DrawFrameRect(line, COLOUR_BROWN, FR_LOWERED); - const Rect text = line.Shrink(WidgetDimensions::scaled.framerect).Translate(lowered ? WidgetDimensions::scaled.pressed : 0, lowered ? WidgetDimensions::scaled.pressed : 0); + const Rect text = line.Shrink(WidgetDimensions::scaled.framerect); uint icon_offset = 0; if (this->show_cargo_colors) { @@ -825,7 +825,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { - case WID_CPR_KEY_BUTTON: + case WID_GRAPH_KEY_BUTTON: ShowGraphLegend(); break; @@ -973,7 +973,7 @@ void ShowOperatingProfitGraph() struct IncomeGraphWindow : ExcludingCargoBaseGraphWindow { IncomeGraphWindow(WindowDesc *desc, WindowNumber window_number) : - ExcludingCargoBaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT, false) + ExcludingCargoBaseGraphWindow(desc, STR_JUST_CURRENCY_SHORT, false) { this->num_on_x_axis = GRAPH_NUM_MONTHS; this->num_vert_lines = GRAPH_NUM_MONTHS; @@ -1068,18 +1068,18 @@ static const NWidgetPart _nested_income_graph_widgets2[] = { EndContainer(), }; -static WindowDesc _income_graph_desc1( +static WindowDesc _income_graph_desc1(__FILE__, __LINE__, WDP_AUTO, "graph_income", 0, 0, WC_INCOME_GRAPH, WC_NONE, 0, - _nested_income_graph_widgets1, lengthof(_nested_income_graph_widgets1) + std::begin(_nested_income_graph_widgets1), std::end(_nested_income_graph_widgets1) ); -static WindowDesc _income_graph_desc2( +static WindowDesc _income_graph_desc2(__FILE__, __LINE__, WDP_AUTO, "graph_income", 0, 0, WC_INCOME_GRAPH, WC_NONE, 0, - _nested_income_graph_widgets2, lengthof(_nested_income_graph_widgets2) + std::begin(_nested_income_graph_widgets2), std::end(_nested_income_graph_widgets2) ); void ShowIncomeGraph() @@ -1093,7 +1093,7 @@ void ShowIncomeGraph() struct DeliveredCargoGraphWindow : ExcludingCargoBaseGraphWindow { DeliveredCargoGraphWindow(WindowDesc *desc, WindowNumber window_number) : - ExcludingCargoBaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_COMMA, false) + ExcludingCargoBaseGraphWindow(desc, STR_JUST_COMMA, false) { this->num_on_x_axis = GRAPH_NUM_MONTHS; this->num_vert_lines = GRAPH_NUM_MONTHS; @@ -1104,7 +1104,6 @@ struct DeliveredCargoGraphWindow : ExcludingCargoBaseGraphWindow { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); this->vscroll->SetCount(_sorted_standard_cargo_specs.size()); - this->OnHundredthTick(); this->FinishInitNested(window_number); } @@ -1132,9 +1131,9 @@ static const NWidgetPart _nested_delivered_cargo_graph_widgets1[] = { NWidget(WWT_DEFSIZEBOX, WINDOW_BG1), NWidget(WWT_STICKYBOX, WINDOW_BG1), EndContainer(), - NWidget(WWT_PANEL, WINDOW_BG1, WID_CPR_BACKGROUND), + NWidget(WWT_PANEL, WINDOW_BG1, WID_GRAPH_BACKGROUND), NWidget(NWID_HORIZONTAL), - NWidget(WWT_EMPTY, WINDOW_BG1, WID_CPR_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1), + NWidget(WWT_EMPTY, WINDOW_BG1, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_VERTICAL), NWidget(NWID_SPACER), SetMinimalSize(0, 4), SetFill(0, 0), NWidget(WWT_PUSHTXTBTN, WINDOW_BG1, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0), @@ -1165,9 +1164,9 @@ static const NWidgetPart _nested_delivered_cargo_graph_widgets2[] = { NWidget(WWT_DEFSIZEBOX, WINDOW_BG2), NWidget(WWT_STICKYBOX, WINDOW_BG2), EndContainer(), - NWidget(WWT_PANEL, WINDOW_BG2, WID_CPR_BACKGROUND), + NWidget(WWT_PANEL, WINDOW_BG2, WID_GRAPH_BACKGROUND), NWidget(NWID_HORIZONTAL), - NWidget(WWT_EMPTY, WINDOW_BG2, WID_CPR_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1), + NWidget(WWT_EMPTY, WINDOW_BG2, WID_GRAPH_GRAPH), SetMinimalSize(576, 128), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_VERTICAL), NWidget(NWID_SPACER), SetMinimalSize(0, 4), SetFill(0, 0), NWidget(WWT_PUSHTXTBTN, WINDOW_BG2, WID_CPR_ENABLE_CARGOES), SetDataTip(STR_GRAPH_CARGO_ENABLE_ALL, STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL), SetFill(1, 0), @@ -1189,14 +1188,14 @@ static const NWidgetPart _nested_delivered_cargo_graph_widgets2[] = { EndContainer(), }; -static WindowDesc _delivered_cargo_graph_desc1( +static WindowDesc _delivered_cargo_graph_desc1(__FILE__, __LINE__, WDP_AUTO, "graph_delivered_cargo", 0, 0, WC_DELIVERED_CARGO, WC_NONE, 0, std::begin(_nested_delivered_cargo_graph_widgets1), std::end(_nested_delivered_cargo_graph_widgets1) ); -static WindowDesc _delivered_cargo_graph_desc2( +static WindowDesc _delivered_cargo_graph_desc2(__FILE__, __LINE__, WDP_AUTO, "graph_delivered_cargo", 0, 0, WC_DELIVERED_CARGO, WC_NONE, 0, @@ -1247,7 +1246,7 @@ static const NWidgetPart _nested_performance_history_widgets1[] = { NWidget(WWT_DEFSIZEBOX, WINDOW_BG1), NWidget(WWT_STICKYBOX, WINDOW_BG1), EndContainer(), - NWidget(WWT_PANEL, WINDOW_BG1, WID_PHG_BACKGROUND), + NWidget(WWT_PANEL, WINDOW_BG1, WID_GRAPH_BACKGROUND), NWidget(NWID_VERTICAL), NWidget(WWT_EMPTY, WINDOW_BG1, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), @@ -1270,7 +1269,7 @@ static const NWidgetPart _nested_performance_history_widgets2[] = { NWidget(WWT_DEFSIZEBOX, WINDOW_BG2), NWidget(WWT_STICKYBOX, WINDOW_BG2), EndContainer(), - NWidget(WWT_PANEL, WINDOW_BG2, WID_PHG_BACKGROUND), + NWidget(WWT_PANEL, WINDOW_BG2, WID_GRAPH_BACKGROUND), NWidget(NWID_VERTICAL), NWidget(WWT_EMPTY, WINDOW_BG2, WID_GRAPH_GRAPH), SetMinimalSize(576, 224), SetFill(1, 1), SetResize(1, 1), NWidget(NWID_HORIZONTAL), @@ -1282,14 +1281,14 @@ static const NWidgetPart _nested_performance_history_widgets2[] = { EndContainer(), EndContainer(), }; -static WindowDesc _performance_history_desc1( +static WindowDesc _performance_history_desc1(__FILE__, __LINE__, WDP_AUTO, "graph_performance", 0, 0, WC_PERFORMANCE_HISTORY, WC_NONE, 0, std::begin(_nested_performance_history_widgets1), std::end(_nested_performance_history_widgets1) ); -static WindowDesc _performance_history_desc2( +static WindowDesc _performance_history_desc2(__FILE__, __LINE__, WDP_AUTO, "graph_performance", 0, 0, WC_PERFORMANCE_HISTORY, WC_NONE, 0, @@ -1368,14 +1367,14 @@ static const NWidgetPart _nested_company_value_graph_widgets2[] = { EndContainer(), }; -static WindowDesc _company_value_graph_desc1( +static WindowDesc _company_value_graph_desc1(__FILE__, __LINE__, WDP_AUTO, "graph_company_value", 0, 0, WC_COMPANY_VALUE, WC_NONE, 0, std::begin(_nested_company_value_graph_widgets1), std::end(_nested_company_value_graph_widgets1) ); -static WindowDesc _company_value_graph_desc2( +static WindowDesc _company_value_graph_desc2(__FILE__, __LINE__, WDP_AUTO, "graph_company_value", 0, 0, WC_COMPANY_VALUE, WC_NONE, 0, @@ -1393,7 +1392,7 @@ void ShowCompanyValueGraph() struct PaymentRatesGraphWindow : ExcludingCargoBaseGraphWindow { PaymentRatesGraphWindow(WindowDesc *desc, WindowNumber window_number) : - ExcludingCargoBaseGraphWindow(desc, WID_CPR_GRAPH, STR_JUST_CURRENCY_SHORT, true) + ExcludingCargoBaseGraphWindow(desc, STR_JUST_CURRENCY_SHORT, true) { this->num_on_x_axis = 24; this->num_vert_lines = 24; @@ -1570,7 +1569,7 @@ struct PaymentRatesGraphWindow : ExcludingCargoBaseGraphWindow { } i++; } - this->num_dataset = numd; + this->num_dataset = i; } }; @@ -1654,14 +1653,14 @@ static WindowDesc _cargo_payment_rates_desc1(__FILE__, __LINE__, WDP_AUTO, "graph_cargo_payment_rates", 0, 0, WC_PAYMENT_RATES, WC_NONE, 0, - std::begin(_nested_cargo_payment_rates_widgets), std::end(_nested_cargo_payment_rates_widgets) + std::begin(_nested_cargo_payment_rates_widgets1), std::end(_nested_cargo_payment_rates_widgets1) ); static WindowDesc _cargo_payment_rates_desc2(__FILE__, __LINE__, WDP_AUTO, "graph_cargo_payment_rates", 0, 0, WC_PAYMENT_RATES, WC_NONE, 0, - std::begin(_nested_cargo_payment_rates_widgets), std::end(_nested_cargo_payment_rates_widgets) + std::begin(_nested_cargo_payment_rates_widgets2), std::end(_nested_cargo_payment_rates_widgets2) ); @@ -1937,7 +1936,7 @@ std::unique_ptr MakeCompanyButtonRowsGraphGUI() return MakeCompanyButtonRows(WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST, ChooseGraphColour(WINDOW_BG1, WINDOW_BG2), 8, STR_PERFORMANCE_DETAIL_SELECT_COMPANY_TOOLTIP); } -static constexpr NWidgetPart _nested_performance_rating_detail_widgets[] = { +static constexpr NWidgetPart _nested_performance_rating_detail_widgets1[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, WINDOW_BG1), NWidget(WWT_CAPTION, WINDOW_BG1), SetDataTip(STR_PERFORMANCE_DETAIL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), @@ -1963,14 +1962,14 @@ static constexpr NWidgetPart _nested_performance_rating_detail_widgets2[] = { NWidgetFunction(MakePerformanceDetailPanels), }; -static WindowDesc _performance_rating_detail_desc1( +static WindowDesc _performance_rating_detail_desc1(__FILE__, __LINE__, WDP_AUTO, "league_details", 0, 0, WC_PERFORMANCE_DETAIL, WC_NONE, 0, std::begin(_nested_performance_rating_detail_widgets1), std::end(_nested_performance_rating_detail_widgets1) ); -static WindowDesc _performance_rating_detail_desc2( +static WindowDesc _performance_rating_detail_desc2(__FILE__, __LINE__, WDP_AUTO, "league_details", 0, 0, WC_PERFORMANCE_DETAIL, WC_NONE, 0, diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index fb8a45b5bb..e51615260d 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -330,10 +330,6 @@ static WindowDesc _build_industry_desc(__FILE__, __LINE__, class BuildIndustryWindow : public Window { IndustryType selected_type; ///< industry corresponding to the above index - TODO is this even used - uint16 callback_timer; ///< timer counter for callback eventual verification - bool timer_enabled; ///< timer can be used - std::vector list; ///< List of industries. bool enabled; ///< Availability state of the selected industry. Scrollbar *vscroll; @@ -376,7 +372,6 @@ class BuildIndustryWindow : public Window { /* First industry type is selected if the current selection is invalid. */ if (this->selected_type == INVALID_INDUSTRYTYPE && !this->list.empty()) { _cm_funding_type = this->selected_type = this->list[0]; - TODO what is _cm_funding_type citymania::SetIndustryForbiddenTilesHighlight(this->selected_type); } @@ -837,25 +832,22 @@ public: return Window::OnHotkey(hotkey); } - static HotkeyList hotkeys; + /* CityMania code start */ + static inline HotkeyList hotkeys{"cm_build_industry", { + Hotkey((uint16)0, "display_chain", WID_DPI_DISPLAY_WIDGET), + Hotkey((uint16)0, "build_button", WID_DPI_FUND_WIDGET), + Hotkey(CM_WKC_MOUSE_MIDDLE, "switch_layout", CM_HOTKEY_SWITCH_LAYOUT), + }}; + /* CityMania code end */ }; -static Hotkey build_industry_hotkeys[] = { - Hotkey((uint16)0, "display_chain", WID_DPI_DISPLAY_WIDGET), - Hotkey((uint16)0, "build_button", WID_DPI_FUND_WIDGET), - Hotkey(CM_WKC_MOUSE_MIDDLE, "cm_switch_layout", CM_HOTKEY_SWITCH_LAYOUT), - HOTKEY_LIST_END -}; - -HotkeyList BuildIndustryWindow::hotkeys("industry_fund_gui", build_industry_hotkeys); - /** Window definition of the dynamic place industries gui */ -static WindowDesc _build_industry_desc( +static WindowDesc _build_industry_desc(__FILE__, __LINE__, WDP_AUTO, "build_industry", 170, 212, WC_BUILD_INDUSTRY, WC_NONE, WDF_CONSTRUCTION, - _nested_build_industry_widgets, lengthof(_nested_build_industry_widgets), - &BuildIndustryWindow::hotkeys + std::begin(_nested_build_industry_widgets), std::end(_nested_build_industry_widgets), + &BuildIndustryWindow::hotkeys // CM ); @@ -3213,11 +3205,10 @@ struct IndustryCargoesWindow : public Window { continue; } - TODO make list icon item - DropDownListParamStringItem *item = new DropDownListParamStringItem(CM_STR_CARGO_WITH_ID, cs->Index(), false); - item->SetParam(0, cs->name); - item->SetParam(1, cs->Index()); - lst.emplace_back(item); + SetDParam(0, cs->name); + SetDParam(1, cs->Index()); + auto s = GetString(CM_STR_CARGO_WITH_ID); + lst.push_back(std::make_unique(d, cs->GetCargoIcon(), PAL_NONE, s, cs->Index(), false)); } if (!lst.empty()) { int selected = (this->ind_cargo >= NUM_INDUSTRYTYPES) ? (int)(this->ind_cargo - NUM_INDUSTRYTYPES) : -1; @@ -3236,11 +3227,10 @@ struct IndustryCargoesWindow : public Window { continue; } - TODO make list icon item - DropDownListParamStringItem *item = new DropDownListParamStringItem(CM_STR_INDUSTRY_TYPE_WITH_ID, ind, false); - item->SetParam(0, indsp->name); - item->SetParam(1, ind); - lst.emplace_back(item); + SetDParam(0, indsp->name); + SetDParam(1, ind); + auto s = GetString(CM_STR_INDUSTRY_TYPE_WITH_ID); + lst.push_back(std::make_unique(s, ind, false)); } if (!lst.empty()) { int selected = (this->ind_cargo < NUM_INDUSTRYTYPES) ? (int)this->ind_cargo : -1; diff --git a/src/lang/english.txt b/src/lang/english.txt index 195c5cb600..ab3cb6cf7f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -6225,7 +6225,6 @@ CM_STR_CONFIG_SETTING_IMPROVED_STATION_JOIN :Use improved st CM_STR_CONFIG_SETTING_IMPROVED_STATION_JOIN_HELPTEXT :Use Ctrl-click on station tile to select or deselect station to join. If station has no tiles Ctrl-click its sign. Ctrl-click empty tile for a new station. Also recently built station is automatically selected as a station to join. {RED}Doesn't work if joining stations not directly adjacent(distant join) is not allowed in settings. CM_STR_CONFIG_SETTING_VEHICLES_CTRL :{ORANGE}Controls & Orders -CM_STR_CONFIG_SETTING_ORDER_SHORTCUTS :{ORANGE}Order's Shortcuts CM_STR_CONFIG_SETTING_AUTOSET_NOLOAD_ON_TRANSFER :"Transfer" orders are "No Loading" by default: {STRING2} CM_STR_CONFIG_SETTING_AUTOSET_NOLOAD_ON_UNLOAD :"Unload all" orders are "No Loading" by default: {STRING2} diff --git a/src/lang/german.txt b/src/lang/german.txt index 222ef62de0..00805ce49c 100644 --- a/src/lang/german.txt +++ b/src/lang/german.txt @@ -6024,7 +6024,6 @@ CM_STR_CONFIG_SETTING_IMPROVED_STATION_JOIN :Verbesserte Ste CM_STR_CONFIG_SETTING_IMPROVED_STATION_JOIN_HELPTEXT :Strg-Klick auf ein Stationsfeld anwenden, um eine Station zum verbinden an- oder abzuwählen. Strg-Klick auf das Stationsschild, falls die Station keine Felder hat. Für eine neue Station, Strg-Klick auf ein leeres Feld. Eine kürzlich gebaute Station ist automatisch zum Verbinden ausgewählt. {RED}Funktioniert nicht, falls das Verbinden von nicht direkt angrenzenden Stationen in den Einstellungen verboten ist. CM_STR_CONFIG_SETTING_VEHICLES_CTRL :{ORANGE}Steuerung & Aufträge -CM_STR_CONFIG_SETTING_ORDER_SHORTCUTS :{ORANGE}Auftrag-Tastenkürzel CM_STR_CONFIG_SETTING_AUTOSET_NOLOAD_ON_TRANSFER :"Umladen"-Aufträge sind standardmäßig "Nicht beladen": {STRING} CM_STR_CONFIG_SETTING_AUTOSET_NOLOAD_ON_UNLOAD :"Alles entladen"-Aufträge sind standardmäßig "Nicht beladen": {STRING} diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index ce7901d747..ad086ebbaf 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -431,9 +431,7 @@ Point LinkGraphOverlay::GetStationMiddle(const Station *st) const return GetViewportStationMiddle(this->window->viewport, st); } else { /* assume this is a smallmap */ - TODO fix GetSmallMapStationMiddle return GetSmallMapStationMiddle(this->window, st); - return static_cast(this->window)->GetStationMiddle(st); } } diff --git a/src/map.cpp b/src/map.cpp index 6807f37a59..642143ef71 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -66,7 +66,7 @@ extern "C" _CRTIMP void __cdecl _assert(void *, void *, unsigned); Tile::extended_tiles = CallocT(Map::size); AllocateWaterRegions(); - citymania::AllocateZoningMap(_map_size); + citymania::AllocateZoningMap(Map::size); } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 0787f96d2e..6942875a2e 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -186,7 +186,7 @@ public: td.road_speed = 0; td.tramtype = STR_NULL; td.tram_speed = 0; - td.population = 0; + td.cm_population = 0; td.grf = nullptr; @@ -324,11 +324,12 @@ public: this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_NEWGRF_NAME)); } - /* House pop */ - if (td.population != 0) { - SetDParam(0, td.population); + /* CityMania code start (House pop) */ + if (td.cm_population != 0) { + SetDParam(0, td.cm_population); this->landinfo_data.push_back(GetString(CM_STR_LAND_AREA_INFORMATION_POP)); } + /* CityMania code end */ /* Cargo acceptance is displayed in a extra multiline */ std::stringstream line; @@ -1288,6 +1289,6 @@ void GuiPrepareTooltipsExtra(Window *parent){ } citymania::ShowLandInfo(INVALID_TILE); - if (tile >= MapSize()) tile = INVALID_TILE; + if (tile >= Map::Size()) tile = INVALID_TILE; citymania::ShowLandTooltips(tile, parent); } diff --git a/src/network/network.cpp b/src/network/network.cpp index 234795b5f9..8f5ced6093 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1203,7 +1203,7 @@ void NetworkGameLoop() NetworkExecuteLocalCommandQueue(); if (citymania::_pause_countdown > 0 && --citymania::_pause_countdown == 0) Command::Post(PM_PAUSED_NORMAL, 1); - citymania::ExecuteFakeCommands(_date, _date_fract); + citymania::ExecuteFakeCommands(TimerGameTick::counter); /* Then we make the frame */ StateGameLoop(); diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp index c4f6d94b9c..baa3397a98 100644 --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -332,8 +332,7 @@ void NetworkExecuteLocalCommandQueue() if (_frame_counter > cp->frame) { /* If we reach here, it means for whatever reason, we've already executed * past the command we need to execute. */ - TODO {} format? - FatalError("[net] Trying to execute a packet in the past! (frame=%u cmd_frame=%u cmd=%u)", (uint)_frame_counter, (uint)cp->frame, (uint)cp->cmd); + FatalError("[net] Trying to execute a packet in the past! (frame={} cmd_frame={} cmd={})", (uint)_frame_counter, (uint)cp->frame, (uint)cp->cmd); } /* We can execute this command */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index cdd7c733c0..9e51688d71 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -181,24 +181,7 @@ public: } else { std::for_each(std::begin(this->children), std::end(this->children), assign_position); } - return nullptr; } - - /* CityMania code start */ - TODO the heck is this even doing - void FillDirtyWidgets(std::vector &dirty_widgets) override - { - if (this->base_flags & WBF_DIRTY) { - dirty_widgets.push_back(this); - } else { - int i = 0; - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { - if (!this->visible[i++]) continue; - child_wid->FillDirtyWidgets(dirty_widgets); - } - } - } - /* CityMania code end */ }; class NetworkGameWindow : public Window { diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 253487291f..21ba90b4a1 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -455,7 +455,7 @@ struct NewGRFInspectWindow : Window { const void *base_spec = nih->GetSpec(index); uint i = 0; - this->DrawString(r, i++, "Industry type: %d", (int)((const Industry *)base)->type); + this->DrawString(r, i++, fmt::format("Industry type: {}", (int)((const Industry *)base)->type)); if (nif->variables != nullptr) { this->DrawString(r, i++, "Variables:"); for (const NIVariable *niv = nif->variables; niv->name != nullptr; niv++) { diff --git a/src/openttd.cpp b/src/openttd.cpp index c08960dae2..3b3dfe931a 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -159,7 +159,7 @@ static void ShowHelp() str.reserve(8192); std::back_insert_iterator output_iterator = std::back_inserter(str); - fmt::format_to(output_iterator, "OpenTTD {}\n", _openttd_revision); + fmt::format_to(output_iterator, "OpenTTD {} (CityMania Fork)\n", _openttd_revision); str += "\n" "\n" @@ -672,7 +672,7 @@ int openttd_main(int argc, char *argv[]) return ret; } citymania::load_replay_commands(mgo.opt, [](auto error) { - fprintf(stderr, "%s\n", error.c_str()); + fmt::print(stderr, "{}\n", error.c_str()); }); break; } @@ -1643,7 +1643,7 @@ void GameLoop() * We do this here, because it means that the network is really closed */ NetworkClientConnectGame(_settings_client.network.last_joined, COMPANY_SPECTATOR); } - citymania::ExecuteFakeCommands(_date, _date_fract); + citymania::ExecuteFakeCommands(TimerGameTick::counter); /* Singleplayer */ StateGameLoop(); citymania::CheckIntervalSave(); diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 5901091eba..0247548886 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -501,18 +501,6 @@ struct BuildRailToolbarWindow : Window { return true; } - /** - * Some data on this window has become invalid. - * @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. - */ - void OnInvalidateData(int data = 0, bool gui_scope = true) override - { - if (!gui_scope) return; - - if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) this->Close(); - } - /** * Configures the rail toolbar for railtype given * @param railtype the railtype to display @@ -2174,14 +2162,12 @@ static void ShowSignalBuilder(Window *parent) } -struct BuildRailDepotWindow : public PickerWindowBase { -/* CityMania code start */ -public: - enum class Hotkey : int { - ROTATE, - }; -/* CityMania code end */ +enum BuildRailDepotWindowHotkeys { + BRDHK_ROTATE, +}; +struct BuildRailDepotWindow : public PickerWindowBase { +public: BuildRailDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent) { this->InitNested(TRANSPORT_RAIL); @@ -2239,10 +2225,10 @@ public: /* CityMania code start */ EventState OnHotkey(int hotkey) override { - switch ((BuildRailDepotWindow::Hotkey)hotkey) { + switch (hotkey) { /* Indicate to the OnClick that the action comes from a hotkey rather * then from a click and that the CTRL state should be ignored. */ - case BuildRailDepotWindow::Hotkey::ROTATE: + case BRDHK_ROTATE: if (_build_depot_direction < DIAGDIR_END) { this->RaiseWidget(_build_depot_direction + WID_BRAD_DEPOT_NE); _build_depot_direction = ChangeDiagDir(_build_depot_direction, DIAGDIRDIFF_90RIGHT); @@ -2260,19 +2246,13 @@ public: return ES_NOT_HANDLED; } - static HotkeyList hotkeys; + /* CityMania code start */ + static inline HotkeyList hotkeys {"cm_build_rail_depot", { + Hotkey(CM_WKC_MOUSE_MIDDLE, "rotate", BRDHK_ROTATE), + }}; /* CityMania code end */ }; -/* CityMania code start */ -TODO needs to go in the window -static Hotkey build_depot_hotkeys[] = { - Hotkey(CM_WKC_MOUSE_MIDDLE, "rotate", (int)BuildRailDepotWindow::Hotkey::ROTATE), - HOTKEY_LIST_END -}; -HotkeyList BuildRailDepotWindow::hotkeys("cm_build_rail_depot", build_depot_hotkeys); -/* CityMania code end */ - /** Nested widget definition of the build rail depot window */ static constexpr NWidgetPart _nested_build_depot_widgets[] = { NWidget(NWID_HORIZONTAL), @@ -2302,7 +2282,8 @@ static WindowDesc _build_depot_desc(__FILE__, __LINE__, WDP_AUTO, nullptr, 0, 0, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, - std::begin(_nested_build_depot_widgets), std::end(_nested_build_depot_widgets) + std::begin(_nested_build_depot_widgets), std::end(_nested_build_depot_widgets), + &BuildRailDepotWindow::hotkeys // CM ); static void ShowBuildTrainDepotPicker(Window *parent) diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 8066f542b3..d67abc0e39 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -76,7 +76,7 @@ struct RoadStopGUISettings { uint16_t roadstop_type; uint16_t roadstop_count; }; -static RoadStopGUISettings _roadstop_gui_settings; +/* CM static */ RoadStopGUISettings _roadstop_gui_settings; /** * Check whether a road stop type can be built. @@ -228,8 +228,8 @@ static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType TileArea ta(start_tile, end_tile); assert(_thd.cm.type == citymania::ObjectHighlight::Type::ROAD_STOP); + // DiagDirection ddir = _roadstop_gui_settings.orientation; DiagDirection ddir = _thd.cm.ddir; - TODO // DiagDirection ddir = _roadstop_gui_settings.orientation; bool drive_through = ddir >= DIAGDIR_END; if (drive_through) ddir = static_cast(ddir - DIAGDIR_END); // Adjust picker result to actual direction. RoadStopClassID spec_class = _roadstop_gui_settings.roadstop_class; @@ -308,7 +308,7 @@ static bool RoadToolbar_CtrlChanged(Window *w) if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false; /* allow ctrl to switch remove mode only for these widgets */ - for (WidgetID i = WID_ROT_ROAD_X; i <= WID_ROT_AUTOROAD; i++) { + for (WidgetID i = WID_ROT_ROAD_X; i <= CM_WID_ROT_AUTOROAD; i++) { if (w->GetWidget(i) && w->IsWidgetLowered(i)) { ToggleRoadButton_Remove(w); return true; @@ -398,7 +398,7 @@ struct BuildRoadToolbarWindow : Window { { this->GetWidget(WID_ROT_ROAD_X)->widget_data = rti->gui_sprites.build_x_road; this->GetWidget(WID_ROT_ROAD_Y)->widget_data = rti->gui_sprites.build_y_road; - this->GetWidget(WID_ROT_AUTOROAD)->widget_data = rti->gui_sprites.auto_road; + this->GetWidget(CM_WID_ROT_AUTOROAD)->widget_data = rti->gui_sprites.auto_road; if (_game_mode != GM_EDITOR) { this->GetWidget(WID_ROT_DEPOT)->widget_data = rti->gui_sprites.build_depot; } @@ -462,7 +462,7 @@ struct BuildRoadToolbarWindow : Window { case WID_ROT_ROAD_X: case WID_ROT_ROAD_Y: - case WID_ROT_AUTOROAD: + case CM_WID_ROT_AUTOROAD: this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget)); if (RoadTypeIsRoad(this->roadtype)) { this->SetWidgetDisabledState(WID_ROT_ONE_WAY, !this->IsWidgetLowered(clicked_widget)); @@ -499,8 +499,8 @@ struct BuildRoadToolbarWindow : Window { this->last_started_action = widget; break; - case WID_ROT_AUTOROAD: - HandlePlacePushButton(this, WID_ROT_AUTOROAD, this->rti->cursor.autoroad, HT_RECT, DDSP_PLACE_AUTOROAD); + case CM_WID_ROT_AUTOROAD: + HandlePlacePushButton(this, CM_WID_ROT_AUTOROAD, this->rti->cursor.autoroad, HT_RECT, DDSP_PLACE_AUTOROAD); this->last_started_action = widget; break; @@ -593,7 +593,7 @@ struct BuildRoadToolbarWindow : Window { VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_ROAD_Y_DIR); break; - case WID_ROT_AUTOROAD: + case CM_WID_ROT_AUTOROAD: _place_road_dir = INVALID_AXIS; _place_road_start_half_x = _tile_fract_coords.x >= 8; _place_road_start_half_y = _tile_fract_coords.y >= 8; @@ -820,7 +820,7 @@ struct BuildRoadToolbarWindow : Window { static inline HotkeyList road_hotkeys{"roadtoolbar", { Hotkey('1', "build_x", WID_ROT_ROAD_X), Hotkey('2', "build_y", WID_ROT_ROAD_Y), - Hotkey('3', "autoroad", WID_ROT_AUTOROAD), + Hotkey('3', "cm_autoroad", CM_WID_ROT_AUTOROAD), Hotkey('4', "demolish", WID_ROT_DEMOLISH), Hotkey('5', "depot", WID_ROT_DEPOT), Hotkey('6', "bus_station", WID_ROT_BUS_STATION), @@ -835,7 +835,7 @@ struct BuildRoadToolbarWindow : Window { static inline HotkeyList tram_hotkeys{"tramtoolbar", { Hotkey('1', "build_x", WID_ROT_ROAD_X), Hotkey('2', "build_y", WID_ROT_ROAD_Y), - Hotkey('3', "autoroad", WID_ROT_AUTOROAD), + Hotkey('3', "cm_autoroad", CM_WID_ROT_AUTOROAD), Hotkey('4', "demolish", WID_ROT_DEMOLISH), Hotkey('5', "depot", WID_ROT_DEPOT), Hotkey('6', "bus_station", WID_ROT_BUS_STATION), @@ -858,7 +858,7 @@ static constexpr NWidgetPart _nested_build_road_widgets[] = { SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION), - NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD), + NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, CM_WID_ROT_AUTOROAD), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC), @@ -901,7 +901,7 @@ static constexpr NWidgetPart _nested_build_tramway_widgets[] = { SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION), - NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD), + NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, CM_WID_ROT_AUTOROAD), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC), @@ -960,7 +960,7 @@ static constexpr NWidgetPart _nested_build_road_scen_widgets[] = { SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION), - NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD), + NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, CM_WID_ROT_AUTOROAD), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC), @@ -997,7 +997,7 @@ static constexpr NWidgetPart _nested_build_tramway_scen_widgets[] = { SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION), - NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD), + NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, CM_WID_ROT_AUTOROAD), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC), @@ -1033,14 +1033,12 @@ Window *ShowBuildRoadScenToolbar(RoadType roadtype) return AllocateWindowDescFront(RoadTypeIsRoad(_cur_roadtype) ? &_build_road_scen_desc : &_build_tramway_scen_desc, TRANSPORT_ROAD); } -struct BuildRoadDepotWindow : public PickerWindowBase { -/* CityMania code start */ -public: - enum class Hotkey : int { - ROTATE, - }; -/* CityMania code end */ +enum BuildRoadDepotHotkeys { + BRDHK_ROTATE, +}; +struct BuildRoadDepotWindow : public PickerWindowBase { +public: BuildRoadDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent) { this->CreateNestedTree(); @@ -1048,7 +1046,7 @@ public: this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation); if (RoadTypeIsTram(_cur_roadtype)) { this->GetWidget(WID_BROD_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION; - for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_AUTO; i++) { + for (WidgetID i = WID_BROD_DEPOT_NE; i <= CM_WID_BROD_DEPOT_AUTO; i++) { this->GetWidget(i)->tool_tip = STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP; } } @@ -1066,7 +1064,7 @@ public: size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); size->height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); break; - case WID_BROD_DEPOT_AUTO: + case CM_WID_BROD_DEPOT_AUTO: size->width = ScaleGUITrad(128 + 2) + 2 * WidgetDimensions::scaled.fullbevel.Horizontal(); break; default: @@ -1095,7 +1093,7 @@ public: case WID_BROD_DEPOT_NE: case WID_BROD_DEPOT_SW: case WID_BROD_DEPOT_SE: - case WID_BROD_DEPOT_AUTO: + case CM_WID_BROD_DEPOT_AUTO: this->RaiseWidget(WID_BROD_DEPOT_NE + _road_depot_orientation); _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE); this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation); @@ -1111,10 +1109,10 @@ public: /* CityMania code start */ EventState OnHotkey(int hotkey) override { - switch ((BuildRoadDepotWindow::Hotkey)hotkey) { + switch (hotkey) { /* Indicate to the OnClick that the action comes from a hotkey rather * then from a click and that the CTRL state should be ignored. */ - case BuildRoadDepotWindow::Hotkey::ROTATE: + case BRDHK_ROTATE: if (_road_depot_orientation < DIAGDIR_END) { this->RaiseWidget(_road_depot_orientation + WID_BROD_DEPOT_NE); _road_depot_orientation = ChangeDiagDir(_road_depot_orientation, DIAGDIRDIFF_90RIGHT); @@ -1132,8 +1130,11 @@ public: return ES_NOT_HANDLED; } - static HotkeyList hotkeys; + static inline HotkeyList hotkeys {"cm_build_road_depot", { + Hotkey(CM_WKC_MOUSE_MIDDLE, "rotate", BRDHK_ROTATE), + }}; /* CityMania code end */ + }; static constexpr NWidgetPart _nested_build_road_depot_widgets[] = { @@ -1153,25 +1154,17 @@ static constexpr NWidgetPart _nested_build_road_depot_widgets[] = { NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SE), SetMinimalSize(66, 50), SetFill(0, 0), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP), EndContainer(), EndContainer(), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_AUTO), SetMinimalSize(134, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_BUILD_DEPOT_ROAD_ORIENTATION_AUTO_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, CM_WID_BROD_DEPOT_AUTO), SetMinimalSize(134, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_BUILD_DEPOT_ROAD_ORIENTATION_AUTO_TOOLTIP), EndContainer(), EndContainer(), }; -/* CityMania code start */ -TODO -static Hotkey build_depot_hotkeys[] = { - Hotkey(CM_WKC_MOUSE_MIDDLE, "rotate", (int)BuildRoadDepotWindow::Hotkey::ROTATE), - HOTKEY_LIST_END -}; -HotkeyList BuildRoadDepotWindow::hotkeys("cm_build_road_depot", build_depot_hotkeys); -/* CityMania code end */ - -static WindowDesc _build_road_depot_desc( +static WindowDesc _build_road_depot_desc(__FILE__, __LINE__, WDP_AUTO, nullptr, 0, 0, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, - std::begin(_nested_build_road_depot_widgets), std::end(_nested_build_road_depot_widgets) + std::begin(_nested_build_road_depot_widgets), std::end(_nested_build_road_depot_widgets), + &BuildRoadDepotWindow::hotkeys ); static void ShowRoadDepotPicker(Window *parent) @@ -1275,7 +1268,7 @@ public: if (RoadTypeIsTram(_cur_roadtype)) { this->GetWidget(WID_BROS_STATION_X)->tool_tip = rti->strings.picker_tooltip[rs]; this->GetWidget(WID_BROS_STATION_Y)->tool_tip = rti->strings.picker_tooltip[rs]; - this->GetWidget(WID_BROS_STATION_XY_AUTO)->tool_tip = rti->strings.picker_tooltip[rs]; + this->GetWidget(CM_WID_BROS_STATION_XY_AUTO)->tool_tip = rti->strings.picker_tooltip[rs]; } else { for (WidgetID i = WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) { this->GetWidget(i)->tool_tip = rti->strings.picker_tooltip[rs]; @@ -1400,6 +1393,24 @@ public: return ES_HANDLED; } + if (hotkey == CM_BROSHK_ROTATE) { + if (_road_station_picker_orientation < citymania::STATIONDIR_AUTO) { + this->RaiseWidget(_road_station_picker_orientation + WID_BROS_STATION_NE); + if (_road_station_picker_orientation < DIAGDIR_END) { + _road_station_picker_orientation = ChangeDiagDir(_road_station_picker_orientation, DIAGDIRDIFF_90RIGHT); + } else if (_road_station_picker_orientation == citymania::STATIONDIR_X) { + _road_station_picker_orientation = citymania::STATIONDIR_Y; + } else if (_road_station_picker_orientation == citymania::STATIONDIR_Y) { + _road_station_picker_orientation = citymania::STATIONDIR_X; + } + this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE); + } else { + citymania::RotateAutodetection(); + } + this->SetDirty(); + return ES_HANDLED; + } + return ES_NOT_HANDLED; } @@ -1482,10 +1493,10 @@ public: break; /* CityMania code start */ - case WID_BROS_STATION_AUTO: + case CM_WID_BROS_STATION_AUTO: size->width = ScaleGUITrad(128 + 2) + 2 * WidgetDimensions::scaled.fullbevel.Horizontal(); break; - case WID_BROS_STATION_XY_AUTO: + case CM_WID_BROS_STATION_XY_AUTO: if (RoadTypeIsTram(_cur_roadtype)) size->width = ScaleGUITrad(128 + 2) + 2 * WidgetDimensions::scaled.fullbevel.Horizontal(); else @@ -1613,8 +1624,8 @@ public: case WID_BROS_STATION_NW: case WID_BROS_STATION_X: case WID_BROS_STATION_Y: - case WID_BROS_STATION_AUTO: - case WID_BROS_STATION_XY_AUTO: + case CM_WID_BROS_STATION_AUTO: + case CM_WID_BROS_STATION_XY_AUTO: if (widget < WID_BROS_STATION_X) { const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type); if (spec != nullptr && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) return; @@ -1694,40 +1705,14 @@ public: this->InvalidateData(); }}; - /* CityMania code start */ - EventState OnHotkey(int hotkey) override - { - switch ((BuildRoadStationWindow::Hotkey)hotkey) { - /* Indicate to the OnClick that the action comes from a hotkey rather - * then from a click and that the CTRL state should be ignored. */ - case BuildRoadStationWindow::Hotkey::ROTATE: - if (_road_station_picker_orientation < citymania::STATIONDIR_AUTO) { - this->RaiseWidget(_road_station_picker_orientation + WID_BROS_STATION_NE); - if (_road_station_picker_orientation < DIAGDIR_END) { - _road_station_picker_orientation = ChangeDiagDir(_road_station_picker_orientation, DIAGDIRDIFF_90RIGHT); - } else if (_road_station_picker_orientation == citymania::STATIONDIR_X) { - _road_station_picker_orientation = citymania::STATIONDIR_Y; - } else if (_road_station_picker_orientation == citymania::STATIONDIR_Y) { - _road_station_picker_orientation = citymania::STATIONDIR_X; - } - this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE); - } else { - citymania::RotateAutodetection(); - } - this->SetDirty(); - return ES_HANDLED; - - default: - NOT_REACHED(); - } - - return ES_NOT_HANDLED; - } - - /* CityMania code end */ - static inline HotkeyList hotkeys{"buildroadstop", { + static inline HotkeyList road_hotkeys{"buildroadstop", { Hotkey('F', "focus_filter_box", BROSHK_FOCUS_FILTER_BOX), - Hotkey(CM_WKC_MOUSE_MIDDLE, "rotate", TODO), + Hotkey(CM_WKC_MOUSE_MIDDLE, "cm_rotate", CM_BROSHK_ROTATE), + }}; + + static inline HotkeyList tram_hotkeys{"buildtramstop", { + Hotkey('F', "focus_filter_box", BROSHK_FOCUS_FILTER_BOX), + Hotkey(CM_WKC_MOUSE_MIDDLE, "cm_rotate", CM_BROSHK_ROTATE), }}; }; @@ -1790,8 +1775,8 @@ static constexpr NWidgetPart _nested_road_station_picker_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(), EndContainer(), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), SetPIPRatio(1, 0, 1), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_STATION_AUTO), SetMinimalSize(134, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_STATION_XY_AUTO), SetMinimalSize(66, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, CM_WID_BROS_STATION_AUTO), SetMinimalSize(134, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, CM_WID_BROS_STATION_XY_AUTO), SetMinimalSize(66, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), EndContainer(), EndContainer(), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BROS_SHOW_NEWST_TYPE_SEL), @@ -1828,14 +1813,12 @@ static constexpr NWidgetPart _nested_road_station_picker_widgets[] = { EndContainer(), }; -TODO -Hotkey(CM_WKC_MOUSE_MIDDLE, "rotate", (int)BuildRoadStationWindow::Hotkey::ROTATE), - static WindowDesc _road_station_picker_desc(__FILE__, __LINE__, WDP_AUTO, "build_station_road", 0, 0, WC_BUS_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, - std::begin(_nested_road_station_picker_widgets), std::end(_nested_road_station_picker_widgets) + std::begin(_nested_road_station_picker_widgets), std::end(_nested_road_station_picker_widgets), + &BuildRoadStationWindow::road_hotkeys ); /** Widget definition of the build tram station window */ @@ -1874,7 +1857,7 @@ static constexpr NWidgetPart _nested_tram_station_picker_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(), NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(), EndContainer(), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_STATION_XY_AUTO), SetMinimalSize(274, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, CM_WID_BROS_STATION_XY_AUTO), SetMinimalSize(274, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BROS_SHOW_NEWST_TYPE_SEL), NWidget(WWT_LABEL, COLOUR_DARK_GREEN, WID_BROS_SHOW_NEWST_TYPE), SetMinimalSize(144, 8), SetDataTip(STR_JUST_STRING, STR_NULL), SetTextStyle(TC_ORANGE), SetFill(1, 0), EndContainer(), @@ -1898,7 +1881,7 @@ static constexpr NWidgetPart _nested_tram_station_picker_widgets[] = { EndContainer(), EndContainer(), NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, WidgetDimensions::unscaled.vsep_normal), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_STATION_XY_AUTO), SetMinimalSize(274, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, CM_WID_BROS_STATION_XY_AUTO), SetMinimalSize(274, 12), SetDataTip(CM_STR_STATION_BUILD_ORIENTATION_AUTO, CM_STR_STATION_BUILD_ORIENTATION_AUTO_TOOLTIP), EndContainer(), EndContainer(), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BROS_SHOW_NEWST_RESIZE), @@ -1910,12 +1893,12 @@ static constexpr NWidgetPart _nested_tram_station_picker_widgets[] = { EndContainer(), }; -TODO rotate hotkey static WindowDesc _tram_station_picker_desc(__FILE__, __LINE__, WDP_AUTO, "build_station_tram", 0, 0, WC_BUS_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, - std::begin(_nested_tram_station_picker_widgets), std::end(_nested_tram_station_picker_widgets) + std::begin(_nested_tram_station_picker_widgets), std::end(_nested_tram_station_picker_widgets), + &BuildRoadStationWindow::tram_hotkeys ); static void ShowRVStationPicker(Window *parent, RoadStopType rs) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 3b3175a42e..234402b816 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -562,16 +562,16 @@ void AfterLoadFindBTProCBInfo() { if (s.empty() || s[0] == ';' || s[0] == '#' || s[0] == ' ' || s[0] == '\0') continue; if (strncmp(s.c_str(), "STR_TOWN_CLAIMED_CARGOS", strlen("STR_TOWN_CLAIMED_CARGOS")) == 0 || strncmp(s.c_str(), "STR_TOWN_CARGOS_NEEDED_CB", strlen("STR_TOWN_CARGOS_NEEDED_CB")) == 0) { - pn = p - buf + seprintf(p, lastof(buf), "%X:", string_id); + pn = p - buf + fmt::format("{:X}:", string_id).length(); bool with_decay = (strncmp(s.c_str(), "STR_TOWN_CLAIMED_CARGOS_DECAY", strlen("STR_TOWN_CLAIMED_CARGOS_DECAY")) == 0); for (StoryPageElement *se : StoryPageElement::Iterate()) { - if (!se->text || strncmp(se->text, buf, pn) != 0) continue; + if (strncmp(se->text.c_str(), buf, pn) != 0) continue; uint req, cargomask, from, decay=0; if (with_decay) { - sscanf(se->text + pn, "%X:%X:%X:%X", &req, &cargomask, &from, &decay); + sscanf(se->text.c_str() + pn, "%X:%X:%X:%X", &req, &cargomask, &from, &decay); } else { - sscanf(se->text + pn, "%X:%X:%X", &req, &cargomask, &from); + sscanf(se->text.c_str() + pn, "%X:%X:%X", &req, &cargomask, &from); } uint cargo_id = FindFirstBit(cargomask); if (!CB_Enabled()) CB_SetCB(true); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index fdc1d4653b..a395d796f1 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -997,7 +997,17 @@ struct GameOptionsWindow : Window { } } - static HotkeyList hotkeys; + static EventState GameOptionsWindowGlobalHotkeys(int hotkey) { + if (!ToggleFullScreen(!_fullscreen)) { + ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR); + } + return ES_HANDLED; + } + + static inline HotkeyList hotkeys{"cm_game_options", { + Hotkey((uint16)0, "toggle_fullscreen", WID_GO_FULLSCREEN_BUTTON), + }, GameOptionsWindowGlobalHotkeys}; + }; static constexpr NWidgetPart _nested_game_options_widgets[] = { @@ -1175,26 +1185,12 @@ static constexpr NWidgetPart _nested_game_options_widgets[] = { EndContainer(), }; - -TODO -static EventState GameOptionsWindowGlobalHotkeys(int hotkey) { - if (!ToggleFullScreen(!_fullscreen)) { - ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR); - } - return ES_HANDLED; -} - -static Hotkey game_options_hotkeys[] = { - Hotkey((uint16)0, "toggle_fullscreen", WID_GO_FULLSCREEN_BUTTON), - HOTKEY_LIST_END -}; -HotkeyList GameOptionsWindow::hotkeys("game_options", game_options_hotkeys, GameOptionsWindowGlobalHotkeys); - -static WindowDesc _game_options_desc( +static WindowDesc _game_options_desc(__FILE__, __LINE__, WDP_CENTER, "cm_game_options", 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, - std::begin(_nested_game_options_widgets), std::end(_nested_game_options_widgets) + std::begin(_nested_game_options_widgets), std::end(_nested_game_options_widgets), + &GameOptionsWindow::hotkeys ); /** Open the game options window. */ @@ -2166,7 +2162,6 @@ static SettingsContainer &GetSettingsTree() routing->Add(new SettingEntry("pf.pathfinder_for_roadvehs")); routing->Add(new SettingEntry("pf.pathfinder_for_ships")); } - TODO REMOVE CM_STR_CONFIG_SETTING_ORDER_SHORTCUTS SettingsPage *orders = vehicles->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES_ORDERS)); { orders->Add(new SettingEntry("gui.new_nonstop")); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 0af01f9d70..59f00ae52b 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -640,7 +640,7 @@ static inline uint32 CM_GetSmallMapIMBAPixels(TileIndex tile, TileType t) } // if (IsClearGround(tile, CLEAR_SNOW)) // return _vegetation_clear_bits[GetClearGround(tile)]; - FALLTHROUGH; + [[fallthrough]]; default: const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour]; @@ -662,6 +662,7 @@ enum SmallMapType : byte { SMT_ROUTES, SMT_VEGETATION, SMT_OWNER, + CM_SMT_IMBA, }; DECLARE_ENUM_AS_ADDABLE(SmallMapType) @@ -2088,6 +2089,6 @@ bool ScrollMainWindowTo(int x, int y, int z, bool instant) */ Point GetSmallMapStationMiddle(const Window *w, const Station *st) { - TODO fix (this line was changed) - return static_cast(w)->GetStationMiddle(st); + // return static_cast(w)->GetStationMiddle(st); + return static_cast(w)->GetStationMiddle(st); } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 3552ff45c1..f19902d952 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2150,7 +2150,7 @@ struct StationViewWindow : public Window { for (const CargoSpec *cs : _sorted_standard_cargo_specs) { const GoodsEntry *ge = &st->goods[cs->Index()]; if (!ge->HasRating()) continue; - ofs_y -= FONT_HEIGHT_NORMAL; + ofs_y -= GetCharacterHeight(FS_NORMAL); if (ofs_y < 0) { return citymania::ShowStationRatingTooltip(this, st, cs, close_cond); } diff --git a/src/station_gui.h b/src/station_gui.h index 77c18c9b18..bdd803f7b9 100644 --- a/src/station_gui.h +++ b/src/station_gui.h @@ -25,7 +25,7 @@ enum StationCoverageType { int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies); int DrawStationAuthorityText(int left, int right, int top); -void CheckRedrawStationCoverage(const Window *w); +void CheckRedrawStationCoverage(/* CM const */ Window *w); void CheckRedrawWaypointCoverage(const Window *w); using StationPickerCmdProc = std::function; diff --git a/src/stdafx.h b/src/stdafx.h index d63c760577..d22aea4469 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -411,7 +411,10 @@ inline void free(const void *ptr) /* CityMania code start */ #define uint8 uint8_t #define uint16 uint16_t +#define int16 int16_t #define uint32 uint32_t +#define int32 int32_t +#define uint64 uint64_t /* CityMania code end */ #endif /* STDAFX_H */ diff --git a/src/table/settings/citymania_settings.ini b/src/table/settings/citymania_settings.ini index d11db5fd9a..97df8abd62 100644 --- a/src/table/settings/citymania_settings.ini +++ b/src/table/settings/citymania_settings.ini @@ -3,7 +3,7 @@ static const SettingVariant _citymania_settings_table[] = { [post-amble] }; [templates] -SDT_VAR = SDT_VAR(GameSettings, $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $cat, $extra, $startup), +SDT_VAR = SDT_VAR(GameSettings, $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to, $cat, $extra, $startup), [validation] SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for GameSettings.$var exceeds storage size"); @@ -16,6 +16,9 @@ strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT strval = STR_NULL pre_cb = nullptr post_cb = nullptr +str_cb = nullptr +help_cb = nullptr +val_cb = nullptr load = nullptr from = SLV_TABLE_CHUNKS to = SL_MAX_VERSION diff --git a/src/table/settings/cmclient_settings.ini b/src/table/settings/cmclient_settings.ini index 69aacfe2e2..2f7e8fd90c 100644 --- a/src/table/settings/cmclient_settings.ini +++ b/src/table/settings/cmclient_settings.ini @@ -11,12 +11,13 @@ static const SettingVariant _cmclient_settings_table[] = { [post-amble] }; [templates] -SDTC_BOOL = SDTC_BOOL( $var, $flags, $def, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $cat, $extra, $startup), -SDTC_VAR = SDTC_VAR( $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $cat, $extra, $startup), -SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $def, $max, $full, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $cat, $extra, $startup), +SDTC_BOOL = SDTC_BOOL( $var, $flags, $def, $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to, $cat, $extra, $startup), +SDTC_VAR = SDTC_VAR( $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to, $cat, $extra, $startup), +SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $def, $max, $full, $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to, $cat, $extra, $startup), [validation] SDTC_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size"); +SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size"); [defaults] flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | CM_SF_CITYMANIA @@ -26,6 +27,9 @@ strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT strval = STR_NULL pre_cb = nullptr post_cb = nullptr +str_cb = nullptr +help_cb = nullptr +val_cb = nullptr load = nullptr from = SL_MIN_VERSION to = SL_MAX_VERSION diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 01bc093dbe..68a1b4e13e 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -153,7 +153,8 @@ bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_t Command::Post(STR_ERROR_CAN_T_CLEAR_THIS_AREA, CcPlaySound_EXPLOSION, tree_start_tile, tree_recent_tile, 0); } } else { // diagonal area - for (DiagonalTileIterator cur_tile{start_tile, end_tile}; cur_tile != INVALID_TILE; ++cur_tile) { + DiagonalTileArea diag_area{start_tile, end_tile}; + for (auto cur_tile : diag_area) { // same as above but with a different criteria for consecutive tiles TileIndexDiffC tile_diff = TileIndexToTileIndexDiffC(cur_tile, prev_tile); // if we're on a non-consecutive tile or we've hit a black-marked tile @@ -410,69 +411,11 @@ struct TerraformToolbarWindow : Window { Hotkey('I', "trees", WID_TT_PLANT_TREES), Hotkey('O', "placesign", WID_TT_PLACE_SIGN), Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT), + Hotkey('D' | WKC_CTRL | WKC_GLOBAL_HOTKEY, "cm_treedozer", WID_TT_DEMOLISH_TREES), }, TerraformToolbarGlobalHotkeys}; }; -<<<<<<< HEAD -/** - * Handler for global hotkeys of the TerraformToolbarWindow. - * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. - */ -static EventState TerraformToolbarGlobalHotkeys(int hotkey) -{ - if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; - Window *w = ShowTerraformToolbar(nullptr); - if (w == nullptr) return ES_NOT_HANDLED; - return w->OnHotkey(hotkey); -} - -static Hotkey terraform_hotkeys[] = { - Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_TT_LOWER_LAND), - Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_TT_RAISE_LAND), - Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_LEVEL_LAND), - Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_TT_DEMOLISH), - Hotkey('D' | WKC_CTRL | WKC_GLOBAL_HOTKEY, "treedozer", WID_TT_DEMOLISH_TREES), - Hotkey('U', "buyland", WID_TT_BUY_LAND), - Hotkey('I', "trees", WID_TT_PLANT_TREES), - Hotkey('O', "placesign", WID_TT_PLACE_SIGN), - Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT), - HOTKEY_LIST_END -}; -HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys, TerraformToolbarGlobalHotkeys); - -static const NWidgetPart _nested_terraform_widgets[] = { -||||||| 77ed90fc -/** - * Handler for global hotkeys of the TerraformToolbarWindow. - * @param hotkey Hotkey - * @return ES_HANDLED if hotkey was accepted. - */ -static EventState TerraformToolbarGlobalHotkeys(int hotkey) -{ - if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; - Window *w = ShowTerraformToolbar(nullptr); - if (w == nullptr) return ES_NOT_HANDLED; - return w->OnHotkey(hotkey); -} - -static Hotkey terraform_hotkeys[] = { - Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_TT_LOWER_LAND), - Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_TT_RAISE_LAND), - Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_LEVEL_LAND), - Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_TT_DEMOLISH), - Hotkey('U', "buyland", WID_TT_BUY_LAND), - Hotkey('I', "trees", WID_TT_PLANT_TREES), - Hotkey('O', "placesign", WID_TT_PLACE_SIGN), - Hotkey('P', "placeobject", WID_TT_PLACE_OBJECT), - HOTKEY_LIST_END -}; -HotkeyList TerraformToolbarWindow::hotkeys("terraform", terraform_hotkeys, TerraformToolbarGlobalHotkeys); - -static const NWidgetPart _nested_terraform_widgets[] = { -======= static constexpr NWidgetPart _nested_terraform_widgets[] = { ->>>>>>> upstream/master NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN), NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_LANDSCAPING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), diff --git a/src/tilearea.cpp b/src/tilearea.cpp index 974f121b6c..3209e18af1 100644 --- a/src/tilearea.cpp +++ b/src/tilearea.cpp @@ -228,6 +228,27 @@ bool DiagonalTileArea::Contains(TileIndex tile) const return (a >= start_a && a < end_a && b >= start_b && b < end_b); } +/* CityMaina code start (for treedozer) */ +/** + * Returns an iterator to the beginning of the tile area. + * @return The DiagonalTileIterator. + */ +DiagonalTileIterator DiagonalTileArea::begin() const +{ + return DiagonalTileIterator(*this); +} + +/** + * Returns an iterator to the end of the tile area. + * @return The DiagonalTileIterator. + */ +DiagonalTileIterator DiagonalTileArea::end() const +{ + return DiagonalTileIterator(DiagonalTileArea()); +} +/* CityMaina code end */ + + /** * Move ourselves to the next tile in the rectangle on the map. */ diff --git a/src/tilearea_type.h b/src/tilearea_type.h index 1cd29ec1bb..16e5968c26 100644 --- a/src/tilearea_type.h +++ b/src/tilearea_type.h @@ -13,6 +13,7 @@ #include "map_func.h" class OrthogonalTileIterator; +class DiagonalTileIterator; /** Represents the covered area of e.g. a rail station */ struct OrthogonalTileArea { @@ -96,6 +97,12 @@ struct DiagonalTileArea { } bool Contains(TileIndex tile) const; + + /* CityMaina code start (for treedozer) */ + DiagonalTileIterator begin() const; + + DiagonalTileIterator end() const; + /* CityMaina code end */ }; /** Shorthand for the much more common orthogonal tile area. */ diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index c4e31346d3..78fc00897f 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1109,16 +1109,15 @@ static CallBackFunction PlaceLandBlockInfo() static CallBackFunction ToolbarHelpClick(Window *w) { - TODO add citymania login if (_settings_client.gui.newgrf_developer_tools) { PopupMainToolbarMenu(w, _game_mode == GM_EDITOR ? (WidgetID)WID_TE_HELP : (WidgetID)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO, - STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG, + CM_STR_ABOUT_MENU_LOGIN_WINDOW, STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG, STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD, STR_ABOUT_MENU_SPRITE_ALIGNER, STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES, STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS, STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES}); } else { PopupMainToolbarMenu(w, _game_mode == GM_EDITOR ? (WidgetID)WID_TE_HELP : (WidgetID)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO, - STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG, + CM_STR_ABOUT_MENU_LOGIN_WINDOW, STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG, STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD}); } return CBF_NONE; @@ -1530,21 +1529,6 @@ public: this->NWidgetContainer::Draw(w); } - - void FillDirtyWidgets(std::vector &dirty_widgets) override - { - if (this->base_flags & WBF_DIRTY) { - dirty_widgets.push_back(this); - } else { - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { - if (child_wid->type == NWID_SPACER) continue; - if (!this->visible[((NWidgetCore*)child_wid)->index]) continue; - - child_wid->FillDirtyWidgets(dirty_widgets); - } - } - } - /** * Get the arrangement of the buttons for the toolbar. * @param width the new width of the toolbar. @@ -2137,7 +2121,6 @@ struct MainToolbarWindow : Window { case CM_MTHK_COMMANDS_GUI: if (_networking) { citymania::ShowCommandsToolbar(); } break; case CM_MTHK_BUILD_HQ: if(_current_company != COMPANY_SPECTATOR){ cbf = BuildCompanyHQ(); } break; case CM_MTHK_CARGOTABLE: if(_current_company != COMPANY_SPECTATOR){ citymania::ShowCompanyCargos(_current_company); } break; - case CM_MTHK_TREES: if(_current_company != COMPANY_SPECTATOR){ BuildTreesWindow(); } break; case CM_MTHK_ZONING: citymania::ShowZoningToolbar(); break; case CM_MTHK_LOGINWINDOW: citymania::ShowLoginWindow(); break; case CM_MTHK_SETTINGS_ADV: ShowGameSettings(); break; @@ -2260,7 +2243,6 @@ struct MainToolbarWindow : Window { Hotkey(WKC_CTRL | 'H', "cm_build_hq", CM_MTHK_BUILD_HQ), Hotkey((uint16)0, "cm_commands_window", CM_MTHK_COMMANDS_GUI), Hotkey(WKC_CTRL | WKC_F2, "cm_cargo_table", CM_MTHK_CARGOTABLE), - Hotkey('I', "cm_trees", CM_MTHK_TREES), TODO is it different from MTHK_BUILD_TREES Hotkey((uint16)0, "cm_zoning", CM_MTHK_ZONING), Hotkey((uint16)0, "cm_login_window", CM_MTHK_LOGINWINDOW), Hotkey((uint16)0, "cm_settings_advanced", CM_MTHK_SETTINGS_ADV), diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 5ed4e3c646..d326eb188a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -454,7 +454,7 @@ void Town::UpdateVirtCoord() _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeTown(this->index)); SetWindowDirty(WC_TOWN_VIEW, this->index); - SetWindowDirty(WC_CB_TOWN, this->index); + SetWindowDirty(CM_WC_CB_TOWN, this->index); } /** Update the virtual coords needed to draw the town sign for all towns. */ @@ -873,7 +873,7 @@ static void GetTileDesc_Town(TileIndex tile, TileDesc *td) bool house_completed = IsHouseCompleted(tile); td->str = hs->building_name; - td->population = hs->population; + td->cm_population = hs->population; uint16_t callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, Town::GetByTile(tile), tile); if (callback_res != CALLBACK_FAILED && callback_res != 0x400) { @@ -932,27 +932,27 @@ bool TownNeedsFunding(Town *t) { if (!is_growing) return false; - if (do_powerfund && t->grow_counter > 2 * TOWN_GROWTH_TICKS) + if (do_powerfund && t->grow_counter > 2 * Ticks::TOWN_GROWTH_TICKS) return true; return (fund_regularly && t->fund_buildings_months == 0 && ( - t->growth_rate <= 2 * TOWN_GROWTH_TICKS || - t->grow_counter > 2 * TOWN_GROWTH_TICKS + t->growth_rate <= 2 * Ticks::TOWN_GROWTH_TICKS || + t->grow_counter > 2 * Ticks::TOWN_GROWTH_TICKS )); } if (!is_growing) return true; - if (do_powerfund && t->grow_counter > 2 * TOWN_GROWTH_TICKS) + if (do_powerfund && t->grow_counter > 2 * Ticks::TOWN_GROWTH_TICKS) return true; return (fund_regularly && t->fund_buildings_months == 0 && - t->growth_rate >= TOWN_GROWTH_TICKS && ( - t->growth_rate <= 2 * TOWN_GROWTH_TICKS || - t->grow_counter > 2 * TOWN_GROWTH_TICKS + t->growth_rate >= Ticks::TOWN_GROWTH_TICKS && ( + t->growth_rate <= 2 * Ticks::TOWN_GROWTH_TICKS || + t->grow_counter > 2 * Ticks::TOWN_GROWTH_TICKS )); } @@ -964,16 +964,16 @@ static void DoRegularFunding(Town *t) if (!TownNeedsFunding(t)) return; - /* never fund faster than every TOWN_GROWTH_TICKS */ - if (_tick_counter < t->last_funding) { - if (UINT32_MAX - t->last_funding + _tick_counter < TOWN_GROWTH_TICKS) return; - } else if (_tick_counter - t->last_funding < TOWN_GROWTH_TICKS) return; + /* never fund faster than every Ticks::TOWN_GROWTH_TICKS */ + if (TimerGameTick::counter < t->last_funding) { + if (UINT32_MAX - t->last_funding + TimerGameTick::counter < Ticks::TOWN_GROWTH_TICKS) return; + } else if (TimerGameTick::counter - t->last_funding < Ticks::TOWN_GROWTH_TICKS) return; citymania::cmd::DoTownAction(t->xy, t->index, HK_FUND) .no_estimate() .as_company(_local_company) .post(); - t->last_funding = _tick_counter; + t->last_funding = TimerGameTick::counter; } static void DoRegularAdvertising(Town *t) { @@ -1000,10 +1000,10 @@ static void DoRegularAdvertising(Town *t) { return; // don't advertise faster that once per 30 ticks - if (_tick_counter < t->last_advertisement) { - if (UINT32_MAX - t->last_advertisement + _tick_counter < 30) return; - } else if (_tick_counter - t->last_advertisement < 30) return; - t->last_advertisement = _tick_counter; + if (TimerGameTick::counter < t->last_advertisement) { + if (UINT32_MAX - t->last_advertisement + TimerGameTick::counter < 30) return; + } else if (TimerGameTick::counter - t->last_advertisement < 30) return; + t->last_advertisement = TimerGameTick::counter; auto prev_rating = t->ad_ref_goods_entry->rating; citymania::cmd::DoTownAction(t->xy, t->index, HK_LADVERT) @@ -2134,16 +2134,17 @@ uint CB_GetFrom(CargoID cargo){ uint CB_GetDecay(CargoID cargo){ return CBDECAY[cargo]; } + int CB_GetTownReq(uint population, uint req, uint from, bool from_non_important, bool prev_month) { if (req > 0 && (population >= from || from_non_important)) { uint leap = 0; - Month month = _cur_month; + auto month = TimerGameEconomy::month; if (!prev_month) month++; - if(month == 2){ - if((_cur_year % 4 == 0 && _cur_year % 100 != 0) || _cur_year % 400 == 0) leap = 1; + if(month == 1) { + if((TimerGameEconomy::year.base() % 4 == 0 && TimerGameEconomy::year.base() % 100 != 0) || TimerGameEconomy::year.base() % 400 == 0) leap = 1; } - uint days_this_month = days_in_month[month] + leap; + uint days_this_month = days_in_month[month + 1] + leap; // x cargo for 1000 people return population * req * days_this_month / 31000; // 31 days divide by 1000 (pop) } @@ -3310,7 +3311,7 @@ CommandCost CmdTownGrowthRate(DoCommandFlag flags, TownID town_id, uint16_t grow } UpdateTownGrowth(t); InvalidateWindowData(WC_TOWN_VIEW, town_id); - InvalidateWindowData(WC_CB_TOWN, town_id); + InvalidateWindowData(CM_WC_CB_TOWN, town_id); } return CommandCost(); @@ -3674,7 +3675,7 @@ static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags) t->grow_counter = std::min(t->grow_counter, 2 * Ticks::TOWN_GROWTH_TICKS - (t->growth_rate - t->grow_counter) % Ticks::TOWN_GROWTH_TICKS); SetWindowDirty(WC_TOWN_VIEW, t->index); - SetWindowDirty(WC_CB_TOWN, t->index); + SetWindowDirty(CM_WC_CB_TOWN, t->index); } return CommandCost(); } @@ -3977,7 +3978,7 @@ static void UpdateTownGrowth(Town *t) ClrBit(t->flags, TOWN_IS_GROWING); SetWindowDirty(WC_TOWN_VIEW, t->index); - SetWindowDirty(WC_CB_TOWN, t->index); + SetWindowDirty(CM_WC_CB_TOWN, t->index); t->cm.growing_by_chance = false; if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return; @@ -4002,7 +4003,7 @@ static void UpdateTownGrowth(Town *t) if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) { if (t->growth_rate != TOWN_GROWTH_RATE_NONE) SetBit(t->flags, TOWN_IS_GROWING); SetWindowDirty(WC_TOWN_VIEW, t->index); - SetWindowDirty(WC_CB_TOWN, t->index); + SetWindowDirty(CM_WC_CB_TOWN, t->index); return; } @@ -4013,7 +4014,7 @@ static void UpdateTownGrowth(Town *t) SetBit(t->flags, TOWN_IS_GROWING); SetWindowDirty(WC_TOWN_VIEW, t->index); - SetWindowDirty(WC_CB_TOWN, t->index); + SetWindowDirty(CM_WC_CB_TOWN, t->index); } /** @@ -4241,7 +4242,7 @@ static IntervalTimer _economy_towns_monthly({TimerGameEconomy: /* CityMania code end */ SetWindowDirty(WC_TOWN_VIEW, t->index); - SetWindowDirty(WC_CB_TOWN, t->index); + SetWindowDirty(CM_WC_CB_TOWN, t->index); } }); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 151367905e..ecfeba8643 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -371,26 +371,21 @@ public: return ES_HANDLED; } - static HotkeyList hotkeys; - - TODO - static Hotkey town_hotkeys[] = { - Hotkey((uint16)0, "small_advert", HK_SADVERT), - Hotkey((uint16)0, "medium_advert", HK_MADVERT), - Hotkey(WKC_CTRL | 'D', "large_advert", HK_LADVERT), - Hotkey(WKC_CTRL | 'S', "build_statue", HK_STATUE), - Hotkey(WKC_CTRL | 'F', "fund_buildings", HK_FUND), - HOTKEY_LIST_END - }; - HotkeyList TownAuthorityWindow::hotkeys("town_gui", town_hotkeys); - + static inline HotkeyList hotkeys{"cm_town_authority", { + Hotkey((uint16)0, "small_advert", HK_SADVERT), + Hotkey((uint16)0, "medium_advert", HK_MADVERT), + Hotkey(WKC_CTRL | 'D', "large_advert", HK_LADVERT), + Hotkey(WKC_CTRL | 'S', "build_statue", HK_STATUE), + Hotkey(WKC_CTRL | 'F', "fund_buildings", HK_FUND) + }}; }; static WindowDesc _town_authority_desc(__FILE__, __LINE__, WDP_AUTO, "view_town_authority", 317, 222, WC_TOWN_AUTHORITY, WC_NONE, 0, - std::begin(_nested_town_authority_widgets), std::end(_nested_town_authority_widgets) + std::begin(_nested_town_authority_widgets), std::end(_nested_town_authority_widgets), + &TownAuthorityWindow::hotkeys ); static void ShowTownAuthorityWindow(uint town) @@ -483,7 +478,7 @@ public: } } - DrawExtraTownInfo(tr, this->town, FONT_HEIGHT_NORMAL, true); //CB + DrawExtraTownInfo(tr, this->town, GetCharacterHeight(FS_NORMAL), true); // CM (CB) bool first = true; for (int i = TAE_BEGIN; i < TAE_END; i++) { @@ -610,7 +605,7 @@ public: uint GetDesiredInfoHeight(int width) const { uint aimed_height = static_cast(1 + CargoSpec::town_production_cargoes[TPE_PASSENGERS].size() + CargoSpec::town_production_cargoes[TPE_MAIL].size()) * GetCharacterHeight(FS_NORMAL); - TODO uint aimed_height = 3 -> 8 * FONT_HEIGHT_NORMAL; + aimed_height += 4 * GetCharacterHeight(FS_NORMAL); // CM (extra town info) bool first = true; for (int i = TAE_BEGIN; i < TAE_END; i++) { @@ -690,19 +685,14 @@ public: this->SetDirty(); }}; - static HotkeyList hotkeys; + static inline HotkeyList hotkeys{"cm_town_view", { + Hotkey((uint16)0, "location", WID_TV_CENTER_VIEW), + Hotkey((uint16)0, "local_authority", WID_TV_SHOW_AUTHORITY), + Hotkey((uint16)0, "cb_window", WID_TV_CB), + Hotkey(WKC_CTRL | 'S', "build_statue", HK_STATUE + 0x80), + }}; }; -TODO -static Hotkey town_window_hotkeys[] = { - Hotkey((uint16)0, "location", WID_TV_CENTER_VIEW), - Hotkey((uint16)0, "local_authority", WID_TV_SHOW_AUTHORITY), - Hotkey((uint16)0, "cb_window", WID_TV_CB), - Hotkey(WKC_CTRL | 'S', "build_statue", HK_STATUE + 0x80), - HOTKEY_LIST_END -}; -HotkeyList TownViewWindow::hotkeys("town_window", town_window_hotkeys); - static constexpr NWidgetPart _nested_town_game_view_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_BROWN), @@ -731,7 +721,8 @@ static WindowDesc _town_game_view_desc(__FILE__, __LINE__, WDP_AUTO, "view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL, WC_TOWN_VIEW, WC_NONE, 0, - std::begin(_nested_town_game_view_widgets), std::end(_nested_town_game_view_widgets) + std::begin(_nested_town_game_view_widgets), std::end(_nested_town_game_view_widgets), + &TownViewWindow::hotkeys ); static constexpr NWidgetPart _nested_town_editor_view_widgets[] = { @@ -865,20 +856,20 @@ private: } /** Sort by real population (default descending, as big towns are of the most interest). */ - static bool TownRealPopulationSorter(const Town * const &a, const Town * const &b) + static bool TownRealPopulationSorter(const Town * const &a, const Town * const &b, const bool &order) { uint32 a_population = a->cm.real_population; uint32 b_population = b->cm.real_population; - if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b); + if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b, order); return a_population < b_population; } /** Sort by number of houses (default descending, as big towns are of the most interest). */ - static bool TownHousesSorter(const Town * const &a, const Town * const &b) + static bool TownHousesSorter(const Town * const &a, const Town * const &b, const bool &order) { uint32 a_houses = a->cache.num_houses; uint32 b_houses = b->cache.num_houses; - if (a_houses == b_houses) return TownDirectoryWindow::TownPopulationSorter(a, b); + if (a_houses == b_houses) return TownDirectoryWindow::TownPopulationSorter(a, b, order); return a_houses < b_houses; } @@ -1598,7 +1589,7 @@ public: switch(widget){ case WID_CB_DETAILS: - size->height = (FONT_HEIGHT_NORMAL + EXP_LINESPACE) * 5; + size->height = (GetCharacterHeight(FS_NORMAL) + EXP_LINESPACE) * 5; break; case WID_CB_GOALS: { uint desired_height = 0; @@ -1611,7 +1602,7 @@ public: } } if (desired_height > 0) - size->height = desired_height * (FONT_HEIGHT_NORMAL + EXP_LINESPACE) + EXP_TOPPADDING - EXP_LINESPACE; + size->height = desired_height * (GetCharacterHeight(FS_NORMAL) + EXP_LINESPACE) + EXP_TOPPADDING - EXP_LINESPACE; break; } case WID_CB_CARGO_NAME: @@ -1626,7 +1617,7 @@ public: if(CB_GetReq(cargo) > 0) desired_height++; } if (desired_height > 0) - size->height = desired_height * (FONT_HEIGHT_NORMAL + EXP_LINESPACE) + EXP_TOPPADDING - EXP_LINESPACE; + size->height = desired_height * (GetCharacterHeight(FS_NORMAL) + EXP_LINESPACE) + EXP_TOPPADDING - EXP_LINESPACE; break; } } @@ -1634,7 +1625,7 @@ public: void DrawWidget(const Rect &r, int widget) const { - static const uint EXP_LINESPACE = FONT_HEIGHT_NORMAL + 2; + static const uint EXP_LINESPACE = GetCharacterHeight(FS_NORMAL) + 2; Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); switch(widget){ @@ -1643,13 +1634,13 @@ public: if(this->town->cb.growth_state == TownGrowthState::GROWING) DrawString(tr, CM_STR_TOWN_CB_GROWING); else DrawString(tr, CM_STR_TOWN_CB_NOT_GROWING); - tr.top += FONT_HEIGHT_NORMAL; + tr.top += GetCharacterHeight(FS_NORMAL); // population SetDParam(0, this->town->cache.population); SetDParam(1, this->town->cache.num_houses); DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES); - tr.top += FONT_HEIGHT_NORMAL; + tr.top += GetCharacterHeight(FS_NORMAL); DrawExtraTownInfo(tr, this->town, EXP_LINESPACE, false); @@ -1817,11 +1808,14 @@ public: return ES_HANDLED; } - static HotkeyList hotkeys; + static inline HotkeyList hotkeys{"cm_town_cb_view", { + Hotkey((uint16)0, "location", WID_TV_CENTER_VIEW), + Hotkey((uint16)0, "local_authority", WID_TV_SHOW_AUTHORITY), + Hotkey((uint16)0, "cb_window", WID_TV_CB), + Hotkey(WKC_CTRL | 'S', "build_statue", HK_STATUE + 0x80), + }}; }; -HotkeyList CBTownWindow::hotkeys("town_gui", town_hotkeys); - static const NWidgetPart _nested_cb_town_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_BROWN), @@ -1883,11 +1877,11 @@ static const NWidgetPart _nested_cb_town_widgets[] = { EndContainer(), }; -static WindowDesc _cb_town_desc( +static WindowDesc _cb_town_desc(__FILE__, __LINE__, WDP_AUTO, "cb_town", 160, 30, - WC_CB_TOWN, WC_NONE, + CM_WC_CB_TOWN, WC_NONE, 0, - _nested_cb_town_widgets, lengthof(_nested_cb_town_widgets), + std::begin(_nested_cb_town_widgets), std::end(_nested_cb_town_widgets), &CBTownWindow::hotkeys ); diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp index a387895461..5a14623e61 100644 --- a/src/video/null_v.cpp +++ b/src/video/null_v.cpp @@ -9,7 +9,7 @@ #include "../stdafx.h" #include "../console_func.h" -#include "../date_func.h" +#include "../timer/timer_game_tick.h" #include "../gfx_func.h" #include "../blitter/factory.hpp" #include "../saveload/saveload.h" @@ -52,13 +52,13 @@ void VideoDriver_Null::MainLoop() { uint i; - uint16 old_tick; + TimerGameTick::TickCounter old_tick; for (i = 0; i < this->ticks; ) { - old_tick = _tick_counter; + old_tick = TimerGameTick::counter; ::GameLoop(); ::InputLoop(); ::UpdateWindows(); - if (old_tick != _tick_counter) i++; + if (old_tick != TimerGameTick::counter) i++; else _pause_mode = PM_UNPAUSED; } IConsolePrint(CC_DEFAULT, "Null driver ran for {} tics, save: {}", this->ticks, this->savefile); diff --git a/src/video/video_driver.cpp b/src/video/video_driver.cpp index cd4b6cd1ae..31141f1754 100644 --- a/src/video/video_driver.cpp +++ b/src/video/video_driver.cpp @@ -188,5 +188,5 @@ void VideoDriver::SleepTillNextTick() */ /* static */ std::string VideoDriver::GetCaption() { - return fmt::format("OpenTTD {}", _openttd_revision); + return fmt::format("OpenTTD {} (CityMania Fork)", _openttd_revision); } diff --git a/src/viewport.cpp b/src/viewport.cpp index a4cd8b4a73..c454566dae 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -102,7 +102,6 @@ /* CityMania code start */ #include "math.h" #include "core/math_func.hpp" -#include "core/smallvec_type.hpp" #include "citymania/cm_highlight.hpp" #include "citymania/cm_hotkeys.hpp" #include "citymania/cm_zoning.hpp" @@ -1075,7 +1074,7 @@ static TileHighlightType GetTileHighlightType(TileIndex t) if (_viewport_highlight_station->TileIsInCatchment(t)) return THT_BLUE; } #endif - TODO should cm handle this? + // TODO CM should handle this too if (_viewport_highlight_waypoint != nullptr) { if (IsTileType(t, MP_STATION) && GetStationIndex(t) == _viewport_highlight_waypoint->index) return THT_BLUE; } @@ -2923,10 +2922,10 @@ void UpdateTileSelection() * @param str String to be displayed * @param paramcount number of params to deal with */ -static inline void ShowMeasurementTooltips(StringID str, uint paramcount) +static inline void ShowMeasurementTooltips(StringID str, uint paramcount, TooltipCloseCondition close_cond = TCC_EXIT_VIEWPORT) { // CM (why)? if (!_settings_client.gui.measure_tooltip) return; - GuiShowTooltips(_thd.GetCallbackWnd(), str, TCC_EXIT_VIEWPORT, paramcount); + GuiShowTooltips(_thd.GetCallbackWnd(), str, close_cond, paramcount); } static void HideMeasurementTooltips() @@ -3186,6 +3185,7 @@ static void ShowLengthMeasurement(HighLightStyle style, TileIndex start_tile, Ti { static const StringID measure_strings_length[] = {STR_NULL, STR_MEASURE_LENGTH, STR_MEASURE_LENGTH_HEIGHTDIFF}; + uint paramcount = 0; if (_settings_client.gui.measure_tooltip) { uint distance = DistanceManhattan(start_tile, end_tile) + 1; byte index = 0; @@ -3200,11 +3200,11 @@ static void ShowLengthMeasurement(HighLightStyle style, TileIndex start_tile, Ti distance = CeilDiv(distance, 2); } - params[index++] = distance; - if (heightdiff != 0) params[index++] = heightdiff; + SetDParam(paramcount++, distance); + if (heightdiff != 0) SetDParam(paramcount++, heightdiff); } - ShowMeasurementTooltips(measure_strings_length[index], index, params, close_cond); + ShowMeasurementTooltips(measure_strings_length[index], paramcount, close_cond); } } @@ -4264,8 +4264,8 @@ static LineSnapPoint LineSnapPointAtRailTrackEndpoint(TileIndex tile, DiagDirect if (bidirectional) SetBit(ret.dirs, ReverseDir(DiagDirToDir(exit_dir))); /* Add 45 degree rotated directions. */ - ret.dirs |= ROR(ret.dirs, DIRDIFF_45LEFT); - ret.dirs |= ROR(ret.dirs, DIRDIFF_45RIGHT); + ret.dirs |= std::rotr(ret.dirs, DIRDIFF_45LEFT); + ret.dirs |= std::rotr(ret.dirs, DIRDIFF_45RIGHT); return ret; } @@ -4407,7 +4407,7 @@ static void SetRailSnapTile(TileIndex tile) for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { auto point = LineSnapPointAtRailTrackEndpoint(tile, dir, false, NULL); - point.dirs = ROR(point.dirs, DIRDIFF_REVERSE); + point.dirs = std::rotr(point.dirs, DIRDIFF_REVERSE); _tile_snap_points.push_back(point); } } diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 9e127cd1bf..f2d250f124 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -143,6 +143,7 @@ public: virtual void OnMouseOver(Point pt, int widget) { + extern void GuiPrepareTooltipsExtra(Window *parent); if (pt.x != -1) GuiPrepareTooltipsExtra(this); } }; diff --git a/src/widget.cpp b/src/widget.cpp index 070b11f875..e39ee7b028 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1179,6 +1179,9 @@ void NWidgetContainer::FillWidgetLookup(WidgetLookup &widget_lookup) void NWidgetContainer::Draw(const Window *w) { + if (this->IsOutsideDrawArea()) return; + this->base_flags &= ~WBF_DIRTY; + for (const auto &child_wid : this->children) { child_wid->Draw(w); } @@ -1197,6 +1200,19 @@ NWidgetCore *NWidgetContainer::GetWidgetFromPos(int x, int y) return nullptr; } +/* CityMania code start (copied from jgrpp) */ +void NWidgetContainer::FillDirtyWidgets(std::vector &dirty_widgets) +{ + if (this->base_flags & WBF_DIRTY) { + dirty_widgets.push_back(this); + } else { + for (const auto &child_wid : this->children) { + child_wid->FillDirtyWidgets(dirty_widgets); + } + } +} +/* CityMania code end */ + /** * Widgets stacked on top of each other. */ @@ -1304,11 +1320,12 @@ void NWidgetStacked::FillDirtyWidgets(std::vector &dirty_widgets) dirty_widgets.push_back(this); } else { int plane = 0; - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) { + for (const auto &child_wid : this->children) { if (plane == this->shown_plane) { child_wid->FillDirtyWidgets(dirty_widgets); return; } + plane++; } } } @@ -1374,16 +1391,12 @@ void NWidgetPIPContainer::SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_i this->pip_ratio_post = pip_ratio_post; } -TODO this goes into Draw - if (this->IsOutsideDrawArea()) return; - this->base_flags &= ~WBF_DIRTY; - void NWidgetPIPContainer::FillDirtyWidgets(std::vector &dirty_widgets) { if (this->base_flags & WBF_DIRTY) { dirty_widgets.push_back(this); } else { - for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) { + for (const auto &child_wid : this->children) { child_wid->FillDirtyWidgets(dirty_widgets); } } @@ -1778,7 +1791,7 @@ void NWidgetSpacer::Draw(const Window *w) } } -void NWidgetSpacer::SetDirty(const Window *) const +void NWidgetSpacer::SetDirty(Window *) { /* Spacer widget never need repainting. */ } diff --git a/src/widget_type.h b/src/widget_type.h index 4ce9ab34c9..0e7398cd71 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -471,6 +471,7 @@ public: void Draw(const Window *w) override; NWidgetCore *GetWidgetFromPos(int x, int y) override; + void FillDirtyWidgets(std::vector &dirty_widgets) override; // CM (jgrpp) /** Return whether the container is empty. */ inline bool IsEmpty() { return this->children.empty(); } diff --git a/src/widgets/road_widget.h b/src/widgets/road_widget.h index d33139f6a9..859f7869b1 100644 --- a/src/widgets/road_widget.h +++ b/src/widgets/road_widget.h @@ -70,8 +70,6 @@ enum BuildRoadStationWidgets : WidgetID { WID_BROS_SHOW_NEWST_TYPE, ///< Display of selected stop type. WID_BROS_NEWST_LIST, ///< List with new road stops. WID_BROS_NEWST_SCROLL, ///< Scrollbar of the #WID_BROS_NEWST_LIST. - CM_WID_BROS_STATION_AUTO, ///< Terminal station, autoselect entry. - CM_WID_BROS_STATION_XY_AUTO, ///< Drive-through station, autoselect direction. }; #endif /* WIDGETS_ROAD_WIDGET_H */ diff --git a/src/window.cpp b/src/window.cpp index 7414ea26f9..26a832c2a3 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -895,7 +895,7 @@ void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom, D dp->dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top); dp->zoom = ZOOM_LVL_NORMAL; w->OnPaint(); - if (unlikely(flags & DOWF_SHOW_DEBUG)) { + if (flags & DOWF_SHOW_DEBUG) [[ unlikely ]] { extern void ViewportDrawDirtyBlocks(); ViewportDrawDirtyBlocks(); } @@ -3567,7 +3567,7 @@ WindowPopup::WindowPopup(WindowDesc *desc, WindowPopupType t): Window(desc) y = _cursor.pos.y - wid->pos_y + this->wpu_mod_y; break; } - FALLTHROUGH; // suppress warning, no idea if it's actually correct + [[ fallthrough ]]; // suppress warning, no idea if it's actually correct case WPUT_ORIGIN: default: x = _cursor.pos.x + this->wpu_mod_x; diff --git a/src/window_gui.h b/src/window_gui.h index 90987855c4..5f68056afd 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -316,7 +316,7 @@ public: ViewportData *viewport; ///< Pointer to viewport data, if present. NWidgetViewport *viewport_widget; ///< Pointer to viewport widget, if present. - const NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c nullptr if no nested widget has focus. + /* CM const */ NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c nullptr if no nested widget has focus. std::map querystrings; ///< QueryString associated to WWT_EDITBOX widgets. std::unique_ptr nested_root; ///< Root of the nested tree. WidgetLookup widget_lookup; ///< Indexed access to the nested widget tree. Do not access directly, use #Window::GetWidget() instead. @@ -544,7 +544,7 @@ public: (this->RaiseWidgetWhenLowered(widgets), ...); } - void SetWidgetDirty(WidgetID widget_index) const; + void SetWidgetDirty(WidgetID widget_index) /* CM const */; void DrawWidgets() const; void DrawViewport() const; @@ -555,8 +555,8 @@ public: virtual void Close(int data = 0); static void DeleteClosedWindows(); - void SetDirty() const; - void SetDirtyAsBlocks(); TODO const? + void SetDirty(); + void SetDirtyAsBlocks(); void ReInit(int rx = 0, int ry = 0, bool reposition = false); /** Is window shaded currently? */ @@ -1086,7 +1086,7 @@ inline bool MayBeShown(const Window *w) { /* If we're not modal, everything is okay. */ extern bool _in_modal_progress; - if (likely(!_in_modal_progress)) return true; + if (!_in_modal_progress) [[ likely ]] return true; switch (w->window_class) { case WC_MAIN_WINDOW: ///< The background, i.e. the game.