Prepare 1.0 alpha3 release.
[tagua/yd.git] / src / agentgroup.cpp
blob86a4c2bc31e9f54d69841e51aba90ca762e63bb4
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "agentgroup.h"
13 using namespace boost;
15 void AgentGroup::addAgent(const AgentPtr& agent) {
16 m_agents.insert(agent);
19 #define FORWARD(method, args) \
20 for (weak_set<Agent>::iterator i = m_agents.begin(); \
21 i != m_agents.end(); \
22 ++i) { \
23 if (i.get() != source) { \
24 i->method args; \
25 } \
28 void AgentGroup::clockUpdate(Agent* source, int white, int black) {
29 FORWARD(notifyClockUpdate, (white, black))
32 void AgentGroup::move(Agent* source, const Index& index) {
33 FORWARD(notifyMove, (index))
36 void AgentGroup::back(Agent* source) {
37 FORWARD(notifyBack, ())
40 void AgentGroup::forward(Agent* source) {
41 FORWARD(notifyForward, ())
44 void AgentGroup::gotoFirst(Agent* source) {
45 FORWARD(notifyGotoFirst, ())
48 void AgentGroup::gotoLast(Agent* source) {
49 FORWARD(notifyGotoLast, ())
51 #undef FORWARD
56 AgentGroupDispatcher::AgentGroupDispatcher(AgentGroup* group, Agent* agent)
57 : m_group(group)
58 , m_agent(agent) { }
60 void AgentGroupDispatcher::clockUpdate(int white, int black) {
61 m_group->clockUpdate(m_agent, white, black);
64 bool AgentGroupDispatcher::move(const Index& index) {
65 m_group->move(m_agent, index);
66 return true;
69 bool AgentGroupDispatcher::back() {
70 m_group->back(m_agent);
71 return true;
74 bool AgentGroupDispatcher::forward() {
75 m_group->forward(m_agent);
76 return true;
79 bool AgentGroupDispatcher::gotoFirst() {
80 m_group->gotoFirst(m_agent);
81 return true;
84 bool AgentGroupDispatcher::gotoLast() {
85 m_group->gotoLast(m_agent);
86 return true;