Commits

David Stone committed f4cd485

Moved depth out of the network client.

  • Participants
  • Parent commits c10185f

Comments (0)

Files changed (7)

File source/clients/client.cpp

 
 namespace technicalmachine {
 
-Client::Client():
-	random_engine(rd()) {
+Client::Client(unsigned depth):
+	random_engine(rd()),
+	m_depth(depth) {
+}
+
+void Client::set_depth(unsigned const new_depth) {
+	m_depth = new_depth;
 }
 
 void Client::print_with_time_stamp (std::ostream & stream, std::string const & message) const {

File source/clients/client.hpp

 		Evaluate const & evaluation_constants() const;
 		virtual ~Client() { }
 	protected:
-		Client();
+		explicit Client(unsigned depth);
+		void set_depth(unsigned new_depth);
 		Settings load_settings();
 		Team generate_team();
 		void reload_settings();
 		}
 		template<typename Battle, typename ... Args>
 		Battle const & add_pending_challenge (Team const & team, std::string const & opponent, Args && ... args) {
-			return battles.add_pending_challenge<Battle>(opponent, rd(), std::forward<Args>(args)..., team);
+			return battles.add_pending_challenge<Battle>(opponent, rd(), m_depth, std::forward<Args>(args)..., team);
 		}
 		template<typename Battle, typename ... Args>
 		Battle const & add_pending_challenge (std::string const & opponent, Args && ... args) {
-			return battles.add_pending_challenge<Battle>(opponent, rd(), std::forward<Args>(args)..., team_file_name);
+			return battles.add_pending_challenge<Battle>(opponent, rd(), m_depth, std::forward<Args>(args)..., team_file_name);
 		}
 		bool challenges_are_queued() const;
 		std::string const & first_challenger() const;
 		Evaluate m_evaluation_constants;
 		std::string team_file_name;
 		std::string time_format;
+		unsigned m_depth;
 };
 
 }	// namespace technicalmachine

File source/clients/network/client.cpp

 
 }	// unnamed namespace
 
-Client::Client(unsigned set_depth):
+Client::Client(unsigned const depth):
+	Base(depth),
 	highlights (load_highlights ()),
-	trusted_users (load_trusted_users ()),
-	depth (set_depth)
+	trusted_users (load_trusted_users ())
 	{
 	load_settings (false);
 	while (username().empty()) {
 }
 
 void Client::load_settings (bool const reloading) {
-	auto settings = ::technicalmachine::Client::load_settings();
+	auto settings = Base::load_settings();
 	chattiness = settings.chattiness;
 	
 	if (!reloading) {
 		return;
 	constexpr unsigned max_depth = 4;
 	try {
-		depth = boost::lexical_cast<unsigned> (request.substr (start));
+		auto const depth = boost::lexical_cast<unsigned>(request.substr(start));
 		if (depth > max_depth) {
 			// Hopefully this will happen rarely enough that declaring
 			// big_message static would be a pessimization. There is no need to
 			std::cerr << big_message + "\n";
 			send_private_message (user, big_message);
 		}
+		set_depth(depth);
 	}
 	catch (boost::bad_lexical_cast const &) {
 		std::string const invalid_depth = "Invalid depth requested. Please enter a number between 0 and " + std::to_string(max_depth) + " inclusive.";

File source/clients/network/client.hpp

 class OutMessage;
 
 class Client : public ::technicalmachine::Client {
+	typedef ::technicalmachine::Client Base;
 	public:
 		void handle_channel_message (uint32_t channel_id, std::string const & user, std::string const & message) const;
 		void send_message(OutMessage & msg);
 	protected:
-		explicit Client(unsigned set_depth);
+		explicit Client(unsigned depth);
 		void reconnect ();
 		virtual void send_channel_message(std::string const & channel, std::string const & message) = 0;
 		virtual void send_channel_message(uint32_t channel_id, std::string const & message) = 0;
 		void handle_server_message (std::string const & sender, std::string const & message) const;
 		void handle_incoming_challenge (std::string const & opponent, GenericBattleSettings const & settings);
 		template<typename Battle, typename ... Args>
-		Battle const & add_pending_challenge (Team const & team, std::string const & opponent, Args && ... args) {
-			return ::technicalmachine::Client::add_pending_challenge<Battle>(team, opponent, depth, std::forward<Args>(args)...);
-		}
-		template<typename Battle, typename ... Args>
-		Battle const & add_pending_challenge (std::string const & opponent, Args && ... args) {
-			return ::technicalmachine::Client::add_pending_challenge<Battle>(opponent, depth, std::forward<Args>(args)...);
+		Battle const & add_pending_challenge(Args && ... args) {
+			return Base::add_pending_challenge<Battle>(std::forward<Args>(args)...);
 		}
 		template<typename Timer>
 		std::unique_ptr<Timer> make_timer() {
 		std::vector <std::string> highlights;
 		std::vector <std::string> trusted_users;
 		unsigned chattiness;
-		unsigned depth;
 };
 
 }	// namespace network

File source/clients/pokemon_lab/client.cpp

 namespace technicalmachine {
 namespace pl {
 
-Client::Client (unsigned set_depth):
-	network::Client(set_depth),
+Client::Client (unsigned depth):
+	network::Client(depth),
 	timer(make_timer<boost::asio::deadline_timer>())
 	{
 	request_authentication ();

File source/clients/pokemon_online/client.cpp

 namespace technicalmachine {
 namespace po {
 
-Client::Client (unsigned set_depth):
-	network::Client(set_depth),
+Client::Client (unsigned depth):
+	network::Client(depth),
 	team(generate_team()) {
 	log_in ();
 }

File source/clients/pokemon_showdown/client.cpp

 namespace technicalmachine {
 namespace ps {
 
-Client::Client(unsigned set_depth):
-	network::Client(set_depth) {
+Client::Client(unsigned depth):
+	network::Client(depth) {
 	log_in();
 }