Skip to content

Commit 5c20c67

Browse files
author
Guido Pinkas
committed
first version of BaseFacility article
1 parent eb6afd3 commit 5c20c67

9 files changed

Lines changed: 266 additions & 2 deletions

‎src/Ruleset/ArticleDefinition.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ namespace OpenXcom
8484
ArticleDefinitionTextImage::ArticleDefinitionTextImage() : ArticleDefinition(UFOPAEDIA_TYPE_TEXTIMAGE)
8585
{}
8686

87+
/**
88+
* Constructor (only setting type of base class)
89+
*/
90+
ArticleDefinitionBaseFacility::ArticleDefinitionBaseFacility() : ArticleDefinition(UFOPAEDIA_TYPE_BASE_FACILITY), facility(0)
91+
{}
92+
8793
/**
8894
* Constructor (only setting type of base class)
8995
*/

‎src/Ruleset/ArticleDefinition.h‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace OpenXcom
2727
{
2828
class RuleCraft;
2929
class RuleCraftWeapon;
30+
class RuleBaseFacility;
3031
class RuleUfo;
3132

3233
/// define article types
@@ -37,7 +38,7 @@ namespace OpenXcom
3738
UFOPAEDIA_TYPE_HWP = 3,
3839
UFOPAEDIA_TYPE_EQUIPMENT = 4,
3940
UFOPAEDIA_TYPE_WEAPON = 5,
40-
UFOPAEDIA_TYPE_FACILITY = 6,
41+
UFOPAEDIA_TYPE_BASE_FACILITY = 6,
4142
UFOPAEDIA_TYPE_TEXTIMAGE = 7,
4243
UFOPAEDIA_TYPE_TEXT = 8,
4344
UFOPAEDIA_TYPE_UFO = 9
@@ -146,6 +147,20 @@ namespace OpenXcom
146147
int text_width;
147148
};
148149

150+
/**
151+
* ArticleDefinitionBaseFacility defines articles for base facilities, e.g. Access lift.
152+
* They have an image (found in BASEBITS.PCK), a stats block and a description.
153+
*/
154+
155+
class ArticleDefinitionBaseFacility : public ArticleDefinition
156+
{
157+
public:
158+
/// Constructor
159+
ArticleDefinitionBaseFacility();
160+
RuleBaseFacility *facility;
161+
std::string text;
162+
};
163+
149164
/**
150165
* ArticleDefinitionUfo defines articles for UFOs, e.g. Small Scout, Terror Ship, etc.
151166
* They have an image (found in INTERWIN.DAT), a stats block and a description.

‎src/Ruleset/XcomRuleset.cpp‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,18 @@ XcomRuleset::XcomRuleset() : Ruleset()
13911391

13921392
_ufopaediaArticles[article_text.id] = new ArticleDefinitionText(article_text);
13931393

1394+
// BASE FACILITIES
1395+
ArticleDefinitionBaseFacility article_facility;
1396+
article_facility.section = UFOPAEDIA_BASE_FACILITIES;
1397+
1398+
article_facility.id = "STR_ACCESS_LIFT";
1399+
article_facility.title = "STR_ACCESS_LIFT";
1400+
article_facility.text = "STR_ACCESS_LIFT_UFOPEDIA";
1401+
article_facility.facility = _facilities[article_facility.id];
1402+
article_facility.sort_key = sort_key++;
1403+
1404+
_ufopaediaArticles[article_facility.id] = new ArticleDefinitionBaseFacility(article_facility);
1405+
13941406
// UFOs
13951407
ArticleDefinitionUfo article_ufo;
13961408
article_ufo.section = UFOPAEDIA_UFOS;
@@ -1401,8 +1413,16 @@ XcomRuleset::XcomRuleset() : Ruleset()
14011413
article_ufo.ufo = _ufos[article_ufo.id];
14021414
article_ufo.sort_key = sort_key++;
14031415

1404-
_ufopaediaArticles[article_text.id] = new ArticleDefinitionUfo(article_ufo);
1416+
_ufopaediaArticles[article_ufo.id] = new ArticleDefinitionUfo(article_ufo);
14051417

1418+
article_ufo.id = "STR_HARVESTER";
1419+
article_ufo.title = "STR_HARVESTER";
1420+
article_ufo.text = "STR_HARVESTER_UFOPEDIA";
1421+
article_ufo.ufo = _ufos[article_ufo.id];
1422+
article_ufo.sort_key = sort_key++;
1423+
1424+
_ufopaediaArticles[article_ufo.id] = new ArticleDefinitionUfo(article_ufo);
1425+
14061426

14071427
_costSoldier = 20000;
14081428
_costEngineer = 25000;
@@ -1556,6 +1576,11 @@ SavedGame *XcomRuleset::newSave(GameDifficulty diff)
15561576
// save->getUfopaedia()->insertArticle(_ufopaediaArticles["STR_SNAKEMAN"]);
15571577
save->getUfopaedia()->insertArticle(_ufopaediaArticles["STR_ALIEN_ORIGINS"]);
15581578

1579+
save->getUfopaedia()->insertArticle(_ufopaediaArticles["STR_ACCESS_LIFT"]);
1580+
1581+
save->getUfopaedia()->insertArticle(_ufopaediaArticles["STR_SMALL_SCOUT"]);
1582+
save->getUfopaedia()->insertArticle(_ufopaediaArticles["STR_HARVESTER"]);
1583+
15591584
return save;
15601585
}
15611586

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright 2011 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+
20+
#include <sstream>
21+
22+
#include "Ufopaedia.h"
23+
#include "ArticleStateBaseFacility.h"
24+
#include "../Ruleset/ArticleDefinition.h"
25+
#include "../Ruleset/RuleBaseFacility.h"
26+
#include "../Engine/Game.h"
27+
#include "../Engine/Palette.h"
28+
#include "../Engine/Surface.h"
29+
#include "../Engine/Language.h"
30+
#include "../Resource/ResourcePack.h"
31+
#include "../Interface/Text.h"
32+
#include "../Interface/TextButton.h"
33+
#include "../Interface/TextList.h"
34+
35+
namespace OpenXcom
36+
{
37+
38+
ArticleStateBaseFacility::ArticleStateBaseFacility(Game *game, ArticleDefinitionBaseFacility *defs) : ArticleState(game, defs->id)
39+
{
40+
// add screen elements
41+
_txtTitle = new Text(140, 32, 10, 24);
42+
43+
// Set palette
44+
_game->setPalette(_game->getResourcePack()->getPalette("PALETTES.DAT_1")->getColors());
45+
46+
ArticleState::initLayout();
47+
48+
// add other elements
49+
add(_txtTitle);
50+
51+
// Set up objects
52+
_game->getResourcePack()->getSurface("BACK09.SCR")->blit(_bg);
53+
_btnOk->setColor(Palette::blockOffset(4)+2);
54+
_btnPrev->setColor(Palette::blockOffset(4)+2);
55+
_btnNext->setColor(Palette::blockOffset(4)+2);
56+
57+
_txtTitle->setColor(Palette::blockOffset(13)+10);
58+
_txtTitle->setBig();
59+
_txtTitle->setAlign(ALIGN_LEFT);
60+
_txtTitle->setWordWrap(true);
61+
_txtTitle->setText(Ufopaedia::buildText(_game, defs->title));
62+
63+
/*
64+
for (std::vector<BaseFacility*>::iterator i = _base->getFacilities()->begin(); i != _base->getFacilities()->end(); ++i)
65+
{
66+
// Draw facility shape
67+
int num = 0;
68+
for (int y = (*i)->getY(); y < (*i)->getY() + (*i)->getRules()->getSize(); y++)
69+
{
70+
for (int x = (*i)->getX(); x < (*i)->getX() + (*i)->getRules()->getSize(); x++)
71+
{
72+
Surface *frame;
73+
74+
if ((*i)->getBuildTime() == 0)
75+
frame = _texture->getFrame((*i)->getRules()->getSpriteShape() + num);
76+
else
77+
frame = _texture->getFrame((*i)->getRules()->getSpriteShape() + num + 2 + (*i)->getRules()->getSize());
78+
79+
frame->setX(x * GRID_SIZE);
80+
frame->setY(y * GRID_SIZE);
81+
frame->blit(this);
82+
83+
num++;
84+
}
85+
}
86+
}
87+
*/
88+
89+
/*
90+
_image = new Surface(160, 52, 160, 6);
91+
add(_image);
92+
93+
Surface *graphic = _game->getResourcePack()->getSurface("INTERWIN.DAT");
94+
graphic->setX(0);
95+
graphic->setY(0);
96+
graphic->getCrop()->x = 0;
97+
graphic->getCrop()->y = 0;
98+
graphic->getCrop()->w = 160;
99+
graphic->getCrop()->h = 52;
100+
_image->drawRect(graphic->getCrop(), 15);
101+
graphic->getCrop()->y = 140 + 52 * defs->ufo->getSprite();
102+
graphic->getCrop()->h = 52;
103+
graphic->blit(_image);
104+
*/
105+
106+
_txtInfo = new Text(300, 90, 10, 104);
107+
add(_txtInfo);
108+
109+
_txtInfo->setColor(Palette::blockOffset(13)+10);
110+
_txtInfo->setAlign(ALIGN_LEFT);
111+
_txtInfo->setWordWrap(true);
112+
_txtInfo->setText(Ufopaedia::buildText(_game, defs->text));
113+
114+
_lstInfo = new TextList(300, 60, 10, 42);
115+
add(_lstInfo);
116+
117+
_lstInfo->setColor(Palette::blockOffset(13)+10);
118+
_lstInfo->setColumns(2, 140, 40);
119+
_lstInfo->setDot(true);
120+
121+
std::wstringstream ss;
122+
ss.str(L"");ss.clear();
123+
ss << defs->facility->getBuildTime();
124+
ss << _game->getLanguage()->getString("STR_DAYS");
125+
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_CONSTRUCTION_TIME").c_str(), ss.str().c_str());
126+
_lstInfo->getCell(0, 1)->setColor(Palette::blockOffset(13)+0);
127+
128+
ss.str(L"");ss.clear();
129+
ss << Text::formatFunding(defs->facility->getBuildCost());
130+
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_CONSTRUCTION_COST").c_str(), ss.str().c_str());
131+
_lstInfo->getCell(1, 1)->setColor(Palette::blockOffset(13)+0);
132+
133+
ss.str(L"");ss.clear();
134+
ss << Text::formatFunding(defs->facility->getMonthlyCost());
135+
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_MAINTENANCE_COST").c_str(), ss.str().c_str());
136+
_lstInfo->getCell(2, 1)->setColor(Palette::blockOffset(13)+0);
137+
138+
_lstInfo->draw();
139+
}
140+
141+
ArticleStateBaseFacility::~ArticleStateBaseFacility()
142+
{}
143+
144+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2011 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+
20+
#ifndef OPENXCOM_ARTICLESTATEBASEFACILITY_H
21+
#define OPENXCOM_ARTICLESTATEBASEFACILITY_H
22+
23+
#include <string>
24+
#include "ArticleState.h"
25+
26+
namespace OpenXcom
27+
{
28+
class Game;
29+
class Surface;
30+
class Text;
31+
class TextList;
32+
class ArticleDefinitionBaseFacility;
33+
34+
/**
35+
* ArticleStateBaseFacility has a caption, text, preview image and a stats block.
36+
* The facility image is found using the RuleBasefacility class.
37+
*/
38+
39+
class ArticleStateBaseFacility : public ArticleState
40+
{
41+
public:
42+
ArticleStateBaseFacility(Game *game, ArticleDefinitionBaseFacility *article_defs);
43+
virtual ~ArticleStateBaseFacility();
44+
45+
protected:
46+
Surface *_image;
47+
Text *_txtTitle;
48+
Text *_txtInfo;
49+
TextList *_lstInfo;
50+
};
51+
}
52+
53+
#endif

‎src/Ufopaedia/Ufopaedia.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "../Savegame/UfopaediaSaved.h"
2323
#include "../Ruleset/ArticleDefinition.h"
2424
#include "ArticleState.h"
25+
#include "ArticleStateBaseFacility.h"
2526
#include "ArticleStateCraft.h"
2627
#include "ArticleStateCraftWeapon.h"
2728
#include "ArticleStateText.h"
@@ -63,6 +64,9 @@ namespace OpenXcom
6364
case UFOPAEDIA_TYPE_CRAFT_WEAPON:
6465
return new ArticleStateCraftWeapon(game, static_cast<ArticleDefinitionCraftWeapon *> (article));
6566
break;
67+
case UFOPAEDIA_TYPE_BASE_FACILITY:
68+
return new ArticleStateBaseFacility(game, static_cast<ArticleDefinitionBaseFacility *> (article));
69+
break;
6670
case UFOPAEDIA_TYPE_TEXT:
6771
return new ArticleStateText(game, static_cast<ArticleDefinitionText *> (article));
6872
break;

‎src/Ufopaedia/Ufopaedia.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace OpenXcom
3333

3434
/// define Ufopaedia sections, which must be consistent
3535
static const std::string UFOPAEDIA_XCOM_CRAFT_ARMAMENT = "XCOM_CRAFT_ARMAMENT";
36+
static const std::string UFOPAEDIA_BASE_FACILITIES = "BASE_FACILITIES";
3637
static const std::string UFOPAEDIA_ALIEN_LIFE_FORMS = "ALIEN_LIFE_FORMS";
3738
static const std::string UFOPAEDIA_ALIEN_RESEARCH = "ALIEN_RESEARCH";
3839
static const std::string UFOPAEDIA_UFOS = "UFOS";

‎src/Ufopaedia/UfopaediaStartState.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace OpenXcom
4444
// set buttons
4545
_btnOk = new TextButton(224, 12, 48, 167);
4646
_btnCraftArmament = new TextButton(224, 12, 48, 50);
47+
_btnBaseFacilities = new TextButton(224, 12, 48, 102);
4748
_btnAlienLifeforms = new TextButton(224, 12, 48, 115);
4849
_btnAlienResearch = new TextButton(224, 12, 48, 128);
4950
_btnUfos = new TextButton(224, 12, 48, 154);
@@ -55,6 +56,7 @@ namespace OpenXcom
5556
add(_txtTitle);
5657
add(_btnOk);
5758
add(_btnCraftArmament);
59+
add(_btnBaseFacilities);
5860
add(_btnAlienLifeforms);
5961
add(_btnAlienResearch);
6062
add(_btnUfos);
@@ -75,6 +77,10 @@ namespace OpenXcom
7577
_btnCraftArmament->setText(_game->getLanguage()->getString("STR_XCOM_CRAFT_ARMAMENT"));
7678
_btnCraftArmament->onMouseClick((ActionHandler)&UfopaediaStartState::btnCraftArmamentClick);
7779

80+
_btnBaseFacilities->setColor(Palette::blockOffset(8)+8);
81+
_btnBaseFacilities->setText(_game->getLanguage()->getString("STR_BASE_FACILITIES"));
82+
_btnBaseFacilities->onMouseClick((ActionHandler)&UfopaediaStartState::btnBaseFacilitiesClick);
83+
7884
_btnAlienLifeforms->setColor(Palette::blockOffset(8)+8);
7985
_btnAlienLifeforms->setText(_game->getLanguage()->getString("STR_ALIEN_LIFE_FORMS"));
8086
_btnAlienLifeforms->onMouseClick((ActionHandler)&UfopaediaStartState::btnAlienLifeformsClick);
@@ -110,6 +116,15 @@ namespace OpenXcom
110116
_game->pushState(new UfopaediaSelectState(_game, UFOPAEDIA_XCOM_CRAFT_ARMAMENT));
111117
}
112118

119+
/**
120+
*
121+
* @param action Pointer to an action.
122+
*/
123+
void UfopaediaStartState::btnBaseFacilitiesClick(Action *action)
124+
{
125+
_game->pushState(new UfopaediaSelectState(_game, UFOPAEDIA_BASE_FACILITIES));
126+
}
127+
113128
/**
114129
*
115130
* @param action Pointer to an action.

‎src/Ufopaedia/UfopaediaStartState.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace OpenXcom
6060
// navigation callbacks
6161
void btnOkClick(Action *action);
6262
void btnCraftArmamentClick(Action *action);
63+
void btnBaseFacilitiesClick(Action *action);
6364
void btnAlienLifeformsClick(Action *action);
6465
void btnAlienResearchClick(Action *action);
6566
void btnUfosClick(Action *action);

0 commit comments

Comments
 (0)