Fix increased number of NewGRFs support.

Improve error handling if multiplayer limit is exceeded.
This commit is contained in:
Jonathan G Rennison 2017-02-14 00:35:15 +00:00
parent 7e89b9789f
commit f89e8b76d6
8 changed files with 24 additions and 14 deletions

View File

@ -75,7 +75,7 @@ size_t FioGetPos()
* @param slot Index of queried file.
* @return Name of the file.
*/
const char *FioGetFilename(uint8 slot)
const char *FioGetFilename(uint slot)
{
return _fio.shortnames[slot];
}
@ -112,7 +112,7 @@ static void FioRestoreFile(int slot)
* @param slot Slot number of the new file.
* @param pos New absolute position in the new file.
*/
void FioSeekToFile(uint8 slot, size_t pos)
void FioSeekToFile(uint slot, size_t pos)
{
FILE *f;
#if defined(LIMITED_FDS)
@ -247,7 +247,7 @@ static void FioFreeHandle()
* @param filename Name of the file at the disk.
* @param subdir The sub directory to search this file in.
*/
void FioOpenFile(int slot, const char *filename, Subdirectory subdir)
void FioOpenFile(uint slot, const char *filename, Subdirectory subdir)
{
FILE *f;

View File

@ -16,14 +16,14 @@
#include "fileio_type.h"
void FioSeekTo(size_t pos, int mode);
void FioSeekToFile(uint8 slot, size_t pos);
void FioSeekToFile(uint slot, size_t pos);
size_t FioGetPos();
const char *FioGetFilename(uint8 slot);
const char *FioGetFilename(uint slot);
byte FioReadByte();
uint16 FioReadWord();
uint32 FioReadDword();
void FioCloseAll();
void FioOpenFile(int slot, const char *filename, Subdirectory subdir);
void FioOpenFile(uint slot, const char *filename, Subdirectory subdir);
void FioReadBlock(void *ptr, size_t size);
void FioSkipBytes(int n);

View File

@ -90,8 +90,10 @@ enum FileSlots {
SOUND_SLOT = 1,
/** First slot usable for (New)GRFs used during the game. */
FIRST_GRF_SLOT = 2,
/** Maximum number of GRFs in single-player */
MAX_NEWGRFS = 256,
/** Maximum number of slots. */
MAX_FILE_SLOTS = 256,
MAX_FILE_SLOTS = 300,
};
/** Deals with finding savegames */

View File

@ -1179,7 +1179,7 @@ struct NetworkStartServerWindow : public Window {
}
case WID_NSS_GENERATE_GAME: // Start game
if ((uint) CountSelectedGRFs (_grfconfig_newgame) > NETWORK_MAX_GRF_COUNT) {
if (CountSelectedGRFs(_grfconfig_newgame) > NETWORK_MAX_GRF_COUNT) {
ShowErrorMessage(STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, INVALID_STRING_ID, WL_ERROR);
break;
}

View File

@ -9271,7 +9271,7 @@ void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
if (stage == GLS_LABELSCAN) InitNewGRFFile(c);
if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) {
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
if ((_networking && num_non_static == NETWORK_MAX_GRF_COUNT) || slot == MAX_FILE_SLOTS) {
DEBUG(grf, 0, "'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->filename);
c->status = GCS_DISABLED;
c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
@ -9314,12 +9314,13 @@ void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
/**
* Returns amount of user selected NewGRFs files.
*/
int CountSelectedGRFs(GRFConfig *grfconf)
uint CountSelectedGRFs(GRFConfig *grfconf)
{
int i = 0;
uint i = 0;
/* Find last entry in the list */
for (const GRFConfig *list = grfconf; list != NULL; list = list->next, i++) {
for (const GRFConfig *list = grfconf; list != NULL; list = list->next) {
if (!HasBit(list->flags, GCF_STATIC) && !HasBit(list->flags, GCF_SYSTEM)) i++;
}
return i;
}

View File

@ -194,7 +194,7 @@ bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile);
StringID MapGRFStringID(uint32 grfid, StringID str);
void ShowNewGRFError();
int CountSelectedGRFs(GRFConfig *grfconf);
uint CountSelectedGRFs(GRFConfig *grfconf);
struct TemplateVehicle;

View File

@ -1521,7 +1521,7 @@ private:
if (!HasBit((*list)->flags, GCF_STATIC)) count++;
}
if (entry == NULL) entry = list;
if (count >= NETWORK_MAX_GRF_COUNT) {
if (count >= MAX_NEWGRFS) {
ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO);
return false;
}

View File

@ -741,6 +741,13 @@ bool AfterLoadGame()
return false;
}
if (_networking && CountSelectedGRFs(_grfconfig) > NETWORK_MAX_GRF_COUNT) {
SetSaveLoadError(STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
/* Restore the signals */
ResetSignalHandlers();
return false;
}
/* The value of _date_fract got divided, so make sure that old games are converted correctly. */
if (IsSavegameVersionBefore(11, 1) || (IsSavegameVersionBefore(147) && _date_fract > DAY_TICKS)) _date_fract /= 885;