bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename) { GRFConfig *c = new GRFConfig(filename + basepath_length); bool added = true; if (FillGRFDetails(c, false)) { if (_all_grfs == NULL) { _all_grfs = c; } else { /* Insert file into list at a position determined by its * name, so the list is sorted as we go along */ GRFConfig **pd, *d; bool stop = false; for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false; /* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name, * before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of * just after the first with the same name. Avoids doubles in the list. */ if (strcasecmp(c->GetName(), d->GetName()) <= 0) { stop = true; } else if (stop) { break; } } if (added) { c->next = d; *pd = c; } } } else { added = false; } this->num_scanned++; if (this->next_update <= _realtime_tick) { _modal_progress_work_mutex->EndCritical(); _modal_progress_paint_mutex->BeginCritical(); const char *name = NULL; if (c->name != NULL) name = GetGRFStringFromGRFText(c->name->text); if (name == NULL) name = c->filename; UpdateNewGRFScanStatus(this->num_scanned, name); _modal_progress_work_mutex->BeginCritical(); _modal_progress_paint_mutex->EndCritical(); this->next_update = _realtime_tick + 200; } if (!added) { /* File couldn't be opened, or is either not a NewGRF or is a * 'system' NewGRF or it's already known, so forget about it. */ delete c; } return added; }
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length) { GRFConfig *c = CallocT<GRFConfig>(1); c->filename = strdup(filename + basepath_length); bool added = true; if (FillGRFDetails(c, false)) { if (_all_grfs == NULL) { _all_grfs = c; } else { /* Insert file into list at a position determined by its * name, so the list is sorted as we go along */ GRFConfig **pd, *d; bool stop = false; for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false; /* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name, * before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of * just after the first with the same name. Avoids doubles in the list. */ if (strcasecmp(c->name, d->name) <= 0) { stop = true; } else if (stop) { break; } } if (added) { c->next = d; *pd = c; } } } else { added = false; } if (!added) { /* File couldn't be opened, or is either not a NewGRF or is a * 'system' NewGRF or it's already known, so forget about it. */ free(c->filename); free(c->name); free(c->info); free(c); } return added; }
/** Actually load the sprite tables. */ static void LoadSpriteTables() { memset(_palette_remap_grf, 0, sizeof(_palette_remap_grf)); uint i = FIRST_GRF_SLOT; const GraphicsSet *used_set = BaseGraphics::GetUsedSet(); _palette_remap_grf[i] = (PAL_DOS != used_set->palette); LoadGrfFile(used_set->files[GFT_BASE].filename, 0, i++); /* * The second basic file always starts at the given location and does * contain a different amount of sprites depending on the "type"; DOS * has a few sprites less. However, we do not care about those missing * sprites as they are not shown anyway (logos in intro game). */ _palette_remap_grf[i] = (PAL_DOS != used_set->palette); LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, i++); /* * Load additional sprites for climates other than temperate. * This overwrites some of the temperate sprites, such as foundations * and the ground sprites. */ if (_settings_game.game_creation.landscape != LT_TEMPERATE) { _palette_remap_grf[i] = (PAL_DOS != used_set->palette); LoadGrfFileIndexed( used_set->files[GFT_ARCTIC + _settings_game.game_creation.landscape - 1].filename, _landscape_spriteindexes[_settings_game.game_creation.landscape - 1], i++ ); } /* Initialize the unicode to sprite mapping table */ InitializeUnicodeGlyphMap(); /* * Load the base NewGRF with OTTD required graphics as first NewGRF. * However, we do not want it to show up in the list of used NewGRFs, * so we have to manually add it, and then remove it later. */ GRFConfig *top = _grfconfig; GRFConfig *master = new GRFConfig(used_set->files[GFT_EXTRA].filename); /* We know the palette of the base set, so if the base NewGRF is not * setting one, use the palette of the base set and not the global * one which might be the wrong palette for this base NewGRF. * The value set here might be overridden via action14 later. */ switch (used_set->palette) { case PAL_DOS: master->palette |= GRFP_GRF_DOS; break; case PAL_WINDOWS: master->palette |= GRFP_GRF_WINDOWS; break; default: break; } FillGRFDetails(master, false, BASESET_DIR); ClrBit(master->flags, GCF_INIT_ONLY); master->next = top; _grfconfig = master; LoadNewGRF(SPR_NEWGRFS_BASE, i); /* Free and remove the top element. */ delete master; _grfconfig = top; }