src/lib/common/nat.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  *  nat.c: Misc. accesses on the nation file
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1989
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "file.h"
00037 #include "misc.h"
00038 #include "nat.h"
00039 #include "sect.h"
00040 
00041 char *relates[] = {
00042     /* must follow nation relation defines in nat.h */
00043     "At War", "Sitzkrieg", "Mobilizing", "Hostile", "Neutral", "Friendly",
00044     "Allied"
00045 };
00046 
00047 char *
00048 cname(natid n)
00049 {
00050     struct natstr *np;
00051 
00052     if ((np = getnatp(n)) == 0)
00053         return 0;
00054     return np->nat_cnam;
00055 }
00056 
00057 char *
00058 relatename(struct natstr *np, natid other)
00059 {
00060     return relates[getrel(np, other)];
00061 }
00062 
00063 char *
00064 rejectname(struct natstr *np, natid other)
00065 {
00066     static char *rejects[] = {
00067         /* must follow reject flags defined in nat.h */
00068         "  YES  YES  YES  YES",
00069         "  NO   YES  YES  YES",
00070         "  YES  NO   YES  YES",
00071         "  NO   NO   YES  YES",
00072         "  YES  YES  NO   YES",
00073         "  NO   YES  NO   YES",
00074         "  YES  NO   NO   YES",
00075         "  NO   NO   NO   YES",
00076         "  YES  YES  YES  NO ",
00077         "  NO   YES  YES  NO ",
00078         "  YES  NO   YES  NO ",
00079         "  NO   NO   YES  NO ",
00080         "  YES  YES  NO   NO ",
00081         "  NO   YES  NO   NO ",
00082         "  YES  NO   NO   NO ",
00083         "  NO   NO   NO   NO "
00084     };
00085 
00086     return rejects[getrejects(other, np)];
00087 }
00088 
00089 char *
00090 natstate(struct natstr *np)
00091 {
00092     static char *stnam[] = {
00093         /* must match nat_status */
00094         "FREE", "VISITOR", "VISITOR", "SANCTUARY", "ACTIVE", "DEITY"
00095     };
00096     return stnam[np->nat_stat];
00097 }
00098 
00099 /* This returns the relations that np has with them */
00100 int
00101 getrel(struct natstr *np, natid them)
00102 {
00103     return np->nat_relate[them];
00104 }
00105 
00106 int
00107 getrejects(natid them, struct natstr *np)
00108 {
00109     return np->nat_rejects[them];
00110 }
00111 
00112 void
00113 agecontact(struct natstr *np)
00114 {
00115     int them;
00116 
00117     for (them = 1; them < MAXNOC; ++them) {
00118         if (them != np->nat_cnum && np->nat_contact[them]) {
00119             --np->nat_contact[them];
00120         }
00121     }
00122 }
00123 
00124 int
00125 getcontact(struct natstr *np, natid them)
00126 {
00127     return np->nat_contact[them];
00128 }
00129 
00130 void
00131 putrel(struct natstr *np, natid them, int relate)
00132 {
00133     np->nat_relate[them] = relate;
00134 }
00135 
00136 void
00137 putreject(struct natstr *np, natid them, int how, int what)
00138 {
00139     if (how)
00140         np->nat_rejects[them] |= what;
00141     else
00142         np->nat_rejects[them] &= what;
00143 }
00144 
00145 void
00146 putcontact(struct natstr *np, natid them, int contact)
00147 {
00148     if (CANT_HAPPEN(contact < 0))
00149         contact = 0;
00150     if (CANT_HAPPEN(contact > 255))
00151         contact = 255;
00152 
00153     if (np->nat_contact[them] < contact)
00154         np->nat_contact[them] = contact;
00155 }
00156 
00157 int
00158 influx(struct natstr *np)
00159 {
00160     struct sctstr sect;
00161 
00162     getsect(np->nat_xcap, np->nat_ycap, &sect);
00163     if (sect.sct_own != np->nat_cnum ||
00164         (sect.sct_type != SCT_CAPIT && sect.sct_type != SCT_MOUNT &&
00165          sect.sct_type != SCT_SANCT) ||
00166         (np->nat_flags & NF_SACKED))
00167         return 1;
00168     else
00169         return 0;
00170 }

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