src/lib/common/empobj.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  empobj.c: Common functions on struct empobj and
00029  *            union empobj_storage
00030  * 
00031  *  Known contributors to this file:
00032  *     Ron Koenderink, 2006
00033  *     Markus Armbruster, 2006
00034  */
00035 
00036 #include <config.h>
00037 
00038 #include "empobj.h"
00039 #include "file.h"
00040 #include "optlist.h"
00041 #include "prototypes.h"
00042 
00043 char *
00044 obj_nameof(struct empobj *gp)
00045 {
00046     switch (gp->ef_type) {
00047     case EF_SHIP:
00048         return prship((struct shpstr *)gp);
00049     case EF_PLANE:
00050         return prplane((struct plnstr *)gp);
00051     case EF_LAND:
00052         return prland((struct lndstr *)gp);
00053     case EF_NUKE:
00054         return prnuke((struct nukstr *)gp);
00055     }
00056     CANT_REACH();
00057     return "The Beast #666";
00058 }
00059 
00060 struct empobj *
00061 get_empobjp(int type, int id)
00062 {
00063     if (CANT_HAPPEN(type == EF_SECTOR || type == EF_BAD))
00064         return NULL;
00065     return ef_ptr(type, id);
00066 }
00067 
00068 int
00069 put_empobj(struct empobj *gp)
00070 {
00071     switch (gp->ef_type)
00072     {
00073     case EF_SECTOR:
00074         return ef_write(gp->ef_type, sctoff(gp->x, gp->y), gp);
00075     case EF_NATION:
00076     case EF_BMAP:
00077     case EF_MAP:
00078         return ef_write(gp->ef_type, gp->own, gp);
00079     default:
00080         return ef_write(gp->ef_type, gp->uid, gp);
00081     }
00082 }
00083 
00084 struct empobj_chr *
00085 get_empobj_chr(struct empobj *gp)
00086 {
00087     switch (gp->ef_type) {
00088     case EF_LAND:
00089         return (struct empobj_chr *)&lchr[(int)gp->type];
00090     case EF_SHIP:
00091         return (struct empobj_chr *)&mchr[(int)gp->type];
00092     case EF_PLANE:
00093         return (struct empobj_chr *)&plchr[(int)gp->type];
00094     case EF_NUKE:
00095         return (struct empobj_chr *)&nchr[(int)gp->type];
00096     case EF_SECTOR:
00097         return (struct empobj_chr *)&dchr[(int)gp->type];
00098     }
00099     CANT_REACH();
00100     return NULL;
00101 }
00102 
00103 char *
00104 emp_obj_chr_name(struct empobj *gp)
00105 {
00106     switch (gp->ef_type) {
00107     case EF_LAND:
00108         return lchr[(int)gp->type].l_name;
00109     case EF_SHIP:
00110         return mchr[(int)gp->type].m_name;
00111     case EF_PLANE:
00112         return plchr[(int)gp->type].pl_name;
00113     case EF_NUKE:
00114         return nchr[(int)gp->type].n_name;
00115     case EF_SECTOR:
00116         return dchr[(int)gp->type].d_name;
00117     }
00118     CANT_REACH();
00119     return NULL;
00120 }
00121 
00122 int
00123 get_empobj_mob_max(int type)
00124 {
00125     switch (type) {
00126     case EF_SHIP:
00127         return ship_mob_max;
00128     case EF_LAND:
00129         return land_mob_max;
00130     case EF_PLANE:
00131         return plane_mob_max;
00132     case EF_SECTOR:
00133         return sect_mob_max;
00134     }
00135     CANT_REACH();
00136     return -1;
00137 }

Generated on Fri Mar 28 11:01:14 2008 for empserver by  doxygen 1.5.2