include/nat.h

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.h: Definitions for things having to do with nations
00029  * 
00030  *  Known contributors to this file:
00031  *     Thomas Ruschak
00032  *     Ken Stevens, 1995
00033  *     Steve McClure, 1998-2000
00034  */
00035 
00036 #ifndef NAT_H
00037 #define NAT_H
00038 
00039 #include <time.h>
00040 #include "types.h"
00041 
00042 #define MAXNOR          50      /* max # realms */
00043 
00044 /* Nation status */
00045 typedef enum {
00046     /*
00047      * Don't change order without checking inequality comparisons and
00048      * array initializers!
00049      */
00050     STAT_UNUSED,                /* not in use */
00051     STAT_NEW,                   /* just initialized */
00052     STAT_VIS,                   /* visitor */
00053     STAT_SANCT,                 /* still in sanctuary */
00054     STAT_ACTIVE,                /* active (sanctuary broken) */
00055     STAT_GOD                    /* deity powers */
00056 } nat_status;
00057 
00058 
00059 /*
00060  * TODO
00061  *
00062  * One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
00063  *
00064  * The only user of r_cnum and r_realm appears to be xdump.
00065  * If we had working virtual selectors, we could remove r_cnum and r_realm.
00066  */
00067 struct realmstr {
00068     /* initial part must match struct empobj */
00069     short ef_type;
00070     natid r_cnum;               /* country number */
00071     /* end of part matching struct empobj */
00072     short r_uid;                /* realm table index */
00073     unsigned short r_realm;     /* realm number */
00074     short r_xl, r_xh;           /* horizontal bounds */
00075     short r_yl, r_yh;           /* vertical bounds */
00076     time_t r_timestamp; /* Last time this realm was touched */
00077 };
00078 
00079 struct natstr {
00080     /* initial part must match struct empobj */
00081     short ef_type;
00082     natid nat_cnum;             /* our country number */
00083     /* end of part matching struct empobj */
00084     nat_status nat_stat;
00085     char nat_cnam[20];          /* country name */
00086     char nat_pnam[20];          /* representative */
00087     char nat_hostaddr[32];      /* host addr of last user */
00088     char nat_hostname[512];     /* hostname of last user, may be empty */
00089     char nat_userid[32];        /* userid of last user, may be empty */
00090     coord nat_xcap, nat_ycap;   /* cap location in abs coords */
00091     coord nat_xorg, nat_yorg;   /* origin location in abs coords */
00092     signed char nat_dayno;      /* day of the year mod 128 */
00093     signed char nat_update;     /* Want an update or not. */
00094     unsigned short nat_tgms;    /* # of telegrams to be announced */
00095     unsigned short nat_ann;     /* # of annos pending */
00096     unsigned short nat_minused; /* number of minutes used today */
00097     short nat_btu;              /* bureaucratic time units */
00098     short nat_access;           /* The tick when BTUs were last updated */
00099     long nat_reserve;           /* military reserves */
00100     long nat_money;             /* moola */
00101     time_t nat_last_login;      /* time of last login, 0 menas never */
00102     time_t nat_last_logout;     /* time of last logout, 0 means never */
00103     time_t nat_newstim;         /* date news last read */
00104     time_t nat_annotim;         /* date annos last read */
00105     float nat_level[4];         /* technology, etc */
00106     unsigned char nat_relate[MAXNOC];
00107     unsigned char nat_contact[MAXNOC];
00108     unsigned char nat_rejects[MAXNOC];
00109     long nat_flags;             /* nation flags */
00110 };
00111 
00112         /* nation relation codes */
00113 #define AT_WAR          0
00114 #define SITZKRIEG       1
00115 #define MOBILIZATION    2
00116 #define HOSTILE         3
00117 #define NEUTRAL         4
00118 #define FRIENDLY        5
00119 #define ALLIED          6
00120 
00121         /* nation reject codes */
00122 #define REJ_TELE        bit(0)  /* dont allow telegrams to be sent */
00123 #define REJ_TREA        bit(1)  /* dont allow treaties to be offered */
00124 #define REJ_ANNO        bit(2)  /* don't receive announcements */
00125 #define REJ_LOAN        bit(3)  /* don't allow loans to be offered */
00126 
00127 #define NAT_TLEV        0
00128 #define NAT_RLEV        1
00129 #define NAT_ELEV        2
00130 #define NAT_HLEV        3
00131 
00132 /*
00133  * Number of updates contact lasts for various ways of making contact.
00134  * These are only useful with option LOSE_CONTACT option, which
00135  * implies option HIDDEN.
00136  */
00137 /* Planes spotting and being spotted */
00138 #define FOUND_FLY       3
00139 /* Lookout */
00140 #define FOUND_LOOK      5
00141 /* Spies and ground combat */
00142 #define FOUND_SPY       6
00143 /* Communication */
00144 #define FOUND_TELE      3
00145 /* Coastwatch and skywatch */
00146 #define FOUND_COAST     3
00147 
00148 extern char *relates[];
00149 
00150 /* procedures relating to nation stuff */
00151 
00152 #define putnat(p) ef_write(EF_NATION, (p)->nat_cnum, (p))
00153 #define getnatp(n) ((struct natstr *)ef_ptr(EF_NATION, (n)))
00154 
00155 #define getrealm(r, n, p) ef_read(EF_REALM, ((r) + ((n) * MAXNOR)), (p))
00156 #define putrealm(p) ef_write(EF_REALM, (p)->r_uid, (p))
00157 
00158 extern double tfact(natid cn, double mult);
00159 extern double techfact(int level, double mult);
00160 
00161 extern char *cname(natid n);
00162 extern char *relatename(struct natstr *np, natid other);
00163 extern char *rejectname(struct natstr *np, natid other);
00164 extern char *natstate(struct natstr *np);
00165 extern int getrel(struct natstr *np, natid them);
00166 extern int getrejects(natid them, struct natstr *np);
00167 extern int getcontact(struct natstr *np, natid them);
00168 extern void putrel(struct natstr *np, natid them, int relate);
00169 extern void putreject(struct natstr *np, natid them, int how, int what);
00170 extern void putcontact(struct natstr *np, natid them, int contact);
00171 extern void agecontact(struct natstr *np);
00172 extern int influx(struct natstr *np);
00173 
00174 extern int grant_btus(struct natstr *, int );
00175 
00176 /* nation flags */
00177 #define NF_INFORM       bit(0)  /* Inform me of telegrams right away */
00178 #define NF_FLASH        bit(1)  /* Allow other players to flash me (sicko :) */
00179 #define NF_BEEP         bit(2)  /* Make beeping sounds when appropriate */
00180 #define NF_COASTWATCH   bit(3)  /* Turn auto-coastwatch on */
00181 #define NF_SONAR        bit(4)  /* Turn auto-sonar on */
00182 #define NF_TECHLISTS    bit(5)  /* Sort lists by tech not type */
00183 #define NF_SACKED       bit(6)  /* Capital was sacked, and hasn't been reset yet */
00184 
00185 #endif

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