Commits

David Stone committed d370532

Created proper string conversions for Pokemon Lab that falls back on the generic version if necessary.

Comments (0)

Files changed (4)

build_scripts/sources.py

 predict_sources += prepend_dir('move', ['collection.cpp', 'container.cpp', 'power.cpp', 'shared.cpp'])
 predict_sources += prepend_dir('stat', ['ev.cpp', 'invalid_ev.cpp', 'invalid_stat.cpp', 'nature.cpp', 'stat.cpp'])
 predict_sources += prepend_dir('clients/', ['invalid_team_file_format.cpp'])
-predict_sources += prepend_dir('clients/pokemon_lab', ['read_team_file.cpp'])
+predict_sources += prepend_dir('clients/pokemon_lab', ['conversion.cpp', 'read_team_file.cpp'])
 predict_sources += prepend_dir('clients/pokemon_online', ['conversion.cpp', 'read_team_file.cpp'])
 predict_sources += prepend_dir('team_predictor', ['detailed_stats.cpp', 'estimate.cpp', 'load_stats.cpp', 'multiplier.cpp', 'predictor.cpp', 'random_team.cpp', 'team_predictor.cpp'])
 predict_sources += ev_optimizer_sources

source/clients/pokemon_lab/conversion.cpp

 
 #include "conversion.hpp"
 
+#include <map>
 #include <string>
 
 #include "id.hpp"
 
 template<>
 std::string simulator_cast<std::string, Species>(Species const & species) {
-	return to_string(species);
+	switch (species) {
+		case Species::Deoxys_Mediocre:
+			return "Deoxys";
+		case Species::Deoxys_Attack:
+			return "Deoxys-f";
+		case Species::Deoxys_Defense:
+			return "Deoxys-l";
+		case Species::Deoxys_Speed:
+			return "Deoxys-e";
+		case Species::Giratina_Altered:
+			return "Giratina";
+		case Species::Giratina_Origin:
+			return "Giratina-o";
+		case Species::Rotom_Mow:
+			return "Rotom-c";
+		case Species::Rotom_Frost:
+			return "Rotom-f";
+		case Species::Rotom_Heat:
+			return "Rotom-h";
+		case Species::Rotom_Fan:
+			return "Rotom-s";
+		case Species::Rotom_Wash:
+			return "Rotom-w";
+		case Species::Shaymin_Land:
+			return "Shaymin";
+		case Species::Shaymin_Sky:
+			return "Shaymin-s";
+		case Species::Wormadam_Plant:
+			return "Wormadam";
+		case Species::Wormadam_Sandy:
+			return "Wormadam-g";
+		case Species::Wormadam_Trash:
+			return "Wormadam-s";
+		default:
+			return to_string(species);
+	}
 }
 
 template<>
 Species simulator_cast<Species, std::string>(std::string const & str) {
-	return from_string<Species>(str);
+	static std::map<std::string, Species> const convertor = {
+		{ "Deoxys", Species::Deoxys_Mediocre },
+		{ "Deoxys-f", Species::Deoxys_Attack },
+		{ "Deoxys-l", Species::Deoxys_Defense },
+		{ "Deoxys-e", Species::Deoxys_Speed },
+		{ "Giratina", Species::Giratina_Altered },
+		{ "Giratina-o", Species::Giratina_Origin },
+		{ "Rotom-c", Species::Rotom_Mow },
+		{ "Rotom-f", Species::Rotom_Frost },
+		{ "Rotom-h", Species::Rotom_Heat },
+		{ "Rotom-s", Species::Rotom_Fan },
+		{ "Rotom-w", Species::Rotom_Wash },
+		{ "Shaymin", Species::Shaymin_Land },
+		{ "Shaymin-s", Species::Shaymin_Sky },
+		{ "Wormadam", Species::Wormadam_Plant },
+		{ "Wormadam-g", Species::Wormadam_Sandy },
+		{ "Wormadam-s", Species::Wormadam_Trash }
+	};
+	auto const it = convertor.find(str);
+	return (it != convertor.end()) ? it->second : from_string<Species>(str);
 }
 
 template<>

source/clients/pokemon_lab/read_team_file.cpp

 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 
+#include "conversion.hpp"
+
 #include "../../team.hpp"
 
 #include "../../move/move.hpp"
 	Nature const nature(pt.get<std::string>("nature"));
 	Item const item(pt.get<std::string>("item"));
 	Ability const ability(pt.get<std::string>("ability"));
-	team.add_pokemon(from_string<Species>(species_str), level, gender, item, ability, nature, nickname, happiness);
+	team.add_pokemon(simulator_cast<Species>(species_str), level, gender, item, ability, nature, nickname, happiness);
 	Pokemon & pokemon = team.all_pokemon().at_replacement();
 	
 	for (boost::property_tree::ptree::value_type const & value : pt.get_child ("moveset"))

source/clients/pokemon_lab/write_team_file.cpp

 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 
+#include "conversion.hpp"
+
 #include "../../team.hpp"
 
 #include "../../move/move.hpp"
 
 void write_pokemon (Pokemon const & pokemon, boost::property_tree::ptree & pt) {
 	boost::property_tree::ptree & member = pt.add ("pokemon", "");
-	member.put ("<xmlattr>.species", pokemon.to_string ());
+	member.put("<xmlattr>.species", simulator_cast<std::string>(pokemon.name()));
 	member.put ("nickname", pokemon.get_nickname());
 	member.put ("level", pokemon.level());
 	member.put ("happiness", pokemon.happiness());