1 /*
2  *	t_centre.cc
3  *	AYM 1998-11-22
4  */
5 
6 
7 /*
8 This file is part of Yadex.
9 
10 Yadex incorporates code from DEU 5.21 that was put in the public domain in
11 1994 by Rapha�l Quinet and Brendon Wyber.
12 
13 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
14 
15 This program is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any later
18 version.
19 
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
26 Place, Suite 330, Boston, MA 02111-1307, USA.
27 */
28 
29 
30 #include "yadex.h"
31 #include "bitvec.h"
32 #include "levels.h"
33 #include "selectn.h"
34 #include "t_centre.h"
35 
36 
37 /*
38  *	centre_of_things
39  *	Return the coordinates of the centre of a group of things.
40  */
centre_of_things(SelPtr list,int * x,int * y)41 void centre_of_things (SelPtr list, int *x, int *y)
42 {
43 SelPtr cur;
44 int nitems;
45 long x_sum;
46 long y_sum;
47 
48 x_sum = 0;
49 y_sum = 0;
50 for (nitems = 0, cur = list; cur; cur = cur->next, nitems++)
51    {
52    x_sum += Things[cur->objnum].xpos;
53    y_sum += Things[cur->objnum].ypos;
54    }
55 if (nitems == 0)
56    {
57    *x = 0;
58    *y = 0;
59    }
60 else
61    {
62    *x = (int) (x_sum / nitems);
63    *y = (int) (y_sum / nitems);
64    }
65 }
66 
67 
68