(svn r6787) -Codechange: Use PLAYER_NEW_COMPANY as a player identifier wishing to become a
new player instead of a 0.
This commit is contained in:
		@@ -739,7 +739,8 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (argc == 0) {
 | 
						if (argc == 0) {
 | 
				
			||||||
		IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
 | 
							IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
 | 
				
			||||||
		IConsoleHelp("IP can contain port and player: 'IP#Player:Port', eg: 'server.ottd.org#2:443'");
 | 
							IConsoleHelp("IP can contain port and player: 'IP[[#Player]:Port]', eg: 'server.ottd.org#2:443'");
 | 
				
			||||||
 | 
							IConsoleHelp("Player #0 is new company, #255 is spectator all others are a certain company");
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -749,14 +750,25 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 | 
				
			|||||||
		NetworkDisconnect();
 | 
							NetworkDisconnect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ip = argv[1];
 | 
						ip = argv[1];
 | 
				
			||||||
 | 
						/* Default settings: default port and new company */
 | 
				
			||||||
	rport = NETWORK_DEFAULT_PORT;
 | 
						rport = NETWORK_DEFAULT_PORT;
 | 
				
			||||||
 | 
						_network_playas = PLAYER_NEW_COMPANY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ParseConnectionString(&player, &port, ip);
 | 
						ParseConnectionString(&player, &port, ip);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	IConsolePrintF(_icolour_def, "Connecting to %s...", ip);
 | 
						IConsolePrintF(_icolour_def, "Connecting to %s...", ip);
 | 
				
			||||||
	if (player != NULL) {
 | 
						if (player != NULL) {
 | 
				
			||||||
		_network_playas = atoi(player);
 | 
							_network_playas = atoi(player);
 | 
				
			||||||
		IConsolePrintF(_icolour_def, "    player-no: %s", player);
 | 
							IConsolePrintF(_icolour_def, "    player-no: %d", _network_playas);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* From a user pov 0 is a new player, internally it's different and all
 | 
				
			||||||
 | 
							 * players are offset by one to ease up on users (eg players 1-8 not 0-7) */
 | 
				
			||||||
 | 
							if (_network_playas == 0) _network_playas = PLAYER_NEW_COMPANY;
 | 
				
			||||||
 | 
							if (!IsValidPlayer(_network_playas - 1) &&
 | 
				
			||||||
 | 
								  (_network_playas != PLAYER_SPECTATOR &&
 | 
				
			||||||
 | 
								   _network_playas != PLAYER_NEW_COMPANY)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (port != NULL) {
 | 
						if (port != NULL) {
 | 
				
			||||||
		rport = atoi(port);
 | 
							rport = atoi(port);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -511,7 +511,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
 | 
				
			|||||||
		// Say we received the map and loaded it correctly!
 | 
							// Say we received the map and loaded it correctly!
 | 
				
			||||||
		SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
 | 
							SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (_network_playas == 0 || _network_playas > MAX_PLAYERS ||
 | 
							// new company/spectator (invalid player) or company we want to join is not active
 | 
				
			||||||
 | 
							if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayer(_network_playas - 1) ||
 | 
				
			||||||
				!GetPlayer(_network_playas - 1)->is_active) {
 | 
									!GetPlayer(_network_playas - 1)->is_active) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (_network_playas == PLAYER_SPECTATOR) {
 | 
								if (_network_playas == PLAYER_SPECTATOR) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -929,7 +929,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case 8: /* New company */
 | 
							case 8: /* New company */
 | 
				
			||||||
			_network_playas = 0;
 | 
								_network_playas = PLAYER_NEW_COMPANY;
 | 
				
			||||||
			NetworkClientConnectGame(_network_last_host, _network_last_port);
 | 
								NetworkClientConnectGame(_network_last_host, _network_last_port);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case 9: /* Spectate game */
 | 
							case 9: /* Spectate game */
 | 
				
			||||||
@@ -1195,7 +1195,7 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
 | 
				
			|||||||
	_clientlist_proc[i++] = &ClientList_SpeakToAll;
 | 
						_clientlist_proc[i++] = &ClientList_SpeakToAll;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_network_own_client_index != ci->client_index) {
 | 
						if (_network_own_client_index != ci->client_index) {
 | 
				
			||||||
		if (_network_playas >= 1 && _network_playas <= MAX_PLAYERS) {
 | 
							if (IsValidPlayer(_network_playas - 1)) {
 | 
				
			||||||
			// We are no spectator
 | 
								// We are no spectator
 | 
				
			||||||
			if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) {
 | 
								if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) {
 | 
				
			||||||
				GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY);
 | 
									GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -596,7 +596,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// join another company does not affect these values
 | 
						// join another company does not affect these values
 | 
				
			||||||
	switch (playas) {
 | 
						switch (playas) {
 | 
				
			||||||
		case 0: /* New company */
 | 
							case PLAYER_NEW_COMPANY: /* New company */
 | 
				
			||||||
			if (ActivePlayerCount() >= _network_game_info.companies_max) {
 | 
								if (ActivePlayerCount() >= _network_game_info.companies_max) {
 | 
				
			||||||
				SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL);
 | 
									SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL);
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
@@ -608,6 +608,12 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
 | 
				
			|||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							default: /* Join another company (companies 1-8) */
 | 
				
			||||||
 | 
								if (!IsValidPlayer(playas - 1)) {
 | 
				
			||||||
 | 
									SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// We need a valid name.. make it Player
 | 
						// We need a valid name.. make it Player
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -480,7 +480,10 @@ int ttd_main(int argc, char *argv[])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			ParseConnectionString(&player, &port, network_conn);
 | 
								ParseConnectionString(&player, &port, network_conn);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (player != NULL) _network_playas = atoi(player);
 | 
								if (player != NULL) {
 | 
				
			||||||
 | 
									_network_playas = atoi(player);
 | 
				
			||||||
 | 
									if (_network_playas == 0) _network_playas = PLAYER_NEW_COMPANY;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			if (port != NULL) rport = atoi(port);
 | 
								if (port != NULL) rport = atoi(port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			LoadIntroGame();
 | 
								LoadIntroGame();
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								player.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								player.h
									
									
									
									
									
								
							@@ -213,7 +213,8 @@ VARDEF PlayerID _current_player;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* Player identifiers All players below MAX_PLAYERS are playable
 | 
					/* Player identifiers All players below MAX_PLAYERS are playable
 | 
				
			||||||
 * players, above, they are special, computer controlled players */
 | 
					 * players, above, they are special, computer controlled players */
 | 
				
			||||||
enum {
 | 
					enum Players {
 | 
				
			||||||
 | 
						PLAYER_NEW_COMPANY = 254, ///< Command 'player' in Multiplayer to create a new company
 | 
				
			||||||
	PLAYER_SPECTATOR   = 255, ///< Spectator in Multiplayer or the player in the scenario editor
 | 
						PLAYER_SPECTATOR   = 255, ///< Spectator in Multiplayer or the player in the scenario editor
 | 
				
			||||||
	MAX_PLAYERS        = 8,
 | 
						MAX_PLAYERS        = 8,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user