summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-22 18:40:57 +0000
committerrubidium <rubidium@openttd.org>2008-12-22 18:40:57 +0000
commitd146b48063d3c20c78703ef615979cf2a984b761 (patch)
tree68a45cb9d1b5a0a6ab29d8cdecc736cd6dbae7ea /src/network/core
parentc3939135638ac957661a94300076923318192013 (diff)
downloadopenttd-d146b48063d3c20c78703ef615979cf2a984b761.tar.xz
(svn r14712) -Codechange: split server and client side w.r.t. the storage of network related company information.
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/core.cpp48
-rw-r--r--src/network/core/core.h1
2 files changed, 49 insertions, 0 deletions
diff --git a/src/network/core/core.cpp b/src/network/core/core.cpp
index 1f60aba80..e989d0a50 100644
--- a/src/network/core/core.cpp
+++ b/src/network/core/core.cpp
@@ -8,9 +8,16 @@
#include "../../stdafx.h"
#include "../../debug.h"
+#include "../../company_base.h"
+#include "../../strings_func.h"
+#include "../../string_func.h"
+#include "../../date_func.h"
#include "os_abstraction.h"
#include "core.h"
#include "packet.h"
+#include "../network_func.h"
+
+#include "table/strings.h"
#ifdef __MORPHOS__
/* the library base is required here */
@@ -119,4 +126,45 @@ void NetworkSocketHandler::Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf)
}
}
+void NetworkSocketHandler::Send_CompanyInformation(Packet *p, const Company *c, const NetworkCompanyStats *stats)
+{
+ /* Grab the company name */
+ char company_name[NETWORK_COMPANY_NAME_LENGTH];
+ SetDParam(0, c->index);
+ GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
+
+ /* Get the income */
+ Money income = 0;
+ if (_cur_year - 1 == c->inaugurated_year) {
+ /* The company is here just 1 year, so display [2], else display[1] */
+ for (uint i = 0; i < lengthof(c->yearly_expenses[2]); i++) {
+ income -= c->yearly_expenses[2][i];
+ }
+ } else {
+ for (uint i = 0; i < lengthof(c->yearly_expenses[1]); i++) {
+ income -= c->yearly_expenses[1][i];
+ }
+ }
+
+ /* Send the information */
+ p->Send_uint8 (c->index);
+ p->Send_string(company_name);
+ p->Send_uint32(c->inaugurated_year);
+ p->Send_uint64(c->old_economy[0].company_value);
+ p->Send_uint64(c->money);
+ 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 (int i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
+ p->Send_uint16(stats->num_vehicle[i]);
+ }
+
+ for (int i = 0; i < NETWORK_STATION_TYPES; i++) {
+ p->Send_uint16(stats->num_station[i]);
+ }
+}
+
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/core.h b/src/network/core/core.h
index 4c5b3f9bd..272d44adc 100644
--- a/src/network/core/core.h
+++ b/src/network/core/core.h
@@ -74,6 +74,7 @@ public:
void Send_GRFIdentifier(Packet *p, const GRFIdentifier *grf);
void Recv_GRFIdentifier(Packet *p, GRFIdentifier *grf);
+ void Send_CompanyInformation(Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats);
};
#endif /* ENABLE_NETWORK */