oldloader.c
changeset 3626 5569d866ea85
parent 3580 14bf6e7715c8
child 3627 3da11e0769c5
equal deleted inserted replaced
3625:929df0b3484a 3626:5569d866ea85
   164 
   164 
   165 	while (chunk->type != OC_END) {
   165 	while (chunk->type != OC_END) {
   166 		ptr = chunk->ptr;
   166 		ptr = chunk->ptr;
   167 
   167 
   168 		for (i = 0; i < chunk->amount; i++) {
   168 		for (i = 0; i < chunk->amount; i++) {
   169 			if (ls->failed)
   169 			if (ls->failed) return false;
   170 				return false;
       
   171 
   170 
   172 			/* Handle simple types */
   171 			/* Handle simple types */
   173 			if ((chunk->type & 0xFF) != 0) {
   172 			if ((chunk->type & 0xFF) != 0) {
   174 				switch (chunk->type & 0xFF) {
   173 				switch (chunk->type & 0xFF) {
   175 					case OC_NULL:
   174 					/* Just read the byte and forget about it */
   176 						/* Just read the byte and forget about it */
   175 					case OC_NULL: ReadByte(ls); break;
   177 						ReadByte(ls);
       
   178 						break;
       
   179 
   176 
   180 					case OC_CHUNK:
   177 					case OC_CHUNK:
   181 						/* Call function, with 'i' as parameter to tell which item we
   178 						/* Call function, with 'i' as parameter to tell which item we
   182 						 * are going to read */
   179 						 * are going to read */
   183 						if (!chunk->proc(ls, i)) return false;
   180 						if (!chunk->proc(ls, i)) return false;
   184 						break;
   181 						break;
   185 
   182 
   186 					case OC_ASSERT:
   183 					case OC_ASSERT:
   187 						DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value);
   184 						DEBUG(oldloader, 4)("[OldLoader] Assert point: %x / %x", ls->total_read, chunk->offset + _bump_assert_value);
   188 						if (ls->total_read != chunk->offset + _bump_assert_value) {
   185 						if (ls->total_read != chunk->offset + _bump_assert_value) ls->failed = true;
   189 							ls->failed = true;
       
   190 						}
       
   191 						break;
       
   192 
       
   193 				}
   186 				}
   194 			} else {
   187 			} else {
   195 				uint32 res = 0;
   188 				uint32 res = 0;
   196 
   189 
   197 				/* Reading from the file: bit 16 to 23 have the FILE */
   190 				/* Reading from the file: bit 16 to 23 have the FILE */
   393 {
   386 {
   394 	/* Check for shared orders, and link them correctly */
   387 	/* Check for shared orders, and link them correctly */
   395 	Vehicle* v;
   388 	Vehicle* v;
   396 
   389 
   397 	FOR_ALL_VEHICLES(v) {
   390 	FOR_ALL_VEHICLES(v) {
   398 		Vehicle* u;
   391 		Vehicle *u;
   399 
   392 
   400 		if (v->type == 0) continue;
   393 		if (v->type == 0) continue;
   401 
   394 
   402 		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
   395 		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
   403 			if (u->type == 0) continue;
   396 			if (u->type == 0) continue;
   443 
   436 
   444 extern TileIndex _animated_tile_list[256];
   437 extern TileIndex _animated_tile_list[256];
   445 extern char _name_array[512][32];
   438 extern char _name_array[512][32];
   446 extern uint16 _custom_sprites_base;
   439 extern uint16 _custom_sprites_base;
   447 
   440 
   448 static byte   _old_vehicle_multipler;
   441 static byte   _old_vehicle_multiplier;
   449 static uint8  _old_map3[OLD_MAP_SIZE * 2];
   442 static uint8  _old_map3[OLD_MAP_SIZE * 2];
   450 static bool   _new_ttdpatch_format;
   443 static bool   _new_ttdpatch_format;
   451 static uint32 _old_town_index;
   444 static uint32 _old_town_index;
   452 static uint16 _old_string_id;
   445 static uint16 _old_string_id;
   453 static uint16 _old_string_id_2;
   446 static uint16 _old_string_id_2;
   459 	if (_read_ttdpatch_flags) return;
   452 	if (_read_ttdpatch_flags) return;
   460 
   453 
   461 	_read_ttdpatch_flags = true;
   454 	_read_ttdpatch_flags = true;
   462 
   455 
   463 	/* TTDPatch misuses _old_map3 for flags.. read them! */
   456 	/* TTDPatch misuses _old_map3 for flags.. read them! */
   464 	_old_vehicle_multipler = _old_map3[0];
   457 	_old_vehicle_multiplier = _old_map3[0];
   465 	/* Somehow.... there was an error in some savegames, so 0 becomes 1
   458 	/* Somehow.... there was an error in some savegames, so 0 becomes 1
   466 	and 1 becomes 2. The rest of the values are okay */
   459 	and 1 becomes 2. The rest of the values are okay */
   467 	if (_old_vehicle_multipler < 2) _old_vehicle_multipler++;
   460 	if (_old_vehicle_multiplier < 2) _old_vehicle_multiplier++;
   468 
   461 
   469 	/* TTDPatch incraeses the Vehicle-part in the middle of the game,
   462 	/* TTDPatch incraeses the Vehicle-part in the middle of the game,
   470 	so if the multipler is anything else but 1, the assert fails..
   463 	so if the multipler is anything else but 1, the assert fails..
   471 	bump the assert value so it doesn't!
   464 	bump the assert value so it doesn't!
   472 	(1 multipler == 850 vehicles
   465 	(1 multipler == 850 vehicles
   473 	1 vehicle   == 128 bytes */
   466 	1 vehicle   == 128 bytes */
   474 	_bump_assert_value = (_old_vehicle_multipler - 1) * 850 * 128;
   467 	_bump_assert_value = (_old_vehicle_multiplier - 1) * 850 * 128;
   475 
   468 
   476 	/* Check if we have a modern TTDPatch savegame (has extra data all around) */
   469 	/* Check if we have a modern TTDPatch savegame (has extra data all around) */
   477 	_new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0);
   470 	_new_ttdpatch_format = (memcmp(&_old_map3[0x1FFFA], "TTDp", 4) == 0);
   478 
   471 
   479 	/* Clean the misused places */
   472 	/* Clean the misused places */
   481 	for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
   474 	for (i = 0x1FE00; i < 0x20000; i++) _old_map3[i] = 0;
   482 
   475 
   483 	if (_new_ttdpatch_format)
   476 	if (_new_ttdpatch_format)
   484 		DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game");
   477 		DEBUG(oldloader, 1)("[OldLoader] Found TTDPatch game");
   485 
   478 
   486 	DEBUG(oldloader, 1)("[OldLoader] Vehicle-multipler is set to %d (%d vehicles)", _old_vehicle_multipler, _old_vehicle_multipler * 850);
   479 	DEBUG(oldloader, 1)("[OldLoader] Vehicle-multiplier is set to %d (%d vehicles)", _old_vehicle_multiplier, _old_vehicle_multiplier * 850);
   487 }
   480 }
   488 
   481 
   489 static const OldChunks town_chunk[] = {
   482 static const OldChunks town_chunk[] = {
   490 	OCL_SVAR(   OC_TILE, Town, xy ),
   483 	OCL_SVAR(   OC_TILE, Town, xy ),
   491 	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, population ),
   484 	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, population ),
   550 static uint16 _old_order;
   543 static uint16 _old_order;
   551 static const OldChunks order_chunk[] = {
   544 static const OldChunks order_chunk[] = {
   552 	OCL_VAR ( OC_UINT16,   1, &_old_order ),
   545 	OCL_VAR ( OC_UINT16,   1, &_old_order ),
   553 	OCL_END()
   546 	OCL_END()
   554 };
   547 };
       
   548 
   555 static bool LoadOldOrder(LoadgameState *ls, int num)
   549 static bool LoadOldOrder(LoadgameState *ls, int num)
   556 {
   550 {
   557 	if (!AddBlockIfNeeded(&_order_pool, num))
   551 	if (!AddBlockIfNeeded(&_order_pool, num))
   558 		error("Orders: failed loading savegame: too many orders");
   552 		error("Orders: failed loading savegame: too many orders");
   559 
   553 
   560 	if (!LoadChunk(ls, NULL, order_chunk))
   554 	if (!LoadChunk(ls, NULL, order_chunk)) return false;
   561 		return false;
       
   562 
   555 
   563 	AssignOrder(GetOrder(num), UnpackOldOrder(_old_order));
   556 	AssignOrder(GetOrder(num), UnpackOldOrder(_old_order));
   564 
   557 
   565 	/* Relink the orders to eachother (in TTD(Patch) the orders for one
   558 	/* Relink the orders to eachother (in TTD(Patch) the orders for one
   566 	vehicle are behind eachother, with OT_NOTHING as indication that
   559 	vehicle are behind eachother, with OT_NOTHING as indication that
   574 static const OldChunks depot_chunk[] = {
   567 static const OldChunks depot_chunk[] = {
   575 	OCL_SVAR(   OC_TILE, Depot, xy ),
   568 	OCL_SVAR(   OC_TILE, Depot, xy ),
   576 	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
   569 	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
   577 	OCL_END()
   570 	OCL_END()
   578 };
   571 };
       
   572 
   579 static bool LoadOldDepot(LoadgameState *ls, int num)
   573 static bool LoadOldDepot(LoadgameState *ls, int num)
   580 {
   574 {
   581 	if (!AddBlockIfNeeded(&_depot_pool, num))
   575 	if (!AddBlockIfNeeded(&_depot_pool, num))
   582 		error("Depots: failed loading savegame: too many depots");
   576 		error("Depots: failed loading savegame: too many depots");
   583 
   577 
   584 	if (!LoadChunk(ls, GetDepot(num), depot_chunk))
   578 	if (!LoadChunk(ls, GetDepot(num), depot_chunk)) return false;
   585 		return false;
       
   586 
   579 
   587 	if (GetDepot(num)->xy != 0) {
   580 	if (GetDepot(num)->xy != 0) {
   588 		GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
   581 		GetDepot(num)->town_index = REMAP_TOWN_IDX(_old_town_index);
   589 	}
   582 	}
   590 
   583 
   596 static const OldChunks price_chunk[] = {
   589 static const OldChunks price_chunk[] = {
   597 	OCL_VAR (  OC_INT32,   1, &_old_price ),
   590 	OCL_VAR (  OC_INT32,   1, &_old_price ),
   598 	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
   591 	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
   599 	OCL_END()
   592 	OCL_END()
   600 };
   593 };
       
   594 
   601 static bool LoadOldPrice(LoadgameState *ls, int num)
   595 static bool LoadOldPrice(LoadgameState *ls, int num)
   602 {
   596 {
   603 	if (!LoadChunk(ls, NULL, price_chunk))
   597 	if (!LoadChunk(ls, NULL, price_chunk)) return false;
   604 		return false;
       
   605 
   598 
   606 	/* We use a struct to store the prices, but they are ints in a row..
   599 	/* We use a struct to store the prices, but they are ints in a row..
   607 	so just access the struct as an array of int32's */
   600 	so just access the struct as an array of int32's */
   608 	((int32*)&_price)[num] = _old_price;
   601 	((int32*)&_price)[num] = _old_price;
   609 	_price_frac[num] = _old_price_frac;
   602 	_price_frac[num] = _old_price_frac;
   616 	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
   609 	OCL_VAR ( OC_UINT16,   1, &_old_price_frac ),
   617 
   610 
   618 	OCL_NULL( 2 ),         // Junk
   611 	OCL_NULL( 2 ),         // Junk
   619 	OCL_END()
   612 	OCL_END()
   620 };
   613 };
       
   614 
   621 static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num)
   615 static bool LoadOldCargoPaymentRate(LoadgameState *ls, int num)
   622 {
   616 {
   623 	if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk))
   617 	if (!LoadChunk(ls, NULL, cargo_payment_rate_chunk)) return false;
   624 		return false;
       
   625 
   618 
   626 	_cargo_payment_rates[num] = -_old_price;
   619 	_cargo_payment_rates[num] = -_old_price;
   627 	_cargo_payment_rates_frac[num] = _old_price_frac;
   620 	_cargo_payment_rates_frac[num] = _old_price_frac;
   628 
   621 
   629 	return true;
   622 	return true;
   641 	OCL_SVAR(  OC_UINT8, GoodsEntry, last_speed ),
   634 	OCL_SVAR(  OC_UINT8, GoodsEntry, last_speed ),
   642 	OCL_SVAR(  OC_UINT8, GoodsEntry, last_age ),
   635 	OCL_SVAR(  OC_UINT8, GoodsEntry, last_age ),
   643 
   636 
   644 	OCL_END()
   637 	OCL_END()
   645 };
   638 };
       
   639 
   646 static bool LoadOldGood(LoadgameState *ls, int num)
   640 static bool LoadOldGood(LoadgameState *ls, int num)
   647 {
   641 {
   648 	Station *st = GetStation(_current_station_id);
   642 	Station *st = GetStation(_current_station_id);
   649 	return LoadChunk(ls, &st->goods[num], goods_chunk);
   643 	return LoadChunk(ls, &st->goods[num], goods_chunk);
   650 }
   644 }
   759 
   753 
   760 	OCL_NULL( 9 ), // Random junk at the end of this chunk
   754 	OCL_NULL( 9 ), // Random junk at the end of this chunk
   761 
   755 
   762 	OCL_END()
   756 	OCL_END()
   763 };
   757 };
       
   758 
   764 static bool LoadOldIndustry(LoadgameState *ls, int num)
   759 static bool LoadOldIndustry(LoadgameState *ls, int num)
   765 {
   760 {
   766 	Industry *i;
   761 	Industry *i;
   767 
   762 
   768 	if (!AddBlockIfNeeded(&_industry_pool, num))
   763 	if (!AddBlockIfNeeded(&_industry_pool, num))
   769 		error("Industries: failed loading savegame: too many industries");
   764 		error("Industries: failed loading savegame: too many industries");
   770 
   765 
   771 	i = GetIndustry(num);
   766 	i = GetIndustry(num);
   772 	if (!LoadChunk(ls, i, industry_chunk))
   767 	if (!LoadChunk(ls, i, industry_chunk)) return false;
   773 		return false;
       
   774 
   768 
   775 	if (i->xy != 0) {
   769 	if (i->xy != 0) {
   776 		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
   770 		i->town = GetTown(REMAP_TOWN_IDX(_old_town_index));
   777 	}
   771 	}
   778 
   772 
   785 
   779 
   786 static const OldChunks player_yearly_chunk[] = {
   780 static const OldChunks player_yearly_chunk[] = {
   787 	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
   781 	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
   788 	OCL_END()
   782 	OCL_END()
   789 };
   783 };
       
   784 
   790 static bool OldPlayerYearly(LoadgameState *ls, int num)
   785 static bool OldPlayerYearly(LoadgameState *ls, int num)
   791 {
   786 {
   792 	int i;
   787 	int i;
   793 	Player *p = GetPlayer(_current_player_id);
   788 	Player *p = GetPlayer(_current_player_id);
   794 
   789 
   795 	for (i = 0; i < 13; i++) {
   790 	for (i = 0; i < 13; i++) {
   796 		if (!LoadChunk(ls, NULL, player_yearly_chunk))
   791 		if (!LoadChunk(ls, NULL, player_yearly_chunk)) return false;
   797 			return false;
       
   798 
   792 
   799 		p->yearly_expenses[num][i] = _old_yearly;
   793 		p->yearly_expenses[num][i] = _old_yearly;
   800 	}
   794 	}
   801 
   795 
   802 	return true;
   796 	return true;
   809 	OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ),
   803 	OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ),
   810 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ),
   804 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ),
   811 
   805 
   812 	OCL_END()
   806 	OCL_END()
   813 };
   807 };
       
   808 
   814 static bool OldPlayerEconomy(LoadgameState *ls, int num)
   809 static bool OldPlayerEconomy(LoadgameState *ls, int num)
   815 {
   810 {
   816 	int i;
   811 	int i;
   817 	Player *p = GetPlayer(_current_player_id);
   812 	Player *p = GetPlayer(_current_player_id);
   818 
   813 
   819 	if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk))
   814 	if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk)) return false;
   820 		return false;
       
   821 
   815 
   822 	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
   816 	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
   823 	p->cur_economy.income   = -p->cur_economy.income;
   817 	p->cur_economy.income   = -p->cur_economy.income;
   824 	p->cur_economy.expenses = -p->cur_economy.expenses;
   818 	p->cur_economy.expenses = -p->cur_economy.expenses;
   825 
   819 
   826 	for (i = 0; i < 24; i++) {
   820 	for (i = 0; i < 24; i++) {
   827 		if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk))
   821 		if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk)) return false;
   828 			return false;
       
   829 
   822 
   830 		p->old_economy[i].income   = -p->old_economy[i].income;
   823 		p->old_economy[i].income   = -p->old_economy[i].income;
   831 		p->old_economy[i].expenses = -p->old_economy[i].expenses;
   824 		p->old_economy[i].expenses = -p->old_economy[i].expenses;
   832 	}
   825 	}
   833 
   826 
   848 
   841 
   849 	OCL_NULL( 8 ),  // Junk...
   842 	OCL_NULL( 8 ),  // Junk...
   850 
   843 
   851 	OCL_END()
   844 	OCL_END()
   852 };
   845 };
       
   846 
   853 static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
   847 static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
   854 {
   848 {
   855 	Player *p = GetPlayer(_current_player_id);
   849 	Player *p = GetPlayer(_current_player_id);
   856 
   850 
   857 	switch (num) {
   851 	switch (num) {
   963 	OCL_SVAR(  OC_UINT8, PlayerAI, railtype_to_use ),
   957 	OCL_SVAR(  OC_UINT8, PlayerAI, railtype_to_use ),
   964 	OCL_SVAR(  OC_UINT8, PlayerAI, route_type_mask ),
   958 	OCL_SVAR(  OC_UINT8, PlayerAI, route_type_mask ),
   965 
   959 
   966 	OCL_END()
   960 	OCL_END()
   967 };
   961 };
       
   962 
   968 static bool OldPlayerAI(LoadgameState *ls, int num)
   963 static bool OldPlayerAI(LoadgameState *ls, int num)
   969 {
   964 {
   970 	Player *p = GetPlayer(_current_player_id);
   965 	Player *p = GetPlayer(_current_player_id);
   971 
   966 
   972 	return LoadChunk(ls, &p->ai, player_ai_chunk);
   967 	return LoadChunk(ls, &p->ai, player_ai_chunk);
  1018 {
  1013 {
  1019 	Player *p = GetPlayer(num);
  1014 	Player *p = GetPlayer(num);
  1020 
  1015 
  1021 	_current_player_id = num;
  1016 	_current_player_id = num;
  1022 
  1017 
  1023 	if (!LoadChunk(ls, p, player_chunk))
  1018 	if (!LoadChunk(ls, p, player_chunk)) return false;
  1024 		return false;
       
  1025 
  1019 
  1026 	p->name_1 = RemapOldStringID(_old_string_id);
  1020 	p->name_1 = RemapOldStringID(_old_string_id);
  1027 	p->president_name_1 = RemapOldStringID(_old_string_id_2);
  1021 	p->president_name_1 = RemapOldStringID(_old_string_id_2);
  1028 	p->money64 = p->player_money;
  1022 	p->money64 = p->player_money;
  1029 
  1023 
  1074 
  1068 
  1075 	OCL_NULL( 5 ), // Junk
  1069 	OCL_NULL( 5 ), // Junk
  1076 
  1070 
  1077 	OCL_END()
  1071 	OCL_END()
  1078 };
  1072 };
       
  1073 
  1079 static const OldChunks vehicle_road_chunk[] = {
  1074 static const OldChunks vehicle_road_chunk[] = {
  1080 	OCL_SVAR(  OC_UINT8, VehicleRoad, state ),
  1075 	OCL_SVAR(  OC_UINT8, VehicleRoad, state ),
  1081 	OCL_SVAR(  OC_UINT8, VehicleRoad, frame ),
  1076 	OCL_SVAR(  OC_UINT8, VehicleRoad, frame ),
  1082 	OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ),
  1077 	OCL_SVAR( OC_UINT16, VehicleRoad, blocked_ctr ),
  1083 	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking ),
  1078 	OCL_SVAR(  OC_UINT8, VehicleRoad, overtaking ),
  1087 
  1082 
  1088 	OCL_NULL( 1 ), // Junk
  1083 	OCL_NULL( 1 ), // Junk
  1089 
  1084 
  1090 	OCL_END()
  1085 	OCL_END()
  1091 };
  1086 };
       
  1087 
  1092 static const OldChunks vehicle_ship_chunk[] = {
  1088 static const OldChunks vehicle_ship_chunk[] = {
  1093 	OCL_SVAR(  OC_UINT8, VehicleShip, state ),
  1089 	OCL_SVAR(  OC_UINT8, VehicleShip, state ),
  1094 
  1090 
  1095 	OCL_NULL( 9 ), // Junk
  1091 	OCL_NULL( 9 ), // Junk
  1096 
  1092 
  1097 	OCL_END()
  1093 	OCL_END()
  1098 };
  1094 };
       
  1095 
  1099 static const OldChunks vehicle_air_chunk[] = {
  1096 static const OldChunks vehicle_air_chunk[] = {
  1100 	OCL_SVAR(  OC_UINT8, VehicleAir, pos ),
  1097 	OCL_SVAR(  OC_UINT8, VehicleAir, pos ),
  1101 	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ),
  1098 	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, VehicleAir, targetairport ),
  1102 	OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ),
  1099 	OCL_SVAR( OC_UINT16, VehicleAir, crashed_counter ),
  1103 	OCL_SVAR(  OC_UINT8, VehicleAir, state ),
  1100 	OCL_SVAR(  OC_UINT8, VehicleAir, state ),
  1104 
  1101 
  1105 	OCL_NULL( 5 ), // Junk
  1102 	OCL_NULL( 5 ), // Junk
  1106 
  1103 
  1107 	OCL_END()
  1104 	OCL_END()
  1108 };
  1105 };
       
  1106 
  1109 static const OldChunks vehicle_special_chunk[] = {
  1107 static const OldChunks vehicle_special_chunk[] = {
  1110 	OCL_SVAR( OC_UINT16, VehicleSpecial, unk0 ),
  1108 	OCL_SVAR( OC_UINT16, VehicleSpecial, unk0 ),
  1111 	OCL_SVAR(  OC_UINT8, VehicleSpecial, unk2 ),
  1109 	OCL_SVAR(  OC_UINT8, VehicleSpecial, unk2 ),
  1112 
  1110 
  1113 	OCL_NULL( 7 ), // Junk
  1111 	OCL_NULL( 7 ), // Junk
  1114 
  1112 
  1115 	OCL_END()
  1113 	OCL_END()
  1116 };
  1114 };
       
  1115 
  1117 static const OldChunks vehicle_disaster_chunk[] = {
  1116 static const OldChunks vehicle_disaster_chunk[] = {
  1118 	OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ),
  1117 	OCL_SVAR( OC_UINT16, VehicleDisaster, image_override ),
  1119 	OCL_SVAR( OC_UINT16, VehicleDisaster, unk2 ),
  1118 	OCL_SVAR( OC_UINT16, VehicleDisaster, unk2 ),
  1120 
  1119 
  1121 	OCL_NULL( 6 ), // Junk
  1120 	OCL_NULL( 6 ), // Junk
  1122 
  1121 
  1123 	OCL_END()
  1122 	OCL_END()
  1124 };
  1123 };
       
  1124 
  1125 static const OldChunks vehicle_empty_chunk[] = {
  1125 static const OldChunks vehicle_empty_chunk[] = {
  1126 	OCL_NULL( 10 ), // Junk
  1126 	OCL_NULL( 10 ), // Junk
  1127 
  1127 
  1128 	OCL_END()
  1128 	OCL_END()
  1129 };
  1129 };
       
  1130 
  1130 static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
  1131 static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
  1131 {
  1132 {
  1132 	Vehicle *v = GetVehicle(_current_vehicle_id);
  1133 	Vehicle *v = GetVehicle(_current_vehicle_id);
  1133 	uint temp = ls->total_read;
  1134 	uint temp = ls->total_read;
  1134 	bool res;
  1135 	bool res;
  1231 
  1232 
  1232 	OCL_NULL( 20 ), // Junk at end of struct (TTDPatch has some data in it)
  1233 	OCL_NULL( 20 ), // Junk at end of struct (TTDPatch has some data in it)
  1233 
  1234 
  1234 	OCL_END()
  1235 	OCL_END()
  1235 };
  1236 };
       
  1237 
  1236 static bool LoadOldVehicle(LoadgameState *ls, int num)
  1238 static bool LoadOldVehicle(LoadgameState *ls, int num)
  1237 {
  1239 {
  1238 	uint i;
  1240 	uint i;
  1239 
  1241 
  1240 	/* Read the TTDPatch flags, because we need some info from it */
  1242 	/* Read the TTDPatch flags, because we need some info from it */
  1241 	ReadTTDPatchFlags();
  1243 	ReadTTDPatchFlags();
  1242 
  1244 
  1243 	for (i = 0; i < _old_vehicle_multipler; i++) {
  1245 	for (i = 0; i < _old_vehicle_multiplier; i++) {
  1244 		Vehicle *v;
  1246 		Vehicle *v;
  1245 
  1247 
  1246 		_current_vehicle_id = num * _old_vehicle_multipler + i;
  1248 		_current_vehicle_id = num * _old_vehicle_multiplier + i;
  1247 
  1249 
  1248 		if (!AddBlockIfNeeded(&_vehicle_pool, _current_vehicle_id))
  1250 		if (!AddBlockIfNeeded(&_vehicle_pool, _current_vehicle_id))
  1249 			error("Vehicles: failed loading savegame: too many vehicles");
  1251 			error("Vehicles: failed loading savegame: too many vehicles");
  1250 
  1252 
  1251 		v = GetVehicle(_current_vehicle_id);
  1253 		v = GetVehicle(_current_vehicle_id);
  1252 		if (!LoadChunk(ls, v, vehicle_chunk))
  1254 		if (!LoadChunk(ls, v, vehicle_chunk)) return false;
  1253 			return false;
       
  1254 
  1255 
  1255 		/* This should be consistent, else we have a big problem... */
  1256 		/* This should be consistent, else we have a big problem... */
  1256 		if (v->index != _current_vehicle_id) {
  1257 		if (v->index != _current_vehicle_id) {
  1257 			DEBUG(oldloader, 0)("[OldLoader] -- Loading failed - vehicle-array is invalid");
  1258 			DEBUG(oldloader, 0)("[OldLoader] -- Loading failed - vehicle-array is invalid");
  1258 			return false;
  1259 			return false;
  1277 			v->next = GetVehicle(_old_next_ptr);
  1278 			v->next = GetVehicle(_old_next_ptr);
  1278 
  1279 
  1279 		v->string_id = RemapOldStringID(_old_string_id);
  1280 		v->string_id = RemapOldStringID(_old_string_id);
  1280 
  1281 
  1281 		/* Vehicle-subtype is different in TTD(Patch) */
  1282 		/* Vehicle-subtype is different in TTD(Patch) */
  1282 		if (v->type == VEH_Special)
  1283 		if (v->type == VEH_Special) v->subtype = v->subtype >> 1;
  1283 			v->subtype = v->subtype >> 1;
       
  1284 	}
  1284 	}
  1285 
  1285 
  1286 	return true;
  1286 	return true;
  1287 }
  1287 }
  1288 
  1288 
  1294 
  1294 
  1295 	OCL_NULL( 6 ),         // Width of sign, no longer in use
  1295 	OCL_NULL( 6 ),         // Width of sign, no longer in use
  1296 
  1296 
  1297 	OCL_END()
  1297 	OCL_END()
  1298 };
  1298 };
       
  1299 
  1299 static bool LoadOldSign(LoadgameState *ls, int num)
  1300 static bool LoadOldSign(LoadgameState *ls, int num)
  1300 {
  1301 {
  1301 	if (!AddBlockIfNeeded(&_sign_pool, num))
  1302 	if (!AddBlockIfNeeded(&_sign_pool, num))
  1302 		error("Signs: failed loading savegame: too many signs");
  1303 		error("Signs: failed loading savegame: too many signs");
  1303 
  1304 
  1325 
  1326 
  1326 	OCL_NULL( 1 ),         // Junk
  1327 	OCL_NULL( 1 ),         // Junk
  1327 
  1328 
  1328 	OCL_END()
  1329 	OCL_END()
  1329 };
  1330 };
       
  1331 
  1330 static bool LoadOldEngine(LoadgameState *ls, int num)
  1332 static bool LoadOldEngine(LoadgameState *ls, int num)
  1331 {
  1333 {
  1332 	if (!LoadChunk(ls, GetEngine(num), engine_chunk)) return false;
  1334 	if (!LoadChunk(ls, GetEngine(num), engine_chunk)) return false;
  1333 
  1335 
  1334 	/* Make sure wagons are marked as do-not-age */
  1336 	/* Make sure wagons are marked as do-not-age */
  1344 	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, from ),
  1346 	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, from ),
  1345 	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),
  1347 	OCL_SVAR(  OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),
  1346 
  1348 
  1347 	OCL_END()
  1349 	OCL_END()
  1348 };
  1350 };
  1349 static bool LoadOldSubsidy(LoadgameState *ls, int num)
  1351 
       
  1352 static inline bool LoadOldSubsidy(LoadgameState *ls, int num)
  1350 {
  1353 {
  1351 	return LoadChunk(ls, &_subsidies[num], subsidy_chunk);
  1354 	return LoadChunk(ls, &_subsidies[num], subsidy_chunk);
  1352 }
  1355 }
  1353 
  1356 
  1354 static const OldChunks game_difficulty_chunk[] = {
  1357 static const OldChunks game_difficulty_chunk[] = {
  1369 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, economy ),
  1372 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, economy ),
  1370 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, line_reverse_mode ),
  1373 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, line_reverse_mode ),
  1371 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, disasters ),
  1374 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, GameDifficulty, disasters ),
  1372 	OCL_END()
  1375 	OCL_END()
  1373 };
  1376 };
  1374 static bool LoadOldGameDifficulty(LoadgameState *ls, int num)
  1377 
       
  1378 static inline bool LoadOldGameDifficulty(LoadgameState *ls, int num)
  1375 {
  1379 {
  1376 	return LoadChunk(ls, &_opt.diff, game_difficulty_chunk);
  1380 	return LoadChunk(ls, &_opt.diff, game_difficulty_chunk);
  1377 }
  1381 }
  1378 
  1382 
  1379 
  1383 
  1399 		_m[i * 4 + 3].extra = GB(b, 6, 2);
  1403 		_m[i * 4 + 3].extra = GB(b, 6, 2);
  1400 	}
  1404 	}
  1401 
  1405 
  1402 	return !ls->failed;
  1406 	return !ls->failed;
  1403 }
  1407 }
       
  1408 
  1404 static bool LoadOldMapPart2(LoadgameState *ls, int num)
  1409 static bool LoadOldMapPart2(LoadgameState *ls, int num)
  1405 {
  1410 {
  1406 	uint i;
  1411 	uint i;
  1407 
  1412 
  1408 	for (i = 0; i < OLD_MAP_SIZE; i++) {
  1413 	for (i = 0; i < OLD_MAP_SIZE; i++) {
  1412 		_m[i].m5 = ReadByte(ls);
  1417 		_m[i].m5 = ReadByte(ls);
  1413 	}
  1418 	}
  1414 
  1419 
  1415 	return !ls->failed;
  1420 	return !ls->failed;
  1416 }
  1421 }
  1417 
       
  1418 
  1422 
  1419 static uint32 _old_cur_town_ctr;
  1423 static uint32 _old_cur_town_ctr;
  1420 static const OldChunks main_chunk[] = {
  1424 static const OldChunks main_chunk[] = {
  1421 	OCL_ASSERT( 0 ),
  1425 	OCL_ASSERT( 0 ),
  1422 	OCL_VAR ( OC_UINT16,   1, &_date ),
  1426 	OCL_VAR ( OC_UINT16,   1, &_date ),
  1530 
  1534 
  1531 	/* Below any (if available) extra chunks from TTDPatch can follow */
  1535 	/* Below any (if available) extra chunks from TTDPatch can follow */
  1532 
  1536 
  1533 	OCL_END()
  1537 	OCL_END()
  1534 };
  1538 };
       
  1539 
  1535 static bool LoadOldMain(LoadgameState *ls)
  1540 static bool LoadOldMain(LoadgameState *ls)
  1536 {
  1541 {
  1537 	int i;
  1542 	int i;
  1538 
  1543 
  1539 	/* The first 49 is the name of the game + checksum, skip it */
  1544 	/* The first 49 is the name of the game + checksum, skip it */
  1615 	return true;
  1620 	return true;
  1616 }
  1621 }
  1617 
  1622 
  1618 void GetOldSaveGameName(char *title, const char *file)
  1623 void GetOldSaveGameName(char *title, const char *file)
  1619 {
  1624 {
  1620 	FILE *f;
  1625 	FILE *f = fopen(file, "rb");
  1621 
       
  1622 	f = fopen(file, "rb");
       
  1623 	title[0] = 0;
  1626 	title[0] = 0;
  1624 	title[48] = 0;
  1627 	title[48] = 0;
  1625 
  1628 
  1626 	if (f == NULL)
  1629 	if (f == NULL) return;
  1627 		return;
  1630 
  1628 
  1631 	if (fread(title, 1, 48, f) != 48) snprintf(title, 48, "Corrupt file");
  1629 	if (fread(title, 1, 48, f) != 48)
       
  1630 		snprintf(title, 48, "Corrupt file");
       
  1631 
  1632 
  1632 	fclose(f);
  1633 	fclose(f);
  1633 }
  1634 }
  1634 
  1635 
  1635 void GetOldScenarioGameName(char *title, const char *file)
  1636 void GetOldScenarioGameName(char *title, const char *file)