Changeset - r15344:e9ea2cd02607
[Not reviewed]
master
0 4 0
rubidium - 14 years ago 2010-06-19 16:37:56
rubidium@openttd.org
(svn r19996) -Codechange: Add NetworkVehicleType enum.
4 files changed with 37 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/network/network_client.cpp
Show inline comments
 
@@ -420,16 +420,16 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
		company_info->inaugurated_year = p->Recv_uint32();
 
		company_info->company_value    = p->Recv_uint64();
 
		company_info->money            = p->Recv_uint64();
 
		company_info->income           = p->Recv_uint64();
 
		company_info->performance      = p->Recv_uint16();
 
		company_info->use_password     = p->Recv_bool();
 
		for (uint i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
 
		for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
			company_info->num_vehicle[i] = p->Recv_uint16();
 
		}
 
		for (uint i = 0; i < NETWORK_STATION_TYPES; i++) {
 
		for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
			company_info->num_station[i] = p->Recv_uint16();
 
		}
 
		company_info->ai               = p->Recv_bool();
 

	
 
		p->Recv_string(company_info->clients, sizeof(company_info->clients));
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -1600,21 +1600,25 @@ struct NetworkLobbyWindow : public Windo
 
		y += FONT_HEIGHT_NORMAL;
 

	
 
		SetDParam(0, this->company_info[this->company].performance);
 
		DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_PERFORMANCE); // performance
 
		y += FONT_HEIGHT_NORMAL;
 

	
 
		for (uint i = 0; i < lengthof(this->company_info[this->company].num_vehicle); i++) {
 
			SetDParam(i, this->company_info[this->company].num_vehicle[i]);
 
		}
 
		SetDParam(0, this->company_info[this->company].num_vehicle[NETWORK_VEH_TRAIN]);
 
		SetDParam(1, this->company_info[this->company].num_vehicle[NETWORK_VEH_LORRY]);
 
		SetDParam(2, this->company_info[this->company].num_vehicle[NETWORK_VEH_BUS]);
 
		SetDParam(3, this->company_info[this->company].num_vehicle[NETWORK_VEH_PLANE]);
 
		SetDParam(4, this->company_info[this->company].num_vehicle[NETWORK_VEH_SHIP]);
 
		DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_VEHICLES); // vehicles
 
		y += FONT_HEIGHT_NORMAL;
 

	
 
		for (uint i = 0; i < lengthof(this->company_info[this->company].num_station); i++) {
 
			SetDParam(i, this->company_info[this->company].num_station[i]);
 
		}
 
		SetDParam(0, this->company_info[this->company].num_station[NETWORK_VEH_TRAIN]);
 
		SetDParam(1, this->company_info[this->company].num_station[NETWORK_VEH_LORRY]);
 
		SetDParam(2, this->company_info[this->company].num_station[NETWORK_VEH_BUS]);
 
		SetDParam(3, this->company_info[this->company].num_station[NETWORK_VEH_PLANE]);
 
		SetDParam(4, this->company_info[this->company].num_station[NETWORK_VEH_SHIP]);
 
		DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_STATIONS); // stations
 
		y += FONT_HEIGHT_NORMAL;
 

	
 
		SetDParamStr(0, this->company_info[this->company].clients);
 
		DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_GAME_LOBBY_PLAYERS); // players
 
	}
src/network/network_server.cpp
Show inline comments
 
@@ -1372,17 +1372,17 @@ void NetworkSocketHandler::Send_CompanyI
 
	p->Send_uint64(income);
 
	p->Send_uint16(c->old_economy[0].performance_history);
 

	
 
	/* Send 1 if there is a passord for the company else send 0 */
 
	p->Send_bool  (!StrEmpty(_network_company_states[c->index].password));
 

	
 
	for (uint i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
 
	for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
		p->Send_uint16(stats->num_vehicle[i]);
 
	}
 

	
 
	for (uint i = 0; i < NETWORK_STATION_TYPES; i++) {
 
	for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
		p->Send_uint16(stats->num_station[i]);
 
	}
 

	
 
	p->Send_bool(c->is_ai);
 
}
 

	
 
@@ -1399,31 +1399,31 @@ void NetworkPopulateCompanyStats(Network
 

	
 
	/* Go through all vehicles and count the type of vehicles */
 
	FOR_ALL_VEHICLES(v) {
 
		if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
 
		byte type = 0;
 
		switch (v->type) {
 
			case VEH_TRAIN: type = 0; break;
 
			case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? 2 : 1; break;
 
			case VEH_AIRCRAFT: type = 3; break;
 
			case VEH_SHIP: type = 4; break;
 
			case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break;
 
			case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NETWORK_VEH_BUS : NETWORK_VEH_LORRY; break;
 
			case VEH_AIRCRAFT: type = NETWORK_VEH_PLANE; break;
 
			case VEH_SHIP: type = NETWORK_VEH_SHIP; break;
 
			default: continue;
 
		}
 
		stats[v->owner].num_vehicle[type]++;
 
	}
 

	
 
	/* Go through all stations and count the types of stations */
 
	FOR_ALL_STATIONS(s) {
 
		if (Company::IsValidID(s->owner)) {
 
			NetworkCompanyStats *npi = &stats[s->owner];
 

	
 
			if (s->facilities & FACIL_TRAIN)      npi->num_station[0]++;
 
			if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[1]++;
 
			if (s->facilities & FACIL_BUS_STOP)   npi->num_station[2]++;
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[3]++;
 
			if (s->facilities & FACIL_DOCK)       npi->num_station[4]++;
 
			if (s->facilities & FACIL_TRAIN)      npi->num_station[NETWORK_VEH_TRAIN]++;
 
			if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[NETWORK_VEH_LORRY]++;
 
			if (s->facilities & FACIL_BUS_STOP)   npi->num_station[NETWORK_VEH_BUS]++;
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[NETWORK_VEH_PLANE]++;
 
			if (s->facilities & FACIL_DOCK)       npi->num_station[NETWORK_VEH_SHIP]++;
 
		}
 
	}
 
}
 

	
 
/* Send a packet to all clients with updated info about this client_id */
 
void NetworkUpdateClientInfo(ClientID client_id)
src/network/network_type.h
Show inline comments
 
@@ -23,16 +23,24 @@ static const uint MAX_CLIENTS = 255;
 
 * The number of slots; must be at least 1 more than MAX_CLIENTS. It must
 
 * furthermore be less than or equal to 256 as client indices (sent over
 
 * the network) are 8 bits. It needs 1 more for the dedicated server.
 
 */
 
static const uint MAX_CLIENT_SLOTS = 256;
 

	
 
/** How many vehicle types we put over the network */
 
static const uint NETWORK_VEHICLE_TYPES = 5;
 
/** How many station types we put over the network */
 
static const uint NETWORK_STATION_TYPES = 5;
 
/**
 
 * Vehicletypes in the order they are send in info packets.
 
 */
 
enum NetworkVehicleType {
 
	NETWORK_VEH_TRAIN = 0,
 
	NETWORK_VEH_LORRY,
 
	NETWORK_VEH_BUS,
 
	NETWORK_VEH_PLANE,
 
	NETWORK_VEH_SHIP,
 

	
 
	NETWORK_VEH_END
 
};
 

	
 
/** 'Unique' identifier to be given to clients */
 
enum ClientID {
 
	INVALID_CLIENT_ID = 0, ///< Client is not part of anything
 
	CLIENT_ID_SERVER  = 1, ///< Servers always have this ID
 
	CLIENT_ID_FIRST   = 2, ///< The first client ID
 
@@ -40,14 +48,14 @@ enum ClientID {
 

	
 
/** Indices into the client tables */
 
typedef uint8 ClientIndex;
 

	
 
/** Simple calculated statistics of a company */
 
struct NetworkCompanyStats {
 
	uint16 num_vehicle[NETWORK_VEHICLE_TYPES];      ///< How many vehicles are there of this type?
 
	uint16 num_station[NETWORK_STATION_TYPES];      ///< How many stations are there of this type?
 
	uint16 num_vehicle[NETWORK_VEH_END];            ///< How many vehicles are there of this type?
 
	uint16 num_station[NETWORK_VEH_END];            ///< How many stations are there of this type?
 
	bool ai;                                        ///< Is this company an AI
 
};
 

	
 
/** Some state information of a company, especially for servers */
 
struct NetworkCompanyState {
 
	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the company
0 comments (0 inline, 0 general)