]> git.pond.sub.org Git - empserver/blob - src/lib/subs/trechk.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / subs / trechk.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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 /*
36  * Check to see if an actor has a treaty forbidding a given action,
37  * and if so, see if the actor wishes to break the treaty.
38  * All applicable treaties are checked.  All treaties must be broken
39  * if the action is to be allowed.  Propsed treaties are warned about,
40  * but no mention of broken pending treaties are made in the news.
41  */
42
43 #include <config.h>
44
45 #include "misc.h"
46 #include "treaty.h"
47 #include "nat.h"
48 #include "news.h"
49 #include "file.h"
50 #include "xy.h"
51 #include "nsc.h"
52 #include "prototypes.h"
53 #include "optlist.h"
54
55 int
56 trechk(register natid actor, register natid victim, int provision)
57 {
58     register natid cn;
59     s_char buf[1024];
60     int news_verb;
61     int involved[MAXNOC];
62     struct trtstr treaty;
63     time_t now;
64     int conditions;
65     natid other;
66     int broken;
67     int applied;
68     struct nstr_item nstr;
69
70     if (!opt_TREATIES)
71         return 1;
72     (void)time(&now);
73     broken = 0;
74     applied = 0;
75     for (cn = 0; cn < MAXNOC; cn++)
76         involved[cn] = 0;
77     snxtitem_all(&nstr, EF_TREATY);
78     while (nxtitem(&nstr, &treaty)) {
79         if (treaty.trt_status == TS_FREE)
80             continue;
81         if (treaty.trt_exp < now)
82             continue;
83         if (actor == treaty.trt_cna) {
84             conditions = treaty.trt_acond;
85             other = treaty.trt_cnb;
86         } else if (actor == treaty.trt_cnb) {
87             conditions = treaty.trt_bcond;
88             other = treaty.trt_cna;
89         } else
90             continue;
91         if ((conditions & provision) == 0)
92             continue;
93         if (victim != other) {
94             switch (provision) {
95                 /* These are violations no matter who the victim is */
96             case NEWSHP:
97             case NEWLND:
98             case NEWNUK:
99             case NEWPLN:
100             case TRTENL:
101                 break;
102             default:
103                 /* The rest are only violations against the victim */
104                 continue;
105             }
106         }
107         /* treaty applies to actor */
108         applied++;
109         pr("This action is in contravention of ");
110         if (treaty.trt_status == TS_PROPOSED)
111             pr("pending ");
112         pr(" treaty #%d (with %s)\n", nstr.cur, cname(other));
113         getstring("Do you wish to go ahead anyway? [yn] ", buf);
114         if (*buf == 'n' || *buf == 'N')
115             broken = 0;
116         else
117             broken = 1;
118         if (treaty.trt_status == TS_SIGNED)
119             involved[other]++;
120     }
121     if (applied > 0) {
122         news_verb = N_HONOR_TRE;
123         if (broken > 0)
124             news_verb = N_VIOL_TRE;
125         for (cn = 0; cn < MAXNOC; cn++)
126             if (involved[cn] > 0)
127                 nreport(actor, news_verb, cn, 1);
128     }
129     if (applied && !broken) {
130         /*
131          * if any treaty applied, and none were broken
132          * the intended action is NOT performed.
133          */
134         return 0;
135     }
136     return 1;
137 }