]> git.pond.sub.org Git - empserver/blob - src/lib/as/as_init.c
105140854756370c158ab03223692e21e18d7df8
[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
21 #include <config.h>
22
23 #include <stdlib.h>
24 #include "as.h"
25
26 /*
27  * Return an as_data structure with the necessary fields filled in
28  * and space malloced.  Return NULL if malloc fails.
29  */
30 struct as_data *
31 as_init(int maxneighbors,
32         int hashsize,
33         int (*hashfunc)(struct as_coord),
34         int (*neighborfunc)(struct as_coord, struct as_coord *, void *),
35         double (*lbcostfunc)(struct as_coord, struct as_coord, void *),
36         double (*realcostfunc)(struct as_coord, struct as_coord, void *),
37         double (*seccostfunc)(struct as_coord, struct as_coord, void *),
38         void *userdata)
39 {
40     struct as_data *adp;
41
42     AS_NEW(adp, struct as_data, NULL);
43     AS_NEW_ARRAY(adp->neighbor_coords, struct as_coord,
44                  maxneighbors, NULL);
45     AS_NEW_ARRAY(adp->neighbor_nodes, struct as_node *,
46                  maxneighbors + 1, NULL);
47     AS_NEW_ARRAY(adp->hashtab, struct as_hash *, hashsize, NULL);
48
49     adp->maxneighbors = maxneighbors;
50     adp->hashsize = hashsize;
51     adp->hash = hashfunc;
52     adp->neighbor = neighborfunc;
53     adp->lbcost = lbcostfunc;
54     adp->realcost = realcostfunc;
55     adp->seccost = seccostfunc;
56     adp->userdata = userdata;
57
58     return adp;
59 }