initial commit, lordsawar source, slightly modified
[lordsawar] / src / game-station.cpp
1 // Copyright (C) 2008 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #include <iostream>
19 #include <sstream>
20 #include <list>
21
22 #include "game-station.h"
23
24 #include "network-action.h"
25 #include "network-history.h"
26
27
28 GameStation::GameStation()
29 {
30 }
31
32 GameStation::~GameStation()
33 {
34 }
35
36 void GameStation::clearNetworkActionlist(std::list<NetworkAction*> &a)
37 {
38   for (std::list<NetworkAction*>::iterator it = a.begin();
39        it != a.end(); it++)
40     {
41       delete (*it);
42     }
43   a.clear();
44 }
45
46 void GameStation::clearNetworkHistorylist(std::list<NetworkHistory*> &h)
47 {
48   for (std::list<NetworkHistory*>::iterator it = h.begin(); 
49        it != h.end(); it++)
50     {
51       delete (*it);
52     }
53   h.clear();
54 }
55
56 void GameStation::listenForLocalEvents(Player *p)
57 {
58   sigc::connection connection;
59   connection = p->acting.connect(sigc::mem_fun(this, 
60                                                &GameStation::onActionDone));
61   action_listeners[p->getId()] = connection;
62   connection = p->history_written.connect
63     (sigc::mem_fun(this, &GameStation::onHistoryDone));
64   history_listeners[p->getId()] = connection;
65 }
66
67 void GameStation::stopListeningForLocalEvents(Player *p)
68 {
69   sigc::connection connection;
70   std::map<guint32, sigc::connection>::iterator it;
71   it = action_listeners.find(p->getId());
72   if (it != action_listeners.end())
73     {
74       connection = (*it).second;
75       connection.disconnect();
76       action_listeners.erase(it);
77     }
78   it = history_listeners.find(p->getId());
79   if (it != history_listeners.end())
80     {
81       connection = (*it).second;
82       connection.disconnect();
83       history_listeners.erase(it);
84     }
85 }
86 // End of file