MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SendCompanyEconomy

Method SendCompanyEconomy

src/network/network_admin.cpp:378–406  ·  view source on GitHub ↗

Send economic information of all companies. */

Source from the content-addressed store, hash-verified

376
377/** Send economic information of all companies. */
378NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
379{
380 for (const Company *company : Company::Iterate()) {
381 /* Get the income. */
382 Money income = -std::reduce(std::begin(company->yearly_expenses[0]), std::end(company->yearly_expenses[0]));
383
384 auto p = std::make_unique<Packet>(this, ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
385
386 p->Send_uint8(company->index);
387
388 /* Current information. */
389 p->Send_uint64(company->money);
390 p->Send_uint64(company->current_loan);
391 p->Send_uint64(income);
392 p->Send_uint16(static_cast<uint16_t>(std::min<uint64_t>(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>())));
393
394 /* Send stats for the last 2 quarters. */
395 for (uint i = 0; i < 2; i++) {
396 p->Send_uint64(company->old_economy[i].company_value);
397 p->Send_uint16(company->old_economy[i].performance_history);
398 p->Send_uint16(static_cast<uint16_t>(std::min<uint64_t>(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>())));
399 }
400
401 this->SendPacket(std::move(p));
402 }
403
404
405 return NETWORK_RECV_STATUS_OKAY;
406}
407
408/** Send statistics about the companies. */
409NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()

Callers 2

Receive_ADMIN_POLLMethod · 0.95
NetworkAdminUpdateFunction · 0.80

Calls 6

Send_uint64Method · 0.80
Send_uint16Method · 0.80
beginFunction · 0.50
endFunction · 0.50
Send_uint8Method · 0.45
SendPacketMethod · 0.45

Tested by

no test coverage detected