File diff r2624:1fa34b183518 → r2625:27ad3b929a5b
newgrf.c
Show inline comments
 
@@ -797,55 +797,44 @@ static bool StationChangeInfo(uint stid,
 
				/* classid, for a change, is always little-endian */
 
				classid = *(buf++) << 24;
 
				classid |= *(buf++) << 16;
 
				classid |= *(buf++) << 8;
 
				classid |= *(buf++);
 

	
 
				switch (classid) {
 
					case 'DFLT':
 
						stat->sclass = STAT_CLASS_DFLT;
 
						break;
 
					case 'WAYP':
 
						stat->sclass = STAT_CLASS_WAYP;
 
						break;
 
					default:
 
						/* TODO: No support for custom
 
						 * classes for now, so stuff
 
						 * everything to the single
 
						 * default one. --pasky */
 
						stat->sclass = STAT_CLASS_DFLT;
 
						//stat->sclass = STAT_CLASS_CUSTOM;
 
						break;
 
				}
 
				stat->sclass = AllocateStationClass(classid);
 
			}
 
			break;
 
		}
 
		case 0x09:
 
		{	/* Define sprite layout */
 
			FOR_EACH_OBJECT {
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				int t;
 

	
 
				stat->tiles = grf_load_byte(&buf);
 
				stat->tiles = grf_load_extended(&buf);
 
				stat->renderdata = calloc(stat->tiles, sizeof(*stat->renderdata));
 
				for (t = 0; t < stat->tiles; t++) {
 
					DrawTileSprites *dts = &stat->renderdata[t];
 
					int seq_count = 0;
 

	
 
					if (t >= 8) {
 
						grfmsg(GMS_WARN, "StationChangeInfo: Sprite %d>=8, skipping.", t);
 
						grf_load_dword(&buf); // at least something
 
						continue;
 
					}
 

	
 
					dts->ground_sprite = grf_load_dword(&buf);
 
					if (!dts->ground_sprite) {
 
					PalSpriteID ground_sprite;
 

	
 
					ground_sprite = grf_load_dword(&buf);
 
					if (ground_sprite == 0) {
 
						static const DrawTileSeqStruct empty = {0x80, 0, 0, 0, 0, 0, 0};
 
						dts->seq = &empty;
 
						continue;
 
					}
 

	
 
					if (HASBIT(ground_sprite, 31)) {
 
						// Bit 31 indicates that we should use a custom sprite.
 
						dts->ground_sprite = GB(ground_sprite, 0, 15) - 0x42D;
 
						dts->ground_sprite += _cur_grffile->first_spriteset;
 
					} else {
 
						dts->ground_sprite = ground_sprite;
 
					}
 

	
 
					dts->seq = NULL;
 
					while (buf < *bufp + len) {
 
						DrawTileSeqStruct *dtss;
 

	
 
						// no relative bounding box support
 
						dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
 
@@ -870,12 +859,13 @@ static bool StationChangeInfo(uint stid,
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				byte srcid = grf_load_byte(&buf);
 
				const StationSpec *srcstat = &_cur_grffile->stations[srcid];
 
				int t;
 

	
 
				stat->tiles = srcstat->tiles;
 
				stat->renderdata = calloc(stat->tiles, sizeof(*stat->renderdata));
 
				for (t = 0; t < stat->tiles; t++) {
 
					DrawTileSprites *dts = &stat->renderdata[t];
 
					const DrawTileSprites *sdts = &srcstat->renderdata[t];
 
					DrawTileSeqStruct const *sdtss = sdts->seq;
 
					int seq_count = 0;
 

	
 
@@ -1545,12 +1535,15 @@ static void NewSpriteGroup(byte *buf, in
 
	check_length(bufend - buf, 5, "NewSpriteGroup");
 
	buf += 5;
 
	check_length(bufend - buf, 2 * numloaded, "NewSpriteGroup");
 
	loaded_ptr = buf;
 
	loading_ptr = buf + 2 * numloaded;
 

	
 
	if (_cur_grffile->first_spriteset == 0)
 
		_cur_grffile->first_spriteset = _cur_grffile->spriteset_start;
 

	
 
	if (numloaded > 16) {
 
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
 
		numloaded = 16;
 
	}
 
	if (numloading > 16) {
 
		grfmsg(GMS_WARN, "NewSpriteGroup: More than 16 sprites in group %x, skipping the rest.", setid);
 
@@ -1685,14 +1678,14 @@ static void NewVehicle_SpriteGroupMappin
 
				uint8 stid = buf[3 + i];
 
				StationSpec *stat = &_cur_grffile->stations[stid];
 

	
 
				stat->spritegroup[0] = _cur_grffile->spritegroups[groupid];
 
				stat->spritegroup[0]->ref_count++;
 
				stat->grfid = _cur_grffile->grfid;
 
				SetCustomStation(stid, stat);
 
				stat->sclass = STAT_CLASS_NONE;
 
				stat->localidx = stid;
 
				SetCustomStation(stat);
 
			}
 
		}
 
		return;
 
	}
 

	
 

	
 
@@ -2393,12 +2386,34 @@ static void ReleaseSpriteGroups(GRFFile 
 
	}
 
	free(file->spritegroups);
 
	file->spritegroups = NULL;
 
	file->spritegroups_count = 0;
 
}
 

	
 
static void ResetCustomStations(void)
 
{
 
	GRFFile *file;
 
	int i;
 
	CargoID c;
 

	
 
	for (file = _first_grffile; file != NULL; file = file->next) {
 
		for (i = 0; i < 256; i++) {
 
			if (file->stations[i].grfid != file->grfid)
 
				continue;
 

	
 
			// TODO: Release renderdata, platforms and layouts
 

	
 
			// Release this stations sprite groups.
 
			for (c = 0; c < NUM_GLOBAL_CID; c++) {
 
				if (file->stations[i].spritegroup[c] != NULL)
 
					UnloadSpriteGroup(&file->stations[i].spritegroup[c]);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Reset all NewGRF loaded data
 
 * TODO
 
 */
 
static void ResetNewGRFData(void)
 
{
 
@@ -2430,12 +2445,16 @@ static void ResetNewGRFData(void)
 
	// Unload sprite group data
 
	UnloadWagonOverrides();
 
	UnloadCustomEngineSprites();
 

	
 
	// Reset price base data
 
	ResetPriceBaseMultipliers();
 

	
 
	// Reset station classes
 
	ResetStationClasses();
 
	ResetCustomStations();
 
}
 

	
 
static void InitNewGRFFile(const char* filename, int sprite_offset)
 
{
 
	GRFFile *newfile;