Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6633: Cargo monitor industry delivery now accounts for which IndustryID the cargo was delivered to #7176

Merged
merged 1 commit into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cargomonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring)
* @param src_type type of \a src.
* @param src index of source.
* @param st station where the cargo is delivered to.
* @param dest industry index where the cargo is delivered to.
*/
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st)
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest)
{
if (amount == 0) return;

Expand Down Expand Up @@ -151,6 +152,7 @@ void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, Sour

/* Industry delivery. */
for (const Industry * const *ip = st->industries_near.Begin(); ip != st->industries_near.End(); ip++) {
if ((*ip)->index != dest) continue;
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, (*ip)->index);
CargoMonitorMap::iterator iter = _cargo_deliveries.find(num);
if (iter != _cargo_deliveries.end()) iter->second += amount;
Expand Down
2 changes: 1 addition & 1 deletion src/cargomonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ void ClearCargoPickupMonitoring(CompanyID company = INVALID_OWNER);
void ClearCargoDeliveryMonitoring(CompanyID company = INVALID_OWNER);
int32 GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring);
int32 GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring);
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st);
void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest = INVALID_INDUSTRY);

#endif /* CARGOMONITOR_H */
20 changes: 12 additions & 8 deletions src/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,10 @@ static SmallIndustryList _cargo_delivery_destinations;
* @param cargo_type Type of cargo delivered
* @param num_pieces Amount of cargo delivered
* @param source The source of the cargo
* @param company The company delivering the cargo
* @return actually accepted pieces of cargo
*/
static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint num_pieces, IndustryID source)
static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint num_pieces, IndustryID source, CompanyID company)
{
/* Find the nearest industrytile to the station sign inside the catchment area, whose industry accepts the cargo.
* This fails in three cases:
Expand Down Expand Up @@ -1065,6 +1066,9 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
ind->last_cargo_accepted_at[cargo_index] = _date;
num_pieces -= amount;
accepted += amount;

/* Update the cargo monitor. */
AddCargoDelivery(cargo_type, company, amount, ST_INDUSTRY, source, st, ind->index);
}

return accepted;
Expand All @@ -1090,30 +1094,30 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID dest, Ti
Station *st = Station::Get(dest);

/* Give the goods to the industry. */
uint accepted = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == ST_INDUSTRY ? src : INVALID_INDUSTRY);
uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == ST_INDUSTRY ? src : INVALID_INDUSTRY, company->index);

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

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

/* Update company statistics */
company->cur_economy.delivered_cargo[cargo_type] += accepted;
company->cur_economy.delivered_cargo[cargo_type] += accepted_total;

/* Increase town's counter for town effects */
const CargoSpec *cs = CargoSpec::Get(cargo_type);
st->town->received[cs->town_effect].new_act += accepted;
st->town->received[cs->town_effect].new_act += accepted_total;

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

/* Update the cargo monitor. */
AddCargoDelivery(cargo_type, company->index, accepted, src_type, src, st);
AddCargoDelivery(cargo_type, company->index, accepted_total - accepted_ind, src_type, src, st);

/* Modify profit if a subsidy is in effect */
if (CheckSubsidised(cargo_type, company->index, src_type, src, st)) {
Expand Down