src/newgrf_config.cpp
branchNewGRF_ports
changeset 6871 5a9dc001e1ad
parent 6870 ca3fd1fbe311
child 6872 1c4a4a609f85
equal deleted inserted replaced
6870:ca3fd1fbe311 6871:5a9dc001e1ad
    64 		config->status = GCS_NOT_FOUND;
    64 		config->status = GCS_NOT_FOUND;
    65 		return false;
    65 		return false;
    66 	}
    66 	}
    67 
    67 
    68 	/* Find and load the Action 8 information */
    68 	/* Find and load the Action 8 information */
    69 	/* 62 is the last file slot before sample.cat.
    69 	LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
    70 	 * Should perhaps be some "don't care" value */
       
    71 	LoadNewGRFFile(config, 62, GLS_FILESCAN);
       
    72 
    70 
    73 	/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
    71 	/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
    74 	if (config->grfid == 0 || config->grfid == 0xFFFFFFFF) return false;
    72 	if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
    75 
    73 
    76 	if (is_static) {
    74 	if (is_static) {
    77 		/* Perform a 'safety scan' for static GRFs */
    75 		/* Perform a 'safety scan' for static GRFs */
    78 		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
    76 		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
    79 
    77 
    80 		/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
    78 		/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
    81 		if (HASBIT(config->flags, GCF_UNSAFE)) return false;
    79 		if (HasBit(config->flags, GCF_UNSAFE)) return false;
    82 	}
    80 	}
    83 
    81 
    84 	return CalcGRFMD5Sum(config);
    82 	return CalcGRFMD5Sum(config);
    85 }
    83 }
    86 
    84 
    87 
    85 
    88 void ClearGRFConfig(GRFConfig **config)
    86 void ClearGRFConfig(GRFConfig **config)
    89 {
    87 {
    90 	/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
    88 	/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
    91 	if (!HASBIT((*config)->flags, GCF_COPY)) {
    89 	if (!HasBit((*config)->flags, GCF_COPY)) {
    92 		free((*config)->filename);
    90 		free((*config)->filename);
    93 		free((*config)->name);
    91 		free((*config)->name);
    94 		free((*config)->info);
    92 		free((*config)->info);
    95 
    93 
    96 		if ((*config)->error != NULL) {
    94 		if ((*config)->error != NULL) {
   121 void AddGRFTToGameListByGRFid(uint32 grfid)
   119 void AddGRFTToGameListByGRFid(uint32 grfid)
   122 {
   120 {
   123 	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
   121 	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
   124 		if (c->grfid == grfid) {
   122 		if (c->grfid == grfid) {
   125 			/* The required GRF is already in the list; for it to be loaded properly */
   123 			/* The required GRF is already in the list; for it to be loaded properly */
   126 			CLRBIT(c->flags, GCF_INIT_ONLY);
   124 			ClrBit(c->flags, GCF_INIT_ONLY);
   127 			return;
   125 			return;
   128 		}
   126 		}
   129 	}
   127 	}
   130 
   128 
   131 	/* Copy GRF details from scanned list */
   129 	/* Copy GRF details from scanned list */
   160 			memcpy(c->error, src->error, sizeof(GRFError));
   158 			memcpy(c->error, src->error, sizeof(GRFError));
   161 			if (src->error->data != NULL) c->error->data = strdup(src->error->data);
   159 			if (src->error->data != NULL) c->error->data = strdup(src->error->data);
   162 			if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
   160 			if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
   163 		}
   161 		}
   164 
   162 
   165 		CLRBIT(c->flags, GCF_INIT_ONLY);
   163 		ClrBit(c->flags, GCF_INIT_ONLY);
   166 		if (init_only) SETBIT(c->flags, GCF_INIT_ONLY);
   164 		if (init_only) SetBit(c->flags, GCF_INIT_ONLY);
   167 
   165 
   168 		*dst = c;
   166 		*dst = c;
   169 		dst = &c->next;
   167 		dst = &c->next;
   170 	}
   168 	}
   171 
   169 
   260 			 * same grfid, as it most likely is compatible */
   258 			 * same grfid, as it most likely is compatible */
   261 			f = FindGRFConfig(c->grfid);
   259 			f = FindGRFConfig(c->grfid);
   262 			if (f != NULL) {
   260 			if (f != NULL) {
   263 				md5sumToString(buf, lastof(buf), c->md5sum);
   261 				md5sumToString(buf, lastof(buf), c->md5sum);
   264 				DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf);
   262 				DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf);
   265 				SETBIT(c->flags, GCF_COMPATIBLE);
   263 				SetBit(c->flags, GCF_COMPATIBLE);
   266 
   264 
   267 				/* Non-found has precedence over compatibility load */
   265 				/* Non-found has precedence over compatibility load */
   268 				if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
   266 				if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
   269 				goto compatible_grf;
   267 				goto compatible_grf;
   270 			}
   268 			}
   281 			/* The filename could be the filename as in the savegame. As we need
   279 			/* The filename could be the filename as in the savegame. As we need
   282 			 * to load the GRF here, we need the correct filename, so overwrite that
   280 			 * to load the GRF here, we need the correct filename, so overwrite that
   283 			 * in any case and set the name and info when it is not set already.
   281 			 * in any case and set the name and info when it is not set already.
   284 			 * When the GCF_COPY flag is set, it is certain that the filename is
   282 			 * When the GCF_COPY flag is set, it is certain that the filename is
   285 			 * already a local one, so there is no need to replace it. */
   283 			 * already a local one, so there is no need to replace it. */
   286 			if (!HASBIT(c->flags, GCF_COPY)) {
   284 			if (!HasBit(c->flags, GCF_COPY)) {
   287 				free(c->filename);
   285 				free(c->filename);
   288 				c->filename = strdup(f->filename);
   286 				c->filename = strdup(f->filename);
   289 				memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum));
   287 				memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum));
   290 				if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
   288 				if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
   291 				if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
   289 				if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
   548 		dst += snprintf(dst, last - dst, "%d", c->param[i]);
   546 		dst += snprintf(dst, last - dst, "%d", c->param[i]);
   549 	}
   547 	}
   550 	return dst;
   548 	return dst;
   551 }
   549 }
   552 
   550 
       
   551 /** Base GRF ID for OpenTTD's base graphics GRFs. */
       
   552 static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);
       
   553 
       
   554 /**
       
   555  * Checks whether this GRF is a OpenTTD base graphic GRF.
       
   556  * @return true if and only if it is a base GRF.
       
   557  */
       
   558 bool GRFConfig::IsOpenTTDBaseGRF() const
       
   559 {
       
   560 	return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
       
   561 }
       
   562 
   553 
   563 
   554 static const SaveLoad _grfconfig_desc[] = {
   564 static const SaveLoad _grfconfig_desc[] = {
   555 	SLE_STR(GRFConfig, filename,   SLE_STR, 0x40),
   565 	SLE_STR(GRFConfig, filename,   SLE_STR, 0x40),
   556 	SLE_VAR(GRFConfig, grfid,      SLE_UINT32),
   566 	SLE_VAR(GRFConfig, grfid,      SLE_UINT32),
   557 	SLE_ARR(GRFConfig, md5sum,     SLE_UINT8, 16),
   567 	SLE_ARR(GRFConfig, md5sum,     SLE_UINT8, 16),
   564 static void Save_NGRF()
   574 static void Save_NGRF()
   565 {
   575 {
   566 	int index = 0;
   576 	int index = 0;
   567 
   577 
   568 	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
   578 	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
   569 		if (HASBIT(c->flags, GCF_STATIC)) continue;
   579 		if (HasBit(c->flags, GCF_STATIC)) continue;
   570 		SlSetArrayIndex(index++);
   580 		SlSetArrayIndex(index++);
   571 		SlObject(c, _grfconfig_desc);
   581 		SlObject(c, _grfconfig_desc);
   572 	}
   582 	}
   573 }
   583 }
   574 
   584