Commits

David Stone committed ae309d6

Made the enum of the Ability class private, but added a public const member function that allows access.

Comments (0)

Files changed (10)

source/ability.cpp

 }	// namespace
 
 Ability::Ability():
-	name(END) {
+	m_name(END) {
 }
 
 Ability::Ability(Abilities ability):
-	name(ability) {
+	m_name(ability) {
 }
 
 Ability::Ability(std::string const & str):
-	name(::technicalmachine::from_string<Abilities>(str))
+	m_name(::technicalmachine::from_string<Abilities>(str))
 	{
 }
 
+Ability::Abilities Ability::name() const {
+	return m_name;
+}
+
 bool Ability::is_set() const {
-	return name != END;
+	return name() != END;
 }
 
 void Ability::set_if_unknown(Abilities const ability) {
 	assert(ability < END);
 	if (!is_set())
-		name = ability;
+		m_name = ability;
 }
 
 bool Ability::blocks_switching(ActivePokemon const & switcher, Weather const & weather) const {
-	switch (name) {
+	switch (name()) {
 		case Shadow_Tag:
-			return switcher.ability().name != Shadow_Tag;
+			return switcher.ability().name() != Shadow_Tag;
 		case Arena_Trap:
 			return grounded(switcher, weather);
 		case Magnet_Pull:
 }
 
 bool Ability::blocks_weather() const {
-	switch (name) {
+	switch (name()) {
 		case Air_Lock:
 		case Cloud_Nine:
 			return true;
 
 template<>
 bool Ability::blocks_status<Status::BURN>(Weather const & weather) const {
-	switch (name) {
+	switch (name()) {
 		case Leaf_Guard:
 			return weather.sun();
 		case Water_Veil:
 	// Pass in weather to take advantage of template specialization, but I don't
 	// want to be warned about unused variables.
 	static_cast<void>(weather);
-	return name == Magma_Armor;
+	return name() == Magma_Armor;
 }
 
 template<>
 bool Ability::blocks_status<Status::PARALYSIS>(Weather const & weather) const {
-	switch (name) {
+	switch (name()) {
 		case Leaf_Guard:
 			return weather.sun();
 		case Limber:
 
 template<>
 bool Ability::blocks_status<Status::POISON>(Weather const & weather) const {
-	switch (name) {
+	switch (name()) {
 		case Immunity:
 			return true;
 		case Leaf_Guard:
 
 template<>
 bool Ability::blocks_status<Status::SLEEP>(Weather const & weather) const {
-	switch (name) {
+	switch (name()) {
 		case Insomnia:
 		case Vital_Spirit:
 			return true;
 }
 
 bool Ability::blocks_confusion() const {
-	return name == Own_Tempo;
+	return name() == Own_Tempo;
 }
 
 bool Ability::reflects_status() const {
-	return name == Synchronize;
+	return name() == Synchronize;
 }
 
 bool Ability::absorbs_poison_damage() const {
-	return name == Poison_Heal;
+	return name() == Poison_Heal;
 }
 
 bool Ability::blocks_burn_damage_penalty() const {
-	return name == Guts;
+	return name() == Guts;
 }
 
 bool Ability::blocks_paralysis_speed_penalty() const {
-	return name == Quick_Feet;
+	return name() == Quick_Feet;
 }
 
 bool Ability::blocks_sound_moves() const {
-	return name == Soundproof;
+	return name() == Soundproof;
 }
 
 bool Ability::can_clear_status(Status const status) const {
-	return name == Shed_Skin and !status.is_clear();
+	return name() == Shed_Skin and !status.is_clear();
 }
 
 bool Ability::clears_status_on_switch() const {
-	return name == Natural_Cure;
+	return name() == Natural_Cure;
 }
 
 bool Ability::is_immune_to_ground() const {
-	return name == Levitate;
+	return name() == Levitate;
 }
 
 bool Ability::wakes_up_early() const {
-	return name == Early_Bird;
+	return name() == Early_Bird;
 }
 
 bool Ability::weakens_burn() const {
-	return name == Heatproof;
+	return name() == Heatproof;
 }
 
 bool Ability::harms_sleepers() const {
-	return name == Bad_Dreams;
+	return name() == Bad_Dreams;
 }
 
 bool Ability::blocks_phazing() const {
-	return name == Suction_Cups;
+	return name() == Suction_Cups;
 }
 
 bool Ability::blocks_recoil() const {
-	switch (name) {
+	switch (name()) {
 		case Magic_Guard:
 		case Rock_Head:
 			return true;
 }
 
 bool Ability::blocks_secondary_damage() const {
-	return name == Magic_Guard;
+	return name() == Magic_Guard;
 }
 
 bool Ability::cannot_miss() const {
-	return name == No_Guard;
+	return name() == No_Guard;
 }
 
 bool Ability::damages_leechers() const {
-	return name == Liquid_Ooze;
+	return name() == Liquid_Ooze;
 }
 
 bool Ability::weakens_se_attacks() const {
-	switch (name) {
+	switch (name()) {
 		case Filter:
 		case Solid_Rock:
 			return true;
 }
 
 bool Ability::strengthens_nve_attacks() const {
-	return name == Tinted_Lens;
+	return name() == Tinted_Lens;
 }
 
 bool Ability::uses_extra_pp() const {
-	return name == Pressure;
+	return name() == Pressure;
 }
 
 bool Ability::ignores_blockers() const {
-	return name == Mold_Breaker;
+	return name() == Mold_Breaker;
 }
 
 bool Ability::boosts_critical_hits() const {
-	return name == Sniper;
+	return name() == Sniper;
 }
 
 bool Ability::boosts_defense(Status const status) const {
-	return name == Marvel_Scale and !status.is_clear();
+	return name() == Marvel_Scale and !status.is_clear();
 }
 
 bool Ability::boosts_special_attack(Weather const & weather) const {
-	return name == Solar_Power and weather.sun();
+	return name() == Solar_Power and weather.sun();
 }
 
 bool Ability::boosts_special_defense(Weather const & weather) const {
-	return name == Flower_Gift and weather.sun();
+	return name() == Flower_Gift and weather.sun();
 }
 
 bool Ability::boosts_speed() const {
-	return name == Speed_Boost;
+	return name() == Speed_Boost;
 }
 
 bool Ability::boosts_speed_when_flinched() const {
-	return name == Steadfast;
+	return name() == Steadfast;
 }
 
 bool Ability::boosts_stab() const {
-	return name == Adaptability;
+	return name() == Adaptability;
 }
 
 bool Ability::is_loafing(bool const loaf) const {
-	return name == Truant and loaf;
+	return name() == Truant and loaf;
 }
 
 Rational Ability::accuracy_modifier(ActivePokemon const & user) {
-	switch (user.ability().name) {
+	switch (user.ability().name()) {
 		case Compoundeyes:
 			return Rational(13, 10);
 		case Hustle:
 }
 
 Rational Ability::evasion_modifier(ActivePokemon const & target, Weather const & weather) {
-	switch (target.ability().name) {
+	switch (target.ability().name()) {
 		case Sand_Veil:
 			return weather.sand() ? Rational(4, 5) : Rational(1, 1);
 		case Snow_Cloak:
 }
 
 Rational Ability::attacker_modifier(Pokemon const & attacker, Pokemon const & defender, unsigned const base_power) {
-	switch (attacker.ability().name) {
+	switch (attacker.ability().name()) {
 		case Technician:
 			return (base_power <= 60) ? Rational(3, 2) : Rational(1);
 		case Blaze:
 }	// namespace
 
 Rational Ability::defender_modifier(Move const & move, Ability const ability) {
-	switch (ability.name) {
+	switch (ability.name()) {
 		case Dry_Skin:
 			return (move.type() == Type::Fire) ? Rational(5, 4) : Rational(1);
 		case Heatproof:
 
 template<>
 Rational Ability::stat_modifier<Stat::ATK>(ActivePokemon const & attacker, Weather const & weather) {
-	switch (attacker.ability().name) {
+	switch (attacker.ability().name()) {
 		case Flower_Gift:
 			return weather.sun() ? Rational(3, 2) : Rational(1);
 		case Guts:
 }
 template<>
 Rational Ability::stat_modifier<Stat::SPE>(ActivePokemon const & pokemon, Weather const & weather) {
-	switch (pokemon.ability().name) {
+	switch (pokemon.ability().name()) {
 		case Chlorophyll:
 			return weather.sun() ? Rational(2) : Rational(1);
 		case Swift_Swim:
 }
 
 void Ability::activate_on_switch(ActivePokemon & switcher, ActivePokemon & other, Weather & weather) {
-	switch (switcher.ability().name) {
+	switch (switcher.ability().name()) {
 		case Download: {
 			calculate_defense(other, weather);
 			calculate_special_defense(other, weather);
 }
 
 void Ability::weather_healing(Pokemon & pokemon, Weather const & weather) {
-	switch (pokemon.ability().name) {
+	switch (pokemon.ability().name()) {
 		case Dry_Skin:
 			if (weather.rain()) {
 				heal(pokemon, Rational(1, 8));
 }
 
 bool operator==(Ability const lhs, Ability const rhs) {
-	return lhs.name == rhs.name;
+	return lhs.m_name == rhs.m_name;
 }
 
 bool operator!=(Ability const lhs, Ability const rhs) {
 }
 
 std::string Ability::to_string() const {
-	return ::technicalmachine::to_string(name);
+	return ::technicalmachine::to_string(name());
 }
 
 }	// namespace technicalmachine

source/ability.hpp

 		Water_Veil, White_Smoke, Wonder_Guard, END
 	};
 	Ability ();
-	explicit Ability (Abilities ability);
+	Ability(Abilities ability);
 	explicit Ability (std::string const & str);
+	Abilities name() const;
 	bool is_set () const;
 	void set_if_unknown (Abilities ability);
 	bool blocks_switching (ActivePokemon const & switcher, Weather const & weather) const;
 	static void activate_on_switch (ActivePokemon & switcher, ActivePokemon & other, Weather & weather);
 	static void weather_healing(Pokemon & pokemon, Weather const & weather);
 	friend bool operator== (Ability lhs, Ability rhs);
-	Abilities name;
+private:
+	Abilities m_name;
 };
 bool operator!= (Ability lhs, Ability rhs);
 

source/clients/battle.cpp

 }
 
 void Battle::handle_ability_message(Party party, Ability::Abilities ability) {
-	get_team(party).replacement().ability().name = ability;
+	get_team(party).replacement().ability() = ability;
 }
 
 void Battle::handle_item_message(Party party, Item::Items item) {

source/clients/pokemon_online/outmessage.cpp

 	write_string (pokemon.get_nickname());
 	uint16_t const item = item_to_id (pokemon.item().name);
 	write_short (item);
-	uint16_t const ability = ability_to_id (pokemon.ability().name);
+	uint16_t const ability = ability_to_id (pokemon.ability().name());
 	write_short (ability);
 	uint8_t const nature = nature_to_id (pokemon.nature().name);
 	write_byte (nature);

source/clients/pokemon_online/read_team_file.cpp

 	unsigned const item = pt.get<unsigned>("<xmlattr>.Item");
 	pokemon.item().name = id_to_item(item);
 	unsigned const ability = pt.get<unsigned>("<xmlattr>.Ability");
-	pokemon.ability().name = id_to_ability(ability);
+	pokemon.ability() = id_to_ability(ability);
 	unsigned const nature = pt.get<unsigned>("<xmlattr>.Nature");
 	pokemon.nature().name = id_to_nature(nature);
 

source/clients/pokemon_online/write_team_file.cpp

 void write_pokemon (Pokemon const & pokemon, boost::property_tree::ptree & pt) {
 	boost::property_tree::ptree & member = pt.add ("Pokemon", "");
 	member.put ("<xmlattr>.Item", item_to_id (pokemon.item().name));
-	member.put ("<xmlattr>.Ability", ability_to_id (pokemon.ability().name));
+	member.put ("<xmlattr>.Ability", ability_to_id (pokemon.ability().name()));
 	std::pair<unsigned, unsigned> const ids = species_to_id (pokemon.name());
 	member.put ("<xmlattr>.Num", ids.first);
 	member.put ("<xmlattr>.Nature", nature_to_id (pokemon.nature().name));

source/pokemon/active_pokemon.cpp

 	return get_pokemon().ability();
 }
 
-void ActivePokemon::ability(Ability::Abilities const update) {
-	get_pokemon().ability().name = update;
+Ability & ActivePokemon::ability() {
+	return get_pokemon().ability();
 }
 
 bool ActivePokemon::aqua_ring_is_active() const {

source/pokemon/active_pokemon.hpp

 	void update_before_move();
 	void use_substitute();
 	Ability const & ability() const;
-	void ability(Ability::Abilities update);
+	Ability & ability();
 	void attract();
 	void awaken(bool value);
 	bool can_awaken() const;

source/test/damage.cpp

 	Gender const gender(Gender::MALE);
 	defender.add_pokemon(Species::Paras, level, gender);
 	auto & d = defender.pokemon();
-	d.ability(Ability::Dry_Skin);
+	d.ability() = Ability::Dry_Skin;
 
 	d.stat(Stat::SPD).iv = 0;
 	d.stat(Stat::SPD).ev.set_value(0);
 
 	Team attacker = max_damage_physical_attacker ();
 	attacker.pokemon().item().name = Item::ROCK_INCENSE;
-	attacker.pokemon().ability(Ability::Rivalry);
+	attacker.pokemon().ability() = Ability::Rivalry;
 
 	unsigned const power = move_power(attacker.pokemon(), max_damage_physical_defender().pokemon(), Weather(), Variable());
 	if (power != max_power)
 	Pokemon & pokemon = attacker.pokemon();
 	pokemon.move.add(Moves::Surf, 3);
 	pokemon.item().name = Item::WAVE_INCENSE;
-	pokemon.ability() = Ability(Ability::Torrent);
+	pokemon.ability() = Ability::Torrent;
 
 	Team defender = max_damage_special_defender ();
 	defender.pokemon().dive();
 	a.stat(Stat::DEF).ev.set_value(252);
 	a.nature().name = Nature::IMPISH;
 	attacker.pokemon().activate_power_trick();
-	a.ability() = Ability(Ability::Pure_Power);
+	a.ability() = Ability::Pure_Power;
 	attacker.pokemon().stat_boost(Stat::ATK, 6);
 	calculate_attacking_stat (attacker.pokemon(), weather);
 
 	for (unsigned n = 0; n != 10; ++n)
 		attacker.pokemon().increment_move_use_counter();
 
-	a.ability() = Ability(Ability::Blaze);
+	a.ability() = Ability::Blaze;
 	attacker.pokemon().set_critical_hit(true);
 	attacker.pokemon().activate_flash_fire();
 

source/test/stat.cpp

 	pokemon.stat(Stat::DEF).ev.set_value(252);
 	pokemon.nature().name = Nature::IMPISH;
 	attacker.pokemon().activate_power_trick();
-	pokemon.ability() = Ability(Ability::Pure_Power);
+	pokemon.ability() = Ability::Pure_Power;
 	attacker.pokemon().stat_boost(Stat::ATK, 6);
 
 	pokemon.item().name = Item::CHOICE_BAND;
 	pokemon.nature().name = Nature::MODEST;
 	attacker.pokemon().stat_boost(Stat::SPA, 6);
 
-	pokemon.ability() = Ability(Ability::Solar_Power);
+	pokemon.ability() = Ability::Solar_Power;
 
 	pokemon.item().name = Item::CHOICE_SPECS;
 	
 
 	defender.pokemon().stat_boost(Stat::DEF, 6);
 
-	pokemon.ability() = Ability(Ability::Marvel_Scale);
+	pokemon.ability() = Ability::Marvel_Scale;
 	Status::apply<Status::BURN>(pokemon, weather);
 
 	calculate_defense(defender.pokemon(), weather);
 
 	team.pokemon().stat_boost(Stat::SPE, 6);
 
-	pokemon.ability() = Ability(Ability::Swift_Swim);
+	pokemon.ability() = Ability::Swift_Swim;
 
 	pokemon.item().name = Item::CHOICE_SCARF;