Repository navigation
Expand file tree
/
Copy pathDismantleFacilityState.cpp
More file actions
143 lines (126 loc) · 4.07 KB
/
Copy pathDismantleFacilityState.cpp
File metadata and controls
143 lines (126 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom 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, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom 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 OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DismantleFacilityState.h"
#include "../Engine/Game.h"
#include "../Mod/Mod.h"
#include "../Engine/LocalizedText.h"
#include "../Engine/Options.h"
#include "../Interface/TextButton.h"
#include "../Interface/Window.h"
#include "../Interface/Text.h"
#include "../Savegame/Base.h"
#include "../Savegame/BaseFacility.h"
#include "BaseView.h"
#include "../Mod/RuleBaseFacility.h"
#include "../Savegame/SavedGame.h"
namespace OpenXcom
{
/**
* Initializes all the elements in a Dismantle Facility window.
* @param game Pointer to the core game.
* @param base Pointer to the base to get info from.
* @param view Pointer to the baseview to update.
* @param fac Pointer to the facility to dismantle.
*/
DismantleFacilityState::DismantleFacilityState(Base *base, BaseView *view, BaseFacility *fac) : _base(base), _view(view), _fac(fac)
{
_screen = false;
// Create objects
_window = new Window(this, 152, 80, 20, 60);
_btnOk = new TextButton(44, 16, 36, 115);
_btnCancel = new TextButton(44, 16, 112, 115);
_txtTitle = new Text(142, 9, 25, 75);
_txtFacility = new Text(142, 9, 25, 85);
// Set palette
setInterface("dismantleFacility");
add(_window, "window", "dismantleFacility");
add(_btnOk, "button", "dismantleFacility");
add(_btnCancel, "button", "dismantleFacility");
add(_txtTitle, "text", "dismantleFacility");
add(_txtFacility, "text", "dismantleFacility");
centerAllSurfaces();
// Set up objects
_window->setBackground(_game->getMod()->getSurface("BACK13.SCR"));
_btnOk->setText(tr("STR_OK"));
_btnOk->onMouseClick((ActionHandler)&DismantleFacilityState::btnOkClick);
_btnOk->onKeyboardPress((ActionHandler)&DismantleFacilityState::btnOkClick, Options::keyOk);
_btnCancel->setText(tr("STR_CANCEL_UC"));
_btnCancel->onMouseClick((ActionHandler)&DismantleFacilityState::btnCancelClick);
_btnCancel->onKeyboardPress((ActionHandler)&DismantleFacilityState::btnCancelClick, Options::keyCancel);
_txtTitle->setAlign(ALIGN_CENTER);
_txtTitle->setText(tr("STR_DISMANTLE"));
_txtFacility->setAlign(ALIGN_CENTER);
_txtFacility->setText(tr(_fac->getRules()->getType()));
}
/**
*
*/
DismantleFacilityState::~DismantleFacilityState()
{
}
/**
* Dismantles the facility and returns
* to the previous screen.
* @param action Pointer to an action.
*/
void DismantleFacilityState::btnOkClick(Action *)
{
if (!_fac->getRules()->isLift())
{
// Give refund if this is an unstarted, queued build.
if (_fac->getBuildTime() > _fac->getRules()->getBuildTime())
{
_game->getSavedGame()->setFunds(_game->getSavedGame()->getFunds() + _fac->getRules()->getBuildCost());
}
for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i)
{
if (*i == _fac)
{
_base->getFacilities()->erase(i);
_view->resetSelectedFacility();
delete _fac;
if (Options::allowBuildingQueue) _view->reCalcQueuedBuildings();
break;
}
}
}
// Remove whole base if it's the access lift
else
{
for (std::vector<Base*>::iterator i = _game->getSavedGame()->getBases()->begin(); i != _game->getSavedGame()->getBases()->end(); ++i)
{
if (*i == _base)
{
_game->getSavedGame()->getBases()->erase(i);
delete _base;
break;
}
}
}
_game->popState();
}
/**
* Returns to the previous screen.
* @param action Pointer to an action.
*/
void DismantleFacilityState::btnCancelClick(Action *)
{
_game->popState();
}
}