]> git.pond.sub.org Git - empserver/blob - src/lib/as/as_init.c
Import of Empire 4.2.12
[empserver] / src / lib / as / as_init.c
1 /*
2  *  A* Search - A search library used in Empire to determine paths between
3  *              objects.
4  *  Copyright (C) 1990-1998 Phil Lapsley
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "as.h"
23
24 #if !defined(lint) && !defined(SABER)
25 static  char    sccsid[] = "@(#)as_init.c       1.4     11/13/90";
26 #endif /* not lint */
27
28 /*
29  * Return an as_data structure with the necessary fields filled in
30  * and space malloced.  Return NULL if malloc fails.
31  */
32 struct as_data *
33 as_init(int maxneighbors,
34         int hashsize,
35         int (*hashfunc)        (struct as_coord),
36         int (*neighborfunc)    (struct as_coord, struct as_coord *, s_char *),
37         double (*lbcostfunc)   (struct as_coord, struct as_coord, s_char *),
38         double (*realcostfunc) (struct as_coord, struct as_coord, s_char *),
39         double (*seccostfunc)  (struct as_coord, struct as_coord, s_char *),
40         s_char *userdata)
41 {
42         struct as_data  *adp;
43
44         AS_NEW(adp, struct as_data, NULL);
45         AS_NEW_ARRAY(adp->neighbor_coords, struct as_coord,
46                 maxneighbors, NULL);
47         AS_NEW_ARRAY(adp->neighbor_nodes, struct as_node *,
48                 maxneighbors + 1, NULL);
49         AS_NEW_ARRAY(adp->hashtab, struct as_hash *,
50                 hashsize, NULL);
51
52         adp->maxneighbors = maxneighbors;
53         adp->hashsize = hashsize;
54         adp->hash = hashfunc;
55         adp->neighbor = neighborfunc;
56         adp->lbcost = lbcostfunc;
57         adp->realcost = realcostfunc;
58         adp->seccost = seccostfunc;
59         adp->userdata = userdata;
60
61         return (adp);
62 }