File diff r7710:64254e378532 → r7711:2d9b2a9a2e0b
src/oldloader.cpp
Show inline comments
 
@@ -481,48 +481,71 @@ static bool LoadOldTown(LoadgameState *l
 
	return LoadChunk(ls, new (num) Town(), town_chunk);
 
}
 

	
 
static uint16 _old_order;
 
static const OldChunks order_chunk[] = {
 
	OCL_VAR ( OC_UINT16,   1, &_old_order ),
 
	OCL_END()
 
};
 

	
 
static bool LoadOldOrder(LoadgameState *ls, int num)
 
{
 
	if (!LoadChunk(ls, NULL, order_chunk)) return false;
 

	
 
	AssignOrder(new (num) Order(), UnpackOldOrder(_old_order));
 

	
 
	/* Relink the orders to eachother (in TTD(Patch) the orders for one
 
	vehicle are behind eachother, with an invalid order (OT_NOTHING) as indication that
 
	it is the last order */
 
	if (num > 0 && GetOrder(num)->IsValid())
 
		GetOrder(num - 1)->next = GetOrder(num);
 

	
 
	return true;
 
}
 

	
 
static bool LoadOldAnimTileList(LoadgameState *ls, int num)
 
{
 
	/* This is sligthly hackish - we must load a chunk into an array whose
 
	 * address isn't static, but instead pointed to by _animated_tile_list.
 
	 * To achieve that, create an OldChunks list on the stack on the fly.
 
	 * The list cannot be static because the value of _animated_tile_list
 
	 * can change between calls. */
 

	
 
	const OldChunks anim_chunk[] = {
 
		OCL_VAR (   OC_TILE, 256, _animated_tile_list ),
 
		OCL_END ()
 
	};
 

	
 
	if (!LoadChunk(ls, NULL, anim_chunk)) return false;
 

	
 
	/* Update the animated tile counter by counting till the first zero in the array */
 
	for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
 
		if (_animated_tile_list[_animated_tile_count] == 0) break;
 
	}
 

	
 
	return true;
 
}
 

	
 
static const OldChunks depot_chunk[] = {
 
	OCL_SVAR(   OC_TILE, Depot, xy ),
 
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
 
	OCL_END()
 
};
 

	
 
static bool LoadOldDepot(LoadgameState *ls, int num)
 
{
 
	if (!LoadChunk(ls, new (num) Depot(), depot_chunk)) return false;
 

	
 
	if (IsValidDepotID(num)) {
 
		GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
 
	}
 

	
 
	return true;
 
}
 

	
 
static int32 _old_price;
 
static uint16 _old_price_frac;
 
static const OldChunks price_chunk[] = {
 
	OCL_VAR (  OC_INT32,   1, &_old_price ),
 
	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
 
	OCL_END()
 
};
 
@@ -1402,49 +1425,49 @@ static bool LoadTTDPatchExtraChunks(Load
 
			default:
 
				DEBUG(oldloader, 4, "Skipping unknown extra chunk %X", id);
 
				while (len-- != 0) ReadByte(ls);
 
				break;
 
		}
 
	}
 

	
 
	return !ls->failed;
 
}
 

	
 
static uint32 _old_cur_town_ctr;
 
static const OldChunks main_chunk[] = {
 
	OCL_ASSERT( 0 ),
 
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U32, 1, &_date ),
 
	OCL_VAR ( OC_UINT16,   1, &_date_fract ),
 
	OCL_NULL( 600 ),            ///< TextEffects
 
	OCL_VAR ( OC_UINT32,   2, &_random_seeds[0] ),
 

	
 
	OCL_ASSERT( 0x264 ),
 
	OCL_CHUNK(  70, LoadOldTown ),
 
	OCL_ASSERT( 0x1C18 ),
 
	OCL_CHUNK(5000, LoadOldOrder ),
 
	OCL_ASSERT( 0x4328 ),
 

	
 
	OCL_VAR (   OC_TILE, 256, _animated_tile_list ),
 
	OCL_CHUNK( 1, LoadOldAnimTileList ),
 
	OCL_NULL( 4 ),              ///< old end-of-order-list-pointer, no longer in use
 

	
 
	OCL_CHUNK( 255, LoadOldDepot ),
 
	OCL_ASSERT( 0x4B26 ),
 

	
 
	OCL_VAR ( OC_UINT32,   1, &_old_cur_town_ctr ),
 
	OCL_NULL( 2 ),              ///< timer_counter, no longer in use
 
	OCL_NULL( 2 ),              ///< land_code,     no longer in use
 

	
 
	OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
 
	OCL_VAR ( OC_UINT16,   1, &_tick_counter ),
 
	OCL_VAR (   OC_TILE,   1, &_cur_tileloop_tile ),
 

	
 
	OCL_CHUNK( 49, LoadOldPrice ),
 
	OCL_CHUNK( 12, LoadOldCargoPaymentRate ),
 

	
 
	OCL_ASSERT( 0x4CBA ),
 

	
 
	OCL_CHUNK( 1, LoadOldMapPart1 ),
 

	
 
	OCL_ASSERT( 0x48CBA ),
 

	
 
	OCL_CHUNK(250, LoadOldStation ),
 
	OCL_CHUNK( 90, LoadOldIndustry ),
 
@@ -1533,52 +1556,48 @@ static bool LoadOldMain(LoadgameState *l
 

	
 
	/* The first 49 is the name of the game + checksum, skip it */
 
	fseek(ls->file, HEADER_SIZE, SEEK_SET);
 

	
 
	DEBUG(oldloader, 3, "Reading main chunk...");
 
	/* Load the biggest chunk */
 
	if (!LoadChunk(ls, NULL, main_chunk)) {
 
		DEBUG(oldloader, 0, "Loading failed");
 
		return false;
 
	}
 
	DEBUG(oldloader, 3, "Done, converting game data...");
 

	
 
	/* Fix some general stuff */
 
	_opt.landscape = _opt.landscape & 0xF;
 

	
 
	/* Remap some pointers */
 
	_cur_town_ctr      = REMAP_TOWN_IDX(_old_cur_town_ctr);
 

	
 
	/* _old_map3 is changed in _map3_lo and _map3_hi */
 
	for (i = 0; i < OLD_MAP_SIZE; i++) {
 
		_m[i].m3 = _old_map3[i * 2];
 
		_m[i].m4 = _old_map3[i * 2 + 1];
 
	}
 

	
 
	for (_animated_tile_count = 0; _animated_tile_count < 256; _animated_tile_count++) {
 
		if (_animated_tile_list[_animated_tile_count] == 0) break;
 
	}
 

	
 
	for (i = 0; i < OLD_MAP_SIZE; i ++) {
 
		switch (GetTileType(i)) {
 
			case MP_STATION:
 
				_m[i].m4 = 0; // We do not understand this TTDP station mapping (yet)
 
				switch (_m[i].m5) {
 
					/* We have drive through stops at a totally different place */
 
					case 0x53: case 0x54: _m[i].m5 += 170 - 0x53; break; // Bus drive through
 
					case 0x57: case 0x58: _m[i].m5 += 168 - 0x57; break; // Truck drive through
 
					case 0x55: case 0x56: _m[i].m5 += 170 - 0x55; break; // Bus tram stop
 
					case 0x59: case 0x5A: _m[i].m5 += 168 - 0x59; break; // Truck tram stop
 
					default: break;
 
				}
 
				break;
 

	
 
			case MP_RAILWAY:
 
				/* We save presignals different from TTDPatch, convert them */
 
				if (GetRailTileType(i) == RAIL_TILE_SIGNALS) {
 
					/* This byte is always zero in TTD for this type of tile */
 
					if (_m[i].m4) /* Convert the presignals to our own format */
 
						_m[i].m4 = (_m[i].m4 >> 1) & 7;
 
				}
 
				/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
 
				 * clear it for ourselves and let OTTD's rebuild PBS itself */
 
				_m[i].m4 &= 0xF; /* Only keep the lower four bits; upper four is PBS */