TBTR: Template replacements now also apply to child groups
This commit is contained in:
@@ -6152,6 +6152,7 @@ STR_TMPL_WARNING_FREE_WAGON :{RED}Free Chain
|
|||||||
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Train not buildable: vehicle unavailable!
|
STR_TMPL_WARNING_VEH_UNAVAILABLE :{RED}Train not buildable: vehicle unavailable!
|
||||||
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_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}
|
STR_TMPL_GROUP_NUM_TRAINS :{BLACK}{NUM}
|
||||||
STR_TMPL_CREATEGUI_TITLE :{WHITE}Create/Edit Template Vehicle
|
STR_TMPL_CREATEGUI_TITLE :{WHITE}Create/Edit Template Vehicle
|
||||||
STR_TMPL_MAINGUI_DEFINEDGROUPS :{BLACK}Defined Groups for Company
|
STR_TMPL_MAINGUI_DEFINEDGROUPS :{BLACK}Defined Groups for Company
|
||||||
|
@@ -602,11 +602,14 @@ public:
|
|||||||
StringID str = STR_GROUP_NAME;
|
StringID str = STR_GROUP_NAME;
|
||||||
DrawString(left + ScaleGUITrad(30 + this->indents[i] * 10), right, text_y, str, TC_BLACK);
|
DrawString(left + ScaleGUITrad(30 + this->indents[i] * 10), right, text_y, str, TC_BLACK);
|
||||||
|
|
||||||
const TemplateID tid = GetTemplateIDByGroupID(g_id);
|
const TemplateID tid = GetTemplateIDByGroupIDRecursive(g_id);
|
||||||
|
const TemplateID tid_self = GetTemplateIDByGroupID(g_id);
|
||||||
|
|
||||||
/* Draw the template in use for this group, if there is one */
|
/* Draw the template in use for this group, if there is one */
|
||||||
short template_in_use = FindTemplateIndex(tid);
|
short template_in_use = FindTemplateIndex(tid);
|
||||||
if (template_in_use >= 0) {
|
if (tid != INVALID_TEMPLATE && tid_self == INVALID_TEMPLATE) {
|
||||||
|
DrawString (left, right, text_y, STR_TMP_TEMPLATE_FROM_PARENT_GROUP, TC_SILVER, SA_HOR_CENTER);
|
||||||
|
} else if (template_in_use >= 0) {
|
||||||
SetDParam(0, template_in_use);
|
SetDParam(0, template_in_use);
|
||||||
DrawString (left, right, text_y, STR_TMPL_GROUP_USES_TEMPLATE, TC_BLACK, SA_HOR_CENTER);
|
DrawString (left, right, text_y, STR_TMPL_GROUP_USES_TEMPLATE, TC_BLACK, SA_HOR_CENTER);
|
||||||
} else if (tid != INVALID_TEMPLATE) { /* If there isn't a template applied from the current group, check if there is one for another rail type */
|
} else if (tid != INVALID_TEMPLATE) { /* If there isn't a template applied from the current group, check if there is one for another rail type */
|
||||||
|
@@ -159,6 +159,18 @@ TemplateID GetTemplateIDByGroupID(GroupID gid)
|
|||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TemplateID GetTemplateIDByGroupIDRecursive(GroupID gid)
|
||||||
|
{
|
||||||
|
while (gid != INVALID_GROUP) {
|
||||||
|
auto iter = _template_replacement_index.find(gid);
|
||||||
|
if (iter != _template_replacement_index.end()) return iter->second;
|
||||||
|
const Group *g = Group::GetIfValid(gid);
|
||||||
|
if (g == nullptr) break;
|
||||||
|
gid = Group::Get(gid)->parent;
|
||||||
|
}
|
||||||
|
return INVALID_TEMPLATE;
|
||||||
|
}
|
||||||
|
|
||||||
bool IssueTemplateReplacement(GroupID gid, TemplateID tid)
|
bool IssueTemplateReplacement(GroupID gid, TemplateID tid)
|
||||||
{
|
{
|
||||||
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
|
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
|
||||||
|
@@ -201,6 +201,7 @@ struct TemplateReplacement : TemplateReplacementPool::PoolItem<&_template_replac
|
|||||||
|
|
||||||
TemplateReplacement* GetTemplateReplacementByGroupID(GroupID);
|
TemplateReplacement* GetTemplateReplacementByGroupID(GroupID);
|
||||||
TemplateID GetTemplateIDByGroupID(GroupID);
|
TemplateID GetTemplateIDByGroupID(GroupID);
|
||||||
|
TemplateID GetTemplateIDByGroupIDRecursive(GroupID);
|
||||||
bool IssueTemplateReplacement(GroupID, TemplateID);
|
bool IssueTemplateReplacement(GroupID, TemplateID);
|
||||||
|
|
||||||
short DeleteTemplateReplacementsByGroupID(GroupID);
|
short DeleteTemplateReplacementsByGroupID(GroupID);
|
||||||
|
@@ -208,6 +208,12 @@ TemplateVehicle* GetTemplateVehicleByGroupID(GroupID gid) {
|
|||||||
return tid != INVALID_TEMPLATE ? TemplateVehicle::GetIfValid(tid) : nullptr;
|
return tid != INVALID_TEMPLATE ? TemplateVehicle::GetIfValid(tid) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TemplateVehicle* GetTemplateVehicleByGroupIDRecursive(GroupID gid) {
|
||||||
|
if (gid >= NEW_GROUP) return nullptr;
|
||||||
|
const TemplateID tid = GetTemplateIDByGroupIDRecursive(gid);
|
||||||
|
return tid != INVALID_TEMPLATE ? TemplateVehicle::GetIfValid(tid) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check a template consist whether it contains any engine of the given railtype
|
* Check a template consist whether it contains any engine of the given railtype
|
||||||
*/
|
*/
|
||||||
|
@@ -38,6 +38,7 @@ void tbtr_debug_pvt(const Train*);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TemplateVehicle* GetTemplateVehicleByGroupID(GroupID);
|
TemplateVehicle* GetTemplateVehicleByGroupID(GroupID);
|
||||||
|
TemplateVehicle* GetTemplateVehicleByGroupIDRecursive(GroupID);
|
||||||
bool ChainContainsVehicle(Train*, Train*);
|
bool ChainContainsVehicle(Train*, Train*);
|
||||||
Train* ChainContainsEngine(EngineID, Train*);
|
Train* ChainContainsEngine(EngineID, Train*);
|
||||||
Train* DepotContainsEngine(TileIndex, EngineID, Train*);
|
Train* DepotContainsEngine(TileIndex, EngineID, Train*);
|
||||||
|
@@ -5494,7 +5494,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
Train *new_chain = nullptr;
|
Train *new_chain = nullptr;
|
||||||
Train *remainder_chain = nullptr;
|
Train *remainder_chain = nullptr;
|
||||||
Train *tmp_chain = nullptr;
|
Train *tmp_chain = nullptr;
|
||||||
TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id);
|
TemplateVehicle *tv = GetTemplateVehicleByGroupIDRecursive(incoming->group_id);
|
||||||
if (tv == nullptr) {
|
if (tv == nullptr) {
|
||||||
if (leaveDepot) incoming->vehstatus &= ~VS_STOPPED;
|
if (leaveDepot) incoming->vehstatus &= ~VS_STOPPED;
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
@@ -248,7 +248,7 @@ bool Vehicle::NeedsServicing() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this->type == VEH_TRAIN) {
|
if (this->type == VEH_TRAIN) {
|
||||||
TemplateVehicle *tv = GetTemplateVehicleByGroupID(this->group_id);
|
TemplateVehicle *tv = GetTemplateVehicleByGroupIDRecursive(this->group_id);
|
||||||
if (tv != nullptr) {
|
if (tv != nullptr) {
|
||||||
if (tv->IsReplaceOldOnly() && !this->NeedsAutorenewing(c, false)) return false;
|
if (tv->IsReplaceOldOnly() && !this->NeedsAutorenewing(c, false)) return false;
|
||||||
Money needed_money = c->settings.engine_renew_money;
|
Money needed_money = c->settings.engine_renew_money;
|
||||||
@@ -1092,7 +1092,7 @@ void Vehicle::PreCleanPool()
|
|||||||
void VehicleEnteredDepotThisTick(Vehicle *v)
|
void VehicleEnteredDepotThisTick(Vehicle *v)
|
||||||
{
|
{
|
||||||
/* Template Replacement Setup stuff */
|
/* Template Replacement Setup stuff */
|
||||||
if (GetTemplateIDByGroupID(v->group_id) != INVALID_TEMPLATE) {
|
if (GetTemplateIDByGroupIDRecursive(v->group_id) != INVALID_TEMPLATE) {
|
||||||
/* Vehicle should stop in the depot if it was in 'stopping' state */
|
/* Vehicle should stop in the depot if it was in 'stopping' state */
|
||||||
_vehicles_to_templatereplace.insert(v->index);
|
_vehicles_to_templatereplace.insert(v->index);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user