Initial whitespace, formatting, file headers and NULL usage fixes.
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "vehicle_gui_base.h"
|
#include "vehicle_gui_base.h"
|
||||||
#include "core/geometry_func.hpp"
|
#include "core/geometry_func.hpp"
|
||||||
#include "company_base.h"
|
#include "company_base.h"
|
||||||
|
#include "tbtr_template_gui_main.h"
|
||||||
|
|
||||||
#include "widgets/group_widget.h"
|
#include "widgets/group_widget.h"
|
||||||
|
|
||||||
@@ -34,8 +35,6 @@
|
|||||||
|
|
||||||
static const int LEVEL_WIDTH = 10; ///< Indenting width of a sub-group in pixels
|
static const int LEVEL_WIDTH = 10; ///< Indenting width of a sub-group in pixels
|
||||||
|
|
||||||
#include "tbtr_template_gui_main.h"
|
|
||||||
|
|
||||||
typedef GUIList<const Group*> GUIGroupList;
|
typedef GUIList<const Group*> GUIGroupList;
|
||||||
|
|
||||||
static const NWidgetPart _nested_group_widgets[] = {
|
static const NWidgetPart _nested_group_widgets[] = {
|
||||||
@@ -787,8 +786,9 @@ public:
|
|||||||
|
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case ADI_TEMPLATE_REPLACE: // TemplateReplace Window
|
case ADI_TEMPLATE_REPLACE: // TemplateReplace Window
|
||||||
if ( vli.vtype == VEH_TRAIN )
|
if (vli.vtype == VEH_TRAIN) {
|
||||||
ShowTemplateReplaceWindow(this->unitnumber_digits, this->resize.step_height);
|
ShowTemplateReplaceWindow(this->unitnumber_digits, this->resize.step_height);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ADI_REPLACE: // Replace window
|
case ADI_REPLACE: // Replace window
|
||||||
ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype);
|
ShowReplaceGroupVehicleWindow(this->vli.index, this->vli.vtype);
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_gui_create.cpp Template-based train replacement: template creation GUI. */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#include "gfx_func.h"
|
#include "gfx_func.h"
|
||||||
@@ -29,12 +40,13 @@
|
|||||||
#include "order_backup.h"
|
#include "order_backup.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include "company_base.h"
|
#include "company_base.h"
|
||||||
|
#include "train.h"
|
||||||
|
|
||||||
#include "tbtr_template_gui_create.h"
|
#include "tbtr_template_gui_create.h"
|
||||||
#include "tbtr_template_vehicle.h"
|
#include "tbtr_template_vehicle.h"
|
||||||
#include "tbtr_template_vehicle_func.h"
|
#include "tbtr_template_vehicle_func.h"
|
||||||
|
|
||||||
#include "train.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
class TemplateReplaceWindow;
|
class TemplateReplaceWindow;
|
||||||
|
|
||||||
@@ -87,7 +99,7 @@ static WindowDesc _template_create_window_desc(
|
|||||||
"template create window", // const char* ini_key
|
"template create window", // const char* ini_key
|
||||||
456, 100, // window size
|
456, 100, // window size
|
||||||
WC_CREATE_TEMPLATE, // window class
|
WC_CREATE_TEMPLATE, // window class
|
||||||
WC_NONE, // parent window class
|
WC_TEMPLATEGUI_MAIN, // parent window class
|
||||||
WDF_CONSTRUCTION, // window flags
|
WDF_CONSTRUCTION, // window flags
|
||||||
_widgets, lengthof(_widgets) // widgets + num widgets
|
_widgets, lengthof(_widgets) // widgets + num widgets
|
||||||
);
|
);
|
||||||
@@ -107,7 +119,8 @@ static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Veh
|
|||||||
|
|
||||||
if (wagon == v) return;
|
if (wagon == v) return;
|
||||||
|
|
||||||
DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20 | 1 << 21, wagon == NULL ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE), CcVirtualTrainWaggonsMoved);
|
DoCommandP(v->tile, v->index | ((_ctrl_pressed ? 1 : 0) << 20) | (1 << 21) , wagon == NULL ? INVALID_VEHICLE : wagon->index,
|
||||||
|
CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE), CcVirtualTrainWaggonsMoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TemplateCreateWindow : public Window {
|
class TemplateCreateWindow : public Window {
|
||||||
@@ -142,8 +155,7 @@ public:
|
|||||||
virtualTrainChangedNotice = false;
|
virtualTrainChangedNotice = false;
|
||||||
this->editTemplate = to_edit;
|
this->editTemplate = to_edit;
|
||||||
|
|
||||||
if (to_edit) editMode = true;
|
editMode = (to_edit != NULL);
|
||||||
else editMode = false;
|
|
||||||
|
|
||||||
this->sel = INVALID_VEHICLE;
|
this->sel = INVALID_VEHICLE;
|
||||||
this->vehicle_over = INVALID_VEHICLE;
|
this->vehicle_over = INVALID_VEHICLE;
|
||||||
@@ -157,9 +169,9 @@ public:
|
|||||||
|
|
||||||
~TemplateCreateWindow()
|
~TemplateCreateWindow()
|
||||||
{
|
{
|
||||||
if (virtual_train != nullptr) {
|
if (virtual_train != NULL) {
|
||||||
DoCommandP(0, virtual_train->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
|
DoCommandP(0, virtual_train->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
|
||||||
virtual_train = nullptr;
|
virtual_train = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowClassesDirty(WC_TRAINS_LIST);
|
SetWindowClassesDirty(WC_TRAINS_LIST);
|
||||||
@@ -167,12 +179,11 @@ public:
|
|||||||
/* more cleanup */
|
/* more cleanup */
|
||||||
*createWindowOpen = false;
|
*createWindowOpen = false;
|
||||||
DeleteWindowById(WC_BUILD_VIRTUAL_TRAIN, this->window_number);
|
DeleteWindowById(WC_BUILD_VIRTUAL_TRAIN, this->window_number);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVirtualTrain(Train* const train)
|
void SetVirtualTrain(Train* const train)
|
||||||
{
|
{
|
||||||
if (virtual_train != nullptr) {
|
if (virtual_train != NULL) {
|
||||||
DoCommandP(0, virtual_train->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
|
DoCommandP(0, virtual_train->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,19 +221,18 @@ public:
|
|||||||
this->SetWidgetDirty(TCW_CLONE);
|
this->SetWidgetDirty(TCW_CLONE);
|
||||||
this->ToggleWidgetLoweredState(TCW_CLONE);
|
this->ToggleWidgetLoweredState(TCW_CLONE);
|
||||||
if (this->IsWidgetLowered(TCW_CLONE)) {
|
if (this->IsWidgetLowered(TCW_CLONE)) {
|
||||||
static const CursorID clone_icon = SPR_CURSOR_CLONE_TRAIN;
|
SetObjectToPlaceWnd(SPR_CURSOR_CLONE_TRAIN, PAL_NONE, HT_VEHICLE, this);
|
||||||
SetObjectToPlaceWnd(clone_icon, PAL_NONE, HT_VEHICLE, this);
|
|
||||||
} else {
|
} else {
|
||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TCW_OK: {
|
case TCW_OK: {
|
||||||
uint32 templateIndex = (editTemplate != nullptr) ? editTemplate->index : INVALID_VEHICLE;
|
uint32 templateIndex = (editTemplate != NULL) ? editTemplate->index : INVALID_VEHICLE;
|
||||||
|
|
||||||
if (virtual_train != nullptr) {
|
if (virtual_train != NULL) {
|
||||||
DoCommandP(0, templateIndex, virtual_train->index, CMD_REPLACE_TEMPLATE_VEHICLE);
|
DoCommandP(0, templateIndex, virtual_train->index, CMD_REPLACE_TEMPLATE_VEHICLE);
|
||||||
virtual_train = nullptr;
|
virtual_train = NULL;
|
||||||
} else if (templateIndex != INVALID_VEHICLE) {
|
} else if (templateIndex != INVALID_VEHICLE) {
|
||||||
DoCommandP(0, templateIndex, 0, CMD_DELETE_TEMPLATE_VEHICLE);
|
DoCommandP(0, templateIndex, 0, CMD_DELETE_TEMPLATE_VEHICLE);
|
||||||
}
|
}
|
||||||
@@ -243,9 +253,9 @@ public:
|
|||||||
virtual bool OnVehicleSelect(const Vehicle *v)
|
virtual bool OnVehicleSelect(const Vehicle *v)
|
||||||
{
|
{
|
||||||
// throw away the current virtual train
|
// throw away the current virtual train
|
||||||
if (virtual_train != nullptr) {
|
if (virtual_train != NULL) {
|
||||||
DoCommandP(0, virtual_train->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
|
DoCommandP(0, virtual_train->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
|
||||||
virtual_train = nullptr;
|
virtual_train = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a new one
|
// create a new one
|
||||||
@@ -287,14 +297,14 @@ public:
|
|||||||
DrawString(8, r.right, 4 - this->vscroll->GetPosition(), STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE);
|
DrawString(8, r.right, 4 - this->vscroll->GetPosition(), STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE);
|
||||||
/* Draw cargo summary */
|
/* Draw cargo summary */
|
||||||
CargoArray cargo_caps;
|
CargoArray cargo_caps;
|
||||||
for ( const Train *tmp=this->virtual_train; tmp; tmp=tmp->Next() )
|
for (const Train *tmp = this->virtual_train; tmp != NULL; tmp = tmp->Next()) {
|
||||||
cargo_caps[tmp->cargo_type] += tmp->cargo_cap;
|
cargo_caps[tmp->cargo_type] += tmp->cargo_cap;
|
||||||
|
}
|
||||||
int y = 30 - this->vscroll->GetPosition();
|
int y = 30 - this->vscroll->GetPosition();
|
||||||
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
||||||
if (cargo_caps[i] > 0) {
|
if (cargo_caps[i] > 0) {
|
||||||
SetDParam(0, i);
|
SetDParam(0, i);
|
||||||
SetDParam(1, cargo_caps[i]);
|
SetDParam(1, cargo_caps[i]);
|
||||||
SetDParam(2, _settings_game.vehicle.freight_trains);
|
|
||||||
DrawString(8, r.right, y, STR_TMPL_CARGO_SUMMARY, TC_LIGHT_BLUE, SA_LEFT);
|
DrawString(8, r.right, y, STR_TMPL_CARGO_SUMMARY, TC_LIGHT_BLUE, SA_LEFT);
|
||||||
y += this->line_height / 3;
|
y += this->line_height / 3;
|
||||||
}
|
}
|
||||||
@@ -308,6 +318,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnTick()
|
virtual void OnTick()
|
||||||
{
|
{
|
||||||
if (virtualTrainChangedNotice) {
|
if (virtualTrainChangedNotice) {
|
||||||
@@ -315,6 +326,7 @@ public:
|
|||||||
virtualTrainChangedNotice = false;
|
virtualTrainChangedNotice = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnDragDrop(Point pt, int widget)
|
virtual void OnDragDrop(Point pt, int widget)
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
@@ -344,10 +356,11 @@ public:
|
|||||||
|
|
||||||
Train* train_to_delete = Train::Get(this->sel);
|
Train* train_to_delete = Train::Get(this->sel);
|
||||||
|
|
||||||
if (virtual_train == train_to_delete)
|
if (virtual_train == train_to_delete) {
|
||||||
virtual_train = (_ctrl_pressed) ? nullptr : virtual_train->GetNextUnit();
|
virtual_train = (_ctrl_pressed) ? NULL : virtual_train->GetNextUnit();
|
||||||
|
}
|
||||||
|
|
||||||
DoCommandP(0, this->sel | sell_cmd << 20 | 1 << 21, 0, GetCmdSellVeh(VEH_TRAIN));
|
DoCommandP(0, this->sel | (sell_cmd << 20) | (1 << 21), 0, GetCmdSellVeh(VEH_TRAIN));
|
||||||
|
|
||||||
this->sel = INVALID_VEHICLE;
|
this->sel = INVALID_VEHICLE;
|
||||||
|
|
||||||
@@ -357,6 +370,7 @@ public:
|
|||||||
default:
|
default:
|
||||||
this->sel = INVALID_VEHICLE;
|
this->sel = INVALID_VEHICLE;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
_cursor.vehchain = false;
|
_cursor.vehchain = false;
|
||||||
this->sel = INVALID_VEHICLE;
|
this->sel = INVALID_VEHICLE;
|
||||||
@@ -408,8 +422,8 @@ public:
|
|||||||
uint height = 30;
|
uint height = 30;
|
||||||
CargoArray cargo_caps;
|
CargoArray cargo_caps;
|
||||||
|
|
||||||
if (virtual_train != nullptr) {
|
if (virtual_train != NULL) {
|
||||||
for (Train *train = virtual_train; train != nullptr; train = train->Next()) {
|
for (Train *train = virtual_train; train != NULL; train = train->Next()) {
|
||||||
width += train->GetDisplayImageWidth();
|
width += train->GetDisplayImageWidth();
|
||||||
cargo_caps[train->cargo_type] += train->cargo_cap;
|
cargo_caps[train->cargo_type] += train->cargo_cap;
|
||||||
}
|
}
|
||||||
@@ -429,6 +443,7 @@ public:
|
|||||||
|
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GetDepotVehiclePtData {
|
struct GetDepotVehiclePtData {
|
||||||
const Vehicle *head;
|
const Vehicle *head;
|
||||||
const Vehicle *wagon;
|
const Vehicle *wagon;
|
||||||
@@ -461,7 +476,6 @@ public:
|
|||||||
d->head = d->wagon = v;
|
d->head = d->wagon = v;
|
||||||
|
|
||||||
if (xm <= this->header_width) {
|
if (xm <= this->header_width) {
|
||||||
|
|
||||||
if (wagon) return MODE_ERROR;
|
if (wagon) return MODE_ERROR;
|
||||||
|
|
||||||
return MODE_SHOW_VEHICLE;
|
return MODE_SHOW_VEHICLE;
|
||||||
|
@@ -1,4 +1,13 @@
|
|||||||
// template creation gui
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_gui_create.h Template-based train replacement: template creation GUI header. */
|
||||||
|
|
||||||
#ifndef TEMPLATE_GUI_CREATE
|
#ifndef TEMPLATE_GUI_CREATE
|
||||||
#define TEMPLATE_GUI_CREATE
|
#define TEMPLATE_GUI_CREATE
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* $Id: build_vehicle_gui.cpp 23792 2012-01-12 19:23:00Z yexo $ */
|
/* $Id$ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of OpenTTD.
|
* This file is part of OpenTTD.
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @file build_vehicle_gui.cpp GUI for building vehicles. */
|
/** @file tbtr_template_gui_create_virtualtrain.cpp Template-based train replacement: template creation vehicle build GUI. */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "engine_base.h"
|
#include "engine_base.h"
|
||||||
@@ -30,14 +30,14 @@
|
|||||||
#include "engine_gui.h"
|
#include "engine_gui.h"
|
||||||
#include "cargotype.h"
|
#include "cargotype.h"
|
||||||
#include "core/geometry_func.hpp"
|
#include "core/geometry_func.hpp"
|
||||||
|
#include "vehicle_gui.h"
|
||||||
|
#include "tbtr_template_gui_create_virtualtrain.h"
|
||||||
|
|
||||||
#include "widgets/build_vehicle_widget.h"
|
#include "widgets/build_vehicle_widget.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
#include "tbtr_template_gui_create_virtualtrain.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
#include "vehicle_gui.h"
|
|
||||||
|
|
||||||
static const NWidgetPart _nested_build_vehicle_widgets[] = {
|
static const NWidgetPart _nested_build_vehicle_widgets[] = {
|
||||||
NWidget(NWID_HORIZONTAL),
|
NWidget(NWID_HORIZONTAL),
|
||||||
@@ -431,7 +431,7 @@ struct BuildVirtualTrainWindow : Window {
|
|||||||
BuildVirtualTrainWindow(WindowDesc *desc, Train **vt, bool *notice) : Window(desc)
|
BuildVirtualTrainWindow(WindowDesc *desc, Train **vt, bool *notice) : Window(desc)
|
||||||
{
|
{
|
||||||
this->vehicle_type = VEH_TRAIN;
|
this->vehicle_type = VEH_TRAIN;
|
||||||
this->window_number = 0;//tile == INVALID_TILE ? (int)type : tile;
|
this->window_number = 0;
|
||||||
|
|
||||||
this->sel_engine = INVALID_ENGINE;
|
this->sel_engine = INVALID_ENGINE;
|
||||||
|
|
||||||
@@ -688,6 +688,7 @@ struct BuildVirtualTrainWindow : Window {
|
|||||||
|
|
||||||
case WID_BV_CARGO_FILTER_DROPDOWN:
|
case WID_BV_CARGO_FILTER_DROPDOWN:
|
||||||
SetDParam(0, this->cargo_filter_texts[this->cargo_filter_criteria]);
|
SetDParam(0, this->cargo_filter_texts[this->cargo_filter_criteria]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,7 +718,9 @@ struct BuildVirtualTrainWindow : Window {
|
|||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_BV_LIST:
|
case WID_BV_LIST:
|
||||||
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
|
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
|
||||||
|
&this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(),
|
||||||
|
this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_BV_SORT_ASCENDING_DESCENDING:
|
case WID_BV_SORT_ASCENDING_DESCENDING:
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_gui_create_virtualtrain.cpp Template-based train replacement: template creation vehicle build GUI header. */
|
||||||
|
|
||||||
#ifndef BUILD_VIRTUAL_TRAIN_GUI
|
#ifndef BUILD_VIRTUAL_TRAIN_GUI
|
||||||
#define BUILD_VIRTUAL_TRAIN_GUI
|
#define BUILD_VIRTUAL_TRAIN_GUI
|
||||||
|
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
// mygui.c
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
//#include "tbtr_mygui.h"
|
/** @file tbtr_template_gui_main.cpp Template-based train replacement: main GUI. */
|
||||||
#include <iostream>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "command_func.h"
|
#include "command_func.h"
|
||||||
@@ -47,7 +50,11 @@
|
|||||||
#include "tbtr_template_gui_main.h"
|
#include "tbtr_template_gui_main.h"
|
||||||
#include "tbtr_template_gui_create.h"
|
#include "tbtr_template_gui_create.h"
|
||||||
#include "tbtr_template_vehicle.h"
|
#include "tbtr_template_vehicle.h"
|
||||||
//#include "tbtr_template_vehicle_func.h"
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
|
||||||
typedef GUIList<const Group*> GUIGroupList;
|
typedef GUIList<const Group*> GUIGroupList;
|
||||||
@@ -333,7 +340,7 @@ public:
|
|||||||
short count_columns = 0;
|
short count_columns = 0;
|
||||||
short max_columns = 2;
|
short max_columns = 2;
|
||||||
|
|
||||||
for ( ; tmp; tmp=tmp->Next()) {
|
for (; tmp != NULL; tmp = tmp->Next()) {
|
||||||
cargo_caps[tmp->cargo_type] += tmp->cargo_cap;
|
cargo_caps[tmp->cargo_type] += tmp->cargo_cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,8 +434,7 @@ public:
|
|||||||
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_TOP_MATRIX]->pos_y) / (this->line_height / 2) ) + this->vscroll[0]->GetPosition();
|
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_TOP_MATRIX]->pos_y) / (this->line_height / 2) ) + this->vscroll[0]->GetPosition();
|
||||||
if (newindex == this->selected_group_index || newindex >= this->groups.Length()) {
|
if (newindex == this->selected_group_index || newindex >= this->groups.Length()) {
|
||||||
this->selected_group_index = -1;
|
this->selected_group_index = -1;
|
||||||
}
|
} else if (newindex < this->groups.Length()) {
|
||||||
else if ((newindex >= 0) && (newindex < this->groups.Length())) {
|
|
||||||
this->selected_group_index = newindex;
|
this->selected_group_index = newindex;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -437,8 +443,7 @@ public:
|
|||||||
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_BOTTOM_MATRIX]->pos_y) / this->line_height) + this->vscroll[1]->GetPosition();
|
uint16 newindex = (uint16)((pt.y - this->nested_array[TRW_WIDGET_BOTTOM_MATRIX]->pos_y) / this->line_height) + this->vscroll[1]->GetPosition();
|
||||||
if (newindex == this->selected_template_index || newindex >= templates.Length()) {
|
if (newindex == this->selected_template_index || newindex >= templates.Length()) {
|
||||||
this->selected_template_index = -1;
|
this->selected_template_index = -1;
|
||||||
}
|
} else if (newindex < templates.Length()) {
|
||||||
else if ((newindex >= 0) && (newindex < templates.Length())) {
|
|
||||||
this->selected_template_index = newindex;
|
this->selected_template_index = newindex;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -454,8 +459,9 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TRW_WIDGET_STOP:
|
case TRW_WIDGET_STOP:
|
||||||
if ((this->selected_group_index < 0) || (this->selected_group_index >= (short)this->groups.Length()))
|
if ((this->selected_group_index < 0) || (this->selected_group_index >= (short)this->groups.Length())) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int current_group_index = (this->groups)[this->selected_group_index]->index;
|
int current_group_index = (this->groups)[this->selected_group_index]->index;
|
||||||
|
|
||||||
@@ -527,12 +533,13 @@ public:
|
|||||||
short FindTemplateIndexForGroup(short gid) const
|
short FindTemplateIndexForGroup(short gid) const
|
||||||
{
|
{
|
||||||
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
|
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
|
||||||
if ( !tr )
|
if (!tr) return -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
for ( uint32 i=0; i<this->templates.Length(); ++i )
|
for (uint32 i = 0; i < this->templates.Length(); ++i) {
|
||||||
if ( templates[i]->index == tr->sel_template )
|
if (templates[i]->index == tr->sel_template) {
|
||||||
return i;
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,9 +629,7 @@ public:
|
|||||||
if (template_in_use >= 0) {
|
if (template_in_use >= 0) {
|
||||||
SetDParam(0, template_in_use);
|
SetDParam(0, template_in_use);
|
||||||
DrawString (left, right, y + 2, STR_TMPL_GROUP_USES_TEMPLATE, TC_BLACK, SA_HOR_CENTER);
|
DrawString (left, right, y + 2, STR_TMPL_GROUP_USES_TEMPLATE, TC_BLACK, SA_HOR_CENTER);
|
||||||
}
|
} else if (GetTemplateReplacementByGroupID(g_id)) { /* If there isn't a template applied from the current group, check if there is one for another rail type */
|
||||||
/* If there isn't a template applied from the current group, check if there is one for another rail type */
|
|
||||||
else if ( GetTemplateReplacementByGroupID(g_id) ) {
|
|
||||||
DrawString (left, right, y + 2, STR_TMPL_TMPLRPL_EX_DIFF_RAILTYPE, TC_SILVER, SA_HOR_CENTER);
|
DrawString (left, right, y + 2, STR_TMPL_TMPLRPL_EX_DIFF_RAILTYPE, TC_SILVER, SA_HOR_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,8 +643,11 @@ public:
|
|||||||
if (num_trains) color = TC_BLACK;
|
if (num_trains) color = TC_BLACK;
|
||||||
DrawString(left, right - 16, y + 2, STR_TMPL_NUM_TRAINS_NEED_RPL, color, SA_RIGHT);
|
DrawString(left, right - 16, y + 2, STR_TMPL_NUM_TRAINS_NEED_RPL, color, SA_RIGHT);
|
||||||
// Draw number
|
// Draw number
|
||||||
if ( num_trains ) color = TC_ORANGE;
|
if (num_trains ) {
|
||||||
else color = TC_GREY;
|
color = TC_ORANGE;
|
||||||
|
} else {
|
||||||
|
color = TC_GREY;
|
||||||
|
}
|
||||||
SetDParam(0, num_trains);
|
SetDParam(0, num_trains);
|
||||||
DrawString(left, right - 4, y + 2, STR_JUST_INT, color, SA_RIGHT);
|
DrawString(left, right - 4, y + 2, STR_JUST_INT, color, SA_RIGHT);
|
||||||
}
|
}
|
||||||
@@ -659,7 +667,6 @@ public:
|
|||||||
|
|
||||||
const TemplateVehicle *v;
|
const TemplateVehicle *v;
|
||||||
for (uint i = draw_vscroll->GetPosition(); i < max; ++i) {
|
for (uint i = draw_vscroll->GetPosition(); i < max; ++i) {
|
||||||
|
|
||||||
v = (this->templates)[i];
|
v = (this->templates)[i];
|
||||||
|
|
||||||
/* Fill the background of the current cell in a darker tone for the currently selected template */
|
/* Fill the background of the current cell in a darker tone for the currently selected template */
|
||||||
@@ -695,14 +702,14 @@ public:
|
|||||||
|
|
||||||
/* Draw information about template configuration settings */
|
/* Draw information about template configuration settings */
|
||||||
TextColour color;
|
TextColour color;
|
||||||
if ( v->IsSetReuseDepotVehicles() ) color = TC_LIGHT_BLUE;
|
|
||||||
else color = TC_GREY;
|
color = v->IsSetReuseDepotVehicles() ? TC_LIGHT_BLUE : TC_GREY;
|
||||||
DrawString(left + 300, right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2, STR_TMPL_CONFIG_USEDEPOT, color, SA_LEFT);
|
DrawString(left + 300, right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2, STR_TMPL_CONFIG_USEDEPOT, color, SA_LEFT);
|
||||||
if ( v->IsSetKeepRemainingVehicles() ) color = TC_LIGHT_BLUE;
|
|
||||||
else color = TC_GREY;
|
color = v->IsSetKeepRemainingVehicles() ? TC_LIGHT_BLUE : TC_GREY;
|
||||||
DrawString(left + 400, right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2, STR_TMPL_CONFIG_KEEPREMAINDERS, color, SA_LEFT);
|
DrawString(left + 400, right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2, STR_TMPL_CONFIG_KEEPREMAINDERS, color, SA_LEFT);
|
||||||
if ( v->IsSetRefitAsTemplate() ) color = TC_LIGHT_BLUE;
|
|
||||||
else color = TC_GREY;
|
color = v->IsSetRefitAsTemplate() ? TC_LIGHT_BLUE : TC_GREY;
|
||||||
DrawString(left + 500, right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2, STR_TMPL_CONFIG_REFIT, color, SA_LEFT);
|
DrawString(left + 500, right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 2, STR_TMPL_CONFIG_REFIT, color, SA_LEFT);
|
||||||
|
|
||||||
y += line_height;
|
y += line_height;
|
||||||
@@ -711,13 +718,15 @@ public:
|
|||||||
|
|
||||||
void DrawTemplateInfo(int line_height, const Rect &r) const
|
void DrawTemplateInfo(int line_height, const Rect &r) const
|
||||||
{
|
{
|
||||||
if ((this->selected_template_index < 0) || (this->selected_template_index >= (short)this->templates.Length()))
|
if ((this->selected_template_index < 0) || (this->selected_template_index >= (short)this->templates.Length())) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DrawPixelInfo tmp_dpi, *old_dpi;
|
DrawPixelInfo tmp_dpi, *old_dpi;
|
||||||
|
|
||||||
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left, r.bottom - r.top))
|
if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left, r.bottom - r.top)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
old_dpi = _cur_dpi;
|
old_dpi = _cur_dpi;
|
||||||
_cur_dpi = &tmp_dpi;
|
_cur_dpi = &tmp_dpi;
|
||||||
@@ -738,8 +747,9 @@ public:
|
|||||||
short max_columns = 2;
|
short max_columns = 2;
|
||||||
|
|
||||||
CargoArray cargo_caps;
|
CargoArray cargo_caps;
|
||||||
for ( ; tmp; tmp=tmp->Next() )
|
for (; tmp != NULL; tmp = tmp->Next()) {
|
||||||
cargo_caps[tmp->cargo_type] += tmp->cargo_cap;
|
cargo_caps[tmp->cargo_type] += tmp->cargo_cap;
|
||||||
|
}
|
||||||
int x = left;
|
int x = left;
|
||||||
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
for (CargoID i = 0; i < NUM_CARGO; ++i) {
|
||||||
if (cargo_caps[i] > 0) {
|
if (cargo_caps[i] > 0) {
|
||||||
@@ -764,4 +774,3 @@ void ShowTemplateReplaceWindow(byte dig, int step_h)
|
|||||||
{
|
{
|
||||||
new TemplateReplaceWindow(&_replace_rail_vehicle_desc, dig, step_h);
|
new TemplateReplaceWindow(&_replace_rail_vehicle_desc, dig, step_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,13 @@
|
|||||||
// _template_gui_main.h
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_gui_main.h Template-based train replacement: main GUI header. */
|
||||||
|
|
||||||
#ifndef TEMPLATE_GUI_H
|
#ifndef TEMPLATE_GUI_H
|
||||||
#define TEMPLATE_GUI_H
|
#define TEMPLATE_GUI_H
|
||||||
|
@@ -1,9 +1,38 @@
|
|||||||
// replace all gui impl
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_gui_replaceall.cpp Template-based train replacement: replace all GUI. */
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "window_gui.h"
|
||||||
|
#include "window_func.h"
|
||||||
|
|
||||||
|
#include "company_func.h"
|
||||||
|
#include "engine_base.h"
|
||||||
|
#include "engine_func.h"
|
||||||
|
#include "engine_gui.h"
|
||||||
|
#include "train.h"
|
||||||
|
#include "strings_func.h"
|
||||||
|
#include "vehicle_base.h"
|
||||||
|
#include "vehicle_func.h"
|
||||||
|
|
||||||
|
#include "tbtr_template_vehicle.h"
|
||||||
|
#include "tbtr_template_vehicle_func.h"
|
||||||
|
|
||||||
|
#include "core/math_func.hpp"
|
||||||
|
#include "table/strings.h"
|
||||||
#include "tbtr_template_gui_replaceall.h"
|
#include "tbtr_template_gui_replaceall.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "safeguards.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A wrapper which contains a virtual train and additional info of the template vehicle it is replacing
|
* A wrapper which contains a virtual train and additional info of the template vehicle it is replacing
|
||||||
* We will restore this additional info when creating a new template from the changed virtual train
|
* We will restore this additional info when creating a new template from the changed virtual train
|
||||||
@@ -15,9 +44,9 @@ struct VirtTrainInfo {
|
|||||||
// additional info from the template
|
// additional info from the template
|
||||||
VehicleID original_index;
|
VehicleID original_index;
|
||||||
|
|
||||||
bool reuse_depot_vehicles,
|
bool reuse_depot_vehicles;
|
||||||
keep_remaining_vehicles,
|
bool keep_remaining_vehicles;
|
||||||
refit_as_template;
|
bool refit_as_template;
|
||||||
|
|
||||||
CargoID cargo_type;
|
CargoID cargo_type;
|
||||||
byte cargo_subtype;
|
byte cargo_subtype;
|
||||||
@@ -133,19 +162,19 @@ static int CDECL TrainEnginesThenWagonsSorter(const EngineID *a, const EngineID
|
|||||||
class TemplateReplacementReplaceAllWindow : public Window {
|
class TemplateReplacementReplaceAllWindow : public Window {
|
||||||
private:
|
private:
|
||||||
uint16 line_height;
|
uint16 line_height;
|
||||||
Scrollbar *vscroll_tl,
|
Scrollbar *vscroll_tl;
|
||||||
*vscroll_tr,
|
Scrollbar *vscroll_tr;
|
||||||
*vscroll_bo;
|
Scrollbar *vscroll_bo;
|
||||||
GUIEngineList *engines_left,
|
GUIEngineList *engines_left;
|
||||||
*engines_right;
|
GUIEngineList *engines_right;
|
||||||
short selected_left,
|
short selected_left;
|
||||||
selected_right;
|
short selected_right;
|
||||||
VirtTrainList *virtualTrains;
|
VirtTrainList *virtualTrains;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TemplateReplacementReplaceAllWindow(WindowDesc *wdesc) : Window(wdesc)
|
TemplateReplacementReplaceAllWindow(WindowDesc *wdesc) : Window(wdesc)
|
||||||
{
|
{
|
||||||
this->CreateNestedTree(wdesc != nullptr);
|
this->CreateNestedTree(wdesc != NULL);
|
||||||
|
|
||||||
this->vscroll_tl = this->GetScrollbar(RPLALL_GUI_SCROLL_TL);
|
this->vscroll_tl = this->GetScrollbar(RPLALL_GUI_SCROLL_TL);
|
||||||
this->vscroll_tr = this->GetScrollbar(RPLALL_GUI_SCROLL_TR);
|
this->vscroll_tr = this->GetScrollbar(RPLALL_GUI_SCROLL_TR);
|
||||||
@@ -172,8 +201,9 @@ public:
|
|||||||
|
|
||||||
~TemplateReplacementReplaceAllWindow()
|
~TemplateReplacementReplaceAllWindow()
|
||||||
{
|
{
|
||||||
for ( uint i=0; i<this->virtualTrains->Length(); ++i )
|
for (uint i = 0; i<this->virtualTrains->Length(); ++i) {
|
||||||
delete (*this->virtualTrains)[i]->vt;
|
delete (*this->virtualTrains)[i]->vt;
|
||||||
|
}
|
||||||
SetWindowClassesDirty(WC_TEMPLATEGUI_MAIN);
|
SetWindowClassesDirty(WC_TEMPLATEGUI_MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,19 +265,21 @@ public:
|
|||||||
switch(widget) {
|
switch(widget) {
|
||||||
case RPLALL_GUI_MATRIX_TOPLEFT: {
|
case RPLALL_GUI_MATRIX_TOPLEFT: {
|
||||||
uint16 newindex = (uint16)((pt.y - this->nested_array[RPLALL_GUI_MATRIX_TOPLEFT]->pos_y) / this->line_height) + this->vscroll_tl->GetPosition();
|
uint16 newindex = (uint16)((pt.y - this->nested_array[RPLALL_GUI_MATRIX_TOPLEFT]->pos_y) / this->line_height) + this->vscroll_tl->GetPosition();
|
||||||
if ( newindex >= this->engines_left->Length() || newindex==this->selected_left )
|
if (newindex >= this->engines_left->Length() || newindex == this->selected_left) {
|
||||||
this->selected_left = -1;
|
this->selected_left = -1;
|
||||||
else
|
} else {
|
||||||
this->selected_left = newindex;
|
this->selected_left = newindex;
|
||||||
|
}
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RPLALL_GUI_MATRIX_TOPRIGHT: {
|
case RPLALL_GUI_MATRIX_TOPRIGHT: {
|
||||||
uint16 newindex = (uint16)((pt.y - this->nested_array[RPLALL_GUI_MATRIX_TOPRIGHT]->pos_y) / this->line_height) + this->vscroll_tr->GetPosition();
|
uint16 newindex = (uint16)((pt.y - this->nested_array[RPLALL_GUI_MATRIX_TOPRIGHT]->pos_y) / this->line_height) + this->vscroll_tr->GetPosition();
|
||||||
if ( newindex > this->engines_right->Length() || newindex==this->selected_right )
|
if (newindex > this->engines_right->Length() || newindex==this->selected_right) {
|
||||||
this->selected_right = -1;
|
this->selected_right = -1;
|
||||||
else
|
} else {
|
||||||
this->selected_right = newindex;
|
this->selected_right = newindex;
|
||||||
|
}
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -257,8 +289,9 @@ public:
|
|||||||
}
|
}
|
||||||
case RPLALL_GUI_BUTTON_APPLY: {
|
case RPLALL_GUI_BUTTON_APPLY: {
|
||||||
// check if we actually did anything so far, if not, applying is forbidden
|
// check if we actually did anything so far, if not, applying is forbidden
|
||||||
if ( this->virtualTrains->Length() == 0 )
|
if (this->virtualTrains->Length() == 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// first delete all current templates
|
// first delete all current templates
|
||||||
this->DeleteAllTemplateTrains();
|
this->DeleteAllTemplateTrains();
|
||||||
// then build a new list from the current virtual trains
|
// then build a new list from the current virtual trains
|
||||||
@@ -276,9 +309,10 @@ public:
|
|||||||
tv->cargo_subtype = vti->cargo_subtype;
|
tv->cargo_subtype = vti->cargo_subtype;
|
||||||
// use the original_index information to repoint the relevant TemplateReplacement if existing
|
// use the original_index information to repoint the relevant TemplateReplacement if existing
|
||||||
TemplateReplacement *tr = GetTemplateReplacementByTemplateID(vti->original_index);
|
TemplateReplacement *tr = GetTemplateReplacementByTemplateID(vti->original_index);
|
||||||
if ( tr )
|
if (tr) {
|
||||||
tr->sel_template = tv->index;
|
tr->sel_template = tv->index;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// then close this window and return to parent
|
// then close this window and return to parent
|
||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
@@ -295,11 +329,12 @@ public:
|
|||||||
const TemplateVehicle *tv;
|
const TemplateVehicle *tv;
|
||||||
FOR_ALL_TEMPLATES(tv) {
|
FOR_ALL_TEMPLATES(tv) {
|
||||||
if (tv->Prev() || tv->owner != _local_company) continue;
|
if (tv->Prev() || tv->owner != _local_company) continue;
|
||||||
for ( const TemplateVehicle *tmp=tv; tmp; tmp=tmp->GetNextUnit() ) {
|
for (const TemplateVehicle *tmp = tv; tmp != NULL; tmp = tmp->GetNextUnit()) {
|
||||||
if ( tmp->engine_type == eid )
|
if (tmp->engine_type == eid) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,10 +368,11 @@ public:
|
|||||||
TemplateVehicle *tv, *tmp;
|
TemplateVehicle *tv, *tmp;
|
||||||
FOR_ALL_TEMPLATES(tv) {
|
FOR_ALL_TEMPLATES(tv) {
|
||||||
tmp = tv;
|
tmp = tv;
|
||||||
if ( tmp->Prev()==0 && tmp->owner==this->owner )
|
if (tmp->Prev() == NULL && tmp->owner == this->owner) {
|
||||||
delete tmp;
|
delete tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GenerateIncludedTemplateList()
|
void GenerateIncludedTemplateList()
|
||||||
{
|
{
|
||||||
@@ -368,10 +404,12 @@ public:
|
|||||||
|
|
||||||
for (uint i = 0; i < this->virtualTrains->Length(); ++i) {
|
for (uint i = 0; i < this->virtualTrains->Length(); ++i) {
|
||||||
const Train *tmp = (*this->virtualTrains)[i]->vt;
|
const Train *tmp = (*this->virtualTrains)[i]->vt;
|
||||||
for ( ; tmp; tmp=tmp->Next() )
|
for (; tmp != NULL; tmp = tmp->Next()) {
|
||||||
if ( tmp->engine_type == eid )
|
if (tmp->engine_type == eid) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,25 +418,24 @@ public:
|
|||||||
// first remove all engine ids
|
// first remove all engine ids
|
||||||
for (uint i = 0; i < this->engines_left->Length(); ++i) {
|
for (uint i = 0; i < this->engines_left->Length(); ++i) {
|
||||||
EngineID entry = (*this->engines_left)[i];
|
EngineID entry = (*this->engines_left)[i];
|
||||||
if ( !VirtualTrainHasEngineID(entry) )
|
if (!VirtualTrainHasEngineID(entry)) {
|
||||||
this->engines_left->Erase(&((*this->engines_left)[i]));
|
this->engines_left->Erase(&((*this->engines_left)[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ReplaceAll()
|
void ReplaceAll()
|
||||||
{
|
{
|
||||||
|
if (this->selected_left == -1 || this->selected_right == -1) return;
|
||||||
if ( this->selected_left==-1 || this->selected_right==-1 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
EngineID eid_orig = (*this->engines_left)[this->selected_left];
|
EngineID eid_orig = (*this->engines_left)[this->selected_left];
|
||||||
EngineID eid_repl = (*this->engines_right)[this->selected_right];
|
EngineID eid_repl = (*this->engines_right)[this->selected_right];
|
||||||
|
|
||||||
if ( eid_orig == eid_repl )
|
if (eid_orig == eid_repl) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if ( this->virtualTrains->Length() == 0 )
|
if (this->virtualTrains->Length() == 0) {
|
||||||
this->GenerateVirtualTrains();
|
this->GenerateVirtualTrains();
|
||||||
|
}
|
||||||
|
|
||||||
for (uint i = 0; i < this->virtualTrains->Length(); ++i) {
|
for (uint i = 0; i < this->virtualTrains->Length(); ++i) {
|
||||||
Train *tmp = (*this->virtualTrains)[i]->vt;
|
Train *tmp = (*this->virtualTrains)[i]->vt;
|
||||||
@@ -458,7 +495,7 @@ public:
|
|||||||
this->vscroll_tr->SetCount(this->engines_right->Length());
|
this->vscroll_tr->SetCount(this->engines_right->Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawEngineList(const Rect &r, bool left) const//, GUIEngineList el, Scrollbar* sb) const
|
void DrawEngineList(const Rect &r, bool left) const
|
||||||
{
|
{
|
||||||
uint16 y = r.top;
|
uint16 y = r.top;
|
||||||
uint32 eid;
|
uint32 eid;
|
||||||
@@ -477,12 +514,12 @@ public:
|
|||||||
int maximum = min((int) sb->GetCapacity(), (int) el->Length()) + sb->GetPosition();
|
int maximum = min((int) sb->GetCapacity(), (int) el->Length()) + sb->GetPosition();
|
||||||
|
|
||||||
for (int i = sb->GetPosition(); i < maximum; ++i) {
|
for (int i = sb->GetPosition(); i < maximum; ++i) {
|
||||||
|
|
||||||
eid = (*el)[i];
|
eid = (*el)[i];
|
||||||
|
|
||||||
/* Draw a grey background rectangle if the current line is the selected one */
|
/* Draw a grey background rectangle if the current line is the selected one */
|
||||||
if ( (left && this->selected_left == i) || (!left && this->selected_right == i) )
|
if ((left && this->selected_left == i) || (!left && this->selected_right == i)) {
|
||||||
GfxFillRect(r.left, y, r.right, y + this->line_height, _colour_gradient[COLOUR_GREY][3]);
|
GfxFillRect(r.left, y, r.right, y + this->line_height, _colour_gradient[COLOUR_GREY][3]);
|
||||||
|
}
|
||||||
|
|
||||||
/* Draw a description string of the current engine */
|
/* Draw a description string of the current engine */
|
||||||
SetDParam(0, eid);
|
SetDParam(0, eid);
|
||||||
|
@@ -1,27 +1,17 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_gui_replaceall.cpp Template-based train replacement: replace all GUI header. */
|
||||||
|
|
||||||
#ifndef TMPL_RPLALL_GUI
|
#ifndef TMPL_RPLALL_GUI
|
||||||
#define TMPL_RPLALL_GUI
|
#define TMPL_RPLALL_GUI
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "window_gui.h"
|
|
||||||
#include "window_func.h"
|
|
||||||
|
|
||||||
#include "company_func.h"
|
|
||||||
#include "engine_base.h"
|
|
||||||
#include "engine_func.h"
|
|
||||||
#include "engine_gui.h"
|
|
||||||
#include "train.h"
|
|
||||||
#include "strings_func.h"
|
|
||||||
#include "vehicle_base.h"
|
|
||||||
#include "vehicle_func.h"
|
|
||||||
|
|
||||||
#include "tbtr_template_vehicle.h"
|
|
||||||
#include "tbtr_template_vehicle_func.h"
|
|
||||||
|
|
||||||
#include "core/math_func.hpp"
|
|
||||||
#include "table/strings.h"
|
|
||||||
|
|
||||||
void ShowTemplateReplaceAllGui();
|
void ShowTemplateReplaceAllGui();
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -1,3 +1,14 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_vehicle.cpp Template-based train replacement: template vehicle. */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "company_func.h"
|
#include "company_func.h"
|
||||||
#include "train.h"
|
#include "train.h"
|
||||||
@@ -24,7 +35,6 @@
|
|||||||
|
|
||||||
#include "table/train_cmd.h"
|
#include "table/train_cmd.h"
|
||||||
|
|
||||||
|
|
||||||
#include "tbtr_template_vehicle.h"
|
#include "tbtr_template_vehicle.h"
|
||||||
|
|
||||||
// since doing stuff with sprites
|
// since doing stuff with sprites
|
||||||
@@ -32,6 +42,8 @@
|
|||||||
#include "newgrf_engine.h"
|
#include "newgrf_engine.h"
|
||||||
#include "newgrf_cargo.h"
|
#include "newgrf_cargo.h"
|
||||||
|
|
||||||
|
#include "safeguards.h"
|
||||||
|
|
||||||
TemplatePool _template_pool("TemplatePool");
|
TemplatePool _template_pool("TemplatePool");
|
||||||
INSTANTIATE_POOL_METHODS(Template)
|
INSTANTIATE_POOL_METHODS(Template)
|
||||||
|
|
||||||
@@ -74,7 +86,9 @@ void TemplateVehicle::SetFirst(TemplateVehicle *v) { this->first = v; }
|
|||||||
TemplateVehicle* TemplateVehicle::GetNextUnit() const
|
TemplateVehicle* TemplateVehicle::GetNextUnit() const
|
||||||
{
|
{
|
||||||
TemplateVehicle *tv = this->Next();
|
TemplateVehicle *tv = this->Next();
|
||||||
while ( tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART) ) tv = tv->Next();
|
while (tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART)) {
|
||||||
|
tv = tv->Next();
|
||||||
|
}
|
||||||
if (tv && HasBit(tv->subtype, GVSF_MULTIHEADED) && !HasBit(tv->subtype, GVSF_ENGINE)) tv = tv->Next();
|
if (tv && HasBit(tv->subtype, GVSF_MULTIHEADED) && !HasBit(tv->subtype, GVSF_ENGINE)) tv = tv->Next();
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
@@ -82,7 +96,9 @@ TemplateVehicle* TemplateVehicle::GetNextUnit() const
|
|||||||
TemplateVehicle* TemplateVehicle::GetPrevUnit()
|
TemplateVehicle* TemplateVehicle::GetPrevUnit()
|
||||||
{
|
{
|
||||||
TemplateVehicle *tv = this->Prev();
|
TemplateVehicle *tv = this->Prev();
|
||||||
while ( tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART|GVSF_ENGINE) ) tv = tv->Prev();
|
while (tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART|GVSF_ENGINE)) {
|
||||||
|
tv = tv->Prev();
|
||||||
|
}
|
||||||
if (tv && HasBit(tv->subtype, GVSF_MULTIHEADED|GVSF_ENGINE)) tv = tv->Prev();
|
if (tv && HasBit(tv->subtype, GVSF_MULTIHEADED|GVSF_ENGINE)) tv = tv->Prev();
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
@@ -115,7 +131,10 @@ int TemplateVehicle::Length() const
|
|||||||
{
|
{
|
||||||
int l = 1;
|
int l = 1;
|
||||||
const TemplateVehicle *tmp = this;
|
const TemplateVehicle *tmp = this;
|
||||||
while ( tmp->Next() ) { tmp=tmp->Next(); l++; }
|
while (tmp->Next()) {
|
||||||
|
tmp = tmp->Next();
|
||||||
|
l++;
|
||||||
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,32 +142,33 @@ TemplateReplacement* GetTemplateReplacementByGroupID(GroupID gid)
|
|||||||
{
|
{
|
||||||
TemplateReplacement *tr;
|
TemplateReplacement *tr;
|
||||||
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
||||||
if ( tr->Group() == gid )
|
if (tr->Group() == gid) {
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID tid) {
|
TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID tid)
|
||||||
|
{
|
||||||
TemplateReplacement *tr;
|
TemplateReplacement *tr;
|
||||||
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
||||||
if ( tr->Template() == tid )
|
if (tr->Template() == tid) {
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IssueTemplateReplacement(GroupID gid, TemplateID tid) {
|
bool IssueTemplateReplacement(GroupID gid, TemplateID tid)
|
||||||
|
{
|
||||||
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
|
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
|
||||||
|
|
||||||
if (tr) {
|
if (tr) {
|
||||||
/* Then set the new TemplateVehicle and return */
|
/* Then set the new TemplateVehicle and return */
|
||||||
tr->SetTemplate(tid);
|
tr->SetTemplate(tid);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (TemplateReplacement::CanAllocateItem()) {
|
||||||
|
|
||||||
else if ( TemplateReplacement::CanAllocateItem() ) {
|
|
||||||
tr = new TemplateReplacement(gid, tid);
|
tr = new TemplateReplacement(gid, tid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -161,9 +181,10 @@ short TemplateVehicle::NumGroupsUsingTemplate() const
|
|||||||
short amount = 0;
|
short amount = 0;
|
||||||
const TemplateReplacement *tr;
|
const TemplateReplacement *tr;
|
||||||
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
||||||
if ( tr->sel_template == this->index )
|
if (tr->sel_template == this->index) {
|
||||||
amount++;
|
amount++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,9 +192,11 @@ short TemplateVehicle::CountEnginesInChain()
|
|||||||
{
|
{
|
||||||
TemplateVehicle *tv = this->first;
|
TemplateVehicle *tv = this->first;
|
||||||
short count = 0;
|
short count = 0;
|
||||||
for ( ; tv; tv=tv->GetNextUnit() )
|
for (; tv != NULL; tv = tv->GetNextUnit()) {
|
||||||
if ( HasBit(tv->subtype, GVSF_ENGINE ) )
|
if (HasBit(tv->subtype, GVSF_ENGINE)) {
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,39 +212,3 @@ short deleteIllegalTemplateReplacements(GroupID g_id)
|
|||||||
}
|
}
|
||||||
return del_amount;
|
return del_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,3 +1,14 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_vehicle.h Template-based train replacement: template vehicle header. */
|
||||||
|
|
||||||
#ifndef TEMPLATE_VEH_H
|
#ifndef TEMPLATE_VEH_H
|
||||||
#define TEMPLATE_VEH_H
|
#define TEMPLATE_VEH_H
|
||||||
|
|
||||||
@@ -85,15 +96,18 @@ public:
|
|||||||
|
|
||||||
TemplateVehicle(VehicleType type = VEH_INVALID, EngineID e = INVALID_ENGINE, byte B = 0, Owner = _local_company);
|
TemplateVehicle(VehicleType type = VEH_INVALID, EngineID e = INVALID_ENGINE, byte B = 0, Owner = _local_company);
|
||||||
TemplateVehicle(EngineID, RailVehicleInfo*);
|
TemplateVehicle(EngineID, RailVehicleInfo*);
|
||||||
TemplateVehicle(EngineID eid) {
|
|
||||||
next=0;
|
TemplateVehicle(EngineID eid)
|
||||||
previous=0;
|
{
|
||||||
|
next = NULL;
|
||||||
|
previous = NULL;
|
||||||
first = this;
|
first = this;
|
||||||
engine_type = eid;
|
engine_type = eid;
|
||||||
this->reuse_depot_vehicles = true;
|
this->reuse_depot_vehicles = true;
|
||||||
this->keep_remaining_vehicles = true;
|
this->keep_remaining_vehicles = true;
|
||||||
this->refit_as_template = true;
|
this->refit_as_template = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~TemplateVehicle();
|
~TemplateVehicle();
|
||||||
|
|
||||||
inline TemplateVehicle* Next() const { return this->next; }
|
inline TemplateVehicle* Next() const { return this->next; }
|
||||||
@@ -138,7 +152,6 @@ public:
|
|||||||
int Length() const;
|
int Length() const;
|
||||||
|
|
||||||
SpriteID GetImage(Direction) const;
|
SpriteID GetImage(Direction) const;
|
||||||
//int GetDisplayImageWidth(Point *offset = NULL) const;
|
|
||||||
SpriteID GetSpriteID() const;
|
SpriteID GetSpriteID() const;
|
||||||
|
|
||||||
short NumGroupsUsingTemplate() const;
|
short NumGroupsUsingTemplate() const;
|
||||||
@@ -173,12 +186,15 @@ struct TemplateReplacement : TemplateReplacementPool::PoolItem<&_template_replac
|
|||||||
inline void SetTemplate(TemplateID tid) { this->sel_template = tid; }
|
inline void SetTemplate(TemplateID tid) { this->sel_template = tid; }
|
||||||
|
|
||||||
inline TemplateID GetTemplateVehicleID() { return sel_template; }
|
inline TemplateID GetTemplateVehicleID() { return sel_template; }
|
||||||
inline const TemplateVehicle* GetTemplateVehicle() {
|
|
||||||
|
inline const TemplateVehicle* GetTemplateVehicle()
|
||||||
|
{
|
||||||
const TemplateVehicle *tv;
|
const TemplateVehicle *tv;
|
||||||
FOR_ALL_TEMPLATES(tv) {
|
FOR_ALL_TEMPLATES(tv) {
|
||||||
if ( tv->index == this->sel_template )
|
if (tv->index == this->sel_template) {
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -190,4 +206,3 @@ bool IssueTemplateReplacement(GroupID, TemplateID);
|
|||||||
short deleteIllegalTemplateReplacements(GroupID);
|
short deleteIllegalTemplateReplacements(GroupID);
|
||||||
|
|
||||||
#endif /* TEMPLATE_VEH_H */
|
#endif /* TEMPLATE_VEH_H */
|
||||||
|
|
||||||
|
@@ -1,4 +1,13 @@
|
|||||||
// template_vehicle_func.cpp
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_vehicle_func.cpp Template-based train replacement: template vehicle functions. */
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "window_gui.h"
|
#include "window_gui.h"
|
||||||
@@ -31,6 +40,8 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "safeguards.h"
|
||||||
|
|
||||||
Vehicle *vhead, *vtmp;
|
Vehicle *vhead, *vtmp;
|
||||||
static const uint MAX_ARTICULATED_PARTS = 100;
|
static const uint MAX_ARTICULATED_PARTS = 100;
|
||||||
|
|
||||||
@@ -77,9 +88,9 @@ void BuildTemplateGuiList(GUITemplateList *list, Scrollbar *vscroll, Owner oid,
|
|||||||
const TemplateVehicle *tv;
|
const TemplateVehicle *tv;
|
||||||
|
|
||||||
FOR_ALL_TEMPLATES(tv) {
|
FOR_ALL_TEMPLATES(tv) {
|
||||||
if (tv->owner == oid && (tv->IsPrimaryVehicle() || tv->IsFreeWagonChain()) && TemplateVehicleContainsEngineOfRailtype(tv, railtype))
|
if (tv->owner == oid && (tv->IsPrimaryVehicle() || tv->IsFreeWagonChain()) && TemplateVehicleContainsEngineOfRailtype(tv, railtype)) {
|
||||||
*list->Append() = tv;
|
*list->Append() = tv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list->RebuildDone();
|
list->RebuildDone();
|
||||||
@@ -90,8 +101,9 @@ Money CalculateOverallTemplateCost(const TemplateVehicle *tv)
|
|||||||
{
|
{
|
||||||
Money val = 0;
|
Money val = 0;
|
||||||
|
|
||||||
for (; tv; tv = tv->Next())
|
for (; tv; tv = tv->Next()) {
|
||||||
val += (Engine::Get(tv->engine_type))->GetCost();
|
val += (Engine::Get(tv->engine_type))->GetCost();
|
||||||
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,16 +157,17 @@ inline void SetupTemplateVehicleFromVirtual(TemplateVehicle *tmp, TemplateVehicl
|
|||||||
// create a full TemplateVehicle based train according to a virtual train
|
// create a full TemplateVehicle based train according to a virtual train
|
||||||
TemplateVehicle* TemplateVehicleFromVirtualTrain(Train *virt)
|
TemplateVehicle* TemplateVehicleFromVirtualTrain(Train *virt)
|
||||||
{
|
{
|
||||||
if ( !virt )
|
if (!virt) return NULL;
|
||||||
return 0;
|
|
||||||
|
|
||||||
Train *init_virt = virt;
|
Train *init_virt = virt;
|
||||||
|
|
||||||
int len = CountVehiclesInChain(virt);
|
int len = CountVehiclesInChain(virt);
|
||||||
if ( !TemplateVehicle::CanAllocateItem(len) )
|
if (!TemplateVehicle::CanAllocateItem(len)) {
|
||||||
return 0;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
TemplateVehicle *tmp, *prev=0;
|
TemplateVehicle *tmp;
|
||||||
|
TemplateVehicle *prev = NULL;
|
||||||
for (; virt; virt = virt->Next()) {
|
for (; virt; virt = virt->Next()) {
|
||||||
tmp = new TemplateVehicle(virt->engine_type);
|
tmp = new TemplateVehicle(virt->engine_type);
|
||||||
SetupTemplateVehicleFromVirtual(tmp, prev, virt);
|
SetupTemplateVehicleFromVirtual(tmp, prev, virt);
|
||||||
@@ -166,23 +179,28 @@ TemplateVehicle* TemplateVehicleFromVirtualTrain(Train *virt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return last in a chain (really last, so even a singular articulated part of a vehicle if the last one is artic)
|
// return last in a chain (really last, so even a singular articulated part of a vehicle if the last one is artic)
|
||||||
inline TemplateVehicle* Last(TemplateVehicle *chain) {
|
inline TemplateVehicle* Last(TemplateVehicle *chain)
|
||||||
if ( !chain ) return 0;
|
{
|
||||||
while ( chain->Next() ) chain = chain->Next();
|
if (!chain) return NULL;
|
||||||
|
while (chain->Next()) {
|
||||||
|
chain = chain->Next();
|
||||||
|
}
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Train* Last(Train *chain) {
|
inline Train* Last(Train *chain)
|
||||||
if ( !chain ) return 0;
|
{
|
||||||
while ( chain->GetNextUnit() ) chain = chain->GetNextUnit();
|
if (!chain) return NULL;
|
||||||
|
while (chain->GetNextUnit()) {
|
||||||
|
chain = chain->GetNextUnit();
|
||||||
|
}
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return: pointer to former vehicle
|
// return: pointer to former vehicle
|
||||||
TemplateVehicle *DeleteTemplateVehicle(TemplateVehicle *todel)
|
TemplateVehicle *DeleteTemplateVehicle(TemplateVehicle *todel)
|
||||||
{
|
{
|
||||||
if ( !todel )
|
if (!todel) return NULL;
|
||||||
return 0;
|
|
||||||
TemplateVehicle *cur = todel;
|
TemplateVehicle *cur = todel;
|
||||||
delete todel;
|
delete todel;
|
||||||
return cur;
|
return cur;
|
||||||
@@ -208,17 +226,20 @@ TemplateVehicle* GetTemplateVehicleByGroupID(GroupID gid) {
|
|||||||
TemplateReplacement *tr;
|
TemplateReplacement *tr;
|
||||||
// first try to find a templatereplacement issued for the given groupid
|
// first try to find a templatereplacement issued for the given groupid
|
||||||
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
||||||
if ( tr->Group() == gid )
|
if (tr->Group() == gid) {
|
||||||
return TemplateVehicle::GetIfValid(tr->Template()); // there can be only one
|
return TemplateVehicle::GetIfValid(tr->Template()); // there can be only one
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// if that didn't work, try to find a templatereplacement for ALL_GROUP
|
// if that didn't work, try to find a templatereplacement for ALL_GROUP
|
||||||
if ( gid != ALL_GROUP )
|
if (gid != ALL_GROUP) {
|
||||||
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
||||||
if ( tr->Group() == ALL_GROUP )
|
if (tr->Group() == ALL_GROUP) {
|
||||||
return TemplateVehicle::GetIfValid(tr->Template());
|
return TemplateVehicle::GetIfValid(tr->Template());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// if all failed, just return null
|
// if all failed, just return null
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,26 +250,31 @@ bool TemplateVehicleContainsEngineOfRailtype(const TemplateVehicle *tv, RailType
|
|||||||
/* For standard rail engines, allow only those */
|
/* For standard rail engines, allow only those */
|
||||||
if (type == RAILTYPE_BEGIN || type == RAILTYPE_RAIL) {
|
if (type == RAILTYPE_BEGIN || type == RAILTYPE_RAIL) {
|
||||||
while (tv) {
|
while (tv) {
|
||||||
if ( tv->railtype != type )
|
if (tv->railtype != type) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
tv = tv->GetNextUnit();
|
tv = tv->GetNextUnit();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* For electrified rail engines, standard wagons or engines are allowed to be included */
|
/* For electrified rail engines, standard wagons or engines are allowed to be included */
|
||||||
while (tv) {
|
while (tv) {
|
||||||
if ( tv->railtype == type )
|
if (tv->railtype == type) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
tv = tv->GetNextUnit();
|
tv = tv->GetNextUnit();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//helper
|
//helper
|
||||||
bool ChainContainsVehicle(Train *chain, Train *mem) {
|
bool ChainContainsVehicle(Train *chain, Train *mem)
|
||||||
for (; chain; chain=chain->Next())
|
{
|
||||||
if ( chain == mem )
|
for (; chain; chain = chain->Next()) {
|
||||||
|
if (chain == mem) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,11 +283,12 @@ Train* ChainContainsEngine(EngineID eid, Train *chain) {
|
|||||||
for (; chain; chain=chain->GetNextUnit())
|
for (; chain; chain=chain->GetNextUnit())
|
||||||
if (chain->engine_type == eid)
|
if (chain->engine_type == eid)
|
||||||
return chain;
|
return chain;
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// has O(n^2)
|
// has O(n^2)
|
||||||
Train* DepotContainsEngine(TileIndex tile, EngineID eid, Train *not_in=0) {
|
Train* DepotContainsEngine(TileIndex tile, EngineID eid, Train *not_in = NULL)
|
||||||
|
{
|
||||||
Train *t;
|
Train *t;
|
||||||
FOR_ALL_TRAINS(t) {
|
FOR_ALL_TRAINS(t) {
|
||||||
// conditions: v is stopped in the given depot, has the right engine and if 'not_in' is given v must not be contained within 'not_in'
|
// conditions: v is stopped in the given depot, has the right engine and if 'not_in' is given v must not be contained within 'not_in'
|
||||||
@@ -271,13 +298,15 @@ Train* DepotContainsEngine(TileIndex tile, EngineID eid, Train *not_in=0) {
|
|||||||
// in case of t not a primary veh, we demand it to be a free wagon to consider it for replacement
|
// in case of t not a primary veh, we demand it to be a free wagon to consider it for replacement
|
||||||
&& ((t->IsPrimaryVehicle() && t->IsStoppedInDepot()) || t->IsFreeWagon())
|
&& ((t->IsPrimaryVehicle() && t->IsStoppedInDepot()) || t->IsFreeWagon())
|
||||||
&& t->engine_type == eid
|
&& t->engine_type == eid
|
||||||
&& (not_in==0 || ChainContainsVehicle(not_in, t)==0))
|
&& (not_in == NULL || ChainContainsVehicle(not_in, t) == false)) {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CopyStatus(Train *from, Train *to) {
|
void CopyStatus(Train *from, Train *to)
|
||||||
|
{
|
||||||
DoCommand(to->tile, from->group_id, to->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
|
DoCommand(to->tile, from->group_id, to->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
|
||||||
to->cargo_type = from->cargo_type;
|
to->cargo_type = from->cargo_type;
|
||||||
to->cargo_subtype = from->cargo_subtype;
|
to->cargo_subtype = from->cargo_subtype;
|
||||||
@@ -286,45 +315,49 @@ void CopyStatus(Train *from, Train *to) {
|
|||||||
char *tmp = to->name;
|
char *tmp = to->name;
|
||||||
to->name = from->name;
|
to->name = from->name;
|
||||||
from->name = tmp;
|
from->name = tmp;
|
||||||
/*if ( !from->name || !to->name ) {
|
|
||||||
int tmpind = from->index;
|
|
||||||
from->index = to->index;
|
|
||||||
to->index = tmpind;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
void NeutralizeStatus(Train *t) {
|
|
||||||
|
void NeutralizeStatus(Train *t)
|
||||||
|
{
|
||||||
DoCommand(t->tile, DEFAULT_GROUP, t->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
|
DoCommand(t->tile, DEFAULT_GROUP, t->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP);
|
||||||
DoCommand(0, t->index | CO_UNSHARE << 30, 0, DC_EXEC, CMD_CLONE_ORDER);
|
DoCommand(0, t->index | CO_UNSHARE << 30, 0, DC_EXEC, CMD_CLONE_ORDER);
|
||||||
DoCommand(0, t->index, FreeUnitIDGenerator(VEH_TRAIN, t->owner).NextID(), DC_EXEC, CMD_SET_VEHICLE_UNIT_NUMBER);
|
DoCommand(0, t->index, FreeUnitIDGenerator(VEH_TRAIN, t->owner).NextID(), DC_EXEC, CMD_SET_VEHICLE_UNIT_NUMBER);
|
||||||
DoCommand(0, t->index, 0, DC_EXEC, CMD_RENAME_VEHICLE, NULL);
|
DoCommand(0, t->index, 0, DC_EXEC, CMD_RENAME_VEHICLE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrainMatchesTemplate(const Train *t, TemplateVehicle *tv) {
|
bool TrainMatchesTemplate(const Train *t, TemplateVehicle *tv) {
|
||||||
while (t && tv) {
|
while (t && tv) {
|
||||||
if ( t->engine_type != tv->engine_type )
|
if (t->engine_type != tv->engine_type) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
t = t->GetNextUnit();
|
t = t->GetNextUnit();
|
||||||
tv = tv->GetNextUnit();
|
tv = tv->GetNextUnit();
|
||||||
}
|
}
|
||||||
if ( (t && !tv) || (!t && tv) )
|
if ((t && !tv) || (!t && tv)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TrainMatchesTemplateRefit(const Train *t, TemplateVehicle *tv)
|
bool TrainMatchesTemplateRefit(const Train *t, TemplateVehicle *tv)
|
||||||
{
|
{
|
||||||
if ( !tv->refit_as_template )
|
if (!tv->refit_as_template) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
while (t && tv) {
|
while (t && tv) {
|
||||||
if ( t->cargo_type != tv->cargo_type || t->cargo_subtype != tv->cargo_subtype )
|
if (t->cargo_type != tv->cargo_type || t->cargo_subtype != tv->cargo_subtype) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
t = t->GetNextUnit();
|
t = t->GetNextUnit();
|
||||||
tv = tv->GetNextUnit();
|
tv = tv->GetNextUnit();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void BreakUpRemainders(Train *t) {
|
|
||||||
|
void BreakUpRemainders(Train *t)
|
||||||
|
{
|
||||||
while (t) {
|
while (t) {
|
||||||
Train *move;
|
Train *move;
|
||||||
if (HasBit(t->subtype, GVSF_ENGINE)) {
|
if (HasBit(t->subtype, GVSF_ENGINE)) {
|
||||||
@@ -332,61 +365,73 @@ void BreakUpRemainders(Train *t) {
|
|||||||
t = t->Next();
|
t = t->Next();
|
||||||
DoCommand(move->tile, move->index, INVALID_VEHICLE, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
|
DoCommand(move->tile, move->index, INVALID_VEHICLE, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
|
||||||
NeutralizeStatus(move);
|
NeutralizeStatus(move);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
t = t->Next();
|
t = t->Next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
short CountEnginesInChain(Train *t)
|
short CountEnginesInChain(Train *t)
|
||||||
{
|
{
|
||||||
short count = 0;
|
short count = 0;
|
||||||
for ( ; t; t=t->GetNextUnit() )
|
for (; t != NULL; t = t->GetNextUnit()) {
|
||||||
if ( HasBit(t->subtype, GVSF_ENGINE) )
|
if (HasBit(t->subtype, GVSF_ENGINE)) {
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int countOccurrencesInTrain(Train *t, EngineID eid) {
|
int countOccurrencesInTrain(Train *t, EngineID eid)
|
||||||
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Train *tmp = t;
|
Train *tmp = t;
|
||||||
for ( ; tmp; tmp=tmp->GetNextUnit() )
|
for (; tmp != NULL; tmp = tmp->GetNextUnit()) {
|
||||||
if ( tmp->engine_type == eid )
|
if (tmp->engine_type == eid) {
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int countOccurrencesInTemplateVehicle(TemplateVehicle *contain, EngineID eid) {
|
int countOccurrencesInTemplateVehicle(TemplateVehicle *contain, EngineID eid)
|
||||||
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for ( ; contain; contain=contain->GetNextUnit() )
|
for (; contain; contain=contain->GetNextUnit()) {
|
||||||
if ( contain->engine_type == eid )
|
if (contain->engine_type == eid) {
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int countOccurrencesInDepot(TileIndex tile, EngineID eid, Train *not_in=0) {
|
int countOccurrencesInDepot(TileIndex tile, EngineID eid, Train *not_in = NULL)
|
||||||
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
FOR_ALL_VEHICLES(v) {
|
FOR_ALL_VEHICLES(v) {
|
||||||
// conditions: v is stopped in the given depot, has the right engine and if 'not_in' is given v must not be contained within 'not_in'
|
// conditions: v is stopped in the given depot, has the right engine and if 'not_in' is given v must not be contained within 'not_in'
|
||||||
// if 'not_in' is NULL, no check is needed
|
// if 'not_in' is NULL, no check is needed
|
||||||
if (v->tile == tile && v->IsStoppedInDepot() && v->engine_type == eid &&
|
if (v->tile == tile && v->IsStoppedInDepot() && v->engine_type == eid &&
|
||||||
(not_in==0 || ChainContainsVehicle(not_in, (Train*)v)==0))
|
(not_in == 0 || ChainContainsVehicle(not_in, (Train*)v) == false)) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// basically does the same steps as CmdTemplateReplaceVehicle but without actually moving things around
|
// basically does the same steps as CmdTemplateReplaceVehicle but without actually moving things around
|
||||||
CommandCost CalculateTemplateReplacementCost(Train *incoming) {
|
CommandCost CalculateTemplateReplacementCost(Train *incoming)
|
||||||
|
{
|
||||||
TileIndex tile = incoming->tile;
|
TileIndex tile = incoming->tile;
|
||||||
TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id);
|
TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id);
|
||||||
CommandCost estimate(EXPENSES_NEW_VEHICLES);
|
CommandCost estimate(EXPENSES_NEW_VEHICLES);
|
||||||
|
|
||||||
// count for each different eid in the incoming train
|
// count for each different eid in the incoming train
|
||||||
std::map<EngineID, short> unique_eids;
|
std::map<EngineID, short> unique_eids;
|
||||||
for ( TemplateVehicle *tmp=tv; tmp; tmp=tmp->GetNextUnit() )
|
for (TemplateVehicle *tmp = tv; tmp != NULL; tmp = tmp->GetNextUnit()) {
|
||||||
unique_eids[tmp->engine_type]++;
|
unique_eids[tmp->engine_type]++;
|
||||||
|
}
|
||||||
std::map<EngineID, short>::iterator it = unique_eids.begin();
|
std::map<EngineID, short>::iterator it = unique_eids.begin();
|
||||||
for (; it != unique_eids.end(); it++) {
|
for (; it != unique_eids.end(); it++) {
|
||||||
it->second -= countOccurrencesInTrain(incoming, it->first);
|
it->second -= countOccurrencesInTrain(incoming, it->first);
|
||||||
@@ -405,7 +450,8 @@ CommandCost CalculateTemplateReplacementCost(Train *incoming) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make sure the real train wagon has the right cargo
|
// make sure the real train wagon has the right cargo
|
||||||
void CopyWagonStatus(TemplateVehicle *from, Train *to) {
|
void CopyWagonStatus(TemplateVehicle *from, Train *to)
|
||||||
|
{
|
||||||
to->cargo_type = from->cargo_type;
|
to->cargo_type = from->cargo_type;
|
||||||
to->cargo_subtype = from->cargo_subtype;
|
to->cargo_subtype = from->cargo_subtype;
|
||||||
}
|
}
|
||||||
@@ -417,9 +463,10 @@ int NumTrainsNeedTemplateReplacement(GroupID g_id, TemplateVehicle *tv)
|
|||||||
|
|
||||||
const Train *t;
|
const Train *t;
|
||||||
FOR_ALL_TRAINS(t) {
|
FOR_ALL_TRAINS(t) {
|
||||||
if ( t->IsPrimaryVehicle() && t->group_id == g_id && (!TrainMatchesTemplate(t, tv) || !TrainMatchesTemplateRefit(t, tv)) )
|
if (t->IsPrimaryVehicle() && t->group_id == g_id && (!TrainMatchesTemplate(t, tv) || !TrainMatchesTemplateRefit(t, tv))) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
// refit each vehicle in t as is in tv, assume t and tv contain the same types of vehicles
|
// refit each vehicle in t as is in tv, assume t and tv contain the same types of vehicles
|
||||||
@@ -445,8 +492,9 @@ CommandCost TestBuyAllTemplateVehiclesInChain(TemplateVehicle *tv, TileIndex til
|
|||||||
{
|
{
|
||||||
CommandCost cost(EXPENSES_NEW_VEHICLES);
|
CommandCost cost(EXPENSES_NEW_VEHICLES);
|
||||||
|
|
||||||
for ( ; tv; tv=tv->GetNextUnit() )
|
for (; tv; tv = tv->GetNextUnit()) {
|
||||||
cost.AddCost(DoCommand(tile, tv->engine_type, 0, DC_NONE, CMD_BUILD_VEHICLE));
|
cost.AddCost(DoCommand(tile, tv->engine_type, 0, DC_NONE, CMD_BUILD_VEHICLE));
|
||||||
|
}
|
||||||
|
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
@@ -457,7 +505,7 @@ CommandCost TestBuyAllTemplateVehiclesInChain(TemplateVehicle *tv, TileIndex til
|
|||||||
* to store the cargo from the given single vehicle.
|
* to store the cargo from the given single vehicle.
|
||||||
* @param old_veh: ptr to the single vehicle, which's cargo shall be moved
|
* @param old_veh: ptr to the single vehicle, which's cargo shall be moved
|
||||||
* @param new_head: ptr to the head of the chain, which shall obtain old_veh's cargo
|
* @param new_head: ptr to the head of the chain, which shall obtain old_veh's cargo
|
||||||
* @return: amount of moved cargo TODO
|
* @return: amount of moved cargo, TODO
|
||||||
*/
|
*/
|
||||||
void TransferCargoForTrain(Train *old_veh, Train *new_head)
|
void TransferCargoForTrain(Train *old_veh, Train *new_head)
|
||||||
{
|
{
|
||||||
@@ -469,16 +517,13 @@ void TransferCargoForTrain(Train *old_veh, Train *new_head)
|
|||||||
// how much cargo has to be moved (if possible)
|
// how much cargo has to be moved (if possible)
|
||||||
uint remainingAmount = old_veh->cargo.TotalCount();
|
uint remainingAmount = old_veh->cargo.TotalCount();
|
||||||
// each vehicle in the new chain shall be given as much of the old cargo as possible, until none is left
|
// each vehicle in the new chain shall be given as much of the old cargo as possible, until none is left
|
||||||
for (Train *tmp=new_head; tmp!=NULL && remainingAmount>0; tmp=tmp->GetNextUnit())
|
for (Train *tmp = new_head; tmp != NULL && remainingAmount > 0; tmp = tmp->GetNextUnit()) {
|
||||||
{
|
if (tmp->cargo_type == _cargo_type && tmp->cargo_subtype == _cargo_subtype) {
|
||||||
if (tmp->cargo_type == _cargo_type && tmp->cargo_subtype == _cargo_subtype)
|
|
||||||
{
|
|
||||||
// calculate the free space for new cargo on the current vehicle
|
// calculate the free space for new cargo on the current vehicle
|
||||||
uint curCap = tmp->cargo_cap - tmp->cargo.TotalCount();
|
uint curCap = tmp->cargo_cap - tmp->cargo.TotalCount();
|
||||||
uint moveAmount = min(remainingAmount, curCap);
|
uint moveAmount = min(remainingAmount, curCap);
|
||||||
// move (parts of) the old vehicle's cargo onto the current vehicle of the new chain
|
// move (parts of) the old vehicle's cargo onto the current vehicle of the new chain
|
||||||
if (moveAmount > 0)
|
if (moveAmount > 0) {
|
||||||
{
|
|
||||||
old_veh->cargo.Shift(moveAmount, &tmp->cargo);
|
old_veh->cargo.Shift(moveAmount, &tmp->cargo);
|
||||||
remainingAmount -= moveAmount;
|
remainingAmount -= moveAmount;
|
||||||
}
|
}
|
||||||
@@ -493,33 +538,3 @@ void TransferCargoForTrain(Train *old_veh, Train *new_head)
|
|||||||
/* Update train weight etc., the old vehicle will be sold anyway */
|
/* Update train weight etc., the old vehicle will be sold anyway */
|
||||||
new_head->ConsistChanged(CCF_LOADUNLOAD);
|
new_head->ConsistChanged(CCF_LOADUNLOAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,14 @@
|
|||||||
// template_vehicle_func.h
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tbtr_template_vehicle_func.h Template-based train replacement: template vehicle functions headers. */
|
||||||
|
|
||||||
#ifndef TEMPLATE_VEHICLE_FUNC_H
|
#ifndef TEMPLATE_VEHICLE_FUNC_H
|
||||||
#define TEMPLATE_VEHICLE_FUNC_H
|
#define TEMPLATE_VEHICLE_FUNC_H
|
||||||
|
|
||||||
@@ -7,9 +17,6 @@
|
|||||||
|
|
||||||
#include "tbtr_template_vehicle.h"
|
#include "tbtr_template_vehicle.h"
|
||||||
|
|
||||||
//void DrawTemplateVehicle(TemplateVehicle*, int, const Rect&);
|
|
||||||
|
|
||||||
|
|
||||||
Train* VirtualTrainFromTemplateVehicle(TemplateVehicle* tv);
|
Train* VirtualTrainFromTemplateVehicle(TemplateVehicle* tv);
|
||||||
|
|
||||||
void DrawTemplateVehicle(const TemplateVehicle*, int, int, int, VehicleID, int, VehicleID);
|
void DrawTemplateVehicle(const TemplateVehicle*, int, int, int, VehicleID, int, VehicleID);
|
||||||
@@ -32,8 +39,6 @@ void setupVirtTrain(const TemplateVehicle*, Train*);
|
|||||||
|
|
||||||
TemplateVehicle* TemplateVehicleFromVirtualTrain(Train *virt);
|
TemplateVehicle* TemplateVehicleFromVirtualTrain(Train *virt);
|
||||||
|
|
||||||
//Train* VirtualTrainFromTemplateVehicle(TemplateVehicle*);
|
|
||||||
|
|
||||||
inline TemplateVehicle* Last(TemplateVehicle*);
|
inline TemplateVehicle* Last(TemplateVehicle*);
|
||||||
|
|
||||||
TemplateVehicle *DeleteTemplateVehicle(TemplateVehicle*);
|
TemplateVehicle *DeleteTemplateVehicle(TemplateVehicle*);
|
||||||
|
@@ -169,7 +169,9 @@ struct Train FINAL : public GroundVehicle<Train, VEH_TRAIN> {
|
|||||||
*/
|
*/
|
||||||
inline Train *GetLastUnit() {
|
inline Train *GetLastUnit() {
|
||||||
Train *tmp = this;
|
Train *tmp = this;
|
||||||
while ( tmp->GetNextUnit() ) tmp = tmp->GetNextUnit();
|
while (tmp->GetNextUnit()) {
|
||||||
|
tmp = tmp->GetNextUnit();
|
||||||
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1227,13 +1227,15 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
|||||||
|
|
||||||
/* Check if all vehicles in the source train are stopped inside a depot. */
|
/* Check if all vehicles in the source train are stopped inside a depot. */
|
||||||
/* Do this check only if the vehicle to be moved is non-virtual */
|
/* Do this check only if the vehicle to be moved is non-virtual */
|
||||||
if ( !HasBit(p1, 21) )
|
if (!HasBit(p1, 21)) {
|
||||||
if (!src_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
|
if (!src_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if all vehicles in the destination train are stopped inside a depot. */
|
/* Check if all vehicles in the destination train are stopped inside a depot. */
|
||||||
/* Do this check only if the destination vehicle is non-virtual */
|
/* Do this check only if the destination vehicle is non-virtual */
|
||||||
if ( !HasBit(p1, 21) )
|
if (!HasBit(p1, 21)) {
|
||||||
if (dst_head != NULL && !dst_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
|
if (dst_head != NULL && !dst_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
|
||||||
|
}
|
||||||
|
|
||||||
/* First make a backup of the order of the trains. That way we can do
|
/* First make a backup of the order of the trains. That way we can do
|
||||||
* whatever we want with the order and later on easily revert. */
|
* whatever we want with the order and later on easily revert. */
|
||||||
@@ -4060,7 +4062,6 @@ Trackdir Train::GetVehicleTrackdir() const
|
|||||||
return TrackDirectionToTrackdir(FindFirstTrack(this->track), this->direction);
|
return TrackDirectionToTrackdir(FindFirstTrack(this->track), this->direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get the pixel-width of the image that is used for the train vehicle
|
/* Get the pixel-width of the image that is used for the train vehicle
|
||||||
* @return: the image width number in pixel
|
* @return: the image width number in pixel
|
||||||
*/
|
*/
|
||||||
@@ -4079,7 +4080,6 @@ int GetDisplayImageWidth(Train *t, Point *offset)
|
|||||||
offset->x = reference_width / 2;
|
offset->x = reference_width / 2;
|
||||||
offset->y = vehicle_pitch;
|
offset->y = vehicle_pitch;
|
||||||
}
|
}
|
||||||
//printf(" refwid:%d gdiw.cachedvehlen(%d):%d ", reference_width, this->engine_type, this->gcache.cached_veh_length);
|
|
||||||
return t->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH;
|
return t->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4147,18 +4147,21 @@ Train* CmdBuildVirtualRailWagon(const Engine *e)
|
|||||||
*/
|
*/
|
||||||
Train* CmdBuildVirtualRailVehicle(EngineID eid)
|
Train* CmdBuildVirtualRailVehicle(EngineID eid)
|
||||||
{
|
{
|
||||||
if (!IsEngineBuildable(eid, VEH_TRAIN, _current_company))
|
if (!IsEngineBuildable(eid, VEH_TRAIN, _current_company)) {
|
||||||
return nullptr;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
const Engine* e = Engine::Get(eid);
|
const Engine* e = Engine::Get(eid);
|
||||||
const RailVehicleInfo *rvi = &e->u.rail;
|
const RailVehicleInfo *rvi = &e->u.rail;
|
||||||
|
|
||||||
int num_vehicles = (e->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid, false);
|
int num_vehicles = (e->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid, false);
|
||||||
if (!Train::CanAllocateItem(num_vehicles))
|
if (!Train::CanAllocateItem(num_vehicles)) {
|
||||||
return nullptr;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (rvi->railveh_type == RAILVEH_WAGON)
|
if (rvi->railveh_type == RAILVEH_WAGON) {
|
||||||
return CmdBuildVirtualRailWagon(e);
|
return CmdBuildVirtualRailWagon(e);
|
||||||
|
}
|
||||||
|
|
||||||
Train *v = new Train();
|
Train *v = new Train();
|
||||||
|
|
||||||
@@ -4225,16 +4228,16 @@ Train* CmdBuildVirtualRailVehicle(EngineID eid)
|
|||||||
CommandCost CmdBuildVirtualRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
CommandCost CmdBuildVirtualRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||||
{
|
{
|
||||||
EngineID eid = p1;
|
EngineID eid = p1;
|
||||||
CommandCost cost = CommandCost();
|
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
if (should_execute) {
|
if (should_execute) {
|
||||||
Train* train = CmdBuildVirtualRailVehicle(eid);
|
Train* train = CmdBuildVirtualRailVehicle(eid);
|
||||||
|
|
||||||
if (train == nullptr)
|
if (train == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
@@ -4254,20 +4257,22 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
|
|
||||||
Vehicle* vehicle = Vehicle::GetIfValid(vehicle_id);
|
Vehicle* vehicle = Vehicle::GetIfValid(vehicle_id);
|
||||||
|
|
||||||
if (vehicle == nullptr || vehicle->type != VEH_TRAIN)
|
if (vehicle == NULL || vehicle->type != VEH_TRAIN) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
if (!should_execute)
|
if (!should_execute) {
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
|
}
|
||||||
|
|
||||||
Train* incoming = Train::From(vehicle);
|
Train* incoming = Train::From(vehicle);
|
||||||
bool stayInDepot = p2 != 0;
|
bool stayInDepot = p2 != 0;
|
||||||
|
|
||||||
Train *new_chain = 0,
|
Train *new_chain = NULL;
|
||||||
*remainder_chain = 0,
|
Train *remainder_chain = NULL;
|
||||||
*tmp_chain = 0;
|
Train *tmp_chain = NULL;
|
||||||
TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id);
|
TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id);
|
||||||
EngineID eid = tv->engine_type;
|
EngineID eid = tv->engine_type;
|
||||||
|
|
||||||
@@ -4277,8 +4282,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
|
|
||||||
|
|
||||||
/* first some tests on necessity and sanity */
|
/* first some tests on necessity and sanity */
|
||||||
if (!tv)
|
if (tv == NULL) return buy;
|
||||||
return buy;
|
|
||||||
bool need_replacement = !TrainMatchesTemplate(incoming, tv);
|
bool need_replacement = !TrainMatchesTemplate(incoming, tv);
|
||||||
bool need_refit = !TrainMatchesTemplateRefit(incoming, tv);
|
bool need_refit = !TrainMatchesTemplateRefit(incoming, tv);
|
||||||
bool use_refit = tv->refit_as_template;
|
bool use_refit = tv->refit_as_template;
|
||||||
@@ -4286,7 +4290,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
short store_refit_csubt = 0;
|
short store_refit_csubt = 0;
|
||||||
// if a train shall keep its old refit, store the refit setting of its first vehicle
|
// if a train shall keep its old refit, store the refit setting of its first vehicle
|
||||||
if (!use_refit) {
|
if (!use_refit) {
|
||||||
for (Train *getc = incoming; getc; getc = getc->GetNextUnit())
|
for (Train *getc = incoming; getc != NULL; getc = getc->GetNextUnit())
|
||||||
if (getc->cargo_type != CT_INVALID) {
|
if (getc->cargo_type != CT_INVALID) {
|
||||||
store_refit_ct = getc->cargo_type;
|
store_refit_ct = getc->cargo_type;
|
||||||
break;
|
break;
|
||||||
@@ -4300,8 +4304,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
if (!stayInDepot) incoming->vehstatus &= ~VS_STOPPED;
|
if (!stayInDepot) incoming->vehstatus &= ~VS_STOPPED;
|
||||||
return buy;
|
return buy;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
CommandCost buyCost = TestBuyAllTemplateVehiclesInChain(tv, tile);
|
CommandCost buyCost = TestBuyAllTemplateVehiclesInChain(tv, tile);
|
||||||
if (!buyCost.Succeeded() || !CheckCompanyHasMoney(buyCost)) {
|
if (!buyCost.Succeeded() || !CheckCompanyHasMoney(buyCost)) {
|
||||||
if (!stayInDepot) incoming->vehstatus &= ~VS_STOPPED;
|
if (!stayInDepot) incoming->vehstatus &= ~VS_STOPPED;
|
||||||
@@ -4314,7 +4317,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
bool keepRemainders = tv->IsSetKeepRemainingVehicles();
|
bool keepRemainders = tv->IsSetKeepRemainingVehicles();
|
||||||
|
|
||||||
if (need_replacement) {
|
if (need_replacement) {
|
||||||
/// step 1: generate primary for newchain and generate remainder_chain
|
// step 1: generate primary for newchain and generate remainder_chain
|
||||||
// 1. primary of incoming might already fit the template
|
// 1. primary of incoming might already fit the template
|
||||||
// leave incoming's primary as is and move the rest to a free chain = remainder_chain
|
// leave incoming's primary as is and move the rest to a free chain = remainder_chain
|
||||||
// 2. needed primary might be one of incoming's member vehicles
|
// 2. needed primary might be one of incoming's member vehicles
|
||||||
@@ -4324,25 +4327,24 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
if (eid == incoming->engine_type) { // 1
|
if (eid == incoming->engine_type) { // 1
|
||||||
new_chain = incoming;
|
new_chain = incoming;
|
||||||
remainder_chain = incoming->GetNextUnit();
|
remainder_chain = incoming->GetNextUnit();
|
||||||
if (remainder_chain)
|
if (remainder_chain) {
|
||||||
move_cost.AddCost(CmdMoveRailVehicle(tile, flags, remainder_chain->index | (1 << 20), INVALID_VEHICLE, 0));
|
move_cost.AddCost(CmdMoveRailVehicle(tile, flags, remainder_chain->index | (1 << 20), INVALID_VEHICLE, 0));
|
||||||
}
|
}
|
||||||
else if ((tmp_chain = ChainContainsEngine(eid, incoming)) && tmp_chain != NULL) { // 2
|
} else if ((tmp_chain = ChainContainsEngine(eid, incoming)) && tmp_chain != NULL) { // 2
|
||||||
// new_chain is the needed engine, move it to an empty spot in the depot
|
// new_chain is the needed engine, move it to an empty spot in the depot
|
||||||
new_chain = tmp_chain;
|
new_chain = tmp_chain;
|
||||||
move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE));
|
move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE));
|
||||||
remainder_chain = incoming;
|
remainder_chain = incoming;
|
||||||
}
|
} else if (reuseDepot && (tmp_chain = DepotContainsEngine(tile, eid, incoming)) && tmp_chain != NULL) { // 3
|
||||||
else if (reuseDepot && (tmp_chain = DepotContainsEngine(tile, eid, incoming)) && tmp_chain != NULL) { // 3
|
|
||||||
new_chain = tmp_chain;
|
new_chain = tmp_chain;
|
||||||
move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE));
|
move_cost.AddCost(DoCommand(tile, new_chain->index, INVALID_VEHICLE, flags, CMD_MOVE_RAIL_VEHICLE));
|
||||||
remainder_chain = incoming;
|
remainder_chain = incoming;
|
||||||
}
|
} else { // 4
|
||||||
else { // 4
|
|
||||||
tmp_result = DoCommand(tile, eid, 0, flags, CMD_BUILD_VEHICLE);
|
tmp_result = DoCommand(tile, eid, 0, flags, CMD_BUILD_VEHICLE);
|
||||||
/* break up in case buying the vehicle didn't succeed */
|
/* break up in case buying the vehicle didn't succeed */
|
||||||
if (!tmp_result.Succeeded())
|
if (!tmp_result.Succeeded()) {
|
||||||
return tmp_result;
|
return tmp_result;
|
||||||
|
}
|
||||||
buy.AddCost(tmp_result);
|
buy.AddCost(tmp_result);
|
||||||
new_chain = Train::Get(_new_vehicle_id);
|
new_chain = Train::Get(_new_vehicle_id);
|
||||||
/* make sure the newly built engine is not attached to any free wagons inside the depot */
|
/* make sure the newly built engine is not attached to any free wagons inside the depot */
|
||||||
@@ -4355,17 +4357,15 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
CopyHeadSpecificThings(incoming, new_chain, flags);
|
CopyHeadSpecificThings(incoming, new_chain, flags);
|
||||||
NeutralizeStatus(incoming);
|
NeutralizeStatus(incoming);
|
||||||
|
|
||||||
|
|
||||||
// additionally, if we don't want to use the template refit, refit as incoming
|
// additionally, if we don't want to use the template refit, refit as incoming
|
||||||
// the template refit will be set further down, if we use it at all
|
// the template refit will be set further down, if we use it at all
|
||||||
if (!use_refit) {
|
if (!use_refit) {
|
||||||
uint32 cb = GetCmdRefitVeh(new_chain);
|
uint32 cb = GetCmdRefitVeh(new_chain);
|
||||||
DoCommand(new_chain->tile, new_chain->index, store_refit_ct | store_refit_csubt << 8 | 1 << 16 | (1 << 5), flags, cb);
|
DoCommand(new_chain->tile, new_chain->index, store_refit_ct | store_refit_csubt << 8 | 1 << 16 | (1 << 5), flags, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// step 2: fill up newchain according to the template
|
// step 2: fill up newchain according to the template
|
||||||
// foreach member of template (after primary):
|
// foreach member of template (after primary):
|
||||||
// 1. needed engine might be within remainder_chain already
|
// 1. needed engine might be within remainder_chain already
|
||||||
// 2. needed engine might be orphaned within the depot (copy status)
|
// 2. needed engine might be orphaned within the depot (copy status)
|
||||||
@@ -4376,8 +4376,9 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
// 1. engine contained in remainder chain
|
// 1. engine contained in remainder chain
|
||||||
if ((tmp_chain = ChainContainsEngine(cur_tmpl->engine_type, remainder_chain)) && tmp_chain != NULL) {
|
if ((tmp_chain = ChainContainsEngine(cur_tmpl->engine_type, remainder_chain)) && tmp_chain != NULL) {
|
||||||
// advance remainder_chain (if necessary) to not lose track of it
|
// advance remainder_chain (if necessary) to not lose track of it
|
||||||
if (tmp_chain == remainder_chain)
|
if (tmp_chain == remainder_chain) {
|
||||||
remainder_chain = remainder_chain->GetNextUnit();
|
remainder_chain = remainder_chain->GetNextUnit();
|
||||||
|
}
|
||||||
move_cost.AddCost(CmdMoveRailVehicle(tile, flags, tmp_chain->index, last_veh->index, 0));
|
move_cost.AddCost(CmdMoveRailVehicle(tile, flags, tmp_chain->index, last_veh->index, 0));
|
||||||
}
|
}
|
||||||
// 2. engine contained somewhere else in the depot
|
// 2. engine contained somewhere else in the depot
|
||||||
@@ -4397,13 +4398,11 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
if (need_refit && flags == DC_EXEC) {
|
if (need_refit && flags == DC_EXEC) {
|
||||||
if (use_refit) {
|
if (use_refit) {
|
||||||
uint32 cb = GetCmdRefitVeh(tmp_chain);
|
uint32 cb = GetCmdRefitVeh(tmp_chain);
|
||||||
DoCommand(tmp_chain->tile, tmp_chain->index, cur_tmpl->cargo_type | cur_tmpl->cargo_subtype << 8 | 1 << 16 | (1 << 5), flags, cb);
|
DoCommand(tmp_chain->tile, tmp_chain->index, cur_tmpl->cargo_type | (cur_tmpl->cargo_subtype << 8) | (1 << 16) | (1 << 5), flags, cb);
|
||||||
// old
|
|
||||||
// CopyWagonStatus(cur_tmpl, tmp_chain);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint32 cb = GetCmdRefitVeh(tmp_chain);
|
uint32 cb = GetCmdRefitVeh(tmp_chain);
|
||||||
DoCommand(tmp_chain->tile, tmp_chain->index, store_refit_ct | store_refit_csubt << 8 | 1 << 16 | (1 << 5), flags, cb);
|
DoCommand(tmp_chain->tile, tmp_chain->index, store_refit_ct | (store_refit_csubt << 8) | (1 << 16) | (1 << 5), flags, cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur_tmpl = cur_tmpl->GetNextUnit();
|
cur_tmpl = cur_tmpl->GetNextUnit();
|
||||||
@@ -4424,18 +4423,21 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
CmdRefitTrainFromTemplate(new_chain, tv, flags);
|
CmdRefitTrainFromTemplate(new_chain, tv, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_chain && remainder_chain)
|
if (new_chain && remainder_chain) {
|
||||||
for (Train *ct = remainder_chain; ct; ct = ct->GetNextUnit())
|
for (Train *ct = remainder_chain; ct; ct = ct->GetNextUnit()) {
|
||||||
TransferCargoForTrain(ct, new_chain);
|
TransferCargoForTrain(ct, new_chain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// point incoming to the newly created train so that starting/stopping from the calling function can be done
|
// point incoming to the newly created train so that starting/stopping from the calling function can be done
|
||||||
incoming = new_chain;
|
incoming = new_chain;
|
||||||
if (!stayInDepot && flags == DC_EXEC)
|
if (!stayInDepot && flags == DC_EXEC) {
|
||||||
new_chain->vehstatus &= ~VS_STOPPED;
|
new_chain->vehstatus &= ~VS_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
if (remainder_chain && keepRemainders && flags == DC_EXEC)
|
if (remainder_chain && keepRemainders && flags == DC_EXEC) {
|
||||||
BreakUpRemainders(remainder_chain);
|
BreakUpRemainders(remainder_chain);
|
||||||
else if (remainder_chain) {
|
} else if (remainder_chain) {
|
||||||
buy.AddCost(DoCommand(tile, remainder_chain->index | (1 << 20), 0, flags, CMD_SELL_VEHICLE));
|
buy.AddCost(DoCommand(tile, remainder_chain->index | (1 << 20), 0, flags, CMD_SELL_VEHICLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,13 +52,12 @@
|
|||||||
#include "gamelog.h"
|
#include "gamelog.h"
|
||||||
#include "linkgraph/linkgraph.h"
|
#include "linkgraph/linkgraph.h"
|
||||||
#include "linkgraph/refresh.h"
|
#include "linkgraph/refresh.h"
|
||||||
|
#include "tbtr_template_vehicle_func.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
#include "tbtr_template_vehicle_func.h"
|
|
||||||
|
|
||||||
#define GEN_HASH(x, y) ((GB((y), 6 + ZOOM_LVL_SHIFT, 6) << 6) + GB((x), 7 + ZOOM_LVL_SHIFT, 6))
|
#define GEN_HASH(x, y) ((GB((y), 6 + ZOOM_LVL_SHIFT, 6) << 6) + GB((x), 7 + ZOOM_LVL_SHIFT, 6))
|
||||||
|
|
||||||
VehicleID _new_vehicle_id;
|
VehicleID _new_vehicle_id;
|
||||||
@@ -840,22 +839,21 @@ void VehicleEnteredDepotThisTick(Vehicle *v)
|
|||||||
/* Template Replacement Setup stuff */
|
/* Template Replacement Setup stuff */
|
||||||
bool stayInDepot = v->current_order.GetDepotActionType();
|
bool stayInDepot = v->current_order.GetDepotActionType();
|
||||||
TemplateReplacement *tr = GetTemplateReplacementByGroupID(v->group_id);
|
TemplateReplacement *tr = GetTemplateReplacementByGroupID(v->group_id);
|
||||||
if ( tr ) {
|
if (tr != NULL) {
|
||||||
if ( stayInDepot ) _vehicles_to_templatereplace[(Train*)v] = true;
|
_vehicles_to_templatereplace[(Train*) v] = stayInDepot;
|
||||||
else _vehicles_to_templatereplace[(Train*)v] = false;
|
} else {
|
||||||
}
|
|
||||||
/* Moved the assignment for auto replacement here to prevent auto replacement
|
/* Moved the assignment for auto replacement here to prevent auto replacement
|
||||||
* from happening if template replacement is also scheduled */
|
* from happening if template replacement is also scheduled */
|
||||||
else
|
|
||||||
/* 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_autoreplace[v] = !(v->vehstatus & VS_STOPPED);
|
_vehicles_to_autoreplace[v] = !(v->vehstatus & VS_STOPPED);
|
||||||
|
}
|
||||||
|
|
||||||
/* We ALWAYS set the stopped state. Even when the vehicle does not plan on
|
/* We ALWAYS set the stopped state. Even when the vehicle does not plan on
|
||||||
* stopping in the depot, so we stop it to ensure that it will not reserve
|
* stopping in the depot, so we stop it to ensure that it will not reserve
|
||||||
* the path out of the depot before we might autoreplace it to a different
|
* the path out of the depot before we might autoreplace it to a different
|
||||||
* engine. The new engine would not own the reserved path we store that we
|
* engine. The new engine would not own the reserved path we store that we
|
||||||
* stopped the vehicle, so autoreplace can start it again */
|
* stopped the vehicle, so autoreplace can start it again */
|
||||||
|
|
||||||
v->vehstatus |= VS_STOPPED;
|
v->vehstatus |= VS_STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1024,7 +1022,6 @@ void CallVehicleTicks()
|
|||||||
/* do Template Replacement */
|
/* do Template Replacement */
|
||||||
Backup<CompanyByte> tmpl_cur_company(_current_company, FILE_LINE);
|
Backup<CompanyByte> tmpl_cur_company(_current_company, FILE_LINE);
|
||||||
for (TemplateReplacementMap::iterator it = _vehicles_to_templatereplace.Begin(); it != _vehicles_to_templatereplace.End(); it++) {
|
for (TemplateReplacementMap::iterator it = _vehicles_to_templatereplace.Begin(); it != _vehicles_to_templatereplace.End(); it++) {
|
||||||
|
|
||||||
Train *t = it->first;
|
Train *t = it->first;
|
||||||
|
|
||||||
tmpl_cur_company.Change(t->owner);
|
tmpl_cur_company.Change(t->owner);
|
||||||
|
@@ -426,8 +426,8 @@ static CommandCost RefitVehicle(Vehicle *v, bool only_this, uint8 num_vehicles,
|
|||||||
* @param p1 vehicle ID to refit
|
* @param p1 vehicle ID to refit
|
||||||
* @param p2 various bitstuffed elements
|
* @param p2 various bitstuffed elements
|
||||||
* - p2 = (bit 0-4) - New cargo type to refit to.
|
* - p2 = (bit 0-4) - New cargo type to refit to.
|
||||||
* - p2 = (bit 6) - Automatic refitting.
|
|
||||||
* - p2 = (bit 5) - Is a virtual train (used by template replacement to allow refitting without stopped-in-depot checks)
|
* - p2 = (bit 5) - Is a virtual train (used by template replacement to allow refitting without stopped-in-depot checks)
|
||||||
|
* - p2 = (bit 6) - Automatic refitting.
|
||||||
* - p2 = (bit 7) - Refit only this vehicle. Used only for cloning vehicles.
|
* - p2 = (bit 7) - Refit only this vehicle. Used only for cloning vehicles.
|
||||||
* - p2 = (bit 8-15) - New cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
|
* - p2 = (bit 8-15) - New cargo subtype to refit to. 0xFF means to try keeping the same subtype according to GetBestFittingSubType().
|
||||||
* - p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). Zero means all vehicles.
|
* - p2 = (bit 16-23) - Number of vehicles to refit (not counting articulated parts). Zero means all vehicles.
|
||||||
@@ -458,7 +458,9 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||||||
|
|
||||||
/* Allow auto-refitting only during loading and normal refitting only in a depot. */
|
/* Allow auto-refitting only during loading and normal refitting only in a depot. */
|
||||||
if (!is_virtual_train) {
|
if (!is_virtual_train) {
|
||||||
if (!free_wagon && (!auto_refit || !front->current_order.IsType(OT_LOADING)) && !front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
|
if (!free_wagon && (!auto_refit || !front->current_order.IsType(OT_LOADING)) && !front->IsStoppedInDepot()) {
|
||||||
|
return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
|
||||||
|
}
|
||||||
if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED);
|
||||||
}
|
}
|
||||||
if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
|
if ((flags & DC_QUERY_COST) == 0 && // used by the refit GUI, including the order refit GUI.
|
||||||
@@ -511,8 +513,11 @@ CommandCost CmdRefitVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|||||||
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
|
||||||
}
|
}
|
||||||
/* virtual vehicles get their cargo changed by the TemplateCreateWindow, so set this dirty instead of a depot window */
|
/* virtual vehicles get their cargo changed by the TemplateCreateWindow, so set this dirty instead of a depot window */
|
||||||
if ( HasBit(v->subtype, GVSF_VIRTUAL) ) SetWindowClassesDirty(WC_CREATE_TEMPLATE);
|
if (HasBit(v->subtype, GVSF_VIRTUAL)) {
|
||||||
else SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
|
SetWindowClassesDirty(WC_CREATE_TEMPLATE);
|
||||||
|
} else {
|
||||||
|
SetWindowDirty(WC_VEHICLE_DEPOT, front->tile);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Always invalidate the cache; querycost might have filled it. */
|
/* Always invalidate the cache; querycost might have filled it. */
|
||||||
v->InvalidateNewGRFCacheOfChain();
|
v->InvalidateNewGRFCacheOfChain();
|
||||||
@@ -825,8 +830,9 @@ CommandCost CmdToggleReuseDepotVehicles(TileIndex tile, DoCommandFlag flags, uin
|
|||||||
// Identify template to toggle
|
// Identify template to toggle
|
||||||
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
|
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
|
||||||
|
|
||||||
if (template_vehicle == NULL)
|
if (template_vehicle == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
@@ -853,8 +859,9 @@ CommandCost CmdToggleKeepRemainingVehicles(TileIndex tile, DoCommandFlag flags,
|
|||||||
// Identify template to toggle
|
// Identify template to toggle
|
||||||
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
|
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
|
||||||
|
|
||||||
if (template_vehicle == NULL)
|
if (template_vehicle == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
@@ -881,8 +888,9 @@ CommandCost CmdToggleRefitAsTemplate(TileIndex tile, DoCommandFlag flags, uint32
|
|||||||
// Identify template to toggle
|
// Identify template to toggle
|
||||||
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
|
TemplateVehicle *template_vehicle = TemplateVehicle::GetIfValid(p1);
|
||||||
|
|
||||||
if (template_vehicle == NULL)
|
if (template_vehicle == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
@@ -910,17 +918,19 @@ CommandCost CmdVirtualTrainFromTemplateVehicle(TileIndex tile, DoCommandFlag fla
|
|||||||
|
|
||||||
TemplateVehicle* tv = TemplateVehicle::GetIfValid(template_vehicle_id);
|
TemplateVehicle* tv = TemplateVehicle::GetIfValid(template_vehicle_id);
|
||||||
|
|
||||||
if (tv == NULL)
|
if (tv == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
if (should_execute) {
|
if (should_execute) {
|
||||||
Train* train = VirtualTrainFromTemplateVehicle(tv);
|
Train* train = VirtualTrainFromTemplateVehicle(tv);
|
||||||
|
|
||||||
if (train == nullptr)
|
if (train == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
@@ -931,7 +941,7 @@ Train* VirtualTrainFromTemplateVehicle(TemplateVehicle* tv)
|
|||||||
Train *tmp, *head, *tail;
|
Train *tmp, *head, *tail;
|
||||||
|
|
||||||
head = CmdBuildVirtualRailVehicle(tv->engine_type);
|
head = CmdBuildVirtualRailVehicle(tv->engine_type);
|
||||||
if ( !head ) return nullptr;
|
if (!head) return NULL;
|
||||||
|
|
||||||
tail = head;
|
tail = head;
|
||||||
tv = tv->GetNextUnit();
|
tv = tv->GetNextUnit();
|
||||||
@@ -965,8 +975,9 @@ CommandCost CmdVirtualTrainFromTrain(TileIndex tile, DoCommandFlag flags, uint32
|
|||||||
VehicleID vehicle_id = p1;
|
VehicleID vehicle_id = p1;
|
||||||
Vehicle* vehicle = Vehicle::GetIfValid(vehicle_id);
|
Vehicle* vehicle = Vehicle::GetIfValid(vehicle_id);
|
||||||
|
|
||||||
if (vehicle == nullptr || vehicle->type != VEH_TRAIN)
|
if (vehicle == NULL || vehicle->type != VEH_TRAIN) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
Train* train = Train::From(vehicle);
|
Train* train = Train::From(vehicle);
|
||||||
|
|
||||||
@@ -1013,8 +1024,9 @@ CommandCost CmdDeleteVirtualTrain(TileIndex tile, DoCommandFlag flags, uint32 p1
|
|||||||
|
|
||||||
Vehicle* vehicle = Vehicle::GetIfValid(vehicle_id);
|
Vehicle* vehicle = Vehicle::GetIfValid(vehicle_id);
|
||||||
|
|
||||||
if (vehicle == nullptr || vehicle->type != VEH_TRAIN)
|
if (vehicle == NULL || vehicle->type != VEH_TRAIN) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
Train* train = Train::From(vehicle);
|
Train* train = Train::From(vehicle);
|
||||||
|
|
||||||
@@ -1044,8 +1056,9 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
TemplateVehicle* template_vehicle = TemplateVehicle::GetIfValid(template_vehicle_id);
|
TemplateVehicle* template_vehicle = TemplateVehicle::GetIfValid(template_vehicle_id);
|
||||||
Vehicle* vehicle = Vehicle::GetIfValid(virtual_train_id);
|
Vehicle* vehicle = Vehicle::GetIfValid(virtual_train_id);
|
||||||
|
|
||||||
if (vehicle == nullptr || vehicle->type != VEH_TRAIN)
|
if (vehicle == NULL || vehicle->type != VEH_TRAIN) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
Train* train = Train::From(vehicle);
|
Train* train = Train::From(vehicle);
|
||||||
|
|
||||||
@@ -1054,16 +1067,17 @@ CommandCost CmdReplaceTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint3
|
|||||||
if (should_execute) {
|
if (should_execute) {
|
||||||
VehicleID old_ID = INVALID_VEHICLE;
|
VehicleID old_ID = INVALID_VEHICLE;
|
||||||
|
|
||||||
if (template_vehicle != nullptr) {
|
if (template_vehicle != NULL) {
|
||||||
old_ID = template_vehicle->index;
|
old_ID = template_vehicle->index;
|
||||||
delete template_vehicle;
|
delete template_vehicle;
|
||||||
template_vehicle = nullptr;
|
template_vehicle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template_vehicle = TemplateVehicleFromVirtualTrain(train);
|
template_vehicle = TemplateVehicleFromVirtualTrain(train);
|
||||||
|
|
||||||
if (template_vehicle == nullptr)
|
if (template_vehicle == NULL) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure our replacements still point to the correct thing.
|
// Make sure our replacements still point to the correct thing.
|
||||||
if (old_ID != template_vehicle->index) {
|
if (old_ID != template_vehicle->index) {
|
||||||
@@ -1098,20 +1112,21 @@ CommandCost CmdTemplateVehicleFromTrain(TileIndex tile, DoCommandFlag flags, uin
|
|||||||
Vehicle *t = Vehicle::GetIfValid(p1);
|
Vehicle *t = Vehicle::GetIfValid(p1);
|
||||||
|
|
||||||
Train *clicked = Train::GetIfValid(t->index);
|
Train *clicked = Train::GetIfValid(t->index);
|
||||||
if (!clicked)
|
if (!clicked) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
Train *init_clicked = clicked;
|
Train *init_clicked = clicked;
|
||||||
|
|
||||||
int len = CountVehiclesInChain(clicked);
|
int len = CountVehiclesInChain(clicked);
|
||||||
if (!TemplateVehicle::CanAllocateItem(len))
|
if (!TemplateVehicle::CanAllocateItem(len)) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
if (should_execute) {
|
if (should_execute) {
|
||||||
TemplateVehicle *tmp, *prev=0;
|
TemplateVehicle *tmp;
|
||||||
for (; clicked; clicked=clicked->Next()) {
|
TemplateVehicle *prev = NULL;
|
||||||
|
for (; clicked != NULL; clicked = clicked->Next()) {
|
||||||
tmp = new TemplateVehicle(clicked->engine_type);
|
tmp = new TemplateVehicle(clicked->engine_type);
|
||||||
SetupTemplateVehicleFromVirtual(tmp, prev, clicked);
|
SetupTemplateVehicleFromVirtual(tmp, prev, clicked);
|
||||||
prev = tmp;
|
prev = tmp;
|
||||||
@@ -1142,8 +1157,7 @@ CommandCost CmdDeleteTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint32
|
|||||||
// Identify template to delete
|
// Identify template to delete
|
||||||
TemplateVehicle *del = TemplateVehicle::GetIfValid(p1);
|
TemplateVehicle *del = TemplateVehicle::GetIfValid(p1);
|
||||||
|
|
||||||
if (del == NULL)
|
if (del == NULL) return CMD_ERROR;
|
||||||
return CMD_ERROR;
|
|
||||||
|
|
||||||
bool should_execute = (flags & DC_EXEC) != 0;
|
bool should_execute = (flags & DC_EXEC) != 0;
|
||||||
|
|
||||||
@@ -1181,8 +1195,9 @@ CommandCost CmdIssueTemplateReplacement(TileIndex tile, DoCommandFlag flags, uin
|
|||||||
if (should_execute) {
|
if (should_execute) {
|
||||||
bool succeeded = IssueTemplateReplacement(group_id, template_id);
|
bool succeeded = IssueTemplateReplacement(group_id, template_id);
|
||||||
|
|
||||||
if (!succeeded)
|
if (!succeeded) {
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN, 0);
|
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN, 0);
|
||||||
}
|
}
|
||||||
@@ -1207,8 +1222,9 @@ CommandCost CmdDeleteTemplateReplacement(TileIndex tile, DoCommandFlag flags, ui
|
|||||||
|
|
||||||
if (should_execute) {
|
if (should_execute) {
|
||||||
TemplateReplacement* tr = GetTemplateReplacementByGroupID(group_id);
|
TemplateReplacement* tr = GetTemplateReplacementByGroupID(group_id);
|
||||||
if (tr != NULL)
|
if (tr != NULL) {
|
||||||
delete tr;
|
delete tr;
|
||||||
|
}
|
||||||
|
|
||||||
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN, 0);
|
InvalidateWindowClassesData(WC_TEMPLATEGUI_MAIN, 0);
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
|
||||||
Sorting _sorting;
|
Sorting _sorting;
|
||||||
|
|
||||||
static GUIVehicleList::SortFunction VehicleNumberSorter;
|
static GUIVehicleList::SortFunction VehicleNumberSorter;
|
||||||
@@ -952,7 +953,10 @@ struct RefitWindow : public Window {
|
|||||||
|
|
||||||
if (this->order == INVALID_VEH_ORDER_ID) {
|
if (this->order == INVALID_VEH_ORDER_ID) {
|
||||||
bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
|
bool delete_window = this->selected_vehicle == v->index && this->num_vehicles == UINT8_MAX;
|
||||||
if (DoCommandP(v->tile, this->selected_vehicle, this->cargo->cargo | this->cargo->subtype << 8 | this->num_vehicles << 16 | this->is_virtual_train << 5, GetCmdRefitVeh(v)) && delete_window) delete this;
|
if (DoCommandP(v->tile, this->selected_vehicle, this->cargo->cargo | this->cargo->subtype << 8 | this->num_vehicles << 16 | this->is_virtual_train << 5,
|
||||||
|
GetCmdRefitVeh(v)) && delete_window) {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16 | this->is_virtual_train << 5, CMD_ORDER_REFIT)) delete this;
|
if (DoCommandP(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8 | this->order << 16 | this->is_virtual_train << 5, CMD_ORDER_REFIT)) delete this;
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,6 @@ enum BuildVehicleWidgets {
|
|||||||
WID_BV_SHOW_HIDE, ///< Button to hide or show the selected engine.
|
WID_BV_SHOW_HIDE, ///< Button to hide or show the selected engine.
|
||||||
WID_BV_BUILD_SEL, ///< Build button.
|
WID_BV_BUILD_SEL, ///< Build button.
|
||||||
WID_BV_RENAME, ///< Rename button.
|
WID_BV_RENAME, ///< Rename button.
|
||||||
BUILD_VEHICLE_WIDGET_BUILD, /// TODO: own
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WIDGETS_BUILD_VEHICLE_WIDGET_H */
|
#endif /* WIDGETS_BUILD_VEHICLE_WIDGET_H */
|
||||||
|
Reference in New Issue
Block a user