Example #1
0
/**
 * Scan a file for Rcd meta-data, and add it to the collection if all is well.
 * @param fname Filename of the file to scan.
 * @return Error message, or \c nullptr if no error found.
 */
const char *RcdFileCollection::ScanFileForMetaInfo(const char *fname)
{
	RcdFileReader rcd_file(fname);
	if (!rcd_file.CheckFileHeader("RCDF", 2)) return "Wrong header";

	/* Load block. */
	if (!rcd_file.ReadBlockHeader() || (strcmp(rcd_file.name, "INFO") != 0)) {
		/* End reached or found a non-meta block, end scanning. */
		return "No INFO block found.";
	}

	/* Load INFO block. */
	if (rcd_file.version != 1) return "INFO block has wrong version";
	uint32 remaining = rcd_file.size;
	std::string build = GetString(rcd_file, 16, &remaining);
	std::string name = GetString(rcd_file, 64, &remaining);
	std::string uri = GetString(rcd_file, 128, &remaining);
	std::string website = GetString(rcd_file, 128, &remaining);
	std::string description = GetString(rcd_file, 512, &remaining);
	if (remaining != 0) return "Error while reading INFO text.";

	RcdFileInfo rfi(fname, uri, build);
	this->AddFile(rfi);
	return nullptr; // Success.
}
Example #2
0
/**
 * Load sprites from the disk.
 * @param filename Name of the RCD file to load.
 * @return Error message if load failed, else \c nullptr.
 * @todo Try to re-use already loaded blocks.
 * @todo Code will use last loaded surface as grass.
 */
const char *SpriteManager::Load(const char *filename)
{
	RcdFileReader rcd_file(filename);
	if (!rcd_file.CheckFileHeader("RCDF", 2)) return "Bad header";

	ImageMap sprites; // Sprites loaded from this file.
	TextMap  texts;   // Texts loaded from this file.
	TrackPiecesMap track_pieces; // Track pieces loaded from this file.

	/* Load blocks. */
	for (uint blk_num = 1;; blk_num++) {
		if (!rcd_file.ReadBlockHeader()) return nullptr; // End reached.

		/* Skip meta blocks. */
		if (strcmp(rcd_file.name, "INFO") == 0) {
			rcd_file.SkipBytes(rcd_file.size);
			continue;
		}

		if (strcmp(rcd_file.name, "8PXL") == 0 || strcmp(rcd_file.name, "32PX") == 0) {
			ImageData *imd = LoadImage(&rcd_file);
			if (imd == nullptr) {
				return "Image data loading failed";
			}
			std::pair<uint, ImageData *> p(blk_num, imd);
			sprites.insert(p);
			continue;
		}

		if (strcmp(rcd_file.name, "SURF") == 0) {
			if (!this->LoadSURF(&rcd_file, sprites)) return "Surface block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "TSEL") == 0) {
			if (!this->LoadTSEL(&rcd_file, sprites)) return "Tile-selection block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "PATH") == 0) {
			if (!this->LoadPATH(&rcd_file, sprites)) return "Path-sprites block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "TCOR") == 0) {
			if (!this->LoadTCOR(&rcd_file, sprites)) return "Tile-corners block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "FUND") == 0) {
			if (!this->LoadFUND(&rcd_file, sprites)) return "Foundation block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "PLAT") == 0) {
			if (!this->LoadPLAT(&rcd_file, sprites)) return "Platform block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "SUPP") == 0) {
			if (!this->LoadSUPP(&rcd_file, sprites)) return "Support block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "BDIR") == 0) {
			if (!this->LoadBDIR(&rcd_file, sprites)) return "Build arrows block loading failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "GCHK") == 0) {
			if (!_gui_sprites.LoadGCHK(&rcd_file, sprites)) return "Loading Checkable GUI sprites failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "GBOR") == 0) {
			if (!_gui_sprites.LoadGBOR(&rcd_file, sprites)) return "Loading Border GUI sprites failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "GSLI") == 0) {
			if (!_gui_sprites.LoadGSLI(&rcd_file, sprites)) return "Loading Slider bar GUI sprites failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "GSCL") == 0) {
			if (!_gui_sprites.LoadGSCL(&rcd_file, sprites)) return "Loading Scrollbar GUI sprites failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "GSLP") == 0) {
			if (!_gui_sprites.LoadGSLP(&rcd_file, sprites, texts)) return "Loading slope selection GUI sprites failed.";
			continue;
		}

		if (strcmp(rcd_file.name, "ANIM") == 0) {
			Animation *anim = new Animation;
			if (!anim->Load(&rcd_file)) {
				delete anim;
				return "Animation failed to load.";
			}
			if (anim->person_type == PERSON_INVALID || anim->anim_type == ANIM_INVALID) {
				delete anim;
				return "Unknown animation.";
			}
			this->AddBlock(anim);
			this->AddAnimation(anim);
			this->store.RemoveAnimations(anim->anim_type, (PersonType)anim->person_type);
			continue;
		}

		if (strcmp(rcd_file.name, "ANSP") == 0) {
			AnimationSprites *an_spr = new AnimationSprites;
			if (!an_spr->Load(&rcd_file, sprites)) {
				delete an_spr;
				return "Animation sprites failed to load.";
			}
			if (an_spr->person_type == PERSON_INVALID || an_spr->anim_type == ANIM_INVALID) {
				delete an_spr;
				return "Unknown animation.";
			}
			this->AddBlock(an_spr);
			this->store.AddAnimationSprites(an_spr);
			continue;
		}

		if (strcmp(rcd_file.name, "PRSG") == 0) {
			if (!LoadPRSG(&rcd_file)) return "Graphics Person type data failed to load.";
			continue;
		}

		if (strcmp(rcd_file.name, "TEXT") == 0) {
			TextData *txt = new TextData;
			if (!txt->Load(&rcd_file)) {
				delete txt;
				return "Text block failed to load.";
			}
			this->AddBlock(txt);

			std::pair<uint, TextData *> p(blk_num, txt);
			texts.insert(p);
			continue;
		}

		if (strcmp(rcd_file.name, "SHOP") == 0) {
			ShopType *shop_type = new ShopType;
			if (!shop_type->Load(&rcd_file, sprites, texts)) {
				delete shop_type;
				return "Shop type failed to load.";
			}
			_rides_manager.AddRideType(shop_type);
			continue;
		}

		if (strcmp(rcd_file.name, "TRCK") == 0) {
			auto tp = std::make_shared<TrackPiece>();
			if (!tp->Load(&rcd_file, sprites)) {
				return "Track piece failed to load.";
			}
			track_pieces.insert({blk_num, tp});
			continue;
		}

		if (strcmp(rcd_file.name, "RCST") == 0) {
			CoasterType *ct = new CoasterType;
			if (!ct->Load(&rcd_file, texts, track_pieces)) {
				delete ct;
				return "Coaster type failed to load.";
			}
			_rides_manager.AddRideType(ct);
			continue;
		}

		if (strcmp(rcd_file.name, "CSPL") == 0) {
			if (!LoadCoasterPlatform(&rcd_file, sprites)) return "Coaster platform failed to load.";
			continue;
		}

		if (strcmp(rcd_file.name, "CARS") == 0) {
			CarType *ct = GetNewCarType();
			if (ct == nullptr) return "No room to store a car type.";
			if (!ct->Load(&rcd_file, sprites)) return "Car type failed to load.";
			continue;
		}

		/* Unknown block in the RCD file. Skip the block. */
		fprintf(stderr, "Unknown RCD block '%s', version %i, ignoring it\n", rcd_file.name, rcd_file.version);
		rcd_file.SkipBytes(rcd_file.size);
	}
}