Changeset - r20053:1f0b373e9dce
[Not reviewed]
master
0 7 0
rubidium - 12 years ago 2013-02-17 14:50:54
rubidium@openttd.org
(svn r25011) -Codechange: allow vehicle transfer and profit text effects to be shown at the same time (fonsinchen)
7 files changed with 49 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1137,27 +1137,29 @@ CargoPayment::CargoPayment(Vehicle *fron
 
CargoPayment::~CargoPayment()
 
{
 
	if (this->CleaningPool()) return;
 

	
 
	this->front->cargo_payment = NULL;
 

	
 
	if (this->visual_profit == 0) return;
 
	if (this->visual_profit == 0 && this->visual_transfer == 0) return;
 

	
 
	Backup<CompanyByte> cur_company(_current_company, this->front->owner, FILE_LINE);
 

	
 
	SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit));
 
	this->front->profit_this_year += this->visual_profit << 8;
 
	this->front->profit_this_year += (this->visual_profit + this->visual_transfer) << 8;
 

	
 
	if (this->route_profit != 0 && IsLocalCompany() && !PlayVehicleSound(this->front, VSE_LOAD_UNLOAD)) {
 
		SndPlayVehicleFx(SND_14_CASHTILL, this->front);
 
	}
 

	
 
	if (this->route_profit != 0) {
 
		if (IsLocalCompany() && !PlayVehicleSound(this->front, VSE_LOAD_UNLOAD)) {
 
			SndPlayVehicleFx(SND_14_CASHTILL, this->front);
 
		}
 

	
 
		ShowCostOrIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, -this->visual_profit);
 
	} else {
 
		ShowFeederIncomeAnimation(this->front->x_pos, this->front->y_pos, this->front->z_pos, this->visual_profit);
 
	if (this->visual_transfer != 0) {
 
		ShowFeederIncomeAnimation(this->front->x_pos, this->front->y_pos,
 
				this->front->z_pos, this->visual_transfer, -this->visual_profit);
 
	} else if (this->visual_profit != 0) {
 
		ShowCostOrIncomeAnimation(this->front->x_pos, this->front->y_pos,
 
				this->front->z_pos, -this->visual_profit);
 
	}
 

	
 
	cur_company.Restore();
 
}
 

	
 
/**
 
@@ -1193,13 +1195,13 @@ Money CargoPayment::PayTransfer(const Ca
 
			DistanceManhattan(cp->LoadedAtXY(), Station::Get(this->current_station)->xy),
 
			cp->DaysInTransit(),
 
			this->ct);
 

	
 
	profit = profit * _settings_game.economy.feeder_payment_share / 100;
 

	
 
	this->visual_profit += profit; // accumulate transfer profits for whole vehicle
 
	this->visual_transfer += profit; // accumulate transfer profits for whole vehicle
 
	return profit; // account for the (virtual) profit already made for the cargo packet
 
}
 

	
 
/**
 
 * Prepare the vehicle to be unloaded.
 
 * @param front_v the vehicle to be unloaded
src/economy_base.h
Show inline comments
 
@@ -21,15 +21,16 @@ typedef Pool<CargoPayment, CargoPaymentI
 
extern CargoPaymentPool _cargo_payment_pool;
 

	
 
/**
 
 * Helper class to perform the cargo payment.
 
 */
 
struct CargoPayment : CargoPaymentPool::PoolItem<&_cargo_payment_pool> {
 
	Vehicle *front;      ///< The front vehicle to do the payment of
 
	Money route_profit;  ///< The amount of money to add/remove from the bank account
 
	Money visual_profit; ///< The visual profit to show
 
	Vehicle *front;        ///< The front vehicle to do the payment of
 
	Money route_profit;    ///< The amount of money to add/remove from the bank account
 
	Money visual_profit;   ///< The visual profit to show
 
	Money visual_transfer; ///< The transfer credits to be shown
 

	
 
	/* Unsaved variables */
 
	Company *owner;            ///< The owner of the vehicle
 
	StationID current_station; ///< The current station
 
	CargoID ct;                ///< The currently handled cargo type
 

	
src/lang/english.txt
Show inline comments
 
@@ -3824,12 +3824,16 @@ STR_PERCENT_NONE                        
 
STR_INCOME_FLOAT_COST_SMALL                                     :{TINY_FONT}{RED}Cost: {CURRENCY_LONG}
 
STR_INCOME_FLOAT_COST                                           :{RED}Cost: {CURRENCY_LONG}
 
STR_INCOME_FLOAT_INCOME_SMALL                                   :{TINY_FONT}{GREEN}Income: {CURRENCY_LONG}
 
STR_INCOME_FLOAT_INCOME                                         :{GREEN}Income: {CURRENCY_LONG}
 
STR_FEEDER_TINY                                                 :{TINY_FONT}{YELLOW}Transfer: {CURRENCY_LONG}
 
STR_FEEDER                                                      :{YELLOW}Transfer: {CURRENCY_LONG}
 
STR_FEEDER_INCOME_TINY                                          :{TINY_FONT}{YELLOW}Transfer: {CURRENCY_LONG}{WHITE} / {GREEN}Income: {CURRENCY_LONG}
 
STR_FEEDER_INCOME                                               :{YELLOW}Transfer: {CURRENCY_LONG}{WHITE} / {GREEN}Income: {CURRENCY_LONG}
 
STR_FEEDER_COST_TINY                                            :{TINY_FONT}{YELLOW}Transfer: {CURRENCY_LONG}{WHITE} / {RED}Cost: {CURRENCY_LONG}
 
STR_FEEDER_COST                                                 :{YELLOW}Transfer: {CURRENCY_LONG}{WHITE} / {RED}Cost: {CURRENCY_LONG}
 
STR_MESSAGE_ESTIMATED_COST                                      :{WHITE}Estimated Cost: {CURRENCY_LONG}
 
STR_MESSAGE_ESTIMATED_INCOME                                    :{WHITE}Estimated Income: {CURRENCY_LONG}
 

	
 
# Saveload messages
 
STR_ERROR_SAVE_STILL_IN_PROGRESS                                :{WHITE}Saving still in progress,{}please wait until it is finished!
 
STR_ERROR_AUTOSAVE_FAILED                                       :{WHITE}Autosave failed
src/misc_gui.cpp
Show inline comments
 
@@ -540,23 +540,34 @@ void ShowCostOrIncomeAnimation(int x, in
 
	SetDParam(0, cost);
 
	AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
 
}
 

	
 
/**
 
 * Display animated feeder income.
 
 * @param x    World X position of the animation location.
 
 * @param y    World Y position of the animation location.
 
 * @param z    World Z position of the animation location.
 
 * @param cost Estimated feeder income.
 
 * @param x        World X position of the animation location.
 
 * @param y        World Y position of the animation location.
 
 * @param z        World Z position of the animation location.
 
 * @param transfer Estimated feeder income.
 
 * @param income   Real income from goods being delivered to their final destination.
 
 */
 
void ShowFeederIncomeAnimation(int x, int y, int z, Money cost)
 
void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
 
{
 
	Point pt = RemapCoords(x, y, z);
 

	
 
	SetDParam(0, cost);
 
	AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
 
	SetDParam(0, transfer);
 
	if (income == 0) {
 
		AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
 
	} else {
 
		StringID msg = STR_FEEDER_COST;
 
		if (income < 0) {
 
			income = -income;
 
			msg = STR_FEEDER_INCOME;
 
		}
 
		SetDParam(1, income);
 
		AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
 
	}
 
}
 

	
 
/**
 
 * Display vehicle loading indicators.
 
 * @param x       World X position of the animation location.
 
 * @param y       World Y position of the animation location.
src/saveload/economy_sl.cpp
Show inline comments
 
@@ -60,17 +60,17 @@ static void Load_ECMY()
 
{
 
	SlObject(&_economy, _economy_desc);
 
	StartupIndustryDailyChanges(IsSavegameVersionBefore(102));  // old savegames will need to be initialized
 
}
 

	
 
static const SaveLoad _cargopayment_desc[] = {
 
	SLE_REF(CargoPayment, front,         REF_VEHICLE),
 
	SLE_VAR(CargoPayment, route_profit,  SLE_INT64),
 
	SLE_VAR(CargoPayment, visual_profit, SLE_INT64),
 

	
 
	SLE_END()
 
	    SLE_REF(CargoPayment, front,           REF_VEHICLE),
 
	    SLE_VAR(CargoPayment, route_profit,    SLE_INT64),
 
	    SLE_VAR(CargoPayment, visual_profit,   SLE_INT64),
 
	SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, 181, SL_MAX_VERSION),
 
	    SLE_END()
 
};
 

	
 
static void Save_CAPY()
 
{
 
	CargoPayment *cp;
 
	FOR_ALL_CARGO_PAYMENTS(cp) {
src/texteff.cpp
Show inline comments
 
@@ -17,12 +17,13 @@
 
#include "viewport_func.h"
 
#include "settings_type.h"
 

	
 
/** Container for all information about a text effect */
 
struct TextEffect : public ViewportSign {
 
	uint64 params_1;     ///< DParam parameter
 
	uint64 params_2;     ///< second DParam parameter
 
	StringID string_id;  ///< String to draw for the text effect, if INVALID_STRING_ID then it's not valid
 
	uint8 duration;      ///< How long the text effect should stay, in ticks (applies only when mode == TE_RISING)
 
	TextEffectMode mode; ///< Type of text effect
 

	
 
	/** Reset the text effect */
 
	void Reset()
 
@@ -49,12 +50,13 @@ TextEffectID AddTextEffect(StringID msg,
 
	TextEffect *te = _text_effects.Get(i);
 

	
 
	/* Start defining this object */
 
	te->string_id = msg;
 
	te->duration = duration;
 
	te->params_1 = GetDParam(0);
 
	te->params_2 = GetDParam(1);
 
	te->mode = mode;
 

	
 
	/* Make sure we only dirty the new area */
 
	te->width_normal = 0;
 
	te->UpdatePosition(center, y, msg);
 

	
 
@@ -65,12 +67,13 @@ void UpdateTextEffect(TextEffectID te_id
 
{
 
	/* Update details */
 
	TextEffect *te = _text_effects.Get(te_id);
 
	if (msg == te->string_id && GetDParam(0) == te->params_1) return;
 
	te->string_id = msg;
 
	te->params_1 = GetDParam(0);
 
	te->params_2 = GetDParam(1);
 

	
 
	te->UpdatePosition(te->center, te->top, msg);
 
}
 

	
 
void RemoveTextEffect(TextEffectID te_id)
 
{
 
@@ -106,10 +109,10 @@ void DrawTextEffects(DrawPixelInfo *dpi)
 
	if (dpi->zoom > ZOOM_LVL_OUT_8X) return;
 

	
 
	const TextEffect *end = _text_effects.End();
 
	for (TextEffect *te = _text_effects.Begin(); te != end; te++) {
 
		if (te->string_id == INVALID_STRING_ID) continue;
 
		if (te->mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
 
			ViewportAddString(dpi, ZOOM_LVL_OUT_8X, te, te->string_id, te->string_id - 1, 0, te->params_1);
 
			ViewportAddString(dpi, ZOOM_LVL_OUT_8X, te, te->string_id, te->string_id - 1, 0, te->params_1, te->params_2);
 
		}
 
	}
 
}
src/texteff.hpp
Show inline comments
 
@@ -38,9 +38,9 @@ void RemoveTextEffect(TextEffectID effec
 
/* misc_gui.cpp */
 
TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID colour);
 
void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID colour);
 
void HideFillingPercent(TextEffectID *te_id);
 

	
 
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost);
 
void ShowFeederIncomeAnimation(int x, int y, int z, Money cost);
 
void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income);
 

	
 
#endif /* TEXTEFF_HPP */
0 comments (0 inline, 0 general)