1 // Copyright (C) 2007, 2008, Ole Laursen
2 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include <sigc++/functors/mem_fun.h>
21 #include <sigc++/bind.h>
28 #include "error-utils.h"
30 #include "splash-window.h"
31 #include "game-window.h"
32 #include "game-lobby-dialog.h"
34 #include "GraphicsCache.h"
35 #include "GameScenario.h"
36 #include "CreateScenario.h"
38 #include "shieldsetlist.h"
40 #include "armysetlist.h"
41 #include "playerlist.h"
44 #include "xmlhelper.h"
45 #include "Configuration.h"
46 #include "ucompose.hpp"
48 #include "timed-message-dialog.h"
49 #include "game-preferences-dialog.h"
51 #include "game-client.h"
52 #include "pbm-game-client.h"
53 #include "game-server.h"
54 #include "pbm-game-server.h"
55 #include "NextTurnHotseat.h"
56 #include "NextTurnPbm.h"
57 #include "NextTurnNetworked.h"
59 #include "recently-played-game-list.h"
66 #include "stacklist.h"
68 #include "new-random-map-dialog.h"
70 Driver::Driver(std::string load_filename)
73 game_lobby_dialog = NULL;
75 download_window = NULL;
76 game_scenario_downloaded = "";
77 splash_window = new SplashWindow;
78 splash_window->new_game_requested.connect(
79 sigc::mem_fun(*this, &Driver::on_new_game_requested));
80 splash_window->new_hosted_network_game_requested.connect(
81 sigc::mem_fun(*this, &Driver::on_new_hosted_network_game_requested));
82 splash_window->new_remote_network_game_requested.connect(
83 sigc::mem_fun(*this, &Driver::on_new_remote_network_game_requested));
84 splash_window->new_pbm_game_requested.connect(
85 sigc::mem_fun(*this, &Driver::on_new_pbm_game_requested));
86 splash_window->load_requested.connect(
87 sigc::mem_fun(*this, &Driver::on_load_requested));
88 splash_window->quit_requested.connect(
89 sigc::mem_fun(*this, &Driver::on_quit_requested));
91 d_load_filename = load_filename;
93 //here are the command-line options that don't bring up the splash screen:
94 if (Main::instance().start_stress_test)
96 Sound::deleteInstance();
100 if (Main::instance().start_robots != 0)
105 splash_window->show();
106 //here are the ones that do
112 if (Main::instance().start_test_scenario)
114 // quick load a test scenario
116 GameParameters::Player p;
117 p.type = GameParameters::Player::HUMAN;
120 g.players.push_back(p);
121 p.type = GameParameters::Player::EASY;
124 g.players.push_back(p);
125 for (unsigned int i = 2; i < MAX_PLAYERS; i++)
127 p.type = GameParameters::Player::OFF;
130 g.players.push_back(p);
143 g.play_with_quests = GameParameters::NO_QUESTING;
144 g.hidden_map = false;
145 g.neutral_cities = GameParameters::STRONG;
146 g.razing_cities = GameParameters::ALWAYS;
148 g.random_turns = false;
149 g.quick_start = GameParameters::NO_QUICK_START;
150 g.intense_combat = false;
151 g.military_advisor = false;
152 g.army_theme = "default";
153 g.tile_theme = "default";
154 g.shield_theme = "default";
155 g.city_theme = "default";
156 g.process_armies = GameParameters::PROCESS_ARMIES_AT_PLAYERS_TURN;
157 g.difficulty = GameScenario::calculate_difficulty_rating(g);
158 g.cities_can_produce_allies = false;
159 g.cusp_of_war = false;
160 g.see_opponents_stacks = true;
161 g.see_opponents_production = true;
162 on_new_game_requested(g);
164 else if (Main::instance().turn_filename != "")
166 PbmGameClient *pbm_game_client = PbmGameClient::getInstance();
167 GameScenario *game_scenario = load_game(d_load_filename);
168 if (game_scenario == NULL)
170 //now apply the actions in the turn file
173 //if the active player isn't a network player than don't do anything
174 if (Playerlist::getActiveplayer()->getType() != Player::NETWORKED)
176 //load the file, and decode them as we go.
177 XML_Helper helper(Main::instance().turn_filename, std::ios::in,
178 Configuration::s_zipfiles);
179 NextTurnPbm *nextTurn;
180 nextTurn = new NextTurnPbm(game_scenario->getTurnmode(),
181 game_scenario->s_random_turns);
182 broken = pbm_game_client->loadWithHelper (helper,
183 Playerlist::getActiveplayer());
187 game_scenario->saveGame(d_load_filename);
188 if (Playerlist::getActiveplayer()->getType() != Player::NETWORKED)
191 splash_window->hide();
195 game_window->load_game(game_scenario, nextTurn);
199 else if (Main::instance().start_robots != 0)
201 Sound::deleteInstance();
202 lordsawaromatic("127.0.0.1", LORDSAWAR_PORT, Player::AI_FAST,
203 Main::instance().start_robots);
207 splash_window->show();
208 if (d_load_filename.empty() == false)
211 g.map_path = d_load_filename;
212 size_t found = d_load_filename.find(".map");
213 if (found != std::string::npos)
215 GamePreferencesDialog d(d_load_filename, GameScenario::HOTSEAT);
216 d.set_parent_window(*splash_window->get_window());
217 d.game_started.connect(sigc::mem_fun
218 (*this, &Driver::on_new_game_requested));
223 found = d_load_filename.find(".sav");
224 if (found != std::string::npos)
225 on_load_requested(d_load_filename);
227 on_new_game_requested(g);
238 if (game_lobby_dialog)
239 delete game_lobby_dialog;
241 delete splash_window;
243 delete download_window;
246 void Driver::on_hosted_player_sat_down(Player *player)
248 guint32 id = player->getId();
249 GameServer *game_server = GameServer::getInstance();
250 game_server->sit_down(player);
251 player_replaced.emit(Playerlist::getInstance()->getPlayer(id));
254 void Driver::on_hosted_player_stood_up(Player *player)
256 guint32 id = player->getId();
257 GameServer *game_server = GameServer::getInstance();
258 game_server->stand_up(player);
259 player_replaced.emit(Playerlist::getInstance()->getPlayer(id));
262 void Driver::on_hosted_player_chat(std::string message)
264 GameServer *game_server = GameServer::getInstance();
265 game_server->chat(message);
268 void Driver::on_client_player_sat_down(Player *player)
270 GameClient *game_client = GameClient::getInstance();
271 game_client->sit_down(player);
274 void Driver::on_client_player_stood_up(Player *player)
276 GameClient *game_client = GameClient::getInstance();
277 game_client->stand_up(player);
280 void Driver::on_client_player_chat(std::string message)
282 GameClient *game_client = GameClient::getInstance();
283 game_client->chat(message);
286 GameScenario *Driver::create_new_scenario(GameParameters &g, GameScenario::PlayMode m)
288 bool update_uuid = false;
289 if (g.map_path.empty())
291 // construct new random scenario if we're not going to load the game
293 NewRandomMapDialog::create_and_dump_scenario("random.map", g, NULL);
301 GameScenario* game_scenario = new GameScenario(g.map_path, broken);
303 GameScenarioOptions::s_see_opponents_stacks = g.see_opponents_stacks;
304 GameScenarioOptions::s_see_opponents_production = g.see_opponents_production;
305 GameScenarioOptions::s_play_with_quests = g.play_with_quests;
306 GameScenarioOptions::s_hidden_map = g.hidden_map;
307 GameScenarioOptions::s_diplomacy = g.diplomacy;
308 GameScenarioOptions::s_cusp_of_war = g.cusp_of_war;
309 GameScenarioOptions::s_neutral_cities = g.neutral_cities;
310 GameScenarioOptions::s_razing_cities = g.razing_cities;
311 GameScenarioOptions::s_intense_combat = g.intense_combat;
312 GameScenarioOptions::s_military_advisor = g.military_advisor;
313 GameScenarioOptions::s_random_turns = g.random_turns;
318 game_scenario->setName(g.name);
319 game_scenario->setPlayMode(m);
321 if (game_scenario->getRound() == 0)
324 game_scenario->setNewRandomId();
326 Playerlist::getInstance()->syncPlayers(g.players);
328 game_scenario->initialize(g);
330 return game_scenario;
333 void Driver::on_new_hosted_network_game_requested(GameParameters g, int port,
337 splash_window->hide();
339 GameScenario *game_scenario =
340 create_new_scenario(g, GameScenario::NETWORKED);
342 if (game_scenario == NULL)
344 TimedMessageDialog dialog(*splash_window->get_window(),
345 _("Corrupted saved game file."), 0);
351 GameServer *game_server = GameServer::getInstance();
352 game_server->start(game_scenario, port, nick);
353 NextTurnNetworked *next_turn = new NextTurnNetworked(game_scenario->getTurnmode(), game_scenario->s_random_turns);
354 if (game_scenario->s_random_turns == true)
355 next_turn->snextRound.connect (sigc::mem_fun(GameServer::getInstance(),
356 &GameServer::sendTurnOrder));
357 next_turn->snextPlayerUnavailable.connect(sigc::mem_fun(this, &Driver::on_player_unavailable));
358 if (game_lobby_dialog)
359 delete game_lobby_dialog;
360 game_lobby_dialog = new GameLobbyDialog(game_scenario, next_turn,
362 game_server->round_begins.connect(sigc::mem_fun(next_turn, &NextTurnNetworked::start));
363 Playerlist::getInstance()->splayerDead.connect
364 (sigc::mem_fun(GameServer::getInstance(), &GameServer::sendKillPlayer));
365 game_lobby_dialog->set_parent_window(*splash_window->get_window());
366 game_lobby_dialog->player_sat_down.connect
367 (sigc::mem_fun(this, &Driver::on_hosted_player_sat_down));
368 game_lobby_dialog->player_stood_up.connect
369 (sigc::mem_fun(this, &Driver::on_hosted_player_stood_up));
370 game_lobby_dialog->message_sent.connect
371 (sigc::mem_fun(this, &Driver::on_hosted_player_chat));
372 game_lobby_dialog->start_network_game.connect
373 (sigc::mem_fun(this, &Driver::start_network_game_requested));
374 game_lobby_dialog->show();
375 bool response = game_lobby_dialog->run();
376 game_lobby_dialog->hide();
378 if (response == false)
380 GameServer::deleteInstance();
381 delete game_scenario;
383 splash_window->show();
388 void Driver::on_server_went_away()
390 heartbeat_conn.disconnect();
391 if (game_lobby_dialog)
392 game_lobby_dialog->hide();
394 download_window->hide();
396 splash_window->show();
397 GameClient::deleteInstance();
398 TimedMessageDialog dialog(*splash_window->get_window(),
399 _("Server went away."), 0);
404 void Driver::on_client_could_not_connect()
406 heartbeat_conn.disconnect();
407 if (game_lobby_dialog)
408 game_lobby_dialog->hide();
410 download_window->hide();
412 splash_window->show();
413 GameClient::deleteInstance();
414 TimedMessageDialog dialog(*splash_window->get_window(),
415 _("Could not connect."), 0);
420 void Driver::on_new_remote_network_game_requested(std::string host, unsigned short port, std::string nick)
423 splash_window->hide();
424 GameClient *game_client = GameClient::getInstance();
425 game_client->game_scenario_received.connect
426 (sigc::mem_fun(this, &Driver::on_game_scenario_downloaded));
427 game_client->client_disconnected.connect
428 (sigc::mem_fun(this, &Driver::on_server_went_away));
429 game_client->client_could_not_connect.connect
430 (sigc::mem_fun(this, &Driver::on_client_could_not_connect));
431 game_scenario_received.connect
432 (sigc::mem_fun(this, &Driver::on_game_scenario_received));
434 delete download_window;
435 download_window = new NewNetworkGameDownloadWindow();
436 download_window->pulse();
437 game_client->start(host, port, nick);
438 heartbeat_conn = Glib::signal_timeout().connect
439 (bind_return(sigc::mem_fun(*this, &Driver::heartbeat), true), 1 * 1000);
443 void Driver::heartbeat()
445 static bool already_done = false;
448 if (game_scenario_downloaded == "")
451 download_window->pulse();
455 game_scenario_received.emit(game_scenario_downloaded);
459 void Driver::on_game_scenario_received(std::string path)
461 heartbeat_conn.disconnect();
463 download_window->hide();
464 GameScenario *game_scenario = load_game(path);
465 GameClient *game_client = GameClient::getInstance();
466 std::string host = game_client->getHost();
467 guint32 port = game_client->getPort();
468 RecentlyPlayedGameList::getInstance()->addNetworkedEntry(game_scenario, host, port);
469 RecentlyPlayedGameList::getInstance()->saveToFile(File::getSavePath() + "/recently-played.xml");
471 NextTurnNetworked *next_turn = new NextTurnNetworked(game_scenario->getTurnmode(), game_scenario->s_random_turns);
472 next_turn->snextPlayerUnavailable.connect(sigc::mem_fun(this, &Driver::on_player_unavailable));
473 game_client->round_begins.connect(sigc::mem_fun(next_turn, &NextTurnNetworked::start));
474 if (game_lobby_dialog)
475 delete game_lobby_dialog;
476 game_lobby_dialog = new GameLobbyDialog(game_scenario, next_turn,
477 GameClient::getInstance(), false);
478 game_lobby_dialog->set_parent_window(*splash_window->get_window());
479 game_lobby_dialog->player_sat_down.connect
480 (sigc::mem_fun(this, &Driver::on_client_player_sat_down));
481 game_lobby_dialog->player_stood_up.connect
482 (sigc::mem_fun(this, &Driver::on_client_player_stood_up));
483 game_lobby_dialog->message_sent.connect
484 (sigc::mem_fun(this, &Driver::on_client_player_chat));
485 game_lobby_dialog->start_network_game.connect
486 (sigc::mem_fun(this, &Driver::start_network_game_requested));
487 game_lobby_dialog->show();
488 bool response = game_lobby_dialog->run();
489 game_lobby_dialog->hide();
491 if (response == false)
494 splash_window->show();
496 GameClient::deleteInstance();
497 delete game_scenario;
500 void Driver::on_game_scenario_downloaded(std::string path)
502 game_scenario_downloaded = path;
503 //emitting the signal doesn't work.
504 //it stops the game client from doing more processing.
505 //how can i bring up the game lobby dialog with this scenario?
506 //...without stopping the game client from getting more messages
509 void Driver::on_new_game_requested(GameParameters g)
511 GameScenario *game_scenario = create_new_scenario(g, GameScenario::HOTSEAT);
513 if (game_scenario == NULL)
515 TimedMessageDialog dialog(*splash_window->get_window(),
516 _("Corrupted saved game file."), 0);
519 splash_window->show();
523 std::list<std::string> e, w;
524 if (g.map_path != "" && game_scenario->validate(e, w) == false)
526 TimedMessageDialog dialog
527 (*splash_window->get_window(),
528 _("Invalid map file.\n"
529 "Please validate it in the scenario editor."), 0);
530 std::list<std::string>::iterator it = e.begin();
531 for (; it != e.end(); it++)
533 printf ("error: %s\n", (*it).c_str());
537 splash_window->show();
542 splash_window->hide();
544 NextTurn *next_turn = new NextTurnHotseat(game_scenario->getTurnmode(),
545 game_scenario->s_random_turns);
549 game_window->new_game(game_scenario, next_turn);
552 void Driver::on_load_requested(std::string filename)
555 splash_window->hide();
557 GameScenario *game_scenario = load_game(filename);
558 if (game_scenario == NULL)
560 splash_window->show();
567 if (game_scenario->getPlayMode() == GameScenario::HOTSEAT)
568 game_window->load_game
569 (game_scenario, new NextTurnHotseat(game_scenario->getTurnmode(),
570 game_scenario->s_random_turns));
571 else if (game_scenario->getPlayMode() == GameScenario::PLAY_BY_MAIL)
573 PbmGameServer::getInstance()->start();
574 game_window->load_game
575 (game_scenario, new NextTurnPbm(game_scenario->getTurnmode(),
576 game_scenario->s_random_turns));
578 else if (game_scenario->getPlayMode() == GameScenario::NETWORKED)
579 game_window->load_game
580 (game_scenario, new NextTurnNetworked(game_scenario->getTurnmode(),
581 game_scenario->s_random_turns));
584 void Driver::on_quit_requested()
587 splash_window->hide();
592 Main::instance().stop_main_loop();
595 void Driver::on_game_ended()
601 GameClient::deleteInstance();
602 PbmGameClient::deleteInstance();
603 GameServer::deleteInstance();
604 PbmGameServer::deleteInstance();
606 GraphicsCache::deleteInstance();
608 splash_window->show();
611 void Driver::init_game_window()
615 game_window = new GameWindow;
617 game_window->game_ended.connect(
618 sigc::mem_fun(*this, &Driver::on_game_ended));
619 game_window->show_lobby.connect(
620 sigc::mem_fun(*this, &Driver::on_show_lobby_requested));
621 game_window->quit_requested.connect(
622 sigc::mem_fun(*this, &Driver::on_quit_requested));
624 //make the width+height suitable for the screen size.
625 Glib::RefPtr<Gdk::Screen> screen = Gdk::Display::get_default()->get_default_screen();
626 guint32 screen_height = screen->get_height();
627 guint32 height = 450;
628 if (screen_height <= 600)
631 guint32 width = (int)((float)height * 1.42223);
632 // game_window->init(width, height);
633 game_window->init(800, 480);
637 GameScenario *Driver::load_game(std::string file_path)
640 GameScenario* game_scenario = new GameScenario(file_path, broken);
644 TimedMessageDialog dialog(*splash_window->get_window(),
645 _("Corrupted saved game file."), 0);
650 return game_scenario;
653 void Driver::on_new_pbm_game_requested(GameParameters g)
655 std::string filename;
656 std::string temp_filename = File::getSavePath() + "pbmtmp.sav";
658 GameScenario *game_scenario =
659 create_new_scenario(g, GameScenario::PLAY_BY_MAIL);
660 if (game_scenario == NULL)
662 TimedMessageDialog dialog(*splash_window->get_window(),
663 _("Corrupted saved game file."), 0);
668 game_scenario->saveGame(temp_filename);
669 std::string player_name = Playerlist::getActiveplayer()->getName();
670 delete game_scenario;
672 play_by_mail.init(temp_filename);
674 Gtk::FileChooserDialog chooser(*splash_window->get_window(), _("Save the scenario and mail it to the first player"),
675 Gtk::FILE_CHOOSER_ACTION_SAVE);
676 Gtk::FileFilter sav_filter;
677 sav_filter.add_pattern("*.sav");
678 chooser.set_filter(sav_filter);
679 chooser.set_current_folder(Glib::get_home_dir());
681 chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
682 chooser.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
683 chooser.set_default_response(Gtk::RESPONSE_ACCEPT);
686 int res = chooser.run();
689 if (res == Gtk::RESPONSE_ACCEPT)
691 std::string filename = chooser.get_filename();
693 remove (filename.c_str());
694 if (rename(temp_filename.c_str(), filename.c_str()))
696 char* err = strerror(errno);
697 std::cerr <<_("Error while trying to rename the temporary file to ")
699 std::cerr <<_("Error: ") <<err <<std::endl;
702 Glib::ustring s = String::ucompose(_("Now send the saved-game file to %1"),
704 TimedMessageDialog dialog(*splash_window->get_window(), s, 0);
710 void Driver::stressTestNextRound()
712 static time_t prev_round_start = time(NULL);
713 static int count = 1;
717 FILE * fileptr = fopen("/tmp/crapola.csv", "w");
722 time_t now = time(NULL);
723 printf ("starting round %d!\n", count);
725 FILE * fileptr = fopen("/tmp/crapola.csv", "a");
726 int total_fights = Playerlist::getInstance()->countFightsThisTurn();
727 int total_moves = Playerlist::getInstance()->countMovesThisTurn();
728 fprintf(fileptr, "%d, %d, %d, %d, %d, %d, %d, %d", count,
729 now - prev_round_start,
730 Stacklist::getNoOfStacks(),
731 Stacklist::getNoOfArmies(),
734 Citylist::getInstance()->countCities(Playerlist::getInstance()->getNeutral()),
735 Playerlist::getInstance()->countPlayersAlive());
736 if (Playerlist::getInstance()->countPlayersAlive() == 2)
738 Playerlist *pl = Playerlist::getInstance();
739 for (Playerlist::iterator it = pl->begin(); it != pl->end(); it++)
741 if ((*it)->isDead() == true)
743 if ((*it) == pl->getNeutral())
745 fprintf(fileptr,", %d (%d)", Citylist::getInstance()->countCities(*it), (*it)->getHeroes().size() + (*it)->countAllies());
748 fprintf(fileptr,"\n");
752 prev_round_start = now;
756 void Driver::stress_test()
759 // quick load a test scenario
761 GameParameters::Player p;
762 for (unsigned int i = 0; i < MAX_PLAYERS; i++)
764 p.type = GameParameters::Player::HARD;
768 case 0: p.name = "one"; break;
769 case 1: p.name = "two"; break;
770 case 2: p.name = "three"; break;
771 case 3: p.name = "four"; break;
772 case 4: p.name = "five"; break;
773 case 5: p.name = "six"; break;
774 case 6: p.name = "seven"; break;
775 case 7: p.name = "eight"; break;
777 g.players.push_back(p);
779 g.map.width = MAP_SIZE_NORMAL_WIDTH;
780 g.map.height = MAP_SIZE_NORMAL_HEIGHT;
790 g.map.signposts = 10;
792 g.play_with_quests = GameParameters::ONE_QUEST_PER_PLAYER;
793 g.hidden_map = false;
794 g.neutral_cities = GameParameters::STRONG;
795 g.razing_cities = GameParameters::ALWAYS;
797 g.random_turns = false;
798 g.quick_start = GameParameters::NO_QUICK_START;
799 g.intense_combat = false;
800 g.military_advisor = false;
801 g.army_theme = "default";
802 g.tile_theme = "default";
803 g.shield_theme = "default";
804 g.city_theme = "default";
805 g.process_armies = GameParameters::PROCESS_ARMIES_AT_PLAYERS_TURN;
806 g.difficulty = GameScenario::calculate_difficulty_rating(g);
807 g.cities_can_produce_allies = false;
808 g.cusp_of_war = false;
809 g.see_opponents_stacks = true;
810 g.see_opponents_production = true;
814 path = NewRandomMapDialog::create_and_dump_scenario("random.map", g, NULL);
817 GameScenario* game_scenario = new GameScenario(g.map_path, broken);
822 NextTurnHotseat *nextTurn;
823 nextTurn = new NextTurnHotseat(game_scenario->getTurnmode(),
824 game_scenario->s_random_turns);
826 nextTurn->snextRound.connect
827 (sigc::mem_fun(this, &Driver::stressTestNextRound));
828 if (game_scenario->getRound() == 0)
830 Playerlist::getInstance()->syncPlayers(g.players);
831 game_scenario->initialize(g);
834 //this is a bit unfortunate... we have to instantiate images just to get stack positions into the stack tiles. is there a better way?
836 GameMap::getInstance()->getTileset()->instantiateImages();
837 GameMap::getInstance()->getShieldset()->instantiateImages();
838 GameMap::getInstance()->getCityset()->instantiateImages();
839 guint32 armyset = Playerlist::getInstance()->getNeutral()->getArmyset();
840 Armysetlist::getInstance()->getArmyset(armyset)->instantiateImages();
842 Game game(game_scenario, nextTurn);
843 game.get_smallmap().set_slide_speed(0);
844 Configuration::s_displaySpeedDelay = 0;
845 time_t start = time(NULL);
847 //next turn and game_Scenario get deleted inside game.
848 size_t mins = (time(NULL) - start) / 60;
849 printf("duration: %d mins, turns: %d\n", mins, game_scenario->getRound());
853 void Driver::lordsawaromatic(std::string host, unsigned short port, Player::Type type, int num_players)
855 GameClient *game_client = GameClient::getInstance();
856 game_client->game_scenario_received.connect
857 (sigc::mem_fun(this, &Driver::on_game_scenario_downloaded));
858 game_client->client_disconnected.connect
859 (sigc::mem_fun(this, &Driver::on_server_went_away));
860 game_client->client_could_not_connect.connect
861 (sigc::mem_fun(this, &Driver::on_client_could_not_connect));
862 game_scenario_received.connect
863 (sigc::mem_fun(this, &Driver::on_game_scenario_received_for_robots));
864 game_client->setNickname("lordsawaromatic");
865 game_client->start(host, port, "lordsawaromatic");
866 heartbeat_conn = Glib::signal_timeout().connect
867 (bind_return(sigc::mem_fun(*this, &Driver::heartbeat), true), 1 * 1000);
868 robot_player_type = type;
869 number_of_robots = num_players;
872 void Driver::on_game_scenario_received_for_robots(std::string path)
874 heartbeat_conn.disconnect();
875 GameScenario *game_scenario = load_game(path);
876 NextTurnNetworked *next_turn = new NextTurnNetworked(game_scenario->getTurnmode(), game_scenario->s_random_turns);
877 GameClient::getInstance()->round_begins.connect(sigc::mem_fun(next_turn, &NextTurnNetworked::start));
878 Playerlist *pl = Playerlist::getInstance();
880 unsigned int count = 0;
881 for (Playerlist::iterator it = pl->begin(); it != pl->end(); it++)
883 if (count >= number_of_robots && number_of_robots > 0)
885 if ((*it)->getType() == Player::NETWORKED)
887 on_client_player_sat_down(*it);
892 pl->turnHumansInto(robot_player_type, number_of_robots);
894 for (Playerlist::iterator it = pl->begin(); it != pl->end(); it++)
895 if (Player::Type((*it)->getType()) == robot_player_type)
897 GameClient::getInstance()->listenForLocalEvents(*it);
900 //end turn signals are listened to by next_turn, that are fired by the game client decoder
905 void Driver::on_show_lobby_requested()
907 if (game_lobby_dialog)
908 game_lobby_dialog->show();
911 void Driver::start_network_game_requested(GameScenario *game_scenario, NextTurnNetworked *next_turn)
916 Player *active = Playerlist::getActiveplayer();
917 if (active->getType() == Player::NETWORKED)
921 if (active->hasAlreadyInitializedTurn())
924 game_window->continue_network_game (next_turn);
930 player_replaced.connect
931 (sigc::mem_fun(game_window, &GameWindow::on_player_replaced));
934 game_window->new_network_game (game_scenario, next_turn);
938 void Driver::on_player_unavailable(Player *p)
940 game_lobby_dialog->player_is_unavailable(p);
941 on_show_lobby_requested();