src/oldloader.cpp
changeset 10207 c291a21b304e
parent 10010 09ff8bd74b87
child 10208 72c00af5c95d
equal deleted inserted replaced
10206:0050610c0368 10207:c291a21b304e
   361 
   361 
   362 		/* Sometimes primary vehicles would have a nothing (invalid) order
   362 		/* Sometimes primary vehicles would have a nothing (invalid) order
   363 		 * or vehicles that could not have an order would still have a
   363 		 * or vehicles that could not have an order would still have a
   364 		 * (loading) order which causes assertions and the like later on.
   364 		 * (loading) order which causes assertions and the like later on.
   365 		 */
   365 		 */
   366 		if (!IsPlayerBuildableVehicleType(v) ||
   366 		if (!IsCompanyBuildableVehicleType(v) ||
   367 				(v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
   367 				(v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
   368 			v->current_order.MakeDummy();
   368 			v->current_order.MakeDummy();
   369 		}
   369 		}
   370 
   370 
   371 		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
   371 		FOR_ALL_VEHICLES_FROM(u, v->index + 1) {
   768 	}
   768 	}
   769 
   769 
   770 	return true;
   770 	return true;
   771 }
   771 }
   772 
   772 
   773 static PlayerID _current_player_id;
   773 static CompanyID _current_company_id;
   774 static int32 _old_yearly;
   774 static int32 _old_yearly;
   775 
   775 
   776 static const OldChunks player_yearly_chunk[] = {
   776 static const OldChunks _company_yearly_chunk[] = {
   777 	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
   777 	OCL_VAR(  OC_INT32,   1, &_old_yearly ),
   778 	OCL_END()
   778 	OCL_END()
   779 };
   779 };
   780 
   780 
   781 static bool OldPlayerYearly(LoadgameState *ls, int num)
   781 static bool OldCompanyYearly(LoadgameState *ls, int num)
   782 {
   782 {
   783 	int i;
   783 	int i;
   784 	Player *p = GetPlayer(_current_player_id);
   784 	Company *c = GetCompany(_current_company_id);
   785 
   785 
   786 	for (i = 0; i < 13; i++) {
   786 	for (i = 0; i < 13; i++) {
   787 		if (!LoadChunk(ls, NULL, player_yearly_chunk)) return false;
   787 		if (!LoadChunk(ls, NULL, _company_yearly_chunk)) return false;
   788 
   788 
   789 		p->yearly_expenses[num][i] = _old_yearly;
   789 		c->yearly_expenses[num][i] = _old_yearly;
   790 	}
   790 	}
   791 
   791 
   792 	return true;
   792 	return true;
   793 }
   793 }
   794 
   794 
   795 static const OldChunks player_economy_chunk[] = {
   795 static const OldChunks _company_economy_chunk[] = {
   796 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, income ),
   796 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, income ),
   797 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, expenses ),
   797 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, expenses ),
   798 	OCL_SVAR( OC_INT32, PlayerEconomyEntry, delivered_cargo ),
   798 	OCL_SVAR( OC_INT32,                 CompanyEconomyEntry, delivered_cargo ),
   799 	OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ),
   799 	OCL_SVAR( OC_INT32,                 CompanyEconomyEntry, performance_history ),
   800 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ),
   800 	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, company_value ),
   801 
   801 
   802 	OCL_END()
   802 	OCL_END()
   803 };
   803 };
   804 
   804 
   805 static bool OldPlayerEconomy(LoadgameState *ls, int num)
   805 static bool OldCompanyEconomy(LoadgameState *ls, int num)
   806 {
   806 {
   807 	int i;
   807 	int i;
   808 	Player *p = GetPlayer(_current_player_id);
   808 	Company *c = GetCompany(_current_company_id);
   809 
   809 
   810 	if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk)) return false;
   810 	if (!LoadChunk(ls, &c->cur_economy, _company_economy_chunk)) return false;
   811 
   811 
   812 	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
   812 	/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
   813 	p->cur_economy.income   = -p->cur_economy.income;
   813 	c->cur_economy.income   = -c->cur_economy.income;
   814 	p->cur_economy.expenses = -p->cur_economy.expenses;
   814 	c->cur_economy.expenses = -c->cur_economy.expenses;
   815 
   815 
   816 	for (i = 0; i < 24; i++) {
   816 	for (i = 0; i < 24; i++) {
   817 		if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk)) return false;
   817 		if (!LoadChunk(ls, &c->old_economy[i], _company_economy_chunk)) return false;
   818 
   818 
   819 		p->old_economy[i].income   = -p->old_economy[i].income;
   819 		c->old_economy[i].income   = -c->old_economy[i].income;
   820 		p->old_economy[i].expenses = -p->old_economy[i].expenses;
   820 		c->old_economy[i].expenses = -c->old_economy[i].expenses;
   821 	}
   821 	}
   822 
   822 
   823 	return true;
   823 	return true;
   824 }
   824 }
   825 
   825 
   826 static const OldChunks player_ai_build_rec_chunk[] = {
   826 static const OldChunks _company_ai_build_rec_chunk[] = {
   827 	OCL_SVAR(   OC_TILE, AiBuildRec, spec_tile ),
   827 	OCL_SVAR(   OC_TILE, AiBuildRec, spec_tile ),
   828 	OCL_SVAR(   OC_TILE, AiBuildRec, use_tile ),
   828 	OCL_SVAR(   OC_TILE, AiBuildRec, use_tile ),
   829 	OCL_SVAR(  OC_UINT8, AiBuildRec, rand_rng ),
   829 	OCL_SVAR(  OC_UINT8, AiBuildRec, rand_rng ),
   830 	OCL_SVAR(  OC_UINT8, AiBuildRec, cur_building_rule ),
   830 	OCL_SVAR(  OC_UINT8, AiBuildRec, cur_building_rule ),
   831 	OCL_SVAR(  OC_UINT8, AiBuildRec, unk6 ),
   831 	OCL_SVAR(  OC_UINT8, AiBuildRec, unk6 ),
   840 	OCL_END()
   840 	OCL_END()
   841 };
   841 };
   842 
   842 
   843 static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
   843 static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
   844 {
   844 {
   845 	Player *p = GetPlayer(_current_player_id);
   845 	Company *c = GetCompany(_current_company_id);
   846 
   846 
   847 	switch (num) {
   847 	switch (num) {
   848 		case 0: return LoadChunk(ls, &_players_ai[p->index].src, player_ai_build_rec_chunk);
   848 		case 0: return LoadChunk(ls, &_companies_ai[c->index].src,  _company_ai_build_rec_chunk);
   849 		case 1: return LoadChunk(ls, &_players_ai[p->index].dst, player_ai_build_rec_chunk);
   849 		case 1: return LoadChunk(ls, &_companies_ai[c->index].dst,  _company_ai_build_rec_chunk);
   850 		case 2: return LoadChunk(ls, &_players_ai[p->index].mid1, player_ai_build_rec_chunk);
   850 		case 2: return LoadChunk(ls, &_companies_ai[c->index].mid1, _company_ai_build_rec_chunk);
   851 		case 3: return LoadChunk(ls, &_players_ai[p->index].mid2, player_ai_build_rec_chunk);
   851 		case 3: return LoadChunk(ls, &_companies_ai[c->index].mid2, _company_ai_build_rec_chunk);
   852 	}
   852 	}
   853 
   853 
   854 	return false;
   854 	return false;
   855 }
   855 }
   856 static const OldChunks player_ai_chunk[] = {
   856 static const OldChunks _company_ai_chunk[] = {
   857 	OCL_SVAR(  OC_UINT8, PlayerAI, state ),
   857 	OCL_SVAR(  OC_UINT8, CompanyAI, state ),
   858 	OCL_NULL( 1 ),         ///< Junk
   858 	OCL_NULL( 1 ),         ///< Junk
   859 	OCL_SVAR(  OC_UINT8, PlayerAI, state_mode ),
   859 	OCL_SVAR(  OC_UINT8, CompanyAI, state_mode ),
   860 	OCL_SVAR( OC_UINT16, PlayerAI, state_counter ),
   860 	OCL_SVAR( OC_UINT16, CompanyAI, state_counter ),
   861 	OCL_SVAR( OC_UINT16, PlayerAI, timeout_counter ),
   861 	OCL_SVAR( OC_UINT16, CompanyAI, timeout_counter ),
   862 
   862 
   863 	OCL_CHUNK( 4, OldLoadAIBuildRec ),
   863 	OCL_CHUNK( 4, OldLoadAIBuildRec ),
   864 
   864 
   865 	OCL_NULL( 20 ),        ///< More junk
   865 	OCL_NULL( 20 ),        ///< More junk
   866 
   866 
   867 	OCL_SVAR(  OC_UINT8, PlayerAI, cargo_type ),
   867 	OCL_SVAR(  OC_UINT8, CompanyAI, cargo_type ),
   868 	OCL_SVAR(  OC_UINT8, PlayerAI, num_wagons ),
   868 	OCL_SVAR(  OC_UINT8, CompanyAI, num_wagons ),
   869 	OCL_SVAR(  OC_UINT8, PlayerAI, build_kind ),
   869 	OCL_SVAR(  OC_UINT8, CompanyAI, build_kind ),
   870 	OCL_SVAR(  OC_UINT8, PlayerAI, num_build_rec ),
   870 	OCL_SVAR(  OC_UINT8, CompanyAI, num_build_rec ),
   871 	OCL_SVAR(  OC_UINT8, PlayerAI, num_loco_to_build ),
   871 	OCL_SVAR(  OC_UINT8, CompanyAI, num_loco_to_build ),
   872 	OCL_SVAR(  OC_UINT8, PlayerAI, num_want_fullload ),
   872 	OCL_SVAR(  OC_UINT8, CompanyAI, num_want_fullload ),
   873 
   873 
   874 	OCL_NULL( 14 ),        ///< Oh no more junk :|
   874 	OCL_NULL( 14 ),        ///< Oh no more junk :|
   875 
   875 
   876 	OCL_NULL( 2 ),         ///< Loco-id, not used
   876 	OCL_NULL( 2 ),         ///< Loco-id, not used
   877 
   877 
   878 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[0] ),
   878 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[0] ),
   879 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[1] ),
   879 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[1] ),
   880 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[2] ),
   880 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[2] ),
   881 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[3] ),
   881 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[3] ),
   882 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[4] ),
   882 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[4] ),
   883 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[5] ),
   883 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[5] ),
   884 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[6] ),
   884 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[6] ),
   885 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[7] ),
   885 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[7] ),
   886 	OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[8] ),
   886 	OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[8] ),
   887 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[0] ),
   887 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[0] ),
   888 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[1] ),
   888 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[1] ),
   889 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[2] ),
   889 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[2] ),
   890 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[3] ),
   890 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[3] ),
   891 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[4] ),
   891 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[4] ),
   892 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[5] ),
   892 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[5] ),
   893 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[6] ),
   893 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[6] ),
   894 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[7] ),
   894 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[7] ),
   895 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[8] ),
   895 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[8] ),
   896 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[9] ),
   896 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[9] ),
   897 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[10] ),
   897 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[10] ),
   898 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[11] ),
   898 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[11] ),
   899 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[12] ),
   899 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[12] ),
   900 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[13] ),
   900 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[13] ),
   901 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[14] ),
   901 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[14] ),
   902 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[15] ),
   902 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[15] ),
   903 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[16] ),
   903 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[16] ),
   904 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[17] ),
   904 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[17] ),
   905 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[18] ),
   905 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[18] ),
   906 	OCL_SVAR(  OC_UINT8, PlayerAI, order_list_blocks[19] ),
   906 	OCL_SVAR(  OC_UINT8, CompanyAI, order_list_blocks[19] ),
   907 
   907 
   908 	OCL_SVAR( OC_UINT16, PlayerAI, start_tile_a ),
   908 	OCL_SVAR( OC_UINT16, CompanyAI, start_tile_a ),
   909 	OCL_SVAR( OC_UINT16, PlayerAI, start_tile_b ),
   909 	OCL_SVAR( OC_UINT16, CompanyAI, start_tile_b ),
   910 	OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_a ),
   910 	OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_a ),
   911 	OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_b ),
   911 	OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_b ),
   912 
   912 
   913 	OCL_SVAR(  OC_UINT8, PlayerAI, start_dir_a ),
   913 	OCL_SVAR(  OC_UINT8, CompanyAI, start_dir_a ),
   914 	OCL_SVAR(  OC_UINT8, PlayerAI, start_dir_b ),
   914 	OCL_SVAR(  OC_UINT8, CompanyAI, start_dir_b ),
   915 	OCL_SVAR(  OC_UINT8, PlayerAI, cur_dir_a ),
   915 	OCL_SVAR(  OC_UINT8, CompanyAI, cur_dir_a ),
   916 	OCL_SVAR(  OC_UINT8, PlayerAI, cur_dir_b ),
   916 	OCL_SVAR(  OC_UINT8, CompanyAI, cur_dir_b ),
   917 
   917 
   918 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_tile_count ),
   918 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_tile_count ),
   919 
   919 
   920 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[0] ),
   920 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[0] ),
   921 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[0] ),
   921 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[0] ),
   922 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[1] ),
   922 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[1] ),
   923 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[1] ),
   923 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[1] ),
   924 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[2] ),
   924 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[2] ),
   925 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[2] ),
   925 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[2] ),
   926 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[3] ),
   926 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[3] ),
   927 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[3] ),
   927 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[3] ),
   928 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[4] ),
   928 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[4] ),
   929 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[4] ),
   929 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[4] ),
   930 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[5] ),
   930 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[5] ),
   931 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[5] ),
   931 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[5] ),
   932 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[6] ),
   932 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[6] ),
   933 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[6] ),
   933 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[6] ),
   934 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[7] ),
   934 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[7] ),
   935 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[7] ),
   935 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[7] ),
   936 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[8] ),
   936 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[8] ),
   937 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[8] ),
   937 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[8] ),
   938 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[9] ),
   938 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[9] ),
   939 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[9] ),
   939 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[9] ),
   940 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[10] ),
   940 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[10] ),
   941 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[10] ),
   941 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[10] ),
   942 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[11] ),
   942 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[11] ),
   943 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[11] ),
   943 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[11] ),
   944 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[12] ),
   944 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[12] ),
   945 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[12] ),
   945 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[12] ),
   946 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[13] ),
   946 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[13] ),
   947 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[13] ),
   947 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[13] ),
   948 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[14] ),
   948 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[14] ),
   949 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[14] ),
   949 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[14] ),
   950 	OCL_SVAR(   OC_TILE, PlayerAI, banned_tiles[15] ),
   950 	OCL_SVAR(   OC_TILE, CompanyAI, banned_tiles[15] ),
   951 	OCL_SVAR(  OC_UINT8, PlayerAI, banned_val[15] ),
   951 	OCL_SVAR(  OC_UINT8, CompanyAI, banned_val[15] ),
   952 
   952 
   953 	OCL_SVAR(  OC_UINT8, PlayerAI, railtype_to_use ),
   953 	OCL_SVAR(  OC_UINT8, CompanyAI, railtype_to_use ),
   954 	OCL_SVAR(  OC_UINT8, PlayerAI, route_type_mask ),
   954 	OCL_SVAR(  OC_UINT8, CompanyAI, route_type_mask ),
   955 
   955 
   956 	OCL_END()
   956 	OCL_END()
   957 };
   957 };
   958 
   958 
   959 static bool OldPlayerAI(LoadgameState *ls, int num)
   959 static bool OldCompanyAI(LoadgameState *ls, int num)
   960 {
   960 {
   961 	return LoadChunk(ls, &_players_ai[_current_player_id], player_ai_chunk);
   961 	return LoadChunk(ls, &_companies_ai[_current_company_id], _company_ai_chunk);
   962 }
   962 }
   963 
   963 
   964 uint8 ai_tick;
   964 uint8 ai_tick;
   965 static const OldChunks player_chunk[] = {
   965 static const OldChunks _company_chunk[] = {
   966 	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
   966 	OCL_VAR ( OC_UINT16,   1, &_old_string_id ),
   967 	OCL_SVAR( OC_UINT32, Player, name_2 ),
   967 	OCL_SVAR( OC_UINT32, Company, name_2 ),
   968 	OCL_SVAR( OC_UINT32, Player, face ),
   968 	OCL_SVAR( OC_UINT32, Company, face ),
   969 	OCL_VAR ( OC_UINT16,   1, &_old_string_id_2 ),
   969 	OCL_VAR ( OC_UINT16,   1, &_old_string_id_2 ),
   970 	OCL_SVAR( OC_UINT32, Player, president_name_2 ),
   970 	OCL_SVAR( OC_UINT32, Company, president_name_2 ),
   971 
   971 
   972 	OCL_SVAR(  OC_INT32, Player, player_money ),
   972 	OCL_SVAR(  OC_INT32, Company, money ),
   973 	OCL_SVAR(  OC_INT32, Player, current_loan ),
   973 	OCL_SVAR(  OC_INT32, Company, current_loan ),
   974 
   974 
   975 	OCL_SVAR(  OC_UINT8, Player, player_color ),
   975 	OCL_SVAR(  OC_UINT8, Company, colour ),
   976 	OCL_SVAR(  OC_UINT8, Player, player_money_fraction ),
   976 	OCL_SVAR(  OC_UINT8, Company, money_fraction ),
   977 	OCL_SVAR(  OC_UINT8, Player, quarters_of_bankrupcy ),
   977 	OCL_SVAR(  OC_UINT8, Company, quarters_of_bankrupcy ),
   978 	OCL_SVAR(  OC_UINT8, Player, bankrupt_asked ),
   978 	OCL_SVAR(  OC_UINT8, Company, bankrupt_asked ),
   979 	OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Player, bankrupt_value ),
   979 	OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
   980 	OCL_SVAR( OC_UINT16, Player, bankrupt_timeout ),
   980 	OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
   981 
   981 
   982 	OCL_SVAR( OC_UINT32, Player, cargo_types ),
   982 	OCL_SVAR( OC_UINT32, Company, cargo_types ),
   983 
   983 
   984 	OCL_CHUNK( 3, OldPlayerYearly ),
   984 	OCL_CHUNK( 3, OldCompanyYearly ),
   985 	OCL_CHUNK( 1, OldPlayerEconomy ),
   985 	OCL_CHUNK( 1, OldCompanyEconomy ),
   986 
   986 
   987 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Player, inaugurated_year),
   987 	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Company, inaugurated_year),
   988 	OCL_SVAR(                  OC_TILE, Player, last_build_coordinate ),
   988 	OCL_SVAR(                  OC_TILE, Company, last_build_coordinate ),
   989 	OCL_SVAR(                 OC_UINT8, Player, num_valid_stat_ent ),
   989 	OCL_SVAR(                 OC_UINT8, Company, num_valid_stat_ent ),
   990 
   990 
   991 	OCL_CHUNK( 1, OldPlayerAI ),
   991 	OCL_CHUNK( 1, OldCompanyAI ),
   992 
   992 
   993 	OCL_SVAR(  OC_UINT8, Player, block_preview ),
   993 	OCL_SVAR(  OC_UINT8, Company, block_preview ),
   994 	 OCL_VAR(  OC_UINT8,   1, &ai_tick ),
   994 	 OCL_VAR(  OC_UINT8,   1, &ai_tick ),
   995 	OCL_SVAR(  OC_UINT8, Player, avail_railtypes ),
   995 	OCL_SVAR(  OC_UINT8, Company, avail_railtypes ),
   996 	OCL_SVAR(   OC_TILE, Player, location_of_HQ ),
   996 	OCL_SVAR(   OC_TILE, Company, location_of_HQ ),
   997 	OCL_SVAR(  OC_UINT8, Player, share_owners[0] ),
   997 	OCL_SVAR(  OC_UINT8, Company, share_owners[0] ),
   998 	OCL_SVAR(  OC_UINT8, Player, share_owners[1] ),
   998 	OCL_SVAR(  OC_UINT8, Company, share_owners[1] ),
   999 	OCL_SVAR(  OC_UINT8, Player, share_owners[2] ),
   999 	OCL_SVAR(  OC_UINT8, Company, share_owners[2] ),
  1000 	OCL_SVAR(  OC_UINT8, Player, share_owners[3] ),
  1000 	OCL_SVAR(  OC_UINT8, Company, share_owners[3] ),
  1001 
  1001 
  1002 	OCL_NULL( 8 ), ///< junk at end of chunk
  1002 	OCL_NULL( 8 ), ///< junk at end of chunk
  1003 
  1003 
  1004 	OCL_END()
  1004 	OCL_END()
  1005 };
  1005 };
  1006 
  1006 
  1007 static bool LoadOldPlayer(LoadgameState *ls, int num)
  1007 static bool LoadOldCompany(LoadgameState *ls, int num)
  1008 {
  1008 {
  1009 	Player *p = new (num) Player();
  1009 	Company *c = new (num) Company();
  1010 
  1010 
  1011 	_current_player_id = (PlayerID)num;
  1011 	_current_company_id = (CompanyID)num;
  1012 
  1012 
  1013 	if (!LoadChunk(ls, p, player_chunk)) return false;
  1013 	if (!LoadChunk(ls, c, _company_chunk)) return false;
  1014 
  1014 
  1015 	if (_old_string_id == 0) {
  1015 	if (_old_string_id == 0) {
  1016 		delete p;
  1016 		delete c;
  1017 		return true;
  1017 		return true;
  1018 	}
  1018 	}
  1019 
  1019 
  1020 	p->name_1 = RemapOldStringID(_old_string_id);
  1020 	c->name_1 = RemapOldStringID(_old_string_id);
  1021 	p->president_name_1 = RemapOldStringID(_old_string_id_2);
  1021 	c->president_name_1 = RemapOldStringID(_old_string_id_2);
  1022 	_players_ai[_current_player_id].tick = ai_tick;
  1022 	_companies_ai[_current_company_id].tick = ai_tick;
  1023 
  1023 
  1024 	if (num == 0) {
  1024 	if (num == 0) {
  1025 		/* If the first player has no name, make sure we call it UNNAMED */
  1025 		/* If the first company has no name, make sure we call it UNNAMED */
  1026 		if (p->name_1 == 0)
  1026 		if (c->name_1 == 0)
  1027 			p->name_1 = STR_SV_UNNAMED;
  1027 			c->name_1 = STR_SV_UNNAMED;
  1028 	} else {
  1028 	} else {
  1029 		/* Beside some multiplayer maps (1 on 1), which we don't official support,
  1029 		/* Beside some multiplayer maps (1 on 1), which we don't official support,
  1030 		all other players are an AI.. mark them as such */
  1030 		 * all other companys are an AI.. mark them as such */
  1031 		p->is_ai = true;
  1031 		c->is_ai = true;
  1032 	}
  1032 	}
  1033 
  1033 
  1034 	/* Sometimes it is better to not ask.. in old scenarios, the money
  1034 	/* Sometimes it is better to not ask.. in old scenarios, the money
  1035 	was always 893288 pounds. In the newer versions this is correct,
  1035 	 * was always 893288 pounds. In the newer versions this is correct,
  1036 	but correct for those oldies
  1036 	 * but correct for those oldies
  1037 	Ps: this also means that if you had exact 893288 pounds, you will go back
  1037 	 * Ps: this also means that if you had exact 893288 pounds, you will go back
  1038 	to 10000.. this is a very VERY small chance ;) */
  1038 	 * to 10000.. this is a very VERY small chance ;) */
  1039 	if (p->player_money == 893288)
  1039 	if (c->money == 893288) c->money = c->current_loan = 100000;
  1040 		p->player_money = p->current_loan = 100000;
  1040 
  1041 
  1041 	_company_colours[num] = c->colour;
  1042 	_player_colors[num] = p->player_color;
  1042 	c->inaugurated_year -= ORIGINAL_BASE_YEAR;
  1043 	p->inaugurated_year -= ORIGINAL_BASE_YEAR;
  1043 	if (c->location_of_HQ == 0xFFFF)
  1044 	if (p->location_of_HQ == 0xFFFF)
  1044 		c->location_of_HQ = 0;
  1045 		p->location_of_HQ = 0;
  1045 
  1046 
  1046 	/* State 20 for AI companies is sell vehicle. Since the AI struct is not
  1047 	/* State 20 for AI players is sell vehicle. Since the AI struct is not
  1047 	 * really figured out as of now, _companies_ai[c->index].cur_veh; needed for 'sell vehicle'
  1048 	 * really figured out as of now, _players_ai[p->index].cur_veh; needed for 'sell vehicle'
       
  1049 	 * is NULL and the function will crash. To fix this, just change the state
  1048 	 * is NULL and the function will crash. To fix this, just change the state
  1050 	 * to some harmless state, like 'loop vehicle'; 1 */
  1049 	 * to some harmless state, like 'loop vehicle'; 1 */
  1051 	if (!IsHumanPlayer((PlayerID)num) && _players_ai[p->index].state == 20) _players_ai[p->index].state = 1;
  1050 	if (!IsHumanCompany((CompanyID)num) && _companies_ai[c->index].state == 20) _companies_ai[c->index].state = 1;
  1052 
  1051 
  1053 	if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
  1052 	if (c->is_ai && (!_networking || _network_server) && _ai.enabled)
  1054 		AI_StartNewAI(p->index);
  1053 		AI_StartNewAI(c->index);
  1055 
  1054 
  1056 	return true;
  1055 	return true;
  1057 }
  1056 }
  1058 
  1057 
  1059 static uint32 _old_order_ptr;
  1058 static uint32 _old_order_ptr;
  1321 
  1320 
  1322 	return true;
  1321 	return true;
  1323 }
  1322 }
  1324 
  1323 
  1325 static const OldChunks engine_chunk[] = {
  1324 static const OldChunks engine_chunk[] = {
  1326 	OCL_SVAR( OC_UINT16, Engine, player_avail ),
  1325 	OCL_SVAR( OC_UINT16, Engine, company_avail ),
  1327 	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
  1326 	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
  1328 	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
  1327 	OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
  1329 	OCL_SVAR( OC_UINT16, Engine, reliability ),
  1328 	OCL_SVAR( OC_UINT16, Engine, reliability ),
  1330 	OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
  1329 	OCL_SVAR( OC_UINT16, Engine, reliability_spd_dec ),
  1331 	OCL_SVAR( OC_UINT16, Engine, reliability_start ),
  1330 	OCL_SVAR( OC_UINT16, Engine, reliability_start ),
  1335 	OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
  1334 	OCL_SVAR( OC_UINT16, Engine, duration_phase_2 ),
  1336 	OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
  1335 	OCL_SVAR( OC_UINT16, Engine, duration_phase_3 ),
  1337 
  1336 
  1338 	OCL_SVAR(  OC_UINT8, Engine, lifelength ),
  1337 	OCL_SVAR(  OC_UINT8, Engine, lifelength ),
  1339 	OCL_SVAR(  OC_UINT8, Engine, flags ),
  1338 	OCL_SVAR(  OC_UINT8, Engine, flags ),
  1340 	OCL_SVAR(  OC_UINT8, Engine, preview_player_rank ),
  1339 	OCL_SVAR(  OC_UINT8, Engine, preview_company_rank ),
  1341 	OCL_SVAR(  OC_UINT8, Engine, preview_wait ),
  1340 	OCL_SVAR(  OC_UINT8, Engine, preview_wait ),
  1342 
  1341 
  1343 	OCL_NULL( 2 ), ///< Junk
  1342 	OCL_NULL( 2 ), ///< Junk
  1344 
  1343 
  1345 	OCL_END()
  1344 	OCL_END()
  1540 
  1539 
  1541 	OCL_ASSERT( 0x48CBA ),
  1540 	OCL_ASSERT( 0x48CBA ),
  1542 
  1541 
  1543 	OCL_CHUNK(250, LoadOldStation ),
  1542 	OCL_CHUNK(250, LoadOldStation ),
  1544 	OCL_CHUNK( 90, LoadOldIndustry ),
  1543 	OCL_CHUNK( 90, LoadOldIndustry ),
  1545 	OCL_CHUNK(  8, LoadOldPlayer ),
  1544 	OCL_CHUNK(  8, LoadOldCompany ),
  1546 
  1545 
  1547 	OCL_ASSERT( 0x547F2 ),
  1546 	OCL_ASSERT( 0x547F2 ),
  1548 
  1547 
  1549 	OCL_CHUNK( 850, LoadOldVehicle ),
  1548 	OCL_CHUNK( 850, LoadOldVehicle ),
  1550 
  1549 
  1575 	OCL_NULL( 144 ),             ///< cargo-stuff, calculated in InitializeLandscapeVariables
  1574 	OCL_NULL( 144 ),             ///< cargo-stuff, calculated in InitializeLandscapeVariables
  1576 
  1575 
  1577 	OCL_CHUNK(256, LoadOldEngineName ),
  1576 	OCL_CHUNK(256, LoadOldEngineName ),
  1578 
  1577 
  1579 	OCL_NULL( 144 ),             ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
  1578 	OCL_NULL( 144 ),             ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
  1580 	OCL_NULL( 2 ),               ///< Company indexes of players, no longer in use
  1579 	OCL_NULL( 2 ),               ///< Company indexes of companies, no longer in use
  1581 
  1580 
  1582 	OCL_VAR ( OC_FILE_U8 | OC_VAR_U16,    1, &_station_tick_ctr ),
  1581 	OCL_VAR ( OC_FILE_U8 | OC_VAR_U16,    1, &_station_tick_ctr ),
  1583 
  1582 
  1584 	OCL_VAR (  OC_UINT8,    1, &_settings_game.locale.currency ),
  1583 	OCL_VAR (  OC_UINT8,    1, &_settings_game.locale.currency ),
  1585 	OCL_VAR (  OC_UINT8,    1, &_settings_game.locale.units ),
  1584 	OCL_VAR (  OC_UINT8,    1, &_settings_game.locale.units ),
  1586 	OCL_VAR ( OC_FILE_U8 | OC_VAR_U32,    1, &_cur_player_tick_index ),
  1585 	OCL_VAR ( OC_FILE_U8 | OC_VAR_U32,    1, &_cur_company_tick_index ),
  1587 
  1586 
  1588 	OCL_NULL( 2 ),               ///< Date stuff, calculated automatically
  1587 	OCL_NULL( 2 ),               ///< Date stuff, calculated automatically
  1589 	OCL_NULL( 8 ),               ///< Player colors, calculated automatically
  1588 	OCL_NULL( 8 ),               ///< Company colors, calculated automatically
  1590 
  1589 
  1591 	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount ),
  1590 	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount ),
  1592 	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount_pr ),
  1591 	OCL_VAR (  OC_UINT8,    1, &_economy.infl_amount_pr ),
  1593 	OCL_VAR (  OC_UINT8,    1, &_economy.interest_rate ),
  1592 	OCL_VAR (  OC_UINT8,    1, &_economy.interest_rate ),
  1594 	OCL_NULL( 1 ), // available airports
  1593 	OCL_NULL( 1 ), // available airports
  1691 	 * we will get a "new vehicle"-spree. */
  1690 	 * we will get a "new vehicle"-spree. */
  1692 	Engine *e;
  1691 	Engine *e;
  1693 	FOR_ALL_ENGINES(e) {
  1692 	FOR_ALL_ENGINES(e) {
  1694 		if (_date >= (e->intro_date + 365)) {
  1693 		if (_date >= (e->intro_date + 365)) {
  1695 			e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
  1694 			e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
  1696 			e->player_avail = (byte)-1;
  1695 			e->company_avail = (CompanyMask)-1;
  1697 		}
  1696 		}
  1698 	}
  1697 	}
  1699 
  1698 
  1700 	/* Fix the game to be compatible with OpenTTD */
  1699 	/* Fix the game to be compatible with OpenTTD */
  1701 	FixOldTowns();
  1700 	FixOldTowns();