X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=include%2Fnat.h;h=58a8b1b6e1c25cf8b7c25e8a51563edb5012ca12;hp=5749a1bd0bdbafd7042651fd718ed138bb0387b6;hb=HEAD;hpb=ee20a9cd342f94735617f82019518a5322afba04 diff --git a/include/nat.h b/include/nat.h index 5749a1bd0..58a8b1b6e 100644 --- a/include/nat.h +++ b/include/nat.h @@ -1,11 +1,11 @@ /* * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak, - * Ken Stevens, Steve McClure + * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak, + * Ken Stevens, Steve McClure, Markus Armbruster * - * This program is free software; you can redistribute it and/or modify + * Empire is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * along with this program. If not, see . * * --- * @@ -32,18 +31,18 @@ * Ken Stevens, 1995 * Steve McClure, 1998-2000 * Ron Koenderink, 2005-2008 - * Markus Armbruster, 2005-2008 + * Markus Armbruster, 2005-2016 */ #ifndef NAT_H #define NAT_H -#include +#include "file.h" #include "types.h" #define NATID_BAD 255 -#define MAXNOR 50 /* max # realms */ +#define MAXNOR 50 /* max # realms */ /* Nation status */ enum nat_status { @@ -70,9 +69,10 @@ enum nat_status { */ struct realmstr { /* initial part must match struct empobj */ - short ef_type; - short r_uid; /* realm table index */ - unsigned r_seqno; + signed ef_type: 8; + unsigned r_seqno: 12; + unsigned r_generation: 12; + int r_uid; /* realm table index */ time_t r_timestamp; /* Last time this realm was touched */ natid r_cnum; /* country number */ /* end of part matching struct empobj */ @@ -83,17 +83,18 @@ struct realmstr { struct natstr { /* initial part must match struct empobj */ - short ef_type; - short nat_uid; /* equals nat_cnum */ - unsigned nat_seqno; + signed ef_type: 8; + unsigned nat_seqno: 12; + unsigned nat_generation: 12; + int nat_uid; /* equals nat_cnum */ time_t nat_timestamp; natid nat_cnum; /* our country number */ /* end of part matching struct empobj */ enum nat_status nat_stat; + int nat_flags; /* nation flags */ char nat_cnam[20]; /* country name */ char nat_pnam[20]; /* representative */ - char nat_hostaddr[32]; /* host addr of last user */ - char nat_hostname[512]; /* hostname of last user, may be empty */ + char nat_hostaddr[46]; /* host addr of last user */ char nat_userid[32]; /* userid of last user, may be empty */ coord nat_xcap, nat_ycap; /* cap location in abs coords */ coord nat_xorg, nat_yorg; /* origin location in abs coords */ @@ -103,43 +104,48 @@ struct natstr { int nat_timeused; /* number of seconds used today */ short nat_btu; /* bureaucratic time units */ short nat_access; /* The tick when BTUs were last updated */ - long nat_reserve; /* military reserves */ - long nat_money; /* moola */ + int nat_reserve; /* military reserves */ + int nat_money; /* moola */ time_t nat_last_login; /* time of last login, 0 menas never */ time_t nat_last_logout; /* time of last logout, 0 means never */ time_t nat_newstim; /* date news last read */ time_t nat_annotim; /* date annos last read */ float nat_level[4]; /* technology, etc */ - unsigned char nat_relate[MAXNOC]; - unsigned char nat_contact[MAXNOC]; - unsigned char nat_rejects[MAXNOC]; - long nat_flags; /* nation flags */ }; - /* nation relation codes */ -#define AT_WAR 0 -#define SITZKRIEG 1 -#define MOBILIZATION 2 -#define HOSTILE 3 -#define NEUTRAL 4 -#define FRIENDLY 5 -#define ALLIED 6 - - /* nation reject codes */ -#define REJ_TELE bit(0) /* dont allow telegrams to be sent */ -#define REJ_TREA bit(1) /* dont allow treaties to be offered */ -#define REJ_ANNO bit(2) /* don't receive announcements */ -#define REJ_LOAN bit(3) /* don't allow loans to be offered */ - -#define NAT_TLEV 0 -#define NAT_RLEV 1 -#define NAT_ELEV 2 -#define NAT_HLEV 3 +#define NAT_TLEV 0 +#define NAT_RLEV 1 +#define NAT_ELEV 2 +#define NAT_HLEV 3 + +/* Diplomatic relations */ +enum relations { + /* + * Don't change order without checking inequality comparisons and + * array initializers! + */ + AT_WAR, + HOSTILE, + NEUTRAL, + FRIENDLY, + ALLIED +}; + +struct relatstr { + /* initial part must match struct empobj */ + signed ef_type: 8; + unsigned rel_seqno: 12; + unsigned rel_generation: 12; + int rel_uid; + time_t rel_timestamp; + /* end of part matching struct empobj */ + unsigned char rel_relate[MAXNOC]; /* enum relations */ +}; /* * Number of updates contact lasts for various ways of making contact. - * These are only useful with option LOSE_CONTACT option, which - * implies option HIDDEN. + * These are only useful with option LOSE_CONTACT, which implies + * option HIDDEN. */ /* Planes spotting and being spotted */ #define FOUND_FLY 3 @@ -152,36 +158,82 @@ struct natstr { /* Coastwatch and skywatch */ #define FOUND_COAST 3 -extern char *relates[]; +struct contactstr { + /* initial part must match struct empobj */ + signed ef_type: 8; + unsigned con_seqno: 12; + unsigned con_generation: 12; + int con_uid; + time_t con_timestamp; + /* end of part matching struct empobj */ + unsigned char con_contact[MAXNOC]; +}; + +/* Kinds of communication players can reject */ +enum rej_comm { + REJ_TELE, /* dont allow telegrams to be sent */ + REJ_ANNO, /* don't receive announcements */ + REJ_LOAN /* don't allow loans to be offered */ +}; + +struct rejectstr { + /* initial part must match struct empobj */ + signed ef_type: 8; + unsigned rej_seqno: 12; + unsigned rej_generation: 12; + int rej_uid; + time_t rej_timestamp; + /* end of part matching struct empobj */ + unsigned char rej_rejects[MAXNOC]; +}; /* procedures relating to nation stuff */ #define putnat(p) ef_write(EF_NATION, (p)->nat_cnum, (p)) #define getnatp(n) ((struct natstr *)ef_ptr(EF_NATION, (n))) +#define getrelat(n, p) ef_read(EF_RELAT, (n), (p)) +#define putrelat(p) ef_write(EF_RELAT, (p)->rel_uid, (p)) +#define getrelatp(n) ((struct relatstr *)ef_ptr(EF_RELAT, (n))) + +#define getcontact(n, p) ef_read(EF_CONTACT, (n), (p)) +#define putcontact(p) ef_write(EF_CONTACT, (p)->con_uid, (p)) +#define getcontactp(n) ((struct contactstr *)ef_ptr(EF_CONTACT, (n))) + +#define getreject(n, p) ef_read(EF_REJECT, (n), (p)) +#define putreject(p) ef_write(EF_REJECT, (p)->rej_uid, (p)) +#define getrejectp(n) ((struct rejectstr *)ef_ptr(EF_REJECT, (n))) + #define getrealm(r, n, p) ef_read(EF_REALM, ((r) + ((n) * MAXNOR)), (p)) #define putrealm(p) ef_write(EF_REALM, (p)->r_uid, (p)) +/* src/lib/common/tfact.c */ extern double tfact(natid cn, double mult); extern double techfact(int level, double mult); +/* src/lib/common/nat.c */ extern char *cname(natid n); -extern char *relatename(struct natstr *np, natid other); -extern char *rejectname(struct natstr *np, natid other); extern char *natstate(struct natstr *np); -extern int getrel(struct natstr *np, natid them); -extern int getrejects(natid them, struct natstr *np); -extern int getcontact(struct natstr *np, natid them); -extern void putrel(struct natstr *np, natid them, int relate); -extern void putreject(struct natstr *np, natid them, int how, int what); -extern void putcontact(struct natstr *np, natid them, int contact); +extern enum relations relations_with(natid, natid); +extern char *relations_string(enum relations); +extern int nat_accepts(natid, natid, enum rej_comm); +extern int in_contact(natid, natid); extern void agecontact(struct natstr *np); extern int influx(struct natstr *np); +extern void nat_reset(natid, char *, char *, enum nat_status); + +/* src/lib/subs/natsub.c */ +extern int check_nat_name(char *, natid); +extern char *prnat(struct natstr *); +extern char *prnatid(natid); -extern struct natstr *nat_reset(struct natstr *, enum nat_status, coord, coord); -extern int check_nat_name(char *cname); +/* src/lib/common/btu.c */ +extern int grant_btus(struct natstr *, int); -extern int grant_btus(struct natstr *, int ); +/* src/lib/subs/rej.c */ +extern void setrel(natid, natid, enum relations); +extern void setcont(natid, natid, int); +extern void setrej(natid, natid, int, enum rej_comm); /* nation flags */ #define NF_INFORM bit(0) /* Inform me of telegrams right away */ @@ -189,7 +241,7 @@ extern int grant_btus(struct natstr *, int ); #define NF_BEEP bit(2) /* Make beeping sounds when appropriate */ #define NF_COASTWATCH bit(3) /* Turn auto-coastwatch on */ #define NF_SONAR bit(4) /* Turn auto-sonar on */ -#define NF_TECHLISTS bit(5) /* Sort lists by tech not type */ -#define NF_SACKED bit(6) /* Capital was sacked, and hasn't been reset yet */ +#define NF_TECHLISTS bit(5) /* Sort lists by tech not type */ +#define NF_SACKED bit(6) /* Capital was sacked, and hasn't been reset yet */ #endif