src/players.cpp
branchnoai
changeset 9629 66dde6412125
parent 9626 79f2b5a0cdd7
child 9631 8a2d1c2ceb88
equal deleted inserted replaced
9628:b5c2449616b5 9629:66dde6412125
   171 
   171 
   172 	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
   172 	if (pid == _local_player) InvalidateWindow(WC_STATUS_BAR, 0);
   173 	InvalidateWindow(WC_FINANCES, pid);
   173 	InvalidateWindow(WC_FINANCES, pid);
   174 }
   174 }
   175 
   175 
   176 bool CheckPlayerHasMoney(int32 cost)
   176 bool CheckPlayerHasMoney(CommandCost cost)
   177 {
   177 {
   178 	if (cost > 0) {
   178 	if (cost.GetCost() > 0) {
   179 		PlayerID pid = _current_player;
   179 		PlayerID pid = _current_player;
   180 		if (IsValidPlayer(pid) && cost > GetPlayer(pid)->player_money) {
   180 		if (IsValidPlayer(pid) && cost.GetCost() > GetPlayer(pid)->player_money) {
   181 			SetDParam(0, cost);
   181 			SetDParam(0, cost.GetCost());
   182 			_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
   182 			_error_message = STR_0003_NOT_ENOUGH_CASH_REQUIRES;
   183 			return false;
   183 			return false;
   184 		}
   184 		}
   185 	}
   185 	}
   186 	return true;
   186 	return true;
   187 }
   187 }
   188 
   188 
   189 static void SubtractMoneyFromAnyPlayer(Player *p, int32 cost)
   189 static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost)
   190 {
   190 {
   191 	p->money64 -= cost;
   191 	CommandCost tmp(p->player_money);
   192 	UpdatePlayerMoney32(p);
   192 	tmp.AddCost(-cost.GetCost());
   193 
   193 	p->player_money = tmp.GetCost();
   194 	p->yearly_expenses[0][_yearly_expenses_type] += cost;
   194 
       
   195 	tmp = CommandCost(p->yearly_expenses[0][_yearly_expenses_type]);
       
   196 	tmp.AddCost(cost);
       
   197 	p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost();
   195 
   198 
   196 	if (HASBIT(1 << EXPENSES_TRAIN_INC    |
   199 	if (HASBIT(1 << EXPENSES_TRAIN_INC    |
   197 	           1 << EXPENSES_ROADVEH_INC  |
   200 	           1 << EXPENSES_ROADVEH_INC  |
   198 	           1 << EXPENSES_AIRCRAFT_INC |
   201 	           1 << EXPENSES_AIRCRAFT_INC |
   199 	           1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) {
   202 	           1 << EXPENSES_SHIP_INC, _yearly_expenses_type)) {
   200 		p->cur_economy.income -= cost;
   203 		tmp = CommandCost(p->cur_economy.income);
       
   204 		tmp.AddCost(-cost.GetCost());
       
   205 		p->cur_economy.income = tmp.GetCost();
   201 	} else if (HASBIT(1 << EXPENSES_TRAIN_RUN    |
   206 	} else if (HASBIT(1 << EXPENSES_TRAIN_RUN    |
   202 	                  1 << EXPENSES_ROADVEH_RUN  |
   207 	                  1 << EXPENSES_ROADVEH_RUN  |
   203 	                  1 << EXPENSES_AIRCRAFT_RUN |
   208 	                  1 << EXPENSES_AIRCRAFT_RUN |
   204 	                  1 << EXPENSES_SHIP_RUN     |
   209 	                  1 << EXPENSES_SHIP_RUN     |
   205 	                  1 << EXPENSES_PROPERTY     |
   210 	                  1 << EXPENSES_PROPERTY     |
   206 	                  1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) {
   211 	                  1 << EXPENSES_LOAN_INT, _yearly_expenses_type)) {
   207 		p->cur_economy.expenses -= cost;
   212 		tmp = CommandCost(p->cur_economy.expenses);
       
   213 		tmp.AddCost(-cost.GetCost());
       
   214 		p->cur_economy.expenses = tmp.GetCost();
   208 	}
   215 	}
   209 
   216 
   210 	InvalidatePlayerWindows(p);
   217 	InvalidatePlayerWindows(p);
   211 }
   218 }
   212 
   219 
   213 void SubtractMoneyFromPlayer(int32 cost)
   220 void SubtractMoneyFromPlayer(CommandCost cost)
   214 {
   221 {
   215 	PlayerID pid = _current_player;
   222 	PlayerID pid = _current_player;
   216 
   223 
   217 	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
   224 	if (IsValidPlayer(pid)) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
   218 }
   225 }
   219 
   226 
   220 void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost)
   227 void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cst)
   221 {
   228 {
   222 	Player *p = GetPlayer(player);
   229 	Player *p = GetPlayer(player);
   223 	byte m = p->player_money_fraction;
   230 	byte m = p->player_money_fraction;
       
   231 	Money cost = cst.GetCost();
   224 
   232 
   225 	p->player_money_fraction = m - (byte)cost;
   233 	p->player_money_fraction = m - (byte)cost;
   226 	cost >>= 8;
   234 	cost >>= 8;
   227 	if (p->player_money_fraction > m) cost++;
   235 	if (p->player_money_fraction > m) cost++;
   228 	if (cost != 0) SubtractMoneyFromAnyPlayer(p, cost);
   236 	if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cost));
   229 }
       
   230 
       
   231 /** the player_money field is kept as it is, but money64 contains the actual amount of money. */
       
   232 void UpdatePlayerMoney32(Player *p)
       
   233 {
       
   234 	if (p->money64 < -2000000000) {
       
   235 		p->player_money = -2000000000;
       
   236 	} else if (p->money64 > 2000000000) {
       
   237 		p->player_money = 2000000000;
       
   238 	} else {
       
   239 		p->player_money = (int32)p->money64;
       
   240 	}
       
   241 }
   237 }
   242 
   238 
   243 void GetNameOfOwner(Owner owner, TileIndex tile)
   239 void GetNameOfOwner(Owner owner, TileIndex tile)
   244 {
   240 {
   245 	SetDParam(2, owner);
   241 	SetDParam(2, owner);
   248 		if (!IsValidPlayer(owner)) {
   244 		if (!IsValidPlayer(owner)) {
   249 			SetDParam(0, STR_0150_SOMEONE);
   245 			SetDParam(0, STR_0150_SOMEONE);
   250 		} else {
   246 		} else {
   251 			const Player* p = GetPlayer(owner);
   247 			const Player* p = GetPlayer(owner);
   252 
   248 
   253 			SetDParam(0, p->name_1);
   249 			SetDParam(0, STR_COMPANY_NAME);
   254 			SetDParam(1, p->name_2);
   250 			SetDParam(1, p->index);
   255 		}
   251 		}
   256 	} else {
   252 	} else {
   257 		const Town* t = ClosestTownFromTile(tile, (uint)-1);
   253 		const Town* t = ClosestTownFromTile(tile, (uint)-1);
   258 
   254 
   259 		SetDParam(0, STR_TOWN);
   255 		SetDParam(0, STR_TOWN);
   416 restart:;
   412 restart:;
   417 
   413 
   418 		p->president_name_2 = Random();
   414 		p->president_name_2 = Random();
   419 		p->president_name_1 = SPECSTR_PRESIDENT_NAME;
   415 		p->president_name_1 = SPECSTR_PRESIDENT_NAME;
   420 
   416 
   421 		SetDParam(0, p->president_name_2);
   417 		SetDParam(0, p->index);
   422 		GetString(buffer, p->president_name_1, lastof(buffer));
   418 		GetString(buffer, STR_PLAYER_NAME, lastof(buffer));
   423 		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94)
   419 		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94)
   424 			continue;
   420 			continue;
   425 
   421 
   426 		FOR_ALL_PLAYERS(pp) {
   422 		FOR_ALL_PLAYERS(pp) {
   427 			if (pp->is_active && p != pp) {
   423 			if (pp->is_active && p != pp) {
   428 				SetDParam(0, pp->president_name_2);
   424 				SetDParam(0, pp->index);
   429 				GetString(buffer2, pp->president_name_1, lastof(buffer2));
   425 				GetString(buffer2, STR_PLAYER_NAME, lastof(buffer2));
   430 				if (strcmp(buffer2, buffer) == 0)
   426 				if (strcmp(buffer2, buffer) == 0)
   431 					goto restart;
   427 					goto restart;
   432 			}
   428 			}
   433 		}
   429 		}
   434 		return;
   430 		return;
   472 	ResetPlayerLivery(p);
   468 	ResetPlayerLivery(p);
   473 	_player_colors[p->index] = p->player_color;
   469 	_player_colors[p->index] = p->player_color;
   474 	p->name_1 = STR_SV_UNNAMED;
   470 	p->name_1 = STR_SV_UNNAMED;
   475 	p->is_active = true;
   471 	p->is_active = true;
   476 
   472 
   477 	p->money64 = p->player_money = p->current_loan = 100000;
   473 	p->player_money = p->current_loan = 100000;
   478 
   474 
   479 	p->is_ai = is_ai;
   475 	p->is_ai = is_ai;
   480 	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR;
   476 	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR;
   481 
   477 
   482 	p->avail_railtypes = GetPlayerRailtypes(p->index);
   478 	p->avail_railtypes = GetPlayerRailtypes(p->index);
   554 	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
   550 	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
   555 	if (p->name_1 != 0) GenerateCompanyName(p);
   551 	if (p->name_1 != 0) GenerateCompanyName(p);
   556 
   552 
   557 	if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start)
   553 	if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start)
   558 		MaybeStartNewPlayer();
   554 		MaybeStartNewPlayer();
   559 }
       
   560 
       
   561 /** index is the next parameter in _decode_parameters to set up */
       
   562 StringID GetPlayerNameString(PlayerID player, uint index)
       
   563 {
       
   564 	if (IsHumanPlayer(player) && IsValidPlayer(player)) {
       
   565 		SetDParam(index, player+1);
       
   566 		return STR_7002_PLAYER;
       
   567 	}
       
   568 	return STR_EMPTY;
       
   569 }
   555 }
   570 
   556 
   571 extern void ShowPlayerFinances(PlayerID player);
   557 extern void ShowPlayerFinances(PlayerID player);
   572 
   558 
   573 void PlayersYearlyLoop()
   559 void PlayersYearlyLoop()
   673  * - p1 bits 16-31 = months left before engine expires to replace it
   659  * - p1 bits 16-31 = months left before engine expires to replace it
   674  * - p2 bits  0-31 = minimum amount of money available
   660  * - p2 bits  0-31 = minimum amount of money available
   675  * if p1 = 5, then
   661  * if p1 = 5, then
   676  * - p2 = enable renew_keep_length
   662  * - p2 = enable renew_keep_length
   677  */
   663  */
   678 int32 CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   664 CommandCost CmdSetAutoReplace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   679 {
   665 {
   680 	Player *p;
   666 	Player *p;
   681 	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
   667 	if (!IsValidPlayer(_current_player)) return CMD_ERROR;
   682 
   668 
   683 	p = GetPlayer(_current_player);
   669 	p = GetPlayer(_current_player);
   720 			break;
   706 			break;
   721 		case 3: {
   707 		case 3: {
   722 			EngineID old_engine_type = GB(p2, 0, 16);
   708 			EngineID old_engine_type = GB(p2, 0, 16);
   723 			EngineID new_engine_type = GB(p2, 16, 16);
   709 			EngineID new_engine_type = GB(p2, 16, 16);
   724 			GroupID id_g = GB(p1, 16, 16);
   710 			GroupID id_g = GB(p1, 16, 16);
   725 			int32 cost;
   711 			CommandCost cost;
   726 
   712 
   727 			if (!IsValidGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
   713 			if (!IsValidGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
   728 			if (new_engine_type != INVALID_ENGINE) {
   714 			if (new_engine_type != INVALID_ENGINE) {
   729 				/* First we make sure that it's a valid type the user requested
   715 				/* First we make sure that it's a valid type the user requested
   730 				 * check that it's an engine that is in the engine array */
   716 				 * check that it's an engine that is in the engine array */
   779 				}
   765 				}
   780 			}
   766 			}
   781 		break;
   767 		break;
   782 
   768 
   783 	}
   769 	}
   784 	return 0;
   770 	return CommandCost();
   785 }
   771 }
   786 
   772 
   787 /** Control the players: add, delete, etc.
   773 /** Control the players: add, delete, etc.
   788  * @param tile unused
   774  * @param tile unused
   789  * @param flags operation to perform
   775  * @param flags operation to perform
   802  * on the server itself. First of all this is unbelievably ugly; second of all, well,
   788  * on the server itself. First of all this is unbelievably ugly; second of all, well,
   803  * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
   789  * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
   804  * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
   790  * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
   805  * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
   791  * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
   806  */
   792  */
   807 int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   793 CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   808 {
   794 {
   809 	if (flags & DC_EXEC) _current_player = OWNER_NONE;
   795 	if (flags & DC_EXEC) _current_player = OWNER_NONE;
   810 
   796 
   811 	switch (p1) {
   797 	switch (p1) {
   812 	case 0: { /* Create a new player */
   798 	case 0: { /* Create a new player */
   824 
   810 
   825 		/* This command is only executed in a multiplayer game */
   811 		/* This command is only executed in a multiplayer game */
   826 		if (!_networking) return CMD_ERROR;
   812 		if (!_networking) return CMD_ERROR;
   827 
   813 
   828 		/* Has the network client a correct ClientID? */
   814 		/* Has the network client a correct ClientID? */
   829 		if (!(flags & DC_EXEC)) return 0;
   815 		if (!(flags & DC_EXEC)) return CommandCost();
   830 #ifdef ENABLE_NETWORK
   816 #ifdef ENABLE_NETWORK
   831 		if (cid >= MAX_CLIENT_INFO) return 0;
   817 		if (cid >= MAX_CLIENT_INFO) return CommandCost();
   832 #endif /* ENABLE_NETWORK */
   818 #endif /* ENABLE_NETWORK */
   833 
   819 
   834 		/* Delete multiplayer progress bar */
   820 		/* Delete multiplayer progress bar */
   835 		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
   821 		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
   836 
   822 
   841 #ifdef ENABLE_NETWORK
   827 #ifdef ENABLE_NETWORK
   842 			if (_network_server) {
   828 			if (_network_server) {
   843 				NetworkClientInfo *ci = &_network_client_info[cid];
   829 				NetworkClientInfo *ci = &_network_client_info[cid];
   844 				ci->client_playas = PLAYER_SPECTATOR;
   830 				ci->client_playas = PLAYER_SPECTATOR;
   845 				NetworkUpdateClientInfo(ci->client_index);
   831 				NetworkUpdateClientInfo(ci->client_index);
   846 			} else
   832 			} else if (_local_player == PLAYER_SPECTATOR) {
       
   833 				_network_playas = PLAYER_SPECTATOR;
       
   834 			}
   847 #endif /* ENABLE_NETWORK */
   835 #endif /* ENABLE_NETWORK */
   848 			{
       
   849 				_network_playas = PLAYER_SPECTATOR;
       
   850 				SetLocalPlayer(PLAYER_SPECTATOR);
       
   851 			}
       
   852 			break;
   836 			break;
   853 		}
   837 		}
   854 
   838 
   855 		/* This is the joining client who wants a new company */
   839 		/* This is the joining client who wants a new company */
   856 		if (_local_player != _network_playas && _network_playas == p->index) {
   840 		if (_local_player != _network_playas && _network_playas == p->index) {
   900 		}
   884 		}
   901 #endif /* ENABLE_NETWORK */
   885 #endif /* ENABLE_NETWORK */
   902 	} break;
   886 	} break;
   903 
   887 
   904 	case 1: /* Make a new AI player */
   888 	case 1: /* Make a new AI player */
   905 		if (!(flags & DC_EXEC)) return 0;
   889 		if (!(flags & DC_EXEC)) return CommandCost();
   906 
   890 
   907 		DoStartupNewPlayer(true);
   891 		DoStartupNewPlayer(true);
   908 		break;
   892 		break;
   909 
   893 
   910 	case 2: { /* Delete a player */
   894 	case 2: { /* Delete a player */
   911 		Player *p;
   895 		Player *p;
   912 
   896 
   913 		if (!IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
   897 		if (!IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
   914 
   898 
   915 		if (!(flags & DC_EXEC)) return 0;
   899 		if (!(flags & DC_EXEC)) return CommandCost();
   916 
   900 
   917 		p = GetPlayer((PlayerID)p2);
   901 		p = GetPlayer((PlayerID)p2);
   918 
   902 
   919 		/* Only allow removal of HUMAN companies */
   903 		/* Only allow removal of HUMAN companies */
   920 		if (IsHumanPlayer(p->index)) {
   904 		if (IsHumanPlayer(p->index)) {
   921 			/* Delete any open window of the company */
   905 			/* Delete any open window of the company */
   922 			DeletePlayerWindows(p->index);
   906 			DeletePlayerWindows(p->index);
   923 
   907 
   924 			/* Show the bankrupt news */
   908 			/* Show the bankrupt news */
   925 			SetDParam(0, p->name_1);
   909 			SetDParam(0, p->index);
   926 			SetDParam(1, p->name_2);
       
   927 			AddNewsItem( (StringID)(p->index | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
   910 			AddNewsItem( (StringID)(p->index | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
   928 
   911 
   929 			/* Remove the company */
   912 			/* Remove the company */
   930 			ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
   913 			ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
   931 			p->is_active = false;
   914 			p->is_active = false;
   948 	} break;
   931 	} break;
   949 
   932 
   950 	default: return CMD_ERROR;
   933 	default: return CMD_ERROR;
   951 	}
   934 	}
   952 
   935 
   953 	return 0;
   936 	return CommandCost();
   954 }
   937 }
   955 
   938 
   956 static const StringID _endgame_perf_titles[] = {
   939 static const StringID _endgame_perf_titles[] = {
   957 	STR_0213_BUSINESSMAN,
   940 	STR_0213_BUSINESSMAN,
   958 	STR_0213_BUSINESSMAN,
   941 	STR_0213_BUSINESSMAN,
  1005 	for (i = 0; i < lengthof(_highscore_table[0]); i++) {
   988 	for (i = 0; i < lengthof(_highscore_table[0]); i++) {
  1006 		/* You are in the TOP5. Move all values one down and save us there */
   989 		/* You are in the TOP5. Move all values one down and save us there */
  1007 		if (hs[i].score <= score) {
   990 		if (hs[i].score <= score) {
  1008 			/* move all elements one down starting from the replaced one */
   991 			/* move all elements one down starting from the replaced one */
  1009 			memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1));
   992 			memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1));
  1010 			SetDParam(0, p->president_name_1);
   993 			SetDParam(0, p->index);
  1011 			SetDParam(1, p->president_name_2);
   994 			SetDParam(1, p->index);
  1012 			SetDParam(2, p->name_1);
       
  1013 			SetDParam(3, p->name_2);
       
  1014 			GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string
   995 			GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string
  1015 			hs[i].score = score;
   996 			hs[i].score = score;
  1016 			hs[i].title = EndGameGetPerformanceTitleFromValue(score);
   997 			hs[i].title = EndGameGetPerformanceTitleFromValue(score);
  1017 			return i;
   998 			return i;
  1018 		}
   999 		}
  1050 
  1031 
  1051 		/* Copy over Top5 companies */
  1032 		/* Copy over Top5 companies */
  1052 		for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) {
  1033 		for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) {
  1053 			HighScore* hs = &_highscore_table[LAST_HS_ITEM][i];
  1034 			HighScore* hs = &_highscore_table[LAST_HS_ITEM][i];
  1054 
  1035 
  1055 			SetDParam(0, pl[i]->president_name_1);
  1036 			SetDParam(0, pl[i]->index);
  1056 			SetDParam(1, pl[i]->president_name_2);
  1037 			SetDParam(1, pl[i]->index);
  1057 			SetDParam(2, pl[i]->name_1);
       
  1058 			SetDParam(3, pl[i]->name_2);
       
  1059 			GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string
  1038 			GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string
  1060 			hs->score = pl[i]->old_economy[0].performance_history;
  1039 			hs->score = pl[i]->old_economy[0].performance_history;
  1061 			hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
  1040 			hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
  1062 
  1041 
  1063 			/* get the ranking of the local player */
  1042 			/* get the ranking of the local player */
  1131 	    SLE_VAR(Player, president_name_2,SLE_UINT32),
  1110 	    SLE_VAR(Player, president_name_2,SLE_UINT32),
  1132 
  1111 
  1133 	    SLE_VAR(Player, face,            SLE_UINT32),
  1112 	    SLE_VAR(Player, face,            SLE_UINT32),
  1134 
  1113 
  1135 	/* money was changed to a 64 bit field in savegame version 1. */
  1114 	/* money was changed to a 64 bit field in savegame version 1. */
  1136 	SLE_CONDVAR(Player, money64,               SLE_VAR_I64 | SLE_FILE_I32, 0, 0),
  1115 	SLE_CONDVAR(Player, player_money,          SLE_VAR_I64 | SLE_FILE_I32,  0, 0),
  1137 	SLE_CONDVAR(Player, money64,               SLE_INT64, 1, SL_MAX_VERSION),
  1116 	SLE_CONDVAR(Player, player_money,          SLE_INT64,                   1, SL_MAX_VERSION),
  1138 
  1117 
  1139 	    SLE_VAR(Player, current_loan,          SLE_INT32),
  1118 	SLE_CONDVAR(Player, current_loan,          SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
       
  1119 	SLE_CONDVAR(Player, current_loan,          SLE_INT64,                  65, SL_MAX_VERSION),
  1140 
  1120 
  1141 	    SLE_VAR(Player, player_color,          SLE_UINT8),
  1121 	    SLE_VAR(Player, player_color,          SLE_UINT8),
  1142 	    SLE_VAR(Player, player_money_fraction, SLE_UINT8),
  1122 	    SLE_VAR(Player, player_money_fraction, SLE_UINT8),
  1143 	SLE_CONDVAR(Player, avail_railtypes,       SLE_UINT8,                   0, 57),
  1123 	SLE_CONDVAR(Player, avail_railtypes,       SLE_UINT8,                   0, 57),
  1144 	    SLE_VAR(Player, block_preview,         SLE_UINT8),
  1124 	    SLE_VAR(Player, block_preview,         SLE_UINT8),
  1156 	    SLE_VAR(Player, num_valid_stat_ent,    SLE_UINT8),
  1136 	    SLE_VAR(Player, num_valid_stat_ent,    SLE_UINT8),
  1157 
  1137 
  1158 	    SLE_VAR(Player, quarters_of_bankrupcy, SLE_UINT8),
  1138 	    SLE_VAR(Player, quarters_of_bankrupcy, SLE_UINT8),
  1159 	    SLE_VAR(Player, bankrupt_asked,        SLE_UINT8),
  1139 	    SLE_VAR(Player, bankrupt_asked,        SLE_UINT8),
  1160 	    SLE_VAR(Player, bankrupt_timeout,      SLE_INT16),
  1140 	    SLE_VAR(Player, bankrupt_timeout,      SLE_INT16),
  1161 	    SLE_VAR(Player, bankrupt_value,        SLE_INT32),
  1141 	SLE_CONDVAR(Player, bankrupt_value,        SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
       
  1142 	SLE_CONDVAR(Player, bankrupt_value,        SLE_INT64,                  65, SL_MAX_VERSION),
  1162 
  1143 
  1163 	/* yearly expenses was changed to 64-bit in savegame version 2. */
  1144 	/* yearly expenses was changed to 64-bit in savegame version 2. */
  1164 	SLE_CONDARR(Player, yearly_expenses,       SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
  1145 	SLE_CONDARR(Player, yearly_expenses,       SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
  1165 	SLE_CONDARR(Player, yearly_expenses,       SLE_INT64, 3 * 13,                  2, SL_MAX_VERSION),
  1146 	SLE_CONDARR(Player, yearly_expenses,       SLE_INT64, 3 * 13,                  2, SL_MAX_VERSION),
  1166 
  1147 
  1184 	SLE_END()
  1165 	SLE_END()
  1185 };
  1166 };
  1186 
  1167 
  1187 static const SaveLoad _player_economy_desc[] = {
  1168 static const SaveLoad _player_economy_desc[] = {
  1188 	/* these were changed to 64-bit in savegame format 2 */
  1169 	/* these were changed to 64-bit in savegame format 2 */
  1189 	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_INT32,                  0, 1),
  1170 	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
  1190 	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_INT32,                  0, 1),
  1171 	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_INT64,                  2, SL_MAX_VERSION),
       
  1172 	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
       
  1173 	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_INT64,                  2, SL_MAX_VERSION),
  1191 	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
  1174 	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
  1192 	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_FILE_I64 | SLE_VAR_I32, 2, SL_MAX_VERSION),
       
  1193 	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_FILE_I64 | SLE_VAR_I32, 2, SL_MAX_VERSION),
       
  1194 	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_INT64,                  2, SL_MAX_VERSION),
  1175 	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_INT64,                  2, SL_MAX_VERSION),
  1195 
  1176 
  1196 	    SLE_VAR(PlayerEconomyEntry, delivered_cargo,     SLE_INT32),
  1177 	    SLE_VAR(PlayerEconomyEntry, delivered_cargo,     SLE_INT32),
  1197 	    SLE_VAR(PlayerEconomyEntry, performance_history, SLE_INT32),
  1178 	    SLE_VAR(PlayerEconomyEntry, performance_history, SLE_INT32),
  1198 
  1179 
  1305 	while ((index = SlIterateArray()) != -1) {
  1286 	while ((index = SlIterateArray()) != -1) {
  1306 		Player *p = GetPlayer((PlayerID)index);
  1287 		Player *p = GetPlayer((PlayerID)index);
  1307 		SaveLoad_PLYR(p);
  1288 		SaveLoad_PLYR(p);
  1308 		_player_colors[index] = p->player_color;
  1289 		_player_colors[index] = p->player_color;
  1309 		p->is_noai = true;
  1290 		p->is_noai = true;
  1310 		UpdatePlayerMoney32(p);
       
  1311 
  1291 
  1312 		/* This is needed so an AI is attached to a loaded AI */
  1292 		/* This is needed so an AI is attached to a loaded AI */
  1313 		if (p->is_ai) AI_StartNewAI(p->index);
  1293 		if (p->is_ai) AI_StartNewAI(p->index);
  1314 	}
  1294 	}
  1315 }
  1295 }