Repository navigation
Expand file tree
/
Copy pathUfopaedia.cpp
More file actions
186 lines (171 loc) · 5.64 KB
/
Copy pathUfopaedia.cpp
File metadata and controls
186 lines (171 loc) · 5.64 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Copyright 2010 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 "Ufopaedia.h"
#include "UfopaediaStartState.h"
#include "../Savegame/UfopaediaSaved.h"
#include "../Ruleset/ArticleDefinition.h"
#include "ArticleState.h"
#include "ArticleStateBaseFacility.h"
#include "ArticleStateCraft.h"
#include "ArticleStateCraftWeapon.h"
#include "ArticleStateItem.h"
#include "ArticleStateText.h"
#include "ArticleStateTextImage.h"
#include "ArticleStateUfo.h"
#include "../Engine/Game.h"
#include "../Engine/Language.h"
// these are for runStandalone...
#include "../Resource/ResourcePack.h"
#include "../Ruleset/XcomRuleset.h"
namespace OpenXcom
{
/**
* Adds a new article to the visible list, mainly after a successful research.
* @param game Pointer to actual game.
* @param article_id Article id to release.
*/
void Ufopaedia::releaseArticle(Game *game, std::string &article_id)
{
// TODO: get definition from Ruleset and add it to UPSaved...
}
/**
* Checks, if an article has already been released.
* @param game Pointer to actual game.
* @param article_id Article id to release.
* @returns true, if the article is available.
*/
bool Ufopaedia::isArticleAvailable(Game *game, std::string &article_id)
{
return game->getSavedGame()->getUfopaedia()->isArticleAvailable(article_id);
}
/**
* Creates a new article state dependent on the given article definition.
* @param game Pointer to actual game.
* @param article Article definition to create from.
* @returns Article state object if created, 0 otherwise.
*/
ArticleState *Ufopaedia::createArticleState(Game *game, ArticleDefinition *article)
{
switch(article->getType())
{
case UFOPAEDIA_TYPE_CRAFT:
return new ArticleStateCraft(game, static_cast<ArticleDefinitionCraft *> (article));
break;
case UFOPAEDIA_TYPE_CRAFT_WEAPON:
return new ArticleStateCraftWeapon(game, static_cast<ArticleDefinitionCraftWeapon *> (article));
break;
case UFOPAEDIA_TYPE_ITEM:
return new ArticleStateItem(game, static_cast<ArticleDefinitionItem *> (article));
break;
case UFOPAEDIA_TYPE_BASE_FACILITY:
return new ArticleStateBaseFacility(game, static_cast<ArticleDefinitionBaseFacility *> (article));
break;
case UFOPAEDIA_TYPE_TEXT:
return new ArticleStateText(game, static_cast<ArticleDefinitionText *> (article));
break;
case UFOPAEDIA_TYPE_TEXTIMAGE:
return new ArticleStateTextImage(game, static_cast<ArticleDefinitionTextImage *> (article));
break;
case UFOPAEDIA_TYPE_UFO:
return new ArticleStateUfo(game, static_cast<ArticleDefinitionUfo *> (article));
break;
}
return 0;
}
/**
* Set UPSaved index and open the new state.
* @param game Pointer to actual game.
* @param article Article definition of the article to open.
*/
void Ufopaedia::openArticle(Game *game, ArticleDefinition *article)
{
game->getSavedGame()->getUfopaedia()->setCurrentArticle(article);
game->pushState(createArticleState(game, article));
}
/**
* Checks if selected article_id is available -> if yes, open it.
* Otherwise, open start state!
* @param game Pointer to actual game.
* @param article_id Article id to find.
*/
void Ufopaedia::openArticle(Game *game, std::string &article_id)
{
// TODO: look if article id is available!
}
/**
* Open Ufopaedia start state, presenting the section selection buttons.
* @param game Pointer to actual game.
*/
void Ufopaedia::open(Game *game)
{
game->pushState(new UfopaediaStartState(game));
}
/**
* Open the next article in the list. Loops to the first.
* @param game Pointer to actual game.
*/
void Ufopaedia::next(Game *game)
{
ArticleDefinition *article = game->getSavedGame()->getUfopaedia()->goNextArticle();
if (article)
{
game->popState();
game->pushState(createArticleState(game, article));
}
}
/**
* Open the previous article in the list. Loops to the last.
* @param game Pointer to actual game.
*/
void Ufopaedia::prev(Game *game)
{
ArticleDefinition *article = game->getSavedGame()->getUfopaedia()->goPrevArticle();
if (article)
{
game->popState();
game->pushState(createArticleState(game, article));
}
}
/**
* Build a string from a string template. A template can be a concatenation of string ids,
* f.i. "STR_SECTOID + STR_AUTOPSY". Maybe must add constant for whitepace also.
* @param game Pointer to actual game.
* @param str_template String containing the text constants
* @returns The string built using the text constant(s).
*/
std::wstring Ufopaedia::buildText(Game *game, std::string &str_template)
{
// TODO: actually parse the template string.
return game->getLanguage()->getString(str_template);
}
/**
* Open Ufopaedia to test it without starting a whole game.
* @param game Pointer to actual game.
*/
void Ufopaedia::runStandalone(Game *game)
{
// set game language
game->loadLanguage("English");
// init game
game->setRuleset(new XcomRuleset());
game->setSavedGame(game->getRuleset()->newSave(DIFF_BEGINNER));
// open Ufopaedia
open(game);
}
}