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
 
@@ -423,10 +423,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
		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();
src/network/network_gui.cpp
Show inline comments
 
@@ -1603,15 +1603,19 @@ struct NetworkLobbyWindow : public Windo
 
		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;
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -1375,11 +1375,11 @@ void NetworkSocketHandler::Send_CompanyI
 
	/* 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]);
 
	}
 

	
 
@@ -1402,10 +1402,10 @@ void NetworkPopulateCompanyStats(Network
 
		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]++;
 
@@ -1416,11 +1416,11 @@ void NetworkPopulateCompanyStats(Network
 
		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]++;
 
		}
 
	}
 
}
src/network/network_type.h
Show inline comments
 
@@ -26,10 +26,18 @@ static const uint MAX_CLIENTS = 255;
 
 */
 
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 {
 
@@ -43,8 +51,8 @@ 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
 
};
 

	
0 comments (0 inline, 0 general)