本文整理汇总了C++中CommandCost::GetExpensesType方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandCost::GetExpensesType方法的具体用法?C++ CommandCost::GetExpensesType怎么用?C++ CommandCost::GetExpensesType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandCost
的用法示例。
在下文中一共展示了CommandCost::GetExpensesType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SubtractMoneyFromCompanyFract
/**
* Subtract money from a company, including the money fraction.
* @param company Company paying the bill.
* @param cst Cost of a command.
*/
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
{
Company *c = Company::Get(company);
byte m = c->money_fraction;
Money cost = cst.GetCost();
c->money_fraction = m - (byte)cost;
cost >>= 8;
if (c->money_fraction > m) cost++;
if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost));
}
示例2: SubtractMoneyFromAnyCompany
/**
* Deduct costs of a command from the money of a company.
* @param c Company to pay the bill.
* @param cost Money to pay.
*/
static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost)
{
if (cost.GetCost() == 0) return;
assert(cost.GetExpensesType() != INVALID_EXPENSES);
c->money -= cost.GetCost();
c->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost();
if (HasBit(1 << EXPENSES_TRAIN_INC |
1 << EXPENSES_ROADVEH_INC |
1 << EXPENSES_AIRCRAFT_INC |
1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) {
c->cur_economy.income -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_TRAIN_RUN |
1 << EXPENSES_ROADVEH_RUN |
1 << EXPENSES_AIRCRAFT_RUN |
1 << EXPENSES_SHIP_RUN |
1 << EXPENSES_PROPERTY |
1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) {
c->cur_economy.expenses -= cost.GetCost();
}
InvalidateCompanyWindows(c);
}
示例3: CollectCost
/**
* Aggreagate paste command costs without calling PastingState::DoCommand.
*
* The function works similarly to the PastingState::DoCommand but doesn't actually execute any
* commands, it just collects a given result.
*
* When collecting a success, cost must be of type EXPENSES_CONSTRUCTION. A success also makes
* STR_ERROR_NOTHING_TO_DO no more applies (we "did" something).
*
* Call PastingState::IsInterrupted to test whether the paste operation can be continued.
*
* @param cost The return value of the command, a cost or an error.
* @param tile The tile the error concerns.
* @param error_message Summary message of the error.
*
* @pre The company has enough money if DC_EXEC'ing.
*
* @see PastingState::IsInterrupted
* @see PastingState::CollectError
* @see PastingState::DoCommand
*/
void PastingState::CollectCost(const CommandCost &cost, TileIndex tile, StringID error_summary)
{
if (cost.Succeeded()) {
assert(!this->IsInterrupted());
/* Currently only EXPENSES_CONSTRUCTION expenses are allowed when copy/pasting. If this
* is not sufficient, some upgrade will be required. To allow proper update of finacial
* statistics, the overal cost of paste operation will have to be stored separatly for
* each supported type of expenses. */
assert(cost.GetExpensesType() == EXPENSES_CONSTRUCTION);
/* make sure we are not expending too much */
assert(!(this->dc_flags & DC_EXEC) || cost.GetCost() <= 0 || this->GetAvailableMoney() >= 0);
this->had_success = true; // mark that we had a succes and STR_ERROR_NOTHING_TO_DO no more applies
this->overal_cost += cost.GetCost();
this->last_result = cost;
} else {
this->CollectError(tile, cost.GetErrorMessage(), error_summary);
}
}
示例4: SubtractMoneyFromAnyCompany
/**
* Deduct costs of a command from the money of a company.
* @param c Company to pay the bill.
* @param cost Money to pay.
*/
static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost)
{
if (cost.GetCost() == 0) return;
assert(cost.GetExpensesType() != INVALID_EXPENSES);
if (HasBit(1 << EXPENSES_TRAIN_INC |
1 << EXPENSES_ROADVEH_INC |
1 << EXPENSES_AIRCRAFT_INC |
1 << EXPENSES_SHIP_INC |
1 << EXPENSES_SHARING_INC, cost.GetExpensesType())) {
c->cur_economy.income -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_TRAIN_RUN |
1 << EXPENSES_ROADVEH_RUN |
1 << EXPENSES_AIRCRAFT_RUN |
// 1 << EXPENSES_SHIP_RUN |
// 1 << EXPENSES_LOST_RUN |
// 1 << EXPENSES_PROPERTY |
// 1 << EXPENSES_LOAN_INT |
1 << EXPENSES_SHIP_RUN , cost.GetExpensesType())) {
if ((_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS ||
_settings_game.economy.day_length_balance_type == DBT_RUN_COST)) {
cost.MultiplyCost(_settings_game.economy.day_length_balance_factor);
}
c->cur_economy.expenses -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_LOST_RUN, cost.GetExpensesType())) {
if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS) {
cost.AffectCost(_settings_game.economy.day_length_balance_factor);
}
c->cur_economy.expenses -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_SHARING_COST, cost.GetExpensesType())) {
if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS) {
cost.AffectCost(_settings_game.economy.day_length_balance_factor);
}
c->cur_economy.expenses -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) {
if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS ||
(_settings_game.economy.day_length_balance_type == DBT_RUN_COST &&
_settings_game.economy.include_loan_int_to_run)) {
cost.AffectCost(_settings_game.economy.day_length_balance_factor);
}
c->cur_economy.expenses -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_PROPERTY, cost.GetExpensesType())) {
if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS ||
(_settings_game.economy.day_length_balance_type == DBT_RUN_COST &&
_settings_game.economy.include_prop_main_to_run)) {
cost.AffectCost(_settings_game.economy.day_length_balance_factor);
}
c->cur_economy.expenses -= cost.GetCost();
} else if (HasBit(1 << EXPENSES_CONSTRUCTION, cost.GetExpensesType())) {
/* Multiply construction costs according to day length balance type. */
if (_settings_game.economy.day_length_balance_type == DBT_ALL_COSTS) {
cost.AffectCost(_settings_game.economy.day_length_balance_factor);
}
}
/* Subtract money. */
c->money -= cost.GetCost();
c->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost();
InvalidateCompanyWindows(c);
}