2006-08-04 23:41:13 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/** @file fios.h Declarations for savegames operations */
|
|
|
|
|
2006-08-04 23:41:13 +00:00
|
|
|
#ifndef FIOS_H
|
|
|
|
#define FIOS_H
|
|
|
|
|
2010-06-05 19:02:29 +00:00
|
|
|
#include "gfx_type.h"
|
2010-06-13 14:15:36 +00:00
|
|
|
#include "company_base.h"
|
2010-06-13 14:15:58 +00:00
|
|
|
#include "newgrf_config.h"
|
2012-08-20 21:01:40 +00:00
|
|
|
#include "network/core/tcp_content.h"
|
2008-01-13 01:21:35 +00:00
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
|
2010-06-13 14:15:36 +00:00
|
|
|
typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
|
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
/**
|
|
|
|
* Container for loading in mode SL_LOAD_CHECK.
|
|
|
|
*/
|
|
|
|
struct LoadCheckData {
|
|
|
|
bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
|
|
|
|
StringID error; ///< Error message from loading. INVALID_STRING_ID if no error.
|
|
|
|
char *error_data; ///< Data to pass to SetDParamStr when displaying #error.
|
|
|
|
|
2010-06-13 14:13:49 +00:00
|
|
|
uint32 map_size_x, map_size_y;
|
2010-06-13 14:14:20 +00:00
|
|
|
Date current_date;
|
2010-06-13 14:13:49 +00:00
|
|
|
|
2010-06-13 14:14:37 +00:00
|
|
|
GameSettings settings;
|
|
|
|
|
2010-06-13 14:15:36 +00:00
|
|
|
CompanyPropertiesMap companies; ///< Company information.
|
|
|
|
|
2010-06-13 14:15:58 +00:00
|
|
|
GRFConfig *grfconfig; ///< NewGrf configuration from save.
|
|
|
|
GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found.
|
|
|
|
|
2011-10-30 13:47:45 +00:00
|
|
|
struct LoggedAction *gamelog_action; ///< Gamelog actions
|
|
|
|
uint gamelog_actions; ///< Number of gamelog actions
|
|
|
|
|
2013-11-23 13:12:19 +00:00
|
|
|
LoadCheckData() : error_data(NULL), grfconfig(NULL),
|
|
|
|
grf_compatibility(GLC_NOT_FOUND), gamelog_action(NULL), gamelog_actions(0)
|
2010-06-13 14:13:23 +00:00
|
|
|
{
|
|
|
|
this->Clear();
|
|
|
|
}
|
|
|
|
|
2010-09-06 15:47:11 +00:00
|
|
|
/**
|
|
|
|
* Don't leak memory at program exit
|
|
|
|
*/
|
|
|
|
~LoadCheckData()
|
|
|
|
{
|
|
|
|
this->Clear();
|
|
|
|
}
|
|
|
|
|
2010-06-13 14:17:26 +00:00
|
|
|
/**
|
|
|
|
* Check whether loading the game resulted in errors.
|
|
|
|
* @return true if errors were encountered.
|
|
|
|
*/
|
|
|
|
bool HasErrors()
|
|
|
|
{
|
|
|
|
return this->checkable && this->error != INVALID_STRING_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the game uses any NewGrfs.
|
|
|
|
* @return true if NewGrfs are used.
|
|
|
|
*/
|
|
|
|
bool HasNewGrfs()
|
|
|
|
{
|
|
|
|
return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
void Clear();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern LoadCheckData _load_check_data;
|
|
|
|
|
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
enum FileSlots {
|
2007-10-29 23:02:31 +00:00
|
|
|
/**
|
2017-01-14 13:12:49 +00:00
|
|
|
* Slot used for the GRF scanning and such.
|
|
|
|
* This slot is used for all temporary accesses to files when scanning/testing files,
|
|
|
|
* and thus cannot be used for files, which are continuously accessed during a game.
|
2007-10-29 23:02:31 +00:00
|
|
|
*/
|
|
|
|
CONFIG_SLOT = 0,
|
|
|
|
/** Slot for the sound. */
|
|
|
|
SOUND_SLOT = 1,
|
2013-01-08 22:46:42 +00:00
|
|
|
/** First slot usable for (New)GRFs used during the game. */
|
2007-10-29 23:02:31 +00:00
|
|
|
FIRST_GRF_SLOT = 2,
|
|
|
|
/** Maximum number of slots. */
|
2017-01-14 13:12:49 +00:00
|
|
|
MAX_FILE_SLOTS = 128,
|
2007-10-29 23:02:31 +00:00
|
|
|
};
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/** Deals with finding savegames */
|
2007-12-28 03:14:55 +00:00
|
|
|
struct FiosItem {
|
2008-04-23 12:03:47 +00:00
|
|
|
FiosType type;
|
2007-12-28 03:14:55 +00:00
|
|
|
uint64 mtime;
|
|
|
|
char title[64];
|
2009-03-04 01:09:48 +00:00
|
|
|
char name[MAX_PATH];
|
2007-12-28 03:14:55 +00:00
|
|
|
};
|
|
|
|
|
2016-09-04 12:50:22 +00:00
|
|
|
/** List of file information. */
|
|
|
|
class FileList {
|
|
|
|
public:
|
|
|
|
~FileList();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new entry in the file list.
|
|
|
|
* @return Pointer to the new items to be initialized.
|
|
|
|
*/
|
|
|
|
inline FiosItem *Append()
|
|
|
|
{
|
|
|
|
return this->files.Append();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of files in the list.
|
|
|
|
* @return The number of files stored in the list.
|
|
|
|
*/
|
|
|
|
inline uint Length() const
|
|
|
|
{
|
|
|
|
return this->files.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the first file information.
|
|
|
|
* @return Address of the first file information.
|
|
|
|
*/
|
|
|
|
inline const FiosItem *Begin() const
|
|
|
|
{
|
|
|
|
return this->files.Begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer behind the last file information.
|
|
|
|
* @return Address behind the last file information.
|
|
|
|
*/
|
|
|
|
inline const FiosItem *End() const
|
|
|
|
{
|
|
|
|
return this->files.End();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the indicated file information. File information must exist.
|
|
|
|
* @return Address of the indicated existing file information.
|
|
|
|
*/
|
|
|
|
inline const FiosItem *Get(uint index) const
|
|
|
|
{
|
|
|
|
return this->files.Get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the indicated file information. File information must exist.
|
|
|
|
* @return Address of the indicated existing file information.
|
|
|
|
*/
|
|
|
|
inline FiosItem *Get(uint index)
|
|
|
|
{
|
|
|
|
return this->files.Get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const FiosItem &operator[](uint index) const
|
|
|
|
{
|
|
|
|
return this->files[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a reference to the indicated file information. File information must exist.
|
|
|
|
* @return The requested file information.
|
|
|
|
*/
|
|
|
|
inline FiosItem &operator[](uint index)
|
|
|
|
{
|
|
|
|
return this->files[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove all items from the list. */
|
|
|
|
inline void Clear()
|
|
|
|
{
|
|
|
|
this->files.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Compact the list down to the smallest block size boundary. */
|
|
|
|
inline void Compact()
|
|
|
|
{
|
|
|
|
this->files.Compact();
|
|
|
|
}
|
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
|
2016-09-04 12:54:52 +00:00
|
|
|
const FiosItem *FindItem(const char *file);
|
|
|
|
|
2016-09-04 12:50:22 +00:00
|
|
|
SmallVector<FiosItem, 32> files; ///< The list of files.
|
|
|
|
};
|
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
enum SortingBits {
|
2008-05-29 09:54:47 +00:00
|
|
|
SORT_ASCENDING = 0,
|
|
|
|
SORT_DESCENDING = 1,
|
|
|
|
SORT_BY_DATE = 0,
|
|
|
|
SORT_BY_NAME = 2
|
|
|
|
};
|
2010-06-05 18:44:31 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(SortingBits)
|
2008-05-29 09:54:47 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
/* Variables to display file lists */
|
2010-06-05 18:44:31 +00:00
|
|
|
extern SortingBits _savegame_sort_order;
|
2007-12-27 17:29:27 +00:00
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
|
2006-08-05 00:59:45 +00:00
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
|
|
|
|
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
|
|
|
|
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
|
2011-05-27 21:20:07 +00:00
|
|
|
|
2009-03-04 00:13:52 +00:00
|
|
|
const char *FiosBrowseTo(const FiosItem *item);
|
2011-05-27 21:20:07 +00:00
|
|
|
|
2009-01-16 12:59:47 +00:00
|
|
|
StringID FiosGetDescText(const char **path, uint64 *total_free);
|
2006-08-05 00:59:45 +00:00
|
|
|
bool FiosDelete(const char *name);
|
2014-04-23 21:23:21 +00:00
|
|
|
void FiosMakeHeightmapName(char *buf, const char *name, const char *last);
|
|
|
|
void FiosMakeSavegameName(char *buf, const char *name, const char *last);
|
2011-05-27 21:20:07 +00:00
|
|
|
|
2016-09-04 16:06:50 +00:00
|
|
|
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
|
2006-08-05 00:59:45 +00:00
|
|
|
|
2009-09-13 17:39:33 +00:00
|
|
|
int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
|
2006-08-05 00:59:45 +00:00
|
|
|
|
2006-08-04 23:41:13 +00:00
|
|
|
#endif /* FIOS_H */
|