diff options
author | frosch <frosch@openttd.org> | 2012-12-09 16:55:57 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-12-09 16:55:57 +0000 |
commit | f93602aec9bf70d9ffdcf496e3b8c09fc91d3698 (patch) | |
tree | acb3b6f01d1f43646c732aeb994de497baad30c1 /src | |
parent | 51fca5eec7a5ad6a765c5f1871e5539b33bc24d7 (diff) | |
download | openttd-f93602aec9bf70d9ffdcf496e3b8c09fc91d3698.tar.xz |
(svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index 3cb6d4bfb..04ceec768 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -29,6 +29,7 @@ #include "engine_base.h" #include "company_base.h" #include "vehicle_func.h" +#include "articulated_vehicles.h" #include "table/strings.h" #include "table/engines.h" @@ -767,13 +768,25 @@ static CompanyID GetPreviewCompany(Engine *e) { CompanyID best_company = INVALID_COMPANY; + /* For trains the cargomask has no useful meaning, since you can attach other wagons */ + uint32 cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : (uint32)-1; + int32 best_hist = -1; const Company *c; FOR_ALL_COMPANIES(c) { if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) && c->old_economy[0].performance_history > best_hist) { - best_hist = c->old_economy[0].performance_history; - best_company = c->index; + + /* Check whether the company uses similar vehicles */ + Vehicle *v; + FOR_ALL_VEHICLES(v) { + if (v->owner != c->index || v->type != e->type) continue; + if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue; + + best_hist = c->old_economy[0].performance_history; + best_company = c->index; + break; + } } } |