Beispiel #1
0
	/**
	 * Gets the index of the selected article_id in the visible list.
	 * If the id is not found, returns -1.
	 * @param save Pointer to saved game.
	 * @param rule Pointer to ruleset.
	 * @param article_id Article id to find.
	 * @returns Index of the given article id in the internal list, -1 if not found.
	 */
	size_t Ufopaedia::getArticleIndex(SavedGame *save, Ruleset *rule, std::string &article_id)
	{
		std::string UC_ID = article_id + "_UC";
		ArticleDefinitionList articles = getAvailableArticles(save, rule);
		for (size_t it=0; it<articles.size(); ++it)
		{
			for (std::vector<std::string>::iterator j = articles[it]->requires.begin(); j != articles[it]->requires.end(); ++j)
			{
				if (article_id == *j)
				{
					article_id = articles[it]->id;
					return it;
				}
			}
			if (articles[it]->id == article_id)
			{
				return it;
			}
			if (articles[it]->id == UC_ID)
			{
				article_id = UC_ID;
				return it;
			}
		}
		return -1;
	}
Beispiel #2
0
	/**
	 * Fill an ArticleList with the currently visible ArticleIds of the given section.
	 * @param save Pointer to saved game.
	 * @param rule Pointer to ruleset.
	 * @param section Article section to find, e.g. "XCOM Crafts & Armaments", "Alien Lifeforms", etc.
	 * @param data Article definition list object to fill data in.
	 */
	void Ufopaedia::list(SavedGame *save, Ruleset *rule, const std::string &section, ArticleDefinitionList &data)
	{
		ArticleDefinitionList articles = getAvailableArticles(save, rule);
		for (ArticleDefinitionList::iterator it=articles.begin(); it!=articles.end(); ++it)
		{
			if ((*it)->section == section)
			{
				data.push_back(*it);
			}
		}
	}
	/**
	 * Gets the index of the selected article_id in the visible list.
	 * If the id is not found, returns -1.
	 * @param article_id Article id to find.
	 * @returns Index of the given article id in the internal list, -1 if not found.
	 */
	size_t Ufopaedia::getArticleIndex(Game *game, const std::string &article_id)
	{
		ArticleDefinitionList articles = getAvailableArticles(game);
		for (size_t it=0; it<articles.size(); ++it)
		{
			if (articles[it]->id == article_id)
			{
				return it;
			}
		}
		return -1;
	}
Beispiel #4
0
	/**
	 * Open the previous article in the list. Loops to the last.
	 * @param game Pointer to actual game.
	 */
	void Ufopaedia::prev(Game *game)
	{
		ArticleDefinitionList articles = getAvailableArticles(game->getSavedGame(), game->getRuleset());
		if (_current_index == 0)
		{
			// goto last
			_current_index = articles.size() - 1;
		}
		else
		{
			_current_index--;
		}
		game->popState();
		game->pushState(createArticleState(articles[_current_index]));
	}
Beispiel #5
0
	/**
	 * Open the next article in the list. Loops to the first.
	 * @param game Pointer to actual game.
	 */
	void Ufopaedia::next(Game *game)
	{
		ArticleDefinitionList articles = getAvailableArticles(game->getSavedGame(), game->getRuleset());
		if (_current_index >= articles.size() - 1)
		{
			// goto first
			_current_index = 0;
		}
		else
		{
			_current_index++;
		}
		game->popState();
		game->pushState(createArticleState(articles[_current_index]));
	}