Changeset - r18961:b2e758c9533f
[Not reviewed]
master
0 9 0
rubidium - 13 years ago 2012-01-20 20:18:19
rubidium@openttd.org
(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
9 files changed with 54 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/cargo_type.h
Show inline comments
 
@@ -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;
 
	}
 
};
 

	
 

	
src/company_base.h
Show inline comments
 
@@ -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.
 

	
src/economy.cpp
Show inline comments
 
@@ -214,27 +214,21 @@ int UpdateCompanyRatingAndValue(Company 
 

	
 
	/* 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
 
	}
 

	
 
	/* 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);
src/graph_gui.cpp
Show inline comments
 
@@ -717,7 +717,7 @@ struct DeliveredCargoGraphWindow : BaseG
 

	
 
	virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
 
	{
 
		return c->old_economy[j].delivered_cargo;
 
		return c->old_economy[j].delivered_cargo.GetSum<OverflowSafeInt64>();
 
	}
 
};
 

	
src/network/network_admin.cpp
Show inline comments
 
@@ -412,13 +412,13 @@ NetworkRecvStatus ServerNetworkAdminSock
 
		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);
src/saveload/company_sl.cpp
Show inline comments
 
@@ -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_d
 
	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()
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -887,7 +887,7 @@ static bool LoadOldCompanyYearly(Loadgam
 
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 ),
src/saveload/saveload.cpp
Show inline comments
 
@@ -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
 

	
src/script/api/script_company.cpp
Show inline comments
 
@@ -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)
0 comments (0 inline, 0 general)