Technical Machine / source / team_predictor / detailed_stats.cpp

// Detailed Pokemon stats
// Copyright (C) 2012 David Stone
//
// This file is part of Technical Machine.
//
// Technical Machine is free software: you can redistribute it and / or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "detailed_stats.hpp"

#include <cstddef>
#include <fstream>
#include <string>

#include "../ability.hpp"
#include "../item.hpp"
#include "../invalid_settings_file.hpp"

#include "../move/move.hpp"

#include "../pokemon/pokemon.hpp"
#include "../pokemon/species.hpp"

#include "../stat/nature.hpp"

#include "../string_conversions/conversion.hpp"

namespace technicalmachine {

DetailedStats::DetailedStats():
	ability(),
	item(),
	nature()
	{
	static std::string const file_name = "settings/Generation 4/OU/detailed.txt";
	std::ifstream file(file_name);
	if (!file.is_open()) {
		throw InvalidSettingsFile(file_name, InvalidSettingsFile::does_not_exist);
	}
	std::string line;
	Species old_member = Species::END;
	bool ability_found = false;
	bool item_found = false;
	bool nature_found = false;
	while (getline(file, line)) {
		constexpr char delimiter = '\t';
		size_t const x = line.find (delimiter);
		Species new_member = from_string<Species>(line.substr (0, x));
		if (old_member != new_member) {
			old_member = new_member;
			ability_found = false;
			item_found = false;
			nature_found = false;
		}
		size_t const y = line.find(delimiter, x + 1);
		size_t const z = line.find(delimiter, y + 1);
		std::string const sub = line.substr(x + 1, y - x - 1);
		if (sub == "Ability") {
			if (!ability_found) {
				ability_found = true;
				ability[static_cast<size_t>(new_member)] = from_string<Ability::Abilities>(line.substr(y + 1, z - y - 1));
			}
		}
		else if (sub == "Item") {
			if (!item_found) {
				item_found = true;
				item[static_cast<size_t>(new_member)] = from_string<Item::Items>(line.substr(y + 1, z - y - 1));
			}
		}
		else if (sub == "Nature") {
			if (!nature_found) {
				nature_found = true;
				nature[static_cast<size_t>(new_member)] = from_string<Nature::Natures>(line.substr(y + 1, z - y - 1));
			}
		}
		else if (sub == "Move") {
			// When I get smarter move statistics, I won't want to cap this at 4
			if (move[static_cast<size_t>(new_member)].size() < 4)
				move[static_cast<size_t>(new_member)].emplace_back(from_string<Moves>(line.substr(y + 1, z - y - 1)));
		}
	}
}

}	// namespace technicalmachine
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.