src/players.cpp
changeset 7554 076c42f44a83
parent 7518 06b687829b10
child 7592 48055c5dd43d
equal deleted inserted replaced
7553:bb88bdf61f6d 7554:076c42f44a83
   244 		if (!IsValidPlayer(owner)) {
   244 		if (!IsValidPlayer(owner)) {
   245 			SetDParam(0, STR_0150_SOMEONE);
   245 			SetDParam(0, STR_0150_SOMEONE);
   246 		} else {
   246 		} else {
   247 			const Player* p = GetPlayer(owner);
   247 			const Player* p = GetPlayer(owner);
   248 
   248 
   249 			SetDParam(0, p->name_1);
   249 			SetDParam(0, STR_COMPANY_NAME);
   250 			SetDParam(1, p->name_2);
   250 			SetDParam(1, p->index);
   251 		}
   251 		}
   252 	} else {
   252 	} else {
   253 		const Town* t = ClosestTownFromTile(tile, (uint)-1);
   253 		const Town* t = ClosestTownFromTile(tile, (uint)-1);
   254 
   254 
   255 		SetDParam(0, STR_TOWN);
   255 		SetDParam(0, STR_TOWN);
   412 restart:;
   412 restart:;
   413 
   413 
   414 		p->president_name_2 = Random();
   414 		p->president_name_2 = Random();
   415 		p->president_name_1 = SPECSTR_PRESIDENT_NAME;
   415 		p->president_name_1 = SPECSTR_PRESIDENT_NAME;
   416 
   416 
   417 		SetDParam(0, p->president_name_2);
   417 		SetDParam(0, p->index);
   418 		GetString(buffer, p->president_name_1, lastof(buffer));
   418 		GetString(buffer, STR_PLAYER_NAME, lastof(buffer));
   419 		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94)
   419 		if (strlen(buffer) >= 32 || GetStringBoundingBox(buffer).width >= 94)
   420 			continue;
   420 			continue;
   421 
   421 
   422 		FOR_ALL_PLAYERS(pp) {
   422 		FOR_ALL_PLAYERS(pp) {
   423 			if (pp->is_active && p != pp) {
   423 			if (pp->is_active && p != pp) {
   424 				SetDParam(0, pp->president_name_2);
   424 				SetDParam(0, pp->index);
   425 				GetString(buffer2, pp->president_name_1, lastof(buffer2));
   425 				GetString(buffer2, STR_PLAYER_NAME, lastof(buffer2));
   426 				if (strcmp(buffer2, buffer) == 0)
   426 				if (strcmp(buffer2, buffer) == 0)
   427 					goto restart;
   427 					goto restart;
   428 			}
   428 			}
   429 		}
   429 		}
   430 		return;
   430 		return;
   551 	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
   551 	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
   552 	if (p->name_1 != 0) GenerateCompanyName(p);
   552 	if (p->name_1 != 0) GenerateCompanyName(p);
   553 
   553 
   554 	if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start)
   554 	if (AI_AllowNewAI() && _game_mode != GM_MENU && !--_next_competitor_start)
   555 		MaybeStartNewPlayer();
   555 		MaybeStartNewPlayer();
   556 }
       
   557 
       
   558 /** index is the next parameter in _decode_parameters to set up */
       
   559 StringID GetPlayerNameString(PlayerID player, uint index)
       
   560 {
       
   561 	if (IsHumanPlayer(player) && IsValidPlayer(player)) {
       
   562 		SetDParam(index, player+1);
       
   563 		return STR_7002_PLAYER;
       
   564 	}
       
   565 	return STR_EMPTY;
       
   566 }
   556 }
   567 
   557 
   568 extern void ShowPlayerFinances(PlayerID player);
   558 extern void ShowPlayerFinances(PlayerID player);
   569 
   559 
   570 void PlayersYearlyLoop()
   560 void PlayersYearlyLoop()
   915 		if (IsHumanPlayer(p->index)) {
   905 		if (IsHumanPlayer(p->index)) {
   916 			/* Delete any open window of the company */
   906 			/* Delete any open window of the company */
   917 			DeletePlayerWindows(p->index);
   907 			DeletePlayerWindows(p->index);
   918 
   908 
   919 			/* Show the bankrupt news */
   909 			/* Show the bankrupt news */
   920 			SetDParam(0, p->name_1);
   910 			SetDParam(0, p->index);
   921 			SetDParam(1, p->name_2);
       
   922 			AddNewsItem( (StringID)(p->index | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
   911 			AddNewsItem( (StringID)(p->index | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
   923 
   912 
   924 			/* Remove the company */
   913 			/* Remove the company */
   925 			ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
   914 			ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
   926 			p->is_active = false;
   915 			p->is_active = false;
  1000 	for (i = 0; i < lengthof(_highscore_table[0]); i++) {
   989 	for (i = 0; i < lengthof(_highscore_table[0]); i++) {
  1001 		/* You are in the TOP5. Move all values one down and save us there */
   990 		/* You are in the TOP5. Move all values one down and save us there */
  1002 		if (hs[i].score <= score) {
   991 		if (hs[i].score <= score) {
  1003 			/* move all elements one down starting from the replaced one */
   992 			/* move all elements one down starting from the replaced one */
  1004 			memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1));
   993 			memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1));
  1005 			SetDParam(0, p->president_name_1);
   994 			SetDParam(0, p->index);
  1006 			SetDParam(1, p->president_name_2);
   995 			SetDParam(1, p->index);
  1007 			SetDParam(2, p->name_1);
       
  1008 			SetDParam(3, p->name_2);
       
  1009 			GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string
   996 			GetString(hs[i].company, STR_HIGHSCORE_NAME, lastof(hs[i].company)); // get manager/company name string
  1010 			hs[i].score = score;
   997 			hs[i].score = score;
  1011 			hs[i].title = EndGameGetPerformanceTitleFromValue(score);
   998 			hs[i].title = EndGameGetPerformanceTitleFromValue(score);
  1012 			return i;
   999 			return i;
  1013 		}
  1000 		}
  1045 
  1032 
  1046 		/* Copy over Top5 companies */
  1033 		/* Copy over Top5 companies */
  1047 		for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) {
  1034 		for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < count; i++) {
  1048 			HighScore* hs = &_highscore_table[LAST_HS_ITEM][i];
  1035 			HighScore* hs = &_highscore_table[LAST_HS_ITEM][i];
  1049 
  1036 
  1050 			SetDParam(0, pl[i]->president_name_1);
  1037 			SetDParam(0, pl[i]->index);
  1051 			SetDParam(1, pl[i]->president_name_2);
  1038 			SetDParam(1, pl[i]->index);
  1052 			SetDParam(2, pl[i]->name_1);
       
  1053 			SetDParam(3, pl[i]->name_2);
       
  1054 			GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string
  1039 			GetString(hs->company, STR_HIGHSCORE_NAME, lastof(hs->company)); // get manager/company name string
  1055 			hs->score = pl[i]->old_economy[0].performance_history;
  1040 			hs->score = pl[i]->old_economy[0].performance_history;
  1056 			hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
  1041 			hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
  1057 
  1042 
  1058 			/* get the ranking of the local player */
  1043 			/* get the ranking of the local player */