virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget == MHW_BACKGROUND) { this->line_height = FONT_HEIGHT_NORMAL + 2; resize->height = this->line_height; SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 12, 30)); this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width; size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible. size->width = max(200u, size->width); // At least 200 pixels wide. } }
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget != CW_PANEL) return; uint width = 0; for (int i = 0; i != lengthof(_cheats_ui); i++) { const CheatEntry *ce = &_cheats_ui[i]; switch (ce->type) { case SLE_BOOL: SetDParam(0, STR_CONFIG_SETTING_ON); width = max(width, GetStringBoundingBox(ce->str).width); SetDParam(0, STR_CONFIG_SETTING_OFF); width = max(width, GetStringBoundingBox(ce->str).width); break; default: switch (ce->str) { /* Display date for change date cheat */ case STR_CHEAT_CHANGE_DATE: SetDParam(0, ConvertYMDToDate(MAX_YEAR, 11, 31)); width = max(width, GetStringBoundingBox(ce->str).width); break; /* Draw coloured flag for change company cheat */ case STR_CHEAT_CHANGE_COMPANY: SetDParam(0, 15); width = max(width, GetStringBoundingBox(ce->str).width + 10 + 10); break; /* Set correct string for switch climate cheat */ case STR_CHEAT_SWITCH_CLIMATE: for (StringID i = STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE; i <= STR_CHEAT_SWITCH_CLIMATE_TOYLAND_LANDSCAPE; i++) { SetDParam(0, i); width = max(width, GetStringBoundingBox(ce->str).width); } break; default: SetDParam(0, INT64_MAX); width = max(width, GetStringBoundingBox(ce->str).width); break; } break; } } size->width = width + 50 /* stuff on the left */ + 10 /* extra spacing on right */; this->header_height = GetStringHeight(STR_CHEATS_WARNING, size->width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT) + WD_PAR_VSEP_WIDE; size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL) * lengthof(_cheats_ui); }
virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case WID_SD_DAY: case WID_SD_MONTH: case WID_SD_YEAR: ShowDateDropDown(widget); break; case WID_SD_SET_DATE: if (this->callback != NULL) this->callback(this, ConvertYMDToDate(this->date.year, this->date.month, this->date.day)); delete this; break; } }
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget == WID_MH_BACKGROUND) { this->line_height = FONT_HEIGHT_NORMAL + 2; resize->height = this->line_height; /* Months are off-by-one, so it's actually 8. Not using * month 12 because the 1 is usually less wide. */ SetDParam(0, ConvertYMDToDate(ORIGINAL_MAX_YEAR, 7, 30)); this->date_width = GetStringBoundingBox(STR_SHORT_DATE).width; size->height = 4 * resize->height + this->top_spacing + this->bottom_spacing; // At least 4 lines are visible. size->width = max(200u, size->width); // At least 200 pixels wide. } }
/** * Handle changing of the current year. * @param p1 Unused. * @param p2 +1 (increase) or -1 (decrease). * @return New year. */ static int32 ClickChangeDateCheat(int32 p1, int32 p2) { YearMonthDay ymd; ConvertDateToYMD(_date, &ymd); p1 = Clamp(p1, MIN_YEAR, MAX_YEAR); if (p1 == _cur_year) return _cur_year; SetDate(ConvertYMDToDate(p1, ymd.month, ymd.day), _date_fract); EnginesMonthlyLoop(); SetWindowDirty(WC_STATUS_BAR, 0); InvalidateWindowClassesData(WC_BUILD_STATION, 0); ResetSignalVariant(); return _cur_year; }
/** * Start/initialise one engine. * @param e The engine to initialise. * @param aging_date The date used for age calculations. */ void StartupOneEngine(Engine *e, Date aging_date) { const EngineInfo *ei = &e->info; e->age = 0; e->flags = 0; e->company_avail = 0; /* Don't randomise the start-date in the first two years after gamestart to ensure availability * of engines in early starting games. * Note: TTDP uses fixed 1922 */ uint32 r = Random(); e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; if (e->intro_date <= _date) { e->age = (aging_date - e->intro_date) >> 5; e->company_avail = (CompanyMask)-1; e->flags |= ENGINE_AVAILABLE; }
/** Send a welcome message to the admin. */ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome() { Packet *p = new Packet(ADMIN_PACKET_SERVER_WELCOME); p->Send_string(_settings_client.network.server_name); p->Send_string(_openttd_revision); p->Send_bool (_network_dedicated); p->Send_string(_network_game_info.map_name); p->Send_uint32(_settings_game.game_creation.generation_seed); p->Send_uint8 (_settings_game.game_creation.landscape); p->Send_uint32(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1)); p->Send_uint16(MapSizeX()); p->Send_uint16(MapSizeY()); this->SendPacket(p); return NETWORK_RECV_STATUS_OKAY; }
void ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr) { /* Just a fail-safe.. should never happen */ if (!_network_udp_server) { return; } NetworkGameInfo ngi; /* Update some game_info */ ngi.clients_on = _network_game_info.clients_on; ngi.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1); ngi.server_lang = _settings_client.network.server_lang; ngi.use_password = !StrEmpty(_settings_client.network.server_password); ngi.clients_max = _settings_client.network.max_clients; ngi.companies_on = (byte)Company::GetNumItems(); ngi.companies_max = _settings_client.network.max_companies; ngi.spectators_on = NetworkSpectatorCount(); ngi.spectators_max = _settings_client.network.max_spectators; ngi.game_date = _date; ngi.map_width = MapSizeX(); ngi.map_height = MapSizeY(); ngi.map_set = _settings_game.game_creation.landscape; ngi.dedicated = _network_dedicated; ngi.grfconfig = _grfconfig; strecpy(ngi.map_name, _network_game_info.map_name, lastof(ngi.map_name)); strecpy(ngi.server_name, _settings_client.network.server_name, lastof(ngi.server_name)); strecpy(ngi.server_revision, _openttd_revision, lastof(ngi.server_revision)); Packet packet(PACKET_UDP_SERVER_RESPONSE); this->SendNetworkGameInfo(&packet, &ngi); /* Let the client know that we are here */ this->SendPacket(&packet, client_addr); DEBUG(net, 2, "[udp] queried from %s", client_addr->GetHostname()); }
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings) { /* Make sure there isn't any window that can influence anything * related to the new game we're about to start/load. */ UnInitWindowSystem(); AllocateMap(size_x, size_y); _pause_mode = PM_UNPAUSED; _fast_forward = 0; _tick_counter = 0; _cur_tileloop_tile = 0; _thd.redsq = INVALID_TILE; if (reset_settings) MakeNewgameSettingsLive(); if (reset_date) { SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1), 0); InitializeOldNames(); } PoolBase::Clean(PT_NORMAL); ResetPersistentNewGRFData(); InitializeSound(); InitializeMusic(); InitializeVehicles(); InitNewsItemStructs(); InitializeLandscape(); InitializeRailGui(); InitializeRoadGui(); InitializeAirportGui(); InitializeDockGui(); InitializeObjectGui(); InitializeAIGui(); InitializeTrees(); InitializeIndustries(); InitializeObjects(); InitializeBuildingCounts(); InitializeNPF(); InitializeCompanies(); AI::Initialize(); Game::Initialize(); InitializeCheats(); InitTextEffects(); #ifdef ENABLE_NETWORK NetworkInitChatMessage(); #endif /* ENABLE_NETWORK */ InitializeAnimatedTiles(); InitializeEconomy(); ResetObjectToPlace(); GamelogReset(); GamelogStartAction(GLAT_START); GamelogRevision(); GamelogMode(); GamelogGRFAddList(_grfconfig); GamelogStopAction(); }
/** * Deserializes the NetworkGameInfo struct from the packet * @param p the packet to read the data from * @param info the NetworkGameInfo to deserialize into */ void NetworkUDPSocketHandler::ReceiveNetworkGameInfo(Packet *p, NetworkGameInfo *info) { static const Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11 info->game_info_version = p->Recv_uint8(); /* * Please observe the order. * The parts must be read in the same order as they are sent! */ /* Update the documentation in udp.h on changes * to the NetworkGameInfo wire-protocol! */ switch (info->game_info_version) { case 4: { GRFConfig **dst = &info->grfconfig; uint i; uint num_grfs = p->Recv_uint8(); /* Broken/bad data. It cannot have that many NewGRFs. */ if (num_grfs > NETWORK_MAX_GRF_COUNT) return; for (i = 0; i < num_grfs; i++) { GRFConfig *c = new GRFConfig(); this->ReceiveGRFIdentifier(p, &c->ident); this->HandleIncomingNetworkGameInfoGRFConfig(c); /* Append GRFConfig to the list */ *dst = c; dst = &c->next; } /* FALL THROUGH */ } case 3: info->game_date = Clamp(p->Recv_uint32(), 0, MAX_DATE); info->start_date = Clamp(p->Recv_uint32(), 0, MAX_DATE); /* FALL THROUGH */ case 2: info->companies_max = p->Recv_uint8 (); info->companies_on = p->Recv_uint8 (); info->spectators_max = p->Recv_uint8 (); /* FALL THROUGH */ case 1: p->Recv_string(info->server_name, sizeof(info->server_name)); p->Recv_string(info->server_revision, sizeof(info->server_revision)); info->server_lang = p->Recv_uint8 (); info->use_password = p->Recv_bool (); info->clients_max = p->Recv_uint8 (); info->clients_on = p->Recv_uint8 (); info->spectators_on = p->Recv_uint8 (); if (info->game_info_version < 3) { // 16 bits dates got scrapped and are read earlier info->game_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR; info->start_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR; } p->Recv_string(info->map_name, sizeof(info->map_name)); info->map_width = p->Recv_uint16(); info->map_height = p->Recv_uint16(); info->map_set = p->Recv_uint8 (); info->dedicated = p->Recv_bool (); if (info->server_lang >= NETWORK_NUM_LANGUAGES) info->server_lang = 0; if (info->map_set >= NETWORK_NUM_LANDSCAPES) info->map_set = 0; } }
virtual void DrawWidget(const Rect &r, int widget) const { switch (widget) { case SLWW_SORT_BYNAME: case SLWW_SORT_BYDATE: if (((_savegame_sort_order & SORT_BY_NAME) != 0) == (widget == SLWW_SORT_BYNAME)) { this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP); } break; case SLWW_BACKGROUND: { static const char *path = NULL; static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE; static uint64 tot = 0; if (_fios_path_changed) { str = FiosGetDescText(&path, &tot); _fios_path_changed = false; } if (str != STR_ERROR_UNABLE_TO_READ_DRIVE) SetDParam(0, tot); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP, str); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, path, TC_BLACK); } break; case SLWW_DRIVES_DIRECTORIES_LIST: { GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, 0xD7); uint y = r.top + WD_FRAMERECT_TOP; for (uint pos = this->vscroll.GetPosition(); pos < _fios_items.Length(); pos++) { const FiosItem *item = _fios_items.Get(pos); if (item == this->selected) { GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, 156); } DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type]); y += this->resize.step_height; if (y >= this->vscroll.GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break; } } break; case SLWW_DETAILS: { GfxFillRect(r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL * 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, 0x0A); DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL / 2 + WD_FRAMERECT_TOP, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER); if (this->selected == NULL) break; uint y = r.top + FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; uint y_max = r.bottom - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM; if (y > y_max) break; if (!_load_check_data.checkable) { /* Old savegame, no information available */ DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_NOT_AVAILABLE); y += FONT_HEIGHT_NORMAL; } else if (_load_check_data.error != INVALID_STRING_ID) { /* Incompatible / broken savegame */ SetDParamStr(0, _load_check_data.error_data); y = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.error, TC_RED); } else { /* Mapsize */ SetDParam(0, _load_check_data.map_size_x); SetDParam(1, _load_check_data.map_size_y); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_MAP_SIZE); y += FONT_HEIGHT_NORMAL; if (y > y_max) break; /* Climate */ byte landscape = _load_check_data.settings.game_creation.landscape; if (landscape < NUM_LANDSCAPE) { SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_LANDSCAPE); y += FONT_HEIGHT_NORMAL; } y += WD_PAR_VSEP_NORMAL; if (y > y_max) break; /* Start date (if available) */ if (_load_check_data.settings.game_creation.starting_year != 0) { SetDParam(0, ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1)); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_START_DATE); y += FONT_HEIGHT_NORMAL; } if (y > y_max) break; /* Hide current date for scenarios */ if (_saveload_mode != SLD_LOAD_SCENARIO && _saveload_mode != SLD_SAVE_SCENARIO) { /* Current date */ SetDParam(0, _load_check_data.current_date); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE); y += FONT_HEIGHT_NORMAL; } /* Hide the NewGRF stuff when saving. We also hide the button. */ if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { y += WD_PAR_VSEP_NORMAL; if (y > y_max) break; /* NewGrf compatibility */ SetDParam(0, _load_check_data.grfconfig == NULL ? STR_NEWGRF_LIST_NONE : STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_GRFSTATUS); y += FONT_HEIGHT_NORMAL; } if (y > y_max) break; /* Hide the company stuff for scenarios */ if (_saveload_mode != SLD_LOAD_SCENARIO && _saveload_mode != SLD_SAVE_SCENARIO) { y += FONT_HEIGHT_NORMAL; if (y > y_max) break; /* Companies / AIs */ CompanyPropertiesMap::const_iterator end = _load_check_data.companies.End(); for (CompanyPropertiesMap::const_iterator it = _load_check_data.companies.Begin(); it != end; it++) { SetDParam(0, it->first + 1); const CompanyProperties &c = *it->second; if (c.name != NULL) { SetDParam(1, STR_JUST_RAW_STRING); SetDParamStr(2, c.name); } else { SetDParam(1, c.name_1); SetDParam(2, c.name_2); } DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_COMPANY_INDEX); y += FONT_HEIGHT_NORMAL; if (y > y_max) break; } } } } break; } }