]> git.pond.sub.org Git - empserver/blob - src/lib/subs/trechk.c
Import of Empire 4.2.12
[empserver] / src / lib / subs / trechk.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  trechk.c: Check to see if an actor has violated a treaty.
29  * 
30  *  Known contributors to this file: 
31  *      Steve McClure, 1998-1999
32  *     
33  */
34 /*
35  * Check to see if an actor has a treaty forbidding a given action,
36  * and if so, see if the actor wishes to break the treaty.
37  * All applicable treaties are checked.  All treaties must be broken
38  * if the action is to be allowed.  Propsed treaties are warned about,
39  * but no mention of broken pending treaties are made in the news.
40  */
41
42 #include "misc.h"
43 #include "treaty.h"
44 #include "nat.h"
45 #include "news.h"
46 #include "file.h"
47 #include "xy.h"
48 #include "nsc.h"
49 #include "prototypes.h"
50 #include "optlist.h"
51
52 int
53 trechk(register natid actor, register natid victim, int provision)
54 {
55         register natid cn;
56         s_char  buf[1024];
57         int     news_verb;
58         int     involved[MAXNOC];
59         struct  trtstr treaty;
60         time_t  now;
61         int     conditions;
62         natid   other;
63         int     broken;
64         int     applied;
65         struct  nstr_item nstr;
66
67         if (!opt_TREATIES)
68             return 1;
69         (void) time(&now);
70         broken = 0;
71         applied = 0;
72         for (cn = 0; cn < MAXNOC; cn++)
73                 involved[cn] = 0;
74         snxtitem_all(&nstr, EF_TREATY);
75         while (nxtitem(&nstr, (s_char *)&treaty)) {
76                 if (treaty.trt_status == TS_FREE)
77                         continue;
78                 if (treaty.trt_exp < now)
79                         continue;
80                 if (actor == treaty.trt_cna) {
81                         conditions = treaty.trt_acond;
82                         other = treaty.trt_cnb;
83                 } else if (actor == treaty.trt_cnb) {
84                         conditions = treaty.trt_bcond;
85                         other = treaty.trt_cna;
86                 } else
87                         continue;
88                 if ((conditions & provision) == 0)
89                         continue;
90                 if (victim != other) {
91                         switch (provision) {
92                         /* These are violations no matter who the victim is */
93                         case NEWSHP:
94                         case NEWLND:
95                         case NEWNUK:
96                         case NEWPLN:
97                         case TRTENL:
98                                 break;
99                         default:
100                                 /* The rest are only violations against the victim */
101                                 continue;
102                         }
103                 }
104                 /* treaty applies to actor */
105                 applied++;
106                 pr("This action is in contravention of ");
107                 if (treaty.trt_status == TS_PROPOSED)
108                         pr("pending ");
109                 pr(" treaty #%d (with %s)\n", nstr.cur, cname(other));
110                 getstring("Do you wish to go ahead anyway? [yn] ", buf);
111                 if (*buf == 'n' || *buf == 'N')
112                         broken = 0;
113                 else
114                         broken = 1;
115                 if (treaty.trt_status == TS_SIGNED)
116                         involved[other]++;
117         }
118         if (applied > 0) {
119                 news_verb = N_HONOR_TRE;
120                 if (broken > 0)
121                         news_verb = N_VIOL_TRE;
122                 for (cn=0; cn < MAXNOC; cn++)
123                         if (involved[cn] > 0)
124                                 nreport(actor, news_verb, cn, 1);
125         }
126         if (applied && !broken) {
127                 /*
128                  * if any treaty applied, and none were broken
129                  * the intended action is NOT performed.
130                  */
131                 return 0;
132         }
133         return 1;
134 }