Fix bug in setting up w3 and w4 games
[capablanca.git] / lasker-2.2.3 / src / follow.c
1 /*
2    Copyright (C) Andrew Tridgell 2002
3    
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 2 of the License, or
7    (at your option) any later version.
8    
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 General Public License for more details.
13    
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 /*
20   handle 'follow' lists. These are a little different to FICS in that they are persistent
21   (ie. they are more similar to the personal gnotify list)
22 */
23
24 #include "includes.h"
25
26 /* 
27    a game has started between p1 and p2
28    anyone who has either player in their personal follow list will now send an 
29    effective 'observe' command if they are idle
30 */
31 void follow_start(int p1,int p2)
32 {
33         int p;
34         for (p = 0; p < player_globals.p_num; p++) {
35                 struct player *pp = &player_globals.parray[p];
36                 int in1=0, in2=0;
37
38                 /* don't follow ourselves */
39                 if ((p == p1) || (p == p2)) {
40                         continue;
41                 }
42
43                 /* don't follow while playing, examining etc */
44                 if (pp->status != PLAYER_PROMPT) {
45                         continue;
46                 }
47
48                 /* see if either player is in our follow list */
49                 in1 = in_list(p, L_FOLLOW, player_globals.parray[p1].login);
50                 if (in1 == 0) {
51                         in2 = in_list(p, L_FOLLOW, player_globals.parray[p2].login);
52                 }
53
54                 if (in1 == 0 && in2 == 0) {
55                         continue;
56                 }
57
58                 /* fake up an observe command */
59                 pcommand(p, "observe %s\n", player_globals.parray[in1?p1:p2].login);
60                 send_prompt (p);
61         }
62 }