]> git.pond.sub.org Git - empserver/blob - src/lib/common/empobj.c
(put_empobj): New. Put generic empobj into the appropriate data file.
[empserver] / src / lib / common / empobj.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
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  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  empobj.c: Common functions on struct empobj and
29  *            union empobj_storage
30  * 
31  *  Known contributors to this file:
32  *     Ron Koenderink, 2006
33  *     Markus Armbruster, 2006
34  */
35
36 #include <config.h>
37
38 #include "empobj.h"
39 #include "file.h"
40 #include "prototypes.h"
41
42 char *
43 obj_nameof(struct empobj *gp)
44 {
45     switch (gp->ef_type) {
46     case EF_SHIP:
47         return prship((struct shpstr *)gp);
48     case EF_PLANE:
49         return prplane((struct plnstr *)gp);
50     case EF_LAND:
51         return prland((struct lndstr *)gp);
52     case EF_NUKE:
53         return prnuke((struct nukstr *)gp);
54     }
55     CANT_HAPPEN("unsupported TYPE");
56     return "";
57 }
58
59
60 int
61 put_empobj(struct empobj *gp)
62 {
63     switch (gp->ef_type)
64     {
65     case EF_SECTOR:
66         return ef_write(gp->ef_type, sctoff(gp->x, gp->y), gp);
67     case EF_NATION:
68     case EF_BMAP:
69     case EF_MAP:
70         return ef_write(gp->ef_type, gp->own, gp);
71     default:
72         return ef_write(gp->ef_type, gp->uid, gp);
73     }
74 }
75
76 void *
77 get_empobj_chr(struct empobj *gp)
78 {
79     void *cp;
80
81     switch (gp->ef_type) {
82     case EF_LAND:
83         cp = &lchr[(int)gp->type];
84         break;
85     case EF_SHIP:
86         cp = &mchr[(int)gp->type];
87         break;
88     case EF_PLANE:
89         cp = &plchr[(int)gp->type];
90         break;
91     case EF_NUKE:
92         cp = &nchr[(int)gp->type];
93         break;
94     case EF_SECTOR:
95         cp = &dchr[(int)gp->type];
96         break;
97     default:
98         CANT_HAPPEN("unsupported TYPE");
99         cp = NULL;
100         break;
101     }
102     return cp;
103 }