Template replacement: Show warning if chain not compatible with any rail type
See: #419
This commit is contained in:
@@ -7211,6 +7211,7 @@ STR_TMPL_TEMPLATE_OVR_RUNNING_COST :{BLACK}Estimate
|
|||||||
STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING1}{BLACK} {STRING1}
|
STR_TMPL_TEMPLATE_OVR_MULTIPLE :{BLACK}{STRING1}{BLACK} {STRING1}
|
||||||
STR_TMPL_WARNING_FREE_WAGON :{RED}Free Chain: not runnable!
|
STR_TMPL_WARNING_FREE_WAGON :{RED}Free Chain: not runnable!
|
||||||
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Train not buildable: vehicle unavailable!
|
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Train not buildable: vehicle unavailable!
|
||||||
|
STR_TMPL_WARNING_VEH_NO_COMPATIBLE_RAIL_TYPE :{RED}Train not buildable: chain not compatible with any rail type
|
||||||
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Template in use: {NUM}
|
STR_TMPL_GROUP_USES_TEMPLATE :{BLACK}Template in use: {NUM}
|
||||||
STR_TMP_TEMPLATE_IN_USE :Template is in use
|
STR_TMP_TEMPLATE_IN_USE :Template is in use
|
||||||
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :Using template from parent group
|
STR_TMP_TEMPLATE_FROM_PARENT_GROUP :Using template from parent group
|
||||||
|
@@ -308,13 +308,22 @@ public:
|
|||||||
int y = ScaleGUITrad(4) - this->vscroll->GetPosition();
|
int y = ScaleGUITrad(4) - this->vscroll->GetPosition();
|
||||||
bool buildable = true;
|
bool buildable = true;
|
||||||
Money buy_cost = 0;
|
Money buy_cost = 0;
|
||||||
|
RailTypes types = static_cast<RailTypes>(UINT64_MAX);
|
||||||
for (Train *train = this->virtual_train; train != nullptr; train = train->GetNextUnit()) {
|
for (Train *train = this->virtual_train; train != nullptr; train = train->GetNextUnit()) {
|
||||||
if (!IsEngineBuildable(train->engine_type, VEH_TRAIN, train->owner)) buildable = false;
|
const Engine *e = Engine::Get(train->engine_type);
|
||||||
buy_cost += Engine::Get(train->engine_type)->GetCost();
|
if (!IsEngineBuildable(train->engine_type, VEH_TRAIN, train->owner)) {
|
||||||
|
buildable = false;
|
||||||
|
} else {
|
||||||
|
types &= (GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes;
|
||||||
|
}
|
||||||
|
buy_cost += e->GetCost();
|
||||||
}
|
}
|
||||||
if (!buildable) {
|
if (!buildable) {
|
||||||
DrawString(8, r.right, y, STR_TMPL_WARNING_VEH_UNAVAILABLE);
|
DrawString(8, r.right, y, STR_TMPL_WARNING_VEH_UNAVAILABLE);
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
} else if (types == RAILTYPES_NONE) {
|
||||||
|
DrawString(8, r.right, y, STR_TMPL_WARNING_VEH_NO_COMPATIBLE_RAIL_TYPE);
|
||||||
|
y += FONT_HEIGHT_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDParam(0, STR_TMPL_TEMPLATE_OVR_VALUE_LTBLUE);
|
SetDParam(0, STR_TMPL_TEMPLATE_OVR_VALUE_LTBLUE);
|
||||||
|
@@ -674,15 +674,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool buildable = true;
|
bool buildable = true;
|
||||||
|
RailTypes types = static_cast<RailTypes>(UINT64_MAX);
|
||||||
for (const TemplateVehicle *u = v; u != nullptr; u = u->GetNextUnit()) {
|
for (const TemplateVehicle *u = v; u != nullptr; u = u->GetNextUnit()) {
|
||||||
if (!IsEngineBuildable(u->engine_type, VEH_TRAIN, u->owner)) {
|
if (!IsEngineBuildable(u->engine_type, VEH_TRAIN, u->owner)) {
|
||||||
buildable = false;
|
buildable = false;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
types &= (GetRailTypeInfo(Engine::Get(u->engine_type)->u.rail.railtype))->compatible_railtypes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Draw a notification string for chains that are not buildable */
|
/* Draw a notification string for chains that are not buildable */
|
||||||
if (!buildable) {
|
if (!buildable) {
|
||||||
DrawString(left, right - ScaleGUITrad(24), y + ScaleGUITrad(2), STR_TMPL_WARNING_VEH_UNAVAILABLE, TC_RED, SA_CENTER);
|
DrawString(left, right - ScaleGUITrad(24), y + ScaleGUITrad(2), STR_TMPL_WARNING_VEH_UNAVAILABLE, TC_RED, SA_CENTER);
|
||||||
|
} else if (types == RAILTYPES_NONE) {
|
||||||
|
DrawString(left, right - ScaleGUITrad(24), y + ScaleGUITrad(2), STR_TMPL_WARNING_VEH_NO_COMPATIBLE_RAIL_TYPE, TC_RED, SA_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw the template's length in tile-units */
|
/* Draw the template's length in tile-units */
|
||||||
|
Reference in New Issue
Block a user