1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "PlaceStartFacilityState.h"
20 #include "../Engine/Game.h"
21 #include "../Engine/Language.h"
22 #include "../Engine/Palette.h"
23 #include "../Interface/Text.h"
24 #include "BaseView.h"
25 #include "../Savegame/Base.h"
26 #include "../Savegame/BaseFacility.h"
27 #include "../Ruleset/RuleBaseFacility.h"
28 #include "../Savegame/SavedGame.h"
29 #include "../Menu/ErrorMessageState.h"
30 #include "SelectStartFacilityState.h"
31 
32 namespace OpenXcom
33 {
34 
35 /**
36  * Initializes all the elements in the Place Facility window.
37  * @param game Pointer to the core game.
38  * @param base Pointer to the base to get info from.
39  * @param select Pointer to the selection state.
40  * @param rule Pointer to the facility ruleset to build.
41  */
PlaceStartFacilityState(Game * game,Base * base,SelectStartFacilityState * select,RuleBaseFacility * rule)42 PlaceStartFacilityState::PlaceStartFacilityState(Game *game, Base *base, SelectStartFacilityState *select, RuleBaseFacility *rule) : PlaceFacilityState(game, base, rule), _select(select)
43 {
44 	_view->onMouseClick((ActionHandler)&PlaceStartFacilityState::viewClick);
45 	_numCost->setText(tr("STR_NONE"));
46 	_numTime->setText(tr("STR_NONE"));
47 }
48 
49 /**
50  *
51  */
~PlaceStartFacilityState()52 PlaceStartFacilityState::~PlaceStartFacilityState()
53 {
54 
55 }
56 
57 /**
58  * Processes clicking on facilities.
59  * @param action Pointer to an action.
60  */
viewClick(Action *)61 void PlaceStartFacilityState::viewClick(Action *)
62 {
63 	if (!_view->isPlaceable(_rule))
64 	{
65 		_game->popState();
66 		_game->pushState(new ErrorMessageState(_game, "STR_CANNOT_BUILD_HERE", _palette, Palette::blockOffset(15)+1, "BACK01.SCR", 6));
67 	}
68 	else
69 	{
70 		BaseFacility *fac = new BaseFacility(_rule, _base);
71 		fac->setX(_view->getGridX());
72 		fac->setY(_view->getGridY());
73 		_base->getFacilities()->push_back(fac);
74 		_game->popState();
75 		_select->facilityBuilt();
76 	}
77 }
78 
79 }
80