File diff r9183:200d86a0cdf3 → r9184:cdb864f70553
src/openttd.cpp
Show inline comments
 
@@ -1071,50 +1071,50 @@ static void DoAutosave()
 
	if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
 
		SetDParam(0, _local_player);
 
		SetDParam(1, _date);
 
		GetString(buf, STR_4004, lastof(buf));
 
		ttd_strlcat(buf, ".sav", lengthof(buf));
 
	} else {
 
		/* generate a savegame name and number according to _patches.max_num_autosaves */
 
		snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
 

	
 
		if (++_autosave_ctr >= _patches.max_num_autosaves) _autosave_ctr = 0;
 
	}
 

	
 
	DEBUG(sl, 2, "Autosaving to '%s'", buf);
 
	if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) {
 
		ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
 
	}
 
}
 

	
 
static void ScrollMainViewport(int x, int y)
 
{
 
	if (_game_mode != GM_MENU) {
 
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 
		assert(w);
 

	
 
		WP(w, vp_d).dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
 
		WP(w, vp_d).dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
 
		w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
 
		w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
 
	}
 
}
 

	
 
/**
 
 * Describes all the different arrow key combinations the game allows
 
 * when it is in scrolling mode.
 
 * The real arrow keys are bitwise numbered as
 
 * 1 = left
 
 * 2 = up
 
 * 4 = right
 
 * 8 = down
 
 */
 
static const int8 scrollamt[16][2] = {
 
	{ 0,  0}, ///<  no key specified
 
	{-2,  0}, ///<  1 : left
 
	{ 0, -2}, ///<  2 : up
 
	{-2, -1}, ///<  3 : left  + up
 
	{ 2,  0}, ///<  4 : right
 
	{ 0,  0}, ///<  5 : left  + right = nothing
 
	{ 2, -1}, ///<  6 : right + up
 
	{ 0, -2}, ///<  7 : right + left  + up = up
 
	{ 0  ,2}, ///<  8 : down
 
	{-2  ,1}, ///<  9 : down  + left
 
	{ 0,  0}, ///< 10 : down  + up    = nothing
 
@@ -1182,50 +1182,50 @@ void GameLoop()
 
			 * We do this here, because it means that the network is really closed */
 
			NetworkClientConnectGame(_network_last_host, _network_last_port);
 
		}
 
		/* Singleplayer */
 
		StateGameLoop();
 
	}
 
#else
 
	StateGameLoop();
 
#endif /* ENABLE_NETWORK */
 

	
 
	if (!_pause_game && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
 

	
 
	if (!_pause_game || _cheats.build_in_pause.value) MoveAllTextEffects();
 

	
 
	InputLoop();
 

	
 
	MusicLoop();
 
}
 

	
 
void BeforeSaveGame()
 
{
 
	const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 

	
 
	if (w != NULL) {
 
		_saved_scrollpos_x = WP(w, const vp_d).scrollpos_x;
 
		_saved_scrollpos_y = WP(w, const vp_d).scrollpos_y;
 
		_saved_scrollpos_x = w->viewport->scrollpos_x;
 
		_saved_scrollpos_y = w->viewport->scrollpos_y;
 
		_saved_scrollpos_zoom = w->viewport->zoom;
 
	}
 
}
 

	
 
static void ConvertTownOwner()
 
{
 
	for (TileIndex tile = 0; tile != MapSize(); tile++) {
 
		switch (GetTileType(tile)) {
 
			case MP_ROAD:
 
				if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m4, 7)) {
 
					_m[tile].m4 = OWNER_TOWN;
 
				}
 
				/* FALLTHROUGH */
 

	
 
			case MP_TUNNELBRIDGE:
 
				if (GetTileOwner(tile) & 0x80) SetTileOwner(tile, OWNER_TOWN);
 
				break;
 

	
 
			default: break;
 
		}
 
	}
 
}
 

	
 
/* before savegame version 4, the name of the company determined if it existed */
 
@@ -1295,52 +1295,52 @@ extern void UpdateOldAircraft();
 
static inline RailType UpdateRailType(RailType rt, RailType min)
 
{
 
	return rt >= min ? (RailType)(rt + 1): rt;
 
}
 

	
 
/**
 
 * Initialization of the windows and several kinds of caches.
 
 * This is not done directly in AfterLoadGame because these
 
 * functions require that all saveload conversions have been
 
 * done. As people tend to add savegame conversion stuff after
 
 * the intialization of the windows and caches quite some bugs
 
 * had been made.
 
 * Moving this out of there is both cleaner and less bug-prone.
 
 *
 
 * @return true if everything went according to plan, otherwise false.
 
 */
 
static bool InitializeWindowsAndCaches()
 
{
 
	/* Initialize windows */
 
	ResetWindowSystem();
 
	SetupColorsAndInitialWindow();
 

	
 
	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 

	
 
	WP(w, vp_d).scrollpos_x = _saved_scrollpos_x;
 
	WP(w, vp_d).scrollpos_y = _saved_scrollpos_y;
 
	WP(w, vp_d).dest_scrollpos_x = _saved_scrollpos_x;
 
	WP(w, vp_d).dest_scrollpos_y = _saved_scrollpos_y;
 
	w->viewport->scrollpos_x = _saved_scrollpos_x;
 
	w->viewport->scrollpos_y = _saved_scrollpos_y;
 
	w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
 
	w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
 

	
 
	ViewPort *vp = w->viewport;
 
	vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
 
	vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
 
	vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
 

	
 
	DoZoomInOutWindow(ZOOM_NONE, w); // update button status
 
	MarkWholeScreenDirty();
 

	
 
	/* Update coordinates of the signs. */
 
	UpdateAllStationVirtCoord();
 
	UpdateAllSignVirtCoords();
 
	UpdateAllTownVirtCoords();
 
	UpdateAllWaypointSigns();
 

	
 
	/* Recalculate */
 
	Group *g;
 
	FOR_ALL_GROUPS(g) {
 
		g->num_engines = CallocT<uint16>(GetEnginePoolSize());
 

	
 
		const Vehicle *v;
 
		FOR_ALL_VEHICLES(v) {
 
			if (!IsEngineCountable(v)) continue;