Commits

David Stone committed 4dae72c

Moved the random damage out of Move and into ActivePokemon.

Comments (0)

Files changed (9)

build_scripts/sources.py

 
 bide_sources = prepend_dir('bide', ['bide.cpp', 'damage.cpp', 'duration.cpp'])
 
-move_sources = prepend_dir('move', ['move.cpp', 'accuracy.cpp', 'classification.cpp', 'disable.cpp', 'global_move.cpp', 'pp.cpp', 'priority.cpp', 'random.cpp', 'times_used.cpp'])
+move_sources = prepend_dir('move', ['move.cpp', 'accuracy.cpp', 'classification.cpp', 'disable.cpp', 'global_move.cpp', 'pp.cpp', 'priority.cpp', 'times_used.cpp'])
 
 pokemon_sources = prepend_dir('pokemon', ['collection.cpp', 'invalid_swallow.cpp', 'pokemon_not_found.cpp', 'level.cpp', 'pokemon.cpp', 'seen.cpp'])
 pokemon_sources += move_sources
 
 active_pokemon_sources = prepend_dir('pokemon', ['active_pokemon.cpp', 'confusion.cpp', 'delayed_attack.cpp', 'embargo.cpp', 'encore.cpp', 'heal_block.cpp', 'magnet_rise.cpp', 'partial_trap.cpp', 'perish_song.cpp', 'rampage.cpp', 'slow_start.cpp', 'stockpile.cpp', 'substitute.cpp', 'taunt.cpp', 'toxic.cpp', 'uproar.cpp', 'vanish.cpp', 'yawn.cpp'])
-active_pokemon_sources += bide_sources
-active_pokemon_sources += pokemon_sources
 active_pokemon_sources += prepend_dir('stat', ['chance_to_hit.cpp', 'stage.cpp'])
+active_pokemon_sources += bide_sources + pokemon_sources + ['random_damage.cpp']
 
 team_sources = ['entry_hazards.cpp', 'screen.cpp', 'screens.cpp', 'team.cpp', 'wish.cpp'] + active_pokemon_sources
 

source/damage.cpp

 	damage *= calculate_item_modifier(attacker);
 	damage *= calculate_me_first_modifier(attacker);
 
-	damage *= attacker.move().r();
+	damage *= attacker.random_damage_multiplier();
 	damage *= calculate_stab_modifier(attacker);
 
 	Effectiveness const effectiveness = attacker.move().type().get_effectiveness(defender.pokemon());

source/move/move.hpp

 #include "moves_forward.hpp"
 #include "pp.hpp"
 #include "priority.hpp"
-#include "random.hpp"
 #include "times_used.hpp"
 
 #include "../type/type.hpp"
 		Moves name;
 		Pp pp;
 		Disable disable;
-		// Move r and times_used up to team when it will reduce the size of Move.
-		// The random number (85 through 100)
-		Random r;
+		// Move times_used up to ActivePokemon when it will reduce the size of Move.
 	private:
 		TimesUsed times_used;
 		Accuracy cached_accuracy;

source/move/random.cpp

-// Store information on the random number for damage
-// 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 "random.hpp"
-#include "../rational.hpp"
-
-namespace technicalmachine {
-
-Random::Random() :
-	r(100) {
-}
-
-Rational Random::operator() () const {
-	return Rational(r, 100);
-}
-
-}	// namespace technicalmachine

source/move/random.hpp

-// Store information on the random number for damage
-// 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/>.
-
-#ifndef MOVE__RANDOM_HPP_
-#define MOVE__RANDOM_HPP_
-
-#include <cstdint>
-
-namespace technicalmachine {
-class Rational;
-
-class Random {
-	public:
-		Random();
-		Rational operator() () const;
-	private:
-		uint8_t r;
-};
-
-}	// namespace technicalmachine
-#endif	// MOVE__RANDOM_HPP_

source/pokemon/active_pokemon.cpp

 	return damage_done_to_active;
 }
 
+Rational ActivePokemon::random_damage_multiplier() const {
+	return random_damage();
+}
+
 void ActivePokemon::direct_damage(unsigned damage) {
 	damage = get_pokemon().apply_damage(damage);
 	damage_done_to_active = damage;

source/pokemon/active_pokemon.hpp

 #include "vanish.hpp"
 #include "yawn.hpp"
 
+#include "../random_damage.hpp"
 #include "../rational.hpp"
 
 #include "../bide/bide.hpp"
 		void use_bide(Pokemon & target);
 		bool is_locked_in_to_bide() const;
 		unsigned damaged() const;
+		Rational random_damage_multiplier() const;
 		void direct_damage(unsigned damage);
 		void indirect_damage(unsigned damage);
 		void register_damage(unsigned damage);
 		PartialTrap partial_trap;
 		PerishSong perish_song;
 		Rampage rampage;
+		RandomDamage random_damage;
 		Stage stage;
 		SlowStart slow_start;
 		Stockpile stockpile;

source/random_damage.cpp

+// Store information on the random number for damage
+// 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 "random_damage.hpp"
+#include "rational.hpp"
+
+namespace technicalmachine {
+
+RandomDamage::RandomDamage() :
+	r(100) {
+}
+
+Rational RandomDamage::operator() () const {
+	return Rational(r, 100);
+}
+
+}	// namespace technicalmachine

source/random_damage.hpp

+// Store information on the random number for damage
+// 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/>.
+
+#ifndef RANDOM_DAMAGE_HPP_
+#define RANDOM_DAMAGE_HPP_
+
+#include <cstdint>
+
+namespace technicalmachine {
+class Rational;
+
+class RandomDamage {
+	public:
+		RandomDamage();
+		Rational operator() () const;
+	private:
+		uint8_t r;
+};
+
+}	// namespace technicalmachine
+#endif	// RANDOM_DAMAGE_HPP_