summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-06-19 16:37:56 +0000
committerrubidium <rubidium@openttd.org>2010-06-19 16:37:56 +0000
commit99a11badaf80f6f3a7ddaec74ca7fad712b28957 (patch)
tree699bca4bc13a2575e1e1e5277a2d7b2df2181b14 /src/network
parent5623710593ee9459c7c3faf2da3be92e7e7263f8 (diff)
downloadopenttd-99a11badaf80f6f3a7ddaec74ca7fad712b28957.tar.xz
(svn r19996) -Codechange: Add NetworkVehicleType enum.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_client.cpp4
-rw-r--r--src/network/network_gui.cpp16
-rw-r--r--src/network/network_server.cpp22
-rw-r--r--src/network/network_type.h20
4 files changed, 37 insertions, 25 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 89086451a..56f1c6222 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -423,10 +423,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
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();
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index f2c70f1eb..db071c28e 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1603,15 +1603,19 @@ struct NetworkLobbyWindow : public Window {
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;
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index b75489f2a..64b86c151 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1375,11 +1375,11 @@ void NetworkSocketHandler::Send_CompanyInformation(Packet *p, const Company *c,
/* 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(NetworkCompanyStats *stats)
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(NetworkCompanyStats *stats)
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]++;
}
}
}
diff --git a/src/network/network_type.h b/src/network/network_type.h
index 08bd7756d..a86ad9948 100644
--- a/src/network/network_type.h
+++ b/src/network/network_type.h
@@ -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
};