openttd.c
branch0.5
changeset 5370 fb39e4250252
parent 5363 fe172941ea9e
child 5408 1ed4ede56477
equal deleted inserted replaced
5369:4363e2fc3e4a 5370:fb39e4250252
   299 		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
   299 		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
   300 		WaitTillGeneratedWorld();
   300 		WaitTillGeneratedWorld();
   301 	}
   301 	}
   302 
   302 
   303 	_pause = 0;
   303 	_pause = 0;
   304 	_local_player = 0;
   304 	SetLocalPlayer(0);
   305 	/* Make sure you can't scroll in the menu */
   305 	/* Make sure you can't scroll in the menu */
   306 	_scrolling_viewport = 0;
   306 	_scrolling_viewport = 0;
   307 	_cursor.fix_at = false;
   307 	_cursor.fix_at = false;
   308 	MarkWholeScreenDirty();
   308 	MarkWholeScreenDirty();
   309 
   309 
   593 
   593 
   594 static void MakeNewGameDone(void)
   594 static void MakeNewGameDone(void)
   595 {
   595 {
   596 	/* In a dedicated server, the server does not play */
   596 	/* In a dedicated server, the server does not play */
   597 	if (_network_dedicated) {
   597 	if (_network_dedicated) {
   598 		_local_player = PLAYER_SPECTATOR;
   598 		SetLocalPlayer(PLAYER_SPECTATOR);
   599 		return;
   599 		return;
   600 	}
   600 	}
   601 
   601 
   602 	/* Create a single player */
   602 	/* Create a single player */
   603 	DoStartupNewPlayer(false);
   603 	DoStartupNewPlayer(false);
   604 
   604 
   605 	_local_player = 0;
   605 	SetLocalPlayer(0);
   606 	_current_player = _local_player;
   606 	_current_player = _local_player;
   607 	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
   607 	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
   608 
   608 
   609 	SettingsDisableElrail(_patches.disable_elrails);
   609 	SettingsDisableElrail(_patches.disable_elrails);
   610 
   610 
   621 	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y);
   621 	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y);
   622 }
   622 }
   623 
   623 
   624 static void MakeNewEditorWorldDone(void)
   624 static void MakeNewEditorWorldDone(void)
   625 {
   625 {
   626 	_local_player = OWNER_NONE;
   626 	SetLocalPlayer(OWNER_NONE);
   627 
   627 
   628 	MarkWholeScreenDirty();
   628 	MarkWholeScreenDirty();
   629 }
   629 }
   630 
   630 
   631 static void MakeNewEditorWorld(void)
   631 static void MakeNewEditorWorld(void)
   680 	StartupEconomy();
   680 	StartupEconomy();
   681 	StartupPlayers();
   681 	StartupPlayers();
   682 	StartupEngines();
   682 	StartupEngines();
   683 	StartupDisasters();
   683 	StartupDisasters();
   684 
   684 
   685 	_local_player = 0;
   685 	SetLocalPlayer(0);
   686 	_current_player = _local_player;
   686 	_current_player = _local_player;
   687 	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
   687 	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
   688 
   688 
   689 	MarkWholeScreenDirty();
   689 	MarkWholeScreenDirty();
   690 }
   690 }
   771 			LoadIntroGame();
   771 			LoadIntroGame();
   772 			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
   772 			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
   773 		} else {
   773 		} else {
   774 			/* Update the local player for a loaded game. It is either always
   774 			/* Update the local player for a loaded game. It is either always
   775 			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
   775 			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
   776 			_local_player = _network_dedicated ? PLAYER_SPECTATOR : 0;
   776 			SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : 0);
   777 			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
   777 			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
   778 #ifdef ENABLE_NETWORK
   778 #ifdef ENABLE_NETWORK
   779 			if (_network_server) {
   779 			if (_network_server) {
   780 				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
   780 				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
   781 			}
   781 			}
   792 #endif /* ENABLE_NETWORK */
   792 #endif /* ENABLE_NETWORK */
   793 		MakeNewGame(true);
   793 		MakeNewGame(true);
   794 		break;
   794 		break;
   795 
   795 
   796 	case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
   796 	case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
   797 		_local_player = OWNER_NONE;
   797 		SetLocalPlayer(OWNER_NONE);
   798 
   798 
   799 		GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
   799 		GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
   800 		MarkWholeScreenDirty();
   800 		MarkWholeScreenDirty();
   801 		break;
   801 		break;
   802 
   802 
   804 		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
   804 		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
   805 			Player *p;
   805 			Player *p;
   806 
   806 
   807 			_opt_ptr = &_opt;
   807 			_opt_ptr = &_opt;
   808 
   808 
   809 			_local_player = OWNER_NONE;
   809 			SetLocalPlayer(OWNER_NONE);
   810 			_generating_world = true;
   810 			_generating_world = true;
   811 			/* Delete all players */
   811 			/* Delete all players */
   812 			FOR_ALL_PLAYERS(p) {
   812 			FOR_ALL_PLAYERS(p) {
   813 				if (p->is_active) {
   813 				if (p->is_active) {
   814 					ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
   814 					ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
   836 			DeleteWindowById(WC_SAVELOAD, 0);
   836 			DeleteWindowById(WC_SAVELOAD, 0);
   837 		}
   837 		}
   838 		break;
   838 		break;
   839 
   839 
   840 	case SM_GENRANDLAND: /* Generate random land within scenario editor */
   840 	case SM_GENRANDLAND: /* Generate random land within scenario editor */
   841 		_local_player = OWNER_NONE;
   841 		SetLocalPlayer(OWNER_NONE);
   842 		GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
   842 		GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
   843 		// XXX: set date
   843 		// XXX: set date
   844 		MarkWholeScreenDirty();
   844 		MarkWholeScreenDirty();
   845 		break;
   845 		break;
   846 	}
   846 	}
  1273 
  1273 
  1274 	/* From version 16.0, we included autorenew on engines, which are now saved, but
  1274 	/* From version 16.0, we included autorenew on engines, which are now saved, but
  1275 	 *  of course, we do need to initialize them for older savegames. */
  1275 	 *  of course, we do need to initialize them for older savegames. */
  1276 	if (CheckSavegameVersion(16)) {
  1276 	if (CheckSavegameVersion(16)) {
  1277 		FOR_ALL_PLAYERS(p) {
  1277 		FOR_ALL_PLAYERS(p) {
  1278 			p->engine_renew_list = NULL;
  1278 			p->engine_renew_list   = NULL;
  1279 			p->engine_renew = false;
  1279 			p->engine_renew        = false;
  1280 			p->engine_renew_months = -6;
  1280 			p->engine_renew_months = -6;
  1281 			p->engine_renew_money = 100000;
  1281 			p->engine_renew_money  = 100000;
  1282 		}
  1282 		}
  1283 		if (IsValidPlayer(_local_player)) {
  1283 
  1284 			// Set the human controlled player to the patch settings
  1284 		/* When loading a game, _local_player is not yet set to the correct value.
  1285 			// Scenario editor do not have any companies
  1285 		 * However, in a dedicated server we are a spectator, so nothing needs to
  1286 			p = GetPlayer(_local_player);
  1286 		 * happen. In case we are not a dedicated server, the local player always
  1287 			p->engine_renew = _patches.autorenew;
  1287 		 * becomes player 0, unless we are in the scenario editor where all the
       
  1288 		 * players are 'invalid'.
       
  1289 		 */
       
  1290 		if (!_network_dedicated && IsValidPlayer(0)) {
       
  1291 			p = GetPlayer(0);
       
  1292 			p->engine_renew        = _patches.autorenew;
  1288 			p->engine_renew_months = _patches.autorenew_months;
  1293 			p->engine_renew_months = _patches.autorenew_months;
  1289 			p->engine_renew_money = _patches.autorenew_money;
  1294 			p->engine_renew_money  = _patches.autorenew_money;
  1290 		}
  1295 		}
  1291 	}
  1296 	}
  1292 
  1297 
  1293 	/* Elrails got added in rev 24 */
  1298 	/* Elrails got added in rev 24 */
  1294 	if (CheckSavegameVersion(24)) {
  1299 	if (CheckSavegameVersion(24)) {