summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-01-20 20:18:19 +0000
committerrubidium <rubidium@openttd.org>2012-01-20 20:18:19 +0000
commit70c7fbd90eb0ace75d759725ba4d0085283f152c (patch)
treef807e537b9e78dff6442d4ec2a472217e84157d4 /src
parent15331fa03c5bd87c54ea51e57a9738e867f6bc2e (diff)
downloadopenttd-70c7fbd90eb0ace75d759725ba4d0085283f152c.tar.xz
(svn r23826) -Fix [FS#4972]: the detailed performance rating window showed the cargo count of the current quarter instead of the last quarter like the tooltip says
Diffstat (limited to 'src')
-rw-r--r--src/cargo_type.h27
-rw-r--r--src/company_base.h13
-rw-r--r--src/economy.cpp21
-rw-r--r--src/graph_gui.cpp2
-rw-r--r--src/network/network_admin.cpp4
-rw-r--r--src/saveload/company_sl.cpp7
-rw-r--r--src/saveload/oldloader_sl.cpp6
-rw-r--r--src/saveload/saveload.cpp3
-rw-r--r--src/script/api/script_company.cpp4
9 files changed, 54 insertions, 33 deletions
diff --git a/src/cargo_type.h b/src/cargo_type.h
index 5d3fa9ae5..7b7168a10 100644
--- a/src/cargo_type.h
+++ b/src/cargo_type.h
@@ -105,6 +105,33 @@ public:
{
return this->amount[cargo];
}
+
+ /**
+ * Get the sum of all cargo amounts.
+ * @return The sum.
+ */
+ template <typename T>
+ inline const T GetSum() const
+ {
+ T ret = 0;
+ for (size_t i = 0; i < lengthof(this->amount); i++) {
+ ret += this->amount[i];
+ }
+ return ret;
+ }
+
+ /**
+ * Get the amount of cargos that have an amount.
+ * @return The amount.
+ */
+ inline byte GetCount() const
+ {
+ byte count = 0;
+ for (size_t i = 0; i < lengthof(this->amount); i++) {
+ if (this->amount[i] != 0) count++;
+ }
+ return count;
+ }
};
diff --git a/src/company_base.h b/src/company_base.h
index b8fb7c8e0..58c0a0ce0 100644
--- a/src/company_base.h
+++ b/src/company_base.h
@@ -19,12 +19,13 @@
#include "settings_type.h"
#include "group.h"
+/** Statistics about the economy. */
struct CompanyEconomyEntry {
- Money income;
- Money expenses;
- int32 delivered_cargo;
- int32 performance_history; ///< company score (scale 0-1000)
- Money company_value;
+ Money income; ///< The amount of income.
+ Money expenses; ///< The amount of expenses.
+ CargoArray delivered_cargo; ///< The amount of delivered cargo.
+ int32 performance_history; ///< Company score (scale 0-1000)
+ Money company_value; ///< The value of the company.
};
struct CompanyInfrastructure {
@@ -62,8 +63,6 @@ struct CompanyProperties {
byte block_preview; ///< Number of quarters that the company is not allowed to get new exclusive engine previews (see CompaniesGenStatistics).
- uint32 cargo_types; ///< Which cargo types were transported the last year.
-
TileIndex location_of_HQ; ///< Northern tile of HQ; #INVALID_TILE when there is none.
TileIndex last_build_coordinate; ///< Coordinate of the last build thing by this company.
diff --git a/src/economy.cpp b/src/economy.cpp
index 01fd5b4a4..33dfec3cc 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -214,27 +214,21 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
/* Generate score depending on amount of transported cargo */
{
- const CompanyEconomyEntry *cee;
- int numec;
- uint32 total_delivered;
-
- numec = min(c->num_valid_stat_ent, 4);
+ int numec = min(c->num_valid_stat_ent, 4);
if (numec != 0) {
- cee = c->old_economy;
- total_delivered = 0;
+ const CompanyEconomyEntry *cee = c->old_economy;
+ OverflowSafeInt64 total_delivered = 0;
do {
- total_delivered += cee->delivered_cargo;
+ total_delivered += cee->delivered_cargo.GetSum<OverflowSafeInt64>();
} while (++cee, --numec);
- _score_part[owner][SCORE_DELIVERED] = total_delivered;
+ _score_part[owner][SCORE_DELIVERED] = ClampToI32(total_delivered);
}
}
/* Generate score for variety of cargo */
{
- uint num = CountBits(c->cargo_types);
- _score_part[owner][SCORE_CARGO] = num;
- if (update) c->cargo_types = 0;
+ _score_part[owner][SCORE_CARGO] = c->old_economy->delivered_cargo.GetCount();
}
/* Generate score for company's money */
@@ -1007,8 +1001,7 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, Ti
}
/* Update company statistics */
- company->cur_economy.delivered_cargo += accepted;
- if (accepted > 0) SetBit(company->cargo_types, cargo_type);
+ company->cur_economy.delivered_cargo[cargo_type] += accepted;
/* Increase town's counter for town effects */
const CargoSpec *cs = CargoSpec::Get(cargo_type);
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index eacbfd614..5c6902511 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -717,7 +717,7 @@ struct DeliveredCargoGraphWindow : BaseGraphWindow {
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
{
- return c->old_economy[j].delivered_cargo;
+ return c->old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
}
};
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp
index 592e26b3a..9fe7c4f77 100644
--- a/src/network/network_admin.cpp
+++ b/src/network/network_admin.cpp
@@ -412,13 +412,13 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
p->Send_uint64(company->money);
p->Send_uint64(company->current_loan);
p->Send_uint64(income);
- p->Send_uint16(company->cur_economy.delivered_cargo);
+ p->Send_uint16(min(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>()));
/* Send stats for the last 2 quarters. */
for (uint i = 0; i < 2; i++) {
p->Send_uint64(company->old_economy[i].company_value);
p->Send_uint16(company->old_economy[i].performance_history);
- p->Send_uint16(company->old_economy[i].delivered_cargo);
+ p->Send_uint16(min(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>()));
}
this->SendPacket(p);
diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp
index c1ce88870..836d20783 100644
--- a/src/saveload/company_sl.cpp
+++ b/src/saveload/company_sl.cpp
@@ -252,8 +252,8 @@ static const SaveLoad _company_desc[] = {
SLE_CONDVAR(CompanyProperties, avail_railtypes, SLE_UINT8, 0, 57),
SLE_VAR(CompanyProperties, block_preview, SLE_UINT8),
- SLE_CONDVAR(CompanyProperties, cargo_types, SLE_FILE_U16 | SLE_VAR_U32, 0, 93),
- SLE_CONDVAR(CompanyProperties, cargo_types, SLE_UINT32, 94, SL_MAX_VERSION),
+ SLE_CONDNULL(2, 0, 93), ///< cargo_types
+ SLE_CONDNULL(4, 94, 169), ///< cargo_types
SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, 6, SL_MAX_VERSION),
SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
@@ -338,7 +338,8 @@ static const SaveLoad _company_economy_desc[] = {
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION),
- SLE_VAR(CompanyEconomyEntry, delivered_cargo, SLE_INT32),
+ SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, 0, 169),
+ SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, 170, SL_MAX_VERSION),
SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
SLE_END()
diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp
index 2f0bfead6..479ee206e 100644
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -887,7 +887,7 @@ static bool LoadOldCompanyYearly(LoadgameState *ls, int num)
static const OldChunks _company_economy_chunk[] = {
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, income ),
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, expenses ),
- OCL_SVAR( OC_INT32, CompanyEconomyEntry, delivered_cargo ),
+ OCL_SVAR( OC_INT32, CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1] ),
OCL_SVAR( OC_INT32, CompanyEconomyEntry, performance_history ),
OCL_SVAR( OC_TTD | OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, company_value ),
@@ -931,8 +931,8 @@ static const OldChunks _company_chunk[] = {
OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
- OCL_SVAR( OC_TTD | OC_UINT32, Company, cargo_types ),
- OCL_SVAR( OC_TTO | OC_FILE_U16 | OC_VAR_U32, Company, cargo_types ),
+ OCL_CNULL( OC_TTD, 4 ), // cargo_types
+ OCL_CNULL( OC_TTO, 2 ), // cargo_types
OCL_CHUNK( 3, LoadOldCompanyYearly ),
OCL_CHUNK( 1, LoadOldCompanyEconomy ),
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 8a012b233..74274c1f4 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -233,8 +233,9 @@
* 167 23504
* 168 23637
* 169 23816
+ * 170 23826
*/
-extern const uint16 SAVEGAME_VERSION = 169; ///< Current savegame version of OpenTTD.
+extern const uint16 SAVEGAME_VERSION = 170; ///< Current savegame version of OpenTTD.
SavegameType _savegame_type; ///< type of savegame we are loading
diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp
index dd79feb88..8e19904f9 100644
--- a/src/script/api/script_company.cpp
+++ b/src/script/api/script_company.cpp
@@ -138,9 +138,9 @@
if (quarter > EARLIEST_QUARTER) return -1;
if (quarter == CURRENT_QUARTER) {
- return ::Company::Get((::CompanyID)company)->cur_economy.delivered_cargo;
+ return ::Company::Get((::CompanyID)company)->cur_economy.delivered_cargo.GetSum<OverflowSafeInt<int32, INT32_MAX, INT32_MIN> >();
}
- return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].delivered_cargo;
+ return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].delivered_cargo.GetSum<OverflowSafeInt<int32, INT32_MAX, INT32_MIN> >();
}
/* static */ int32 ScriptCompany::GetQuarterlyPerformanceRating(ScriptCompany::CompanyID company, uint32 quarter)