Merge 1.9.0-beta2

This commit is contained in:
Pavel Stupnikov
2019-02-14 00:47:22 +03:00
1364 changed files with 22213 additions and 10721 deletions
+29 -28
View File
@@ -1,4 +1,4 @@
/* $Id: economy.cpp 27981 2018-03-11 12:46:05Z frosch $ */
/* $Id$ */
/*
* This file is part of OpenTTD.
@@ -96,7 +96,7 @@ const ScoreInfo _score_info[] = {
{ 0, 0} // SCORE_TOTAL
};
int _score_part[MAX_COMPANIES][SCORE_END];
int64 _score_part[MAX_COMPANIES][SCORE_END];
Economy _economy;
Prices _price;
Money _additional_cash_required;
@@ -184,7 +184,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
_score_part[owner][SCORE_VEHICLES] = num;
/* Don't allow negative min_profit to show */
if (min_profit > 0) {
_score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit);
_score_part[owner][SCORE_MIN_PROFIT] = min_profit;
}
}
@@ -214,10 +214,10 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
} while (++cee, --numec);
if (min_income > 0) {
_score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income);
_score_part[owner][SCORE_MIN_INCOME] = min_income;
}
_score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income);
_score_part[owner][SCORE_MAX_INCOME] = max_income;
}
}
@@ -231,7 +231,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
total_delivered += cee->delivered_cargo.GetSum<OverflowSafeInt64>();
} while (++cee, --numec);
_score_part[owner][SCORE_DELIVERED] = ClampToI32(total_delivered);
_score_part[owner][SCORE_DELIVERED] = total_delivered;
}
}
@@ -243,13 +243,13 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
/* Generate score for company's money */
{
if (c->money > 0) {
_score_part[owner][SCORE_MONEY] = ClampToI32(c->money);
_score_part[owner][SCORE_MONEY] = c->money;
}
}
/* Generate score for loan */
{
_score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - c->current_loan);
_score_part[owner][SCORE_LOAN] = _score_info[SCORE_LOAN].needed - c->current_loan;
}
/* Now we calculate the score for each item.. */
@@ -645,7 +645,7 @@ static void CompanyCheckBankrupt(Company *c)
* that changing the current company is okay. In case of single
* player we are sure (the above check) that we are not the local
* company and thus we won't be moved. */
if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL);
if (!_networking || _network_server) DoCommandP(0, CCA_DELETE | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL);
break;
}
}
@@ -699,9 +699,10 @@ static void CompaniesGenStatistics()
if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month)) return;
FOR_ALL_COMPANIES(c) {
memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0]));
/* Drop the oldest history off the end */
std::copy_backward(c->old_economy, c->old_economy + MAX_HISTORY_QUARTERS - 1, c->old_economy + MAX_HISTORY_QUARTERS);
c->old_economy[0] = c->cur_economy;
memset(&c->cur_economy, 0, sizeof(c->cur_economy));
c->cur_economy = {};
if (c->num_valid_stat_ent != MAX_HISTORY_QUARTERS) c->num_valid_stat_ent++;
@@ -1064,6 +1065,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
uint amount = min(num_pieces, 0xFFFFU - ind->incoming_cargo_waiting[cargo_index]);
ind->incoming_cargo_waiting[cargo_index] += amount;
ind->last_cargo_accepted_at[cargo_index] = _date;
num_pieces -= amount;
accepted += amount;
}
@@ -1158,7 +1160,6 @@ static void TriggerIndustryProduction(Industry *i)
uint16 callback = indspec->callback_mask;
i->was_cargo_delivered = true;
i->last_cargo_accepted_at = _date;
if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) {
@@ -1167,14 +1168,15 @@ static void TriggerIndustryProduction(Industry *i)
SetWindowDirty(WC_INDUSTRY_VIEW, i->index);
}
} else {
for (uint cargo_index = 0; cargo_index < lengthof(i->incoming_cargo_waiting); cargo_index++) {
uint cargo_waiting = i->incoming_cargo_waiting[cargo_index];
for (uint ci_in = 0; ci_in < lengthof(i->incoming_cargo_waiting); ci_in++) {
uint cargo_waiting = i->incoming_cargo_waiting[ci_in];
if (cargo_waiting == 0) continue;
i->produced_cargo_waiting[0] = min(i->produced_cargo_waiting[0] + (cargo_waiting * indspec->input_cargo_multiplier[cargo_index][0] / 256), 0xFFFF);
i->produced_cargo_waiting[1] = min(i->produced_cargo_waiting[1] + (cargo_waiting * indspec->input_cargo_multiplier[cargo_index][1] / 256), 0xFFFF);
for (uint ci_out = 0; ci_out < lengthof(i->produced_cargo_waiting); ci_out++) {
i->produced_cargo_waiting[ci_out] = min(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256), 0xFFFF);
}
i->incoming_cargo_waiting[cargo_index] = 0;
i->incoming_cargo_waiting[ci_in] = 0;
}
}
@@ -1262,7 +1264,6 @@ Money CargoPayment::PayTransfer(const CargoPacket *cp, uint count)
/**
* Prepare the vehicle to be unloaded.
* @param curr_station the station where the consist is at the moment
* @param front_v the vehicle to be unloaded
*/
void PrepareUnload(Vehicle *front_v)
@@ -1387,14 +1388,14 @@ struct IsEmptyAction
struct PrepareRefitAction
{
CargoArray &consist_capleft; ///< Capacities left in the consist.
uint32 &refit_mask; ///< Bitmask of possible refit cargoes.
CargoTypes &refit_mask; ///< Bitmask of possible refit cargoes.
/**
* Create a refit preparation action.
* @param consist_capleft Capacities left in consist, to be updated here.
* @param refit_mask Refit mask to be constructed from refit information of vehicles.
*/
PrepareRefitAction(CargoArray &consist_capleft, uint32 &refit_mask) :
PrepareRefitAction(CargoArray &consist_capleft, CargoTypes &refit_mask) :
consist_capleft(consist_capleft), refit_mask(refit_mask) {}
/**
@@ -1490,7 +1491,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
uint32 refit_mask = v->GetEngine()->info.refit_mask;
CargoTypes refit_mask = v->GetEngine()->info.refit_mask;
/* Remove old capacity from consist capacity and collect refit mask. */
IterateVehicleParts(v_start, PrepareRefitAction(consist_capleft, refit_mask));
@@ -1504,7 +1505,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
if (st->goods[cid].cargo.HasCargoFor(next_station)) {
/* Try to find out if auto-refitting would succeed. In case the refit is allowed,
* the returned refit capacity will be greater than zero. */
DoCommand(v_start->tile, v_start->index, cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
DoCommand(v_start->tile, v_start->index, cid | 1U << 24 | 0xFF << 8 | 1U << 16, DC_QUERY_COST, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
/* Try to balance different loadable cargoes between parts of the consist, so that
* all of them can be loaded. Avoid a situation where all vehicles suddenly switch
* to the first loadable cargo for which there is only one packet. If the capacities
@@ -1527,7 +1528,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
* "via any station" before reserving. We rather produce some more "any station" cargo than
* misrouting it. */
IterateVehicleParts(v_start, ReturnCargoAction(st, INVALID_STATION));
CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 6 | 0xFF << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
CommandCost cost = DoCommand(v_start->tile, v_start->index, new_cid | 1U << 24 | 0xFF << 8 | 1U << 16, DC_EXEC, GetCmdRefitVeh(v_start)); // Auto-refit and only this vehicle including artic parts.
if (cost.Succeeded()) v->First()->profit_this_year -= cost.GetCost() << 8;
}
@@ -1648,10 +1649,10 @@ static void LoadUnloadVehicle(Vehicle *front)
bool completely_emptied = true;
bool anything_unloaded = false;
bool anything_loaded = false;
uint32 full_load_amount = 0;
uint32 cargo_not_full = 0;
uint32 cargo_full = 0;
uint32 reservation_left = 0;
CargoTypes full_load_amount = 0;
CargoTypes cargo_not_full = 0;
CargoTypes cargo_full = 0;
CargoTypes reservation_left = 0;
front->cur_speed = 0;
@@ -1859,7 +1860,7 @@ static void LoadUnloadVehicle(Vehicle *front)
/* if the aircraft carries passengers and is NOT full, then
* continue loading, no matter how much mail is in */
if ((front->type == VEH_AIRCRAFT && IsCargoInClass(front->cargo_type, CC_PASSENGERS) && front->cargo_cap > front->cargo.StoredCount()) ||
(cargo_not_full && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes
(cargo_not_full != 0 && (cargo_full & ~cargo_not_full) == 0)) { // There are still non-full cargoes
finished_loading = false;
}
} else if (cargo_not_full != 0) {