]> git.pond.sub.org Git - empserver/blob - src/lib/common/empobj.c
(get_empobj_mob_max): Switch ef_type to type to be more consistent
[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 struct empobj *
61 get_empobjp(int type, int id)
62 {
63     if (CANT_HAPPEN(type == EF_SECTOR || type == EF_BAD))
64         return NULL;
65     else
66         return (struct empobj *)ef_ptr(type, id);
67 }
68
69 int
70 put_empobj(struct empobj *gp)
71 {
72     switch (gp->ef_type)
73     {
74     case EF_SECTOR:
75         return ef_write(gp->ef_type, sctoff(gp->x, gp->y), gp);
76     case EF_NATION:
77     case EF_BMAP:
78     case EF_MAP:
79         return ef_write(gp->ef_type, gp->own, gp);
80     default:
81         return ef_write(gp->ef_type, gp->uid, gp);
82     }
83 }
84
85 void *
86 get_empobj_chr(struct empobj *gp)
87 {
88     void *cp;
89
90     switch (gp->ef_type) {
91     case EF_LAND:
92         cp = &lchr[(int)gp->type];
93         break;
94     case EF_SHIP:
95         cp = &mchr[(int)gp->type];
96         break;
97     case EF_PLANE:
98         cp = &plchr[(int)gp->type];
99         break;
100     case EF_NUKE:
101         cp = &nchr[(int)gp->type];
102         break;
103     case EF_SECTOR:
104         cp = &dchr[(int)gp->type];
105         break;
106     default:
107         CANT_HAPPEN("unsupported TYPE");
108         cp = NULL;
109         break;
110     }
111     return cp;
112 }
113
114 char *
115 emp_obj_chr_name(struct empobj *gp)
116 {
117     switch (gp->ef_type) {
118     case EF_LAND:
119         return lchr[(int)gp->type].l_name;
120     case EF_SHIP:
121         return mchr[(int)gp->type].m_name;
122     case EF_PLANE:
123         return plchr[(int)gp->type].pl_name;
124     case EF_NUKE:
125         return nchr[(int)gp->type].n_name;
126     case EF_SECTOR:
127         return dchr[(int)gp->type].d_name;
128     default:
129         CANT_REACH();
130         return NULL;
131     }
132 }
133
134 int
135 get_empobj_mob_max(int type)
136 {
137     switch (type) {
138     case EF_SHIP:
139         return ship_mob_max;
140     case EF_LAND:
141         return land_mob_max;
142     case EF_PLANE:
143         return plane_mob_max;
144     case EF_SECTOR:
145         return sect_mob_max;
146     default:
147         CANT_REACH();
148         return -1;
149     }
150 }