|
| 1 | +/* |
| 2 | + * Copyright 2010-2012 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 "NewBattleState.h" |
| 20 | +#include "../Engine/Game.h" |
| 21 | +#include "../Resource/ResourcePack.h" |
| 22 | +#include "../Engine/Language.h" |
| 23 | +#include "../Engine/Font.h" |
| 24 | +#include "../Engine/Palette.h" |
| 25 | +#include "../Interface/TextButton.h" |
| 26 | +#include "../Interface/Window.h" |
| 27 | +#include "../Interface/Text.h" |
| 28 | +#include "../Ruleset/XcomRuleset.h" |
| 29 | +#include "../Savegame/SavedGame.h" |
| 30 | +#include "../Savegame/Base.h" |
| 31 | +#include "../Savegame/Craft.h" |
| 32 | +#include "../Savegame/ItemContainer.h" |
| 33 | +#include "../Battlescape/BattlescapeGenerator.h" |
| 34 | +#include "../Battlescape/BattlescapeState.h" |
| 35 | + |
| 36 | +namespace OpenXcom |
| 37 | +{ |
| 38 | + |
| 39 | +/** |
| 40 | + * Initializes all the elements in the Difficulty window. |
| 41 | + * @param game Pointer to the core game. |
| 42 | + */ |
| 43 | +NewBattleState::NewBattleState(Game *game) : State(game) |
| 44 | +{ |
| 45 | + // Create objects |
| 46 | + _window = new Window(this, 320, 200, 0, 0, POPUP_BOTH); |
| 47 | + _txtTitle = new Text(320, 16, 0, 8); |
| 48 | + _btnOk = new TextButton(148, 16, 8, 176); |
| 49 | + _btnCancel = new TextButton(148, 16, 164, 176); |
| 50 | + |
| 51 | + add(_window); |
| 52 | + add(_txtTitle); |
| 53 | + add(_btnOk); |
| 54 | + add(_btnCancel); |
| 55 | + |
| 56 | + // Set up objects |
| 57 | + _window->setColor(Palette::blockOffset(8)+5); |
| 58 | + _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR")); |
| 59 | + |
| 60 | + _txtTitle->setColor(Palette::blockOffset(8)+10); |
| 61 | + _txtTitle->setAlign(ALIGN_CENTER); |
| 62 | + _txtTitle->setBig(); |
| 63 | + _txtTitle->setText(L"THE SIMULATRON"); |
| 64 | + |
| 65 | + _btnOk->setColor(Palette::blockOffset(8)+5); |
| 66 | + _btnOk->setText(_game->getLanguage()->getString("STR_OK")); |
| 67 | + _btnOk->onMouseClick((ActionHandler)&NewBattleState::btnOkClick); |
| 68 | + |
| 69 | + _btnCancel->setColor(Palette::blockOffset(8)+5); |
| 70 | + _btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL_UC")); |
| 71 | + _btnCancel->onMouseClick((ActionHandler)&NewBattleState::btnCancelClick); |
| 72 | + |
| 73 | + initSave(); |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * |
| 78 | + */ |
| 79 | +NewBattleState::~NewBattleState() |
| 80 | +{ |
| 81 | + |
| 82 | +} |
| 83 | + |
| 84 | +void NewBattleState::initSave() |
| 85 | +{ |
| 86 | + //_game->setRuleset(new XcomRuleset()); |
| 87 | + Ruleset *rule = _game->getRuleset(); |
| 88 | + SavedGame *save = new SavedGame(DIFF_BEGINNER); |
| 89 | + Base *base = new Base(rule); |
| 90 | + save->getBases()->push_back(base); |
| 91 | + Craft *craft = new Craft(rule->getCraft("STR_SKYRANGER"), base, save->getCraftIds()); |
| 92 | + base->getCrafts()->push_back(craft); |
| 93 | + |
| 94 | + // Generate soldiers |
| 95 | + for (int i = 0; i < 30; ++i) |
| 96 | + { |
| 97 | + Soldier *soldier = new Soldier(rule->getSoldier("XCOM"), rule->getArmor("STR_NONE_UC"), rule->getPools(), save->getSoldierId()); |
| 98 | + base->getSoldiers()->push_back(soldier); |
| 99 | + if (i < 8) |
| 100 | + soldier->setCraft(craft); |
| 101 | + } |
| 102 | + |
| 103 | + // Generate items |
| 104 | + std::vector<std::string> items = rule->getItemsList(); |
| 105 | + for (std::vector<std::string>::iterator i = items.begin(); i != items.end(); ++i) |
| 106 | + { |
| 107 | + base->getItems()->addItem(*i, 99); |
| 108 | + } |
| 109 | + |
| 110 | + _game->setSavedGame(save); |
| 111 | +} |
| 112 | + |
| 113 | +/** |
| 114 | + * Starts the battle. |
| 115 | + * @param action Pointer to an action. |
| 116 | + */ |
| 117 | +void NewBattleState::btnOkClick(Action *action) |
| 118 | +{ |
| 119 | + SavedBattleGame *bgame = new SavedBattleGame(); |
| 120 | + _game->getSavedGame()->setBattleGame(bgame); |
| 121 | + bgame->setMissionType("STR_TERROR_MISSION"); |
| 122 | + BattlescapeGenerator bgen = BattlescapeGenerator(_game); |
| 123 | + bgen.setWorldTexture(1); |
| 124 | + bgen.setWorldShade(0); |
| 125 | + bgen.setCraft(_game->getSavedGame()->getBases()->at(0)->getCrafts()->at(0)); |
| 126 | + bgen.setBase(_game->getSavedGame()->getBases()->at(0)); |
| 127 | + bgen.setAlienRace("STR_SECTOID"); |
| 128 | + bgen.setAlienItemlevel(0); |
| 129 | + bgen.run(); |
| 130 | + _game->getSavedGame()->getBattleGame()->resetUnitTiles(); |
| 131 | + _game->pushState(new BattlescapeState(_game)); |
| 132 | +} |
| 133 | + |
| 134 | +/** |
| 135 | + * Returns to the previous screen. |
| 136 | + * @param action Pointer to an action. |
| 137 | + */ |
| 138 | +void NewBattleState::btnCancelClick(Action *action) |
| 139 | +{ |
| 140 | + //_game->setRuleset(0); |
| 141 | + _game->setSavedGame(0); |
| 142 | + _game->popState(); |
| 143 | +} |
| 144 | + |
| 145 | +} |
0 commit comments