src/lib/common/land.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  *  land.c: Misc. land unit routines
00029  * 
00030  *  Known contributors to this file:
00031  *     
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "file.h"
00037 #include "land.h"
00038 #include "misc.h"
00039 #include "nat.h"
00040 #include "nsc.h"
00041 #include "path.h"
00042 #include "prototypes.h"
00043 #include "sect.h"
00044 #include "xy.h"
00045 
00046 int
00047 adj_units(coord x, coord y, natid own)
00048 {
00049     int i;
00050     struct sctstr sect;
00051 
00052     for (i = DIR_FIRST; i <= DIR_LAST; i++) {
00053         getsect(x + diroff[i][0], y + diroff[i][1], &sect);
00054         if (has_units(sect.sct_x, sect.sct_y, own, 0))
00055             return 1;
00056     }
00057     return 0;
00058 }
00059 
00060 int
00061 has_units(coord x, coord y, natid cn, struct lndstr *lp)
00062 {
00063     int n;
00064     struct lndstr land;
00065 
00066     for (n = 0; ef_read(EF_LAND, n, &land); n++) {
00067         if (land.lnd_x != x || land.lnd_y != y)
00068             continue;
00069         if (lp) {
00070             /* Check this unit.  If it is this one, we don't want
00071                it included in the count. */
00072             if (lp->lnd_uid == land.lnd_uid)
00073                 continue;
00074         }
00075         if (land.lnd_own == cn)
00076             return 1;
00077     }
00078 
00079     return 0;
00080 }
00081 
00082 int
00083 has_units_with_mob(coord x, coord y, natid cn)
00084 {
00085     struct nstr_item ni;
00086     struct lndstr land;
00087 
00088     snxtitem_xy(&ni, EF_LAND, x, y);
00089     while (nxtitem(&ni, &land)) {
00090         if (land.lnd_own != cn)
00091             continue;
00092         if (land.lnd_mobil > 0)
00093             return 1;
00094     }
00095 
00096     return 0;
00097 }
00098 
00099 /*
00100  * Is there a engineer unit at X,Y that can help nation CN?
00101  */
00102 int
00103 has_helpful_engineer(coord x, coord y, natid cn)
00104 {
00105     struct nstr_item ni;
00106     struct lndstr land;
00107 
00108     snxtitem_xy(&ni, EF_LAND, x, y);
00109     while (nxtitem(&ni, &land)) {
00110         if (land.lnd_own != cn && getrel(getnatp(land.lnd_own), cn) != ALLIED)
00111             continue;
00112         if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER)
00113             return 1;
00114     }
00115 
00116     return 0;
00117 }

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