1. David Stone
  2. Technical Machine

Commits

David Stone  committed 57543d0

Moved battles to not be considered a networked component.

  • Participants
  • Parent commits a152313
  • Branches default

Comments (0)

Files changed (6)

File build_scripts/sources.py

View file
 
 team_sources = ['entry_hazards.cpp', 'screen.cpp', 'screens.cpp', 'team.cpp', 'wish.cpp'] + active_pokemon_sources
 
-network = prepend_dir('network', ['battles.cpp', 'buffer_overrun.cpp', 'client.cpp', 'inmessage.cpp', 'invalid_channel.cpp', 'invalid_packet.cpp', 'outmessage.cpp'])
+network = prepend_dir('network', ['buffer_overrun.cpp', 'client.cpp', 'inmessage.cpp', 'invalid_channel.cpp', 'invalid_packet.cpp', 'outmessage.cpp'])
 pokemon_lab = prepend_dir('pokemon_lab', ['battle.cpp', 'battle_settings.cpp', 'client.cpp', 'conversion.cpp', 'inmessage.cpp', 'outmessage.cpp', 'read_team_file.cpp', 'write_team_file.cpp'])
 pokemon_online = prepend_dir('pokemon_online', ['battle.cpp', 'battle_settings.cpp', 'client.cpp', 'conversion.cpp', 'read_team_file.cpp', 'inmessage.cpp', 'invalid_user.cpp', 'outmessage.cpp', 'read_user_info.cpp', 'write_team_file.cpp'])
 pokemon_showdown = prepend_dir('pokemon_showdown', ['battle.cpp', 'battle_settings.cpp', 'client.cpp', 'inmessage.cpp', 'outmessage.cpp'])
-clients = prepend_dir('clients', ['battle.cpp', 'battle_result.cpp', 'client.cpp', 'invalid_team_file_format.cpp', 'no_pending_challenges.cpp', 'party.cpp', 'updated_hp.cpp'] + network + pokemon_lab + pokemon_online + pokemon_showdown)
+clients = prepend_dir('clients', ['battle.cpp', 'battle_result.cpp', 'battles.cpp', 'client.cpp', 'invalid_team_file_format.cpp', 'no_pending_challenges.cpp', 'party.cpp', 'updated_hp.cpp'] + network + pokemon_lab + pokemon_online + pokemon_showdown)
 
 ev_optimizer_sources = prepend_dir('team_predictor/ev_optimizer', ['combine.cpp', 'defensive.cpp', 'defensive_data_point.cpp', 'ev_optimizer.cpp', 'evs.cpp', 'offensive.cpp', 'single_classification_evs.cpp', 'speed.cpp'])
 

File source/clients/battles.cpp

View file
+// Handles challenges / current battles
+// Copyright (C) 2013 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/>.
+
+// What follows are generic functions and data for connection to any Pokemon
+// sim. Specific functions and data are found in the respective sim's folder.
+
+#include "battles.hpp"
+
+#include <cassert>
+
+#include "battle.hpp"
+#include "no_pending_challenges.hpp"
+
+namespace technicalmachine {
+namespace network {
+
+void Battles::handle_challenge_withdrawn() {
+	if (challenges_are_queued()) {
+		assert(challenges.size() == 1);
+		challenges.erase(challenges.begin());
+	}
+}
+
+void Battles::handle_challenge_withdrawn (std::string const & opponent) {
+	challenges.erase(opponent);
+}
+
+Battle & Battles::handle_begin(uint32_t const battle_id, std::string const & opponent) {
+	auto const it = challenges.find(opponent);
+	if (it == challenges.end())
+		throw NoPendingChallenges(opponent);
+	Battle & battle = *it->second;
+	active.insert(std::make_pair(battle_id, std::move(it->second)));
+	challenges.erase(opponent);
+	return battle;
+}
+
+void Battles::handle_end(uint32_t const battle_id) {
+	active.erase(battle_id);
+}
+
+Battle const & Battles::find(uint32_t const battle_id) const {
+	auto const it = active.find(battle_id);
+	if (it == active.end())
+		throw NoPendingChallenges(battle_id);
+	return *it->second;
+}
+
+Battle & Battles::find(uint32_t const battle_id) {
+	auto const it = active.find(battle_id);
+	if (it == active.end())
+		throw NoPendingChallenges(battle_id);
+	return *it->second;
+}
+
+bool Battles::challenges_are_queued() const {
+	return !challenges.empty();
+}
+
+std::string const & Battles::first_challenger() const {
+	if (!challenges_are_queued())
+		throw NoPendingChallenges();
+	return challenges.begin()->first;
+}
+
+}	// namespace network
+}	// namespace technicalmachine

File source/clients/battles.hpp

View file
+// Handles challenges / current battles
+// Copyright (C) 2013 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 NETWORK__BATTLES_HPP_
+#define NETWORK__BATTLES_HPP_
+
+#include <cstdint>
+#include <map>
+#include <memory>
+#include <string>
+
+namespace technicalmachine {
+class Battle;
+namespace network {
+
+class Battles {
+	public:
+		template<typename SpecificBattle, typename ... Args>
+		SpecificBattle const & add_pending_challenge(std::string const & opponent, Args && ... args) {
+			Pointer battle_ptr(new SpecificBattle(opponent, std::forward<Args>(args)...));
+			auto const & battle = static_cast<SpecificBattle const &>(*battle_ptr);
+			challenges.insert(std::make_pair(opponent, std::move(battle_ptr)));
+			return battle;
+		}
+		void handle_challenge_withdrawn();
+		void handle_challenge_withdrawn(std::string const & opponent);
+		Battle & handle_begin(uint32_t battle_id, std::string const & opponent);
+		void handle_end(uint32_t battle_id);
+		Battle const & find(uint32_t battle_id) const;
+		Battle & find(uint32_t battle_id);
+		bool challenges_are_queued() const;
+		std::string const & first_challenger() const;
+	private:
+		typedef std::unique_ptr<Battle> Pointer;
+		// Battles that have not yet begun
+		typedef std::map<std::string, Pointer> Challenges;
+		// Battles currently underway
+		typedef std::map<uint32_t, Pointer> Active;
+		Challenges challenges;
+		Active active;
+};
+
+}	// namespace network
+}	// namespace technicalmachine
+#endif	// NETWORK__BATTLES_HPP_

File source/clients/network/battles.cpp

-// Handles challenges / current battles
-// Copyright (C) 2013 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/>.
-
-// What follows are generic functions and data for connection to any Pokemon
-// sim. Specific functions and data are found in the respective sim's folder.
-
-#include "battles.hpp"
-
-#include <cassert>
-
-#include "../battle.hpp"
-#include "../no_pending_challenges.hpp"
-
-namespace technicalmachine {
-namespace network {
-
-void Battles::handle_challenge_withdrawn() {
-	if (challenges_are_queued()) {
-		assert(challenges.size() == 1);
-		challenges.erase(challenges.begin());
-	}
-}
-
-void Battles::handle_challenge_withdrawn (std::string const & opponent) {
-	challenges.erase(opponent);
-}
-
-Battle & Battles::handle_begin(uint32_t const battle_id, std::string const & opponent) {
-	auto const it = challenges.find(opponent);
-	if (it == challenges.end())
-		throw NoPendingChallenges(opponent);
-	Battle & battle = *it->second;
-	active.insert(std::make_pair(battle_id, std::move(it->second)));
-	challenges.erase(opponent);
-	return battle;
-}
-
-void Battles::handle_end(uint32_t const battle_id) {
-	active.erase(battle_id);
-}
-
-Battle const & Battles::find(uint32_t const battle_id) const {
-	auto const it = active.find(battle_id);
-	if (it == active.end())
-		throw NoPendingChallenges(battle_id);
-	return *it->second;
-}
-
-Battle & Battles::find(uint32_t const battle_id) {
-	auto const it = active.find(battle_id);
-	if (it == active.end())
-		throw NoPendingChallenges(battle_id);
-	return *it->second;
-}
-
-bool Battles::challenges_are_queued() const {
-	return !challenges.empty();
-}
-
-std::string const & Battles::first_challenger() const {
-	if (!challenges_are_queued())
-		throw NoPendingChallenges();
-	return challenges.begin()->first;
-}
-
-}	// namespace network
-}	// namespace technicalmachine

File source/clients/network/battles.hpp

-// Handles challenges / current battles
-// Copyright (C) 2013 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 NETWORK__BATTLES_HPP_
-#define NETWORK__BATTLES_HPP_
-
-#include <cstdint>
-#include <map>
-#include <memory>
-#include <string>
-
-namespace technicalmachine {
-class Battle;
-namespace network {
-
-class Battles {
-	public:
-		template<typename SpecificBattle, typename ... Args>
-		SpecificBattle const & add_pending_challenge(std::string const & opponent, Args && ... args) {
-			Pointer battle_ptr(new SpecificBattle(opponent, std::forward<Args>(args)...));
-			auto const & battle = static_cast<SpecificBattle const &>(*battle_ptr);
-			challenges.insert(std::make_pair(opponent, std::move(battle_ptr)));
-			return battle;
-		}
-		void handle_challenge_withdrawn();
-		void handle_challenge_withdrawn(std::string const & opponent);
-		Battle & handle_begin(uint32_t battle_id, std::string const & opponent);
-		void handle_end(uint32_t battle_id);
-		Battle const & find(uint32_t battle_id) const;
-		Battle & find(uint32_t battle_id);
-		bool challenges_are_queued() const;
-		std::string const & first_challenger() const;
-	private:
-		typedef std::unique_ptr<Battle> Pointer;
-		// Battles that have not yet begun
-		typedef std::map<std::string, Pointer> Challenges;
-		// Battles currently underway
-		typedef std::map<uint32_t, Pointer> Active;
-		Challenges challenges;
-		Active active;
-};
-
-}	// namespace network
-}	// namespace technicalmachine
-#endif	// NETWORK__BATTLES_HPP_

File source/clients/network/client.hpp

View file
 #include <boost/asio/io_service.hpp>
 #include <boost/asio/ip/tcp.hpp>
 
-#include "battles.hpp"
-
 #include "../battle.hpp"
+#include "../battles.hpp"
 #include "../client.hpp"
 
 #include "../../evaluate/evaluate.hpp"