]> git.pond.sub.org Git - empserver/blob - src/lib/common/empobj.c
(get_empobj_mob_max): New. Return maximum mobility based on ef_type.
[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 "optlist.h"
41 #include "prototypes.h"
42
43 char *
44 obj_nameof(struct empobj *gp)
45 {
46     switch (gp->ef_type) {
47     case EF_SHIP:
48         return prship((struct shpstr *)gp);
49     case EF_PLANE:
50         return prplane((struct plnstr *)gp);
51     case EF_LAND:
52         return prland((struct lndstr *)gp);
53     case EF_NUKE:
54         return prnuke((struct nukstr *)gp);
55     }
56     CANT_HAPPEN("unsupported TYPE");
57     return "";
58 }
59
60
61 int
62 put_empobj(struct empobj *gp)
63 {
64     switch (gp->ef_type)
65     {
66     case EF_SECTOR:
67         return ef_write(gp->ef_type, sctoff(gp->x, gp->y), gp);
68     case EF_NATION:
69     case EF_BMAP:
70     case EF_MAP:
71         return ef_write(gp->ef_type, gp->own, gp);
72     default:
73         return ef_write(gp->ef_type, gp->uid, gp);
74     }
75 }
76
77 void *
78 get_empobj_chr(struct empobj *gp)
79 {
80     void *cp;
81
82     switch (gp->ef_type) {
83     case EF_LAND:
84         cp = &lchr[(int)gp->type];
85         break;
86     case EF_SHIP:
87         cp = &mchr[(int)gp->type];
88         break;
89     case EF_PLANE:
90         cp = &plchr[(int)gp->type];
91         break;
92     case EF_NUKE:
93         cp = &nchr[(int)gp->type];
94         break;
95     case EF_SECTOR:
96         cp = &dchr[(int)gp->type];
97         break;
98     default:
99         CANT_HAPPEN("unsupported TYPE");
100         cp = NULL;
101         break;
102     }
103     return cp;
104 }
105
106 int
107 get_empobj_mob_max(int ef_type)
108 {
109     switch (ef_type) {
110     case EF_SHIP:
111         return ship_mob_max;
112     case EF_LAND:
113         return land_mob_max;
114     case EF_PLANE:
115         return plane_mob_max;
116     case EF_SECTOR:
117         return sect_mob_max;
118     default:
119         CANT_REACH();
120         return -1;
121     }
122 }