Changeset - r18961:b2e758c9533f
[Not reviewed]
master
0 9 0
rubidium - 12 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
 
@@ -96,24 +96,51 @@ public:
 
	{
 
		return this->amount[cargo];
 
	}
 

	
 
	/**
 
	 * Read-only access to an amount of a specific cargo type.
 
	 * @param cargo Cargo type to access.
 
	 */
 
	inline const uint &operator[](CargoID cargo) const
 
	{
 
		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;
 
	}
 
};
 

	
 

	
 
/** Types of cargo source and destination */
 
enum SourceType {
 
	ST_INDUSTRY,     ///< Source/destination is an industry
 
	ST_TOWN,         ///< Source/destination is a town
 
	ST_HEADQUARTERS, ///< Source/destination are company headquarters
 
};
 
typedef SimpleTinyEnumT<SourceType, byte> SourceTypeByte; ///< The SourceType packed into a byte for savegame purposes.
 

	
 
typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
src/company_base.h
Show inline comments
 
@@ -10,30 +10,31 @@
 
/** @file company_base.h Definition of stuff that is very close to a company, like the company struct itself. */
 

	
 
#ifndef COMPANY_BASE_H
 
#define COMPANY_BASE_H
 

	
 
#include "road_type.h"
 
#include "livery.h"
 
#include "autoreplace_type.h"
 
#include "tile_type.h"
 
#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 {
 
	uint32 road[ROADTYPE_END]; ///< Count of company owned track bits for each road type.
 
	uint32 signal;             ///< Count of company owned signals.
 
	uint32 rail[RAILTYPE_END]; ///< Count of company owned track bits for each rail type.
 
	uint32 water;              ///< Count of company owned track bits for canals.
 
	uint32 station;            ///< Count of company owned station tiles.
 
	uint32 airport;            ///< Count of company owned airports.
 
};
 

	
 
typedef Pool<Company, CompanyByte, 1, MAX_COMPANIES> CompanyPool;
 
@@ -53,26 +54,24 @@ struct CompanyProperties {
 
	CompanyManagerFace face;         ///< Face description of the president.
 

	
 
	Money money;                     ///< Money owned by the company.
 
	byte money_fraction;             ///< Fraction of money of the company, too small to represent in #money.
 
	Money current_loan;              ///< Amount of money borrowed from the bank.
 

	
 
	byte colour;                     ///< Company colour.
 

	
 
	RailTypes avail_railtypes;       ///< Rail types available to the company.
 

	
 
	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.
 

	
 
	OwnerByte share_owners[4];       ///< Owners of the 4 shares of the company. #INVALID_OWNER if nobody has bought them yet.
 

	
 
	Year inaugurated_year;           ///< Year of starting the company.
 

	
 
	byte quarters_of_bankruptcy;     ///< Number of quarters (a quarter is 3 months) that the company has a negative balance.
 
	CompanyMask bankrupt_asked;      ///< which companies were asked about buying it?
 
	int16 bankrupt_timeout;          ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company.
 
	Money bankrupt_value;
 

	
src/economy.cpp
Show inline comments
 
@@ -205,45 +205,39 @@ int UpdateCompanyRatingAndValue(Company 
 
			} while (++cee, --numec);
 

	
 
			if (min_income > 0) {
 
				_score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income);
 
			}
 

	
 
			_score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income);
 
		}
 
	}
 

	
 
	/* 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 */
 
	{
 
		if (c->money > 0) {
 
			_score_part[owner][SCORE_MONEY] = ClampToI32(c->money);
 
		}
 
	}
 

	
 
	/* Generate score for loan */
 
	{
 
		_score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - c->current_loan);
 
@@ -998,26 +992,25 @@ static Money DeliverGoods(int num_pieces
 

	
 
	/* If this cargo type is always accepted, accept all */
 
	if (HasBit(st->always_accepted, cargo_type)) accepted = num_pieces;
 

	
 
	/* Update station statistics */
 
	if (accepted > 0) {
 
		SetBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_EVER_ACCEPTED);
 
		SetBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_CURRENT_MONTH);
 
		SetBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::GES_ACCEPTED_BIGTICK);
 
	}
 

	
 
	/* 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);
 
	st->town->received[cs->town_effect].new_act += accepted;
 

	
 
	/* Determine profit */
 
	Money profit = GetTransportedGoodsIncome(accepted, DistanceManhattan(source_tile, st->xy), days_in_transit, cargo_type);
 

	
 
	/* Modify profit if a subsidy is in effect */
 
	if (CheckSubsidised(cargo_type, company->index, src_type, src, st))  {
 
		switch (_settings_game.difficulty.subsidy_multiplier) {
 
			case 0:  profit += profit >> 1; break;
src/graph_gui.cpp
Show inline comments
 
@@ -708,25 +708,25 @@ void ShowIncomeGraph()
 
/* DELIVERED CARGO */
 
/*******************/
 

	
 
struct DeliveredCargoGraphWindow : BaseGraphWindow {
 
	DeliveredCargoGraphWindow(const WindowDesc *desc, WindowNumber window_number) :
 
			BaseGraphWindow(WID_CV_GRAPH, STR_JUST_COMMA)
 
	{
 
		this->InitializeWindow(desc, window_number);
 
	}
 

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

	
 
static const NWidgetPart _nested_delivered_cargo_graph_widgets[] = {
 
	NWidget(NWID_HORIZONTAL),
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GRAPH_CARGO_DELIVERED_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_CV_KEY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GRAPH_KEY_BUTTON, STR_GRAPH_KEY_TOOLTIP),
 
		NWidget(WWT_SHADEBOX, COLOUR_GREY),
 
		NWidget(WWT_STICKYBOX, COLOUR_GREY),
 
	EndContainer(),
 
	NWidget(WWT_PANEL, COLOUR_GREY, WID_CV_BACKGROUND),
src/network/network_admin.cpp
Show inline comments
 
@@ -403,31 +403,31 @@ NetworkRecvStatus ServerNetworkAdminSock
 
		for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
 
			income -= company->yearly_expenses[0][i];
 
		}
 

	
 
		Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
 

	
 
		p->Send_uint8(company->index);
 

	
 
		/* Current information. */
 
		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);
 
	}
 

	
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
 

	
 
/** Send statistics about the companies. */
 
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
 
{
src/saveload/company_sl.cpp
Show inline comments
 
@@ -243,26 +243,26 @@ static const SaveLoad _company_desc[] = 
 
	/* money was changed to a 64 bit field in savegame version 1. */
 
	SLE_CONDVAR(CompanyProperties, money,                 SLE_VAR_I64 | SLE_FILE_I32,  0, 0),
 
	SLE_CONDVAR(CompanyProperties, money,                 SLE_INT64,                   1, SL_MAX_VERSION),
 

	
 
	SLE_CONDVAR(CompanyProperties, current_loan,          SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
 
	SLE_CONDVAR(CompanyProperties, current_loan,          SLE_INT64,                  65, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(CompanyProperties, colour,                SLE_UINT8),
 
	    SLE_VAR(CompanyProperties, money_fraction,        SLE_UINT8),
 
	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),
 
	SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32,                  6, SL_MAX_VERSION),
 
	SLE_CONDVAR(CompanyProperties, inaugurated_year,      SLE_FILE_U8  | SLE_VAR_I32,  0, 30),
 
	SLE_CONDVAR(CompanyProperties, inaugurated_year,      SLE_INT32,                  31, SL_MAX_VERSION),
 

	
 
	    SLE_ARR(CompanyProperties, share_owners,          SLE_UINT8, 4),
 

	
 
	    SLE_VAR(CompanyProperties, num_valid_stat_ent,    SLE_UINT8),
 

	
 
	    SLE_VAR(CompanyProperties, quarters_of_bankruptcy,SLE_UINT8),
 
@@ -329,25 +329,26 @@ static const SaveLoad _company_settings_
 
	SLE_END()
 
};
 

	
 
static const SaveLoad _company_economy_desc[] = {
 
	/* these were changed to 64-bit in savegame format 2 */
 
	SLE_CONDVAR(CompanyEconomyEntry, income,              SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
 
	SLE_CONDVAR(CompanyEconomyEntry, income,              SLE_INT64,                  2, SL_MAX_VERSION),
 
	SLE_CONDVAR(CompanyEconomyEntry, expenses,            SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
 
	SLE_CONDVAR(CompanyEconomyEntry, expenses,            SLE_INT64,                  2, SL_MAX_VERSION),
 
	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()
 
};
 

	
 
/* We do need to read this single value, as the bigger it gets, the more data is stored */
 
struct CompanyOldAI {
 
	uint8 num_build_rec;
 
};
 

	
 
static const SaveLoad _company_ai_desc[] = {
 
	SLE_CONDNULL(2,  0, 106),
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -878,25 +878,25 @@ static bool LoadOldCompanyYearly(Loadgam
 
			if (!LoadChunk(ls, NULL, _company_yearly_chunk)) return false;
 
		}
 

	
 
		c->yearly_expenses[num][i] = _old_yearly;
 
	}
 

	
 
	return true;
 
}
 

	
 
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 ),
 

	
 
	OCL_END()
 
};
 

	
 
static bool LoadOldCompanyEconomy(LoadgameState *ls, int num)
 
{
 
	Company *c = Company::Get(_current_company_id);
 

	
 
	if (!LoadChunk(ls, &c->cur_economy, _company_economy_chunk)) return false;
 

	
 
@@ -922,26 +922,26 @@ static const OldChunks _company_chunk[] 
 
	OCL_SVAR( OC_UINT32, Company, president_name_2 ),
 

	
 
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Company, money ),
 
	OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, Company, current_loan ),
 

	
 
	OCL_SVAR(  OC_UINT8, Company, colour ),
 
	OCL_SVAR(  OC_UINT8, Company, money_fraction ),
 
	OCL_SVAR(  OC_UINT8, Company, quarters_of_bankruptcy ),
 
	OCL_SVAR( OC_FILE_U8  | OC_VAR_U16, Company, bankrupt_asked ),
 
	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 ),
 

	
 
	OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Company, inaugurated_year),
 
	OCL_SVAR(                  OC_TILE, Company, last_build_coordinate ),
 
	OCL_SVAR(                 OC_UINT8, Company, num_valid_stat_ent ),
 

	
 
	OCL_NULL( 230 ),         // Old AI
 

	
 
	OCL_SVAR(  OC_UINT8, Company, block_preview ),
 
	OCL_CNULL( OC_TTD, 1 ),           // Old AI
src/saveload/saveload.cpp
Show inline comments
 
@@ -224,26 +224,27 @@
 
 *  158   21933
 
 *  159   21962
 
 *  160   21974   1.1.x
 
 *  161   22567
 
 *  162   22713
 
 *  163   22767
 
 *  164   23290
 
 *  165   23304
 
 *  166   23415
 
 *  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
 

	
 
uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
char _savegame_format[8]; ///< how to compress savegames
 
bool _do_autosave;        ///< are we doing an autosave at the moment?
 

	
 
/** What are we currently doing? */
 
enum SaveLoadAction {
 
	SLA_LOAD,        ///< loading
src/script/api/script_company.cpp
Show inline comments
 
@@ -129,27 +129,27 @@
 
		return ::Company::Get((::CompanyID)company)->cur_economy.expenses;
 
	}
 
	return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].expenses;
 
}
 

	
 
/* static */ int32 ScriptCompany::GetQuarterlyCargoDelivered(ScriptCompany::CompanyID company, uint32 quarter)
 
{
 
	company = ResolveCompanyID(company);
 
	if (company == COMPANY_INVALID) return -1;
 
	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)
 
{
 
	company = ResolveCompanyID(company);
 
	if (company == COMPANY_INVALID) return -1;
 
	if (quarter > EARLIEST_QUARTER) return -1;
 
	if (quarter == CURRENT_QUARTER) return -1;
 

	
 
	return ::Company::Get((::CompanyID)company)->old_economy[quarter - 1].performance_history;
 
}
 

	
0 comments (0 inline, 0 general)