src/players.cpp
changeset 9354 845e07db4549
parent 9257 8933adfe564f
child 9358 2e1e4d2f71dd
equal deleted inserted replaced
9353:9d76aef9fe2b 9354:845e07db4549
    63 	_local_player = new_player;
    63 	_local_player = new_player;
    64 
    64 
    65 	/* Do not update the patches if we are in the intro GUI */
    65 	/* Do not update the patches if we are in the intro GUI */
    66 	if (IsValidPlayer(new_player) && _game_mode != GM_MENU) {
    66 	if (IsValidPlayer(new_player) && _game_mode != GM_MENU) {
    67 		const Player *p = GetPlayer(new_player);
    67 		const Player *p = GetPlayer(new_player);
    68 		_patches.autorenew        = p->engine_renew;
    68 		_settings.gui.autorenew        = p->engine_renew;
    69 		_patches.autorenew_months = p->engine_renew_months;
    69 		_settings.gui.autorenew_months = p->engine_renew_months;
    70 		_patches.autorenew_money  = p->engine_renew_money;
    70 		_settings.gui.autorenew_money  = p->engine_renew_money;
    71 		InvalidateWindow(WC_GAME_OPTIONS, 0);
    71 		InvalidateWindow(WC_GAME_OPTIONS, 0);
    72 	}
    72 	}
    73 }
    73 }
    74 
    74 
    75 bool IsHumanPlayer(PlayerID pi)
    75 bool IsHumanPlayer(PlayerID pi)
   539 	RandomPlayerFaceBits(p->face, (GenderEthnicity)Random(), false); // create a random player face
   539 	RandomPlayerFaceBits(p->face, (GenderEthnicity)Random(), false); // create a random player face
   540 
   540 
   541 	/* Engine renewal settings */
   541 	/* Engine renewal settings */
   542 	p->engine_renew_list = NULL;
   542 	p->engine_renew_list = NULL;
   543 	p->renew_keep_length = false;
   543 	p->renew_keep_length = false;
   544 	p->engine_renew = _patches_newgame.autorenew;
   544 	p->engine_renew = _settings_newgame.gui.autorenew;
   545 	p->engine_renew_months = _patches_newgame.autorenew_months;
   545 	p->engine_renew_months = _settings_newgame.gui.autorenew_months;
   546 	p->engine_renew_money = _patches_newgame.autorenew_money;
   546 	p->engine_renew_money = _settings_newgame.gui.autorenew_money;
   547 
   547 
   548 	GeneratePresidentName(p);
   548 	GeneratePresidentName(p);
   549 
   549 
   550 	InvalidateWindow(WC_GRAPH_LEGEND, 0);
   550 	InvalidateWindow(WC_GRAPH_LEGEND, 0);
   551 	InvalidateWindow(WC_TOOLBAR_MENU, 0);
   551 	InvalidateWindow(WC_TOOLBAR_MENU, 0);
   628 			memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0]));
   628 			memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0]));
   629 			InvalidateWindow(WC_FINANCES, p->index);
   629 			InvalidateWindow(WC_FINANCES, p->index);
   630 		}
   630 		}
   631 	}
   631 	}
   632 
   632 
   633 	if (_patches.show_finances && _local_player != PLAYER_SPECTATOR) {
   633 	if (_settings.gui.show_finances && _local_player != PLAYER_SPECTATOR) {
   634 		ShowPlayerFinances(_local_player);
   634 		ShowPlayerFinances(_local_player);
   635 		p = GetPlayer(_local_player);
   635 		p = GetPlayer(_local_player);
   636 		if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) {
   636 		if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) {
   637 			SndPlayFx(SND_01_BAD_YEAR);
   637 			SndPlayFx(SND_01_BAD_YEAR);
   638 		} else {
   638 		} else {
   693 			if (p->engine_renew == HasBit(p2, 0)) return CMD_ERROR;
   693 			if (p->engine_renew == HasBit(p2, 0)) return CMD_ERROR;
   694 
   694 
   695 			if (flags & DC_EXEC) {
   695 			if (flags & DC_EXEC) {
   696 				p->engine_renew = HasBit(p2, 0);
   696 				p->engine_renew = HasBit(p2, 0);
   697 				if (IsLocalPlayer()) {
   697 				if (IsLocalPlayer()) {
   698 					_patches.autorenew = p->engine_renew;
   698 					_settings.gui.autorenew = p->engine_renew;
   699 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   699 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   700 				}
   700 				}
   701 			}
   701 			}
   702 			break;
   702 			break;
   703 
   703 
   706 			if (p->engine_renew_months == (int16)p2) return CMD_ERROR;
   706 			if (p->engine_renew_months == (int16)p2) return CMD_ERROR;
   707 
   707 
   708 			if (flags & DC_EXEC) {
   708 			if (flags & DC_EXEC) {
   709 				p->engine_renew_months = (int16)p2;
   709 				p->engine_renew_months = (int16)p2;
   710 				if (IsLocalPlayer()) {
   710 				if (IsLocalPlayer()) {
   711 					_patches.autorenew_months = p->engine_renew_months;
   711 					_settings.gui.autorenew_months = p->engine_renew_months;
   712 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   712 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   713 				}
   713 				}
   714 			}
   714 			}
   715 			break;
   715 			break;
   716 
   716 
   719 			if (p->engine_renew_money == p2) return CMD_ERROR;
   719 			if (p->engine_renew_money == p2) return CMD_ERROR;
   720 
   720 
   721 			if (flags & DC_EXEC) {
   721 			if (flags & DC_EXEC) {
   722 				p->engine_renew_money = p2;
   722 				p->engine_renew_money = p2;
   723 				if (IsLocalPlayer()) {
   723 				if (IsLocalPlayer()) {
   724 					_patches.autorenew_money = p->engine_renew_money;
   724 					_settings.gui.autorenew_money = p->engine_renew_money;
   725 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   725 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   726 				}
   726 				}
   727 			}
   727 			}
   728 			break;
   728 			break;
   729 
   729 
   769 				p->engine_renew = HasBit(p1, 15);
   769 				p->engine_renew = HasBit(p1, 15);
   770 				p->engine_renew_months = (int16)GB(p1, 16, 16);
   770 				p->engine_renew_months = (int16)GB(p1, 16, 16);
   771 				p->engine_renew_money = p2;
   771 				p->engine_renew_money = p2;
   772 
   772 
   773 				if (IsLocalPlayer()) {
   773 				if (IsLocalPlayer()) {
   774 					_patches.autorenew = p->engine_renew;
   774 					_settings.gui.autorenew = p->engine_renew;
   775 					_patches.autorenew_months = p->engine_renew_months;
   775 					_settings.gui.autorenew_months = p->engine_renew_months;
   776 					_patches.autorenew_money = p->engine_renew_money;
   776 					_settings.gui.autorenew_money = p->engine_renew_money;
   777 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   777 					InvalidateWindow(WC_GAME_OPTIONS, 0);
   778 				}
   778 				}
   779 			}
   779 			}
   780 			break;
   780 			break;
   781 
   781 
   874 		}
   874 		}
   875 
   875 
   876 		/* Now that we have a new player, broadcast its autorenew settings to
   876 		/* Now that we have a new player, broadcast its autorenew settings to
   877 		 * all clients so everything is in sync */
   877 		 * all clients so everything is in sync */
   878 		DoCommand(0,
   878 		DoCommand(0,
   879 			(_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4,
   879 			(_settings.gui.autorenew << 15 ) | (_settings.gui.autorenew_months << 16) | 4,
   880 			_patches.autorenew_money,
   880 			_settings.gui.autorenew_money,
   881 			DC_EXEC,
   881 			DC_EXEC,
   882 			CMD_SET_AUTOREPLACE
   882 			CMD_SET_AUTOREPLACE
   883 		);
   883 		);
   884 
   884 
   885 #ifdef ENABLE_NETWORK
   885 #ifdef ENABLE_NETWORK
  1120 		}
  1120 		}
  1121 		fclose(fp);
  1121 		fclose(fp);
  1122 	}
  1122 	}
  1123 
  1123 
  1124 	/* Initialize end of game variable (when to show highscore chart) */
  1124 	/* Initialize end of game variable (when to show highscore chart) */
  1125 	_patches.ending_year = 2051;
  1125 	_settings.gui.ending_year = 2051;
  1126 }
  1126 }
  1127 
  1127 
  1128 /* Save/load of players */
  1128 /* Save/load of players */
  1129 static const SaveLoad _player_desc[] = {
  1129 static const SaveLoad _player_desc[] = {
  1130 	    SLE_VAR(Player, name_2,          SLE_UINT32),
  1130 	    SLE_VAR(Player, name_2,          SLE_UINT32),